/*************************************************************************
* Copyright (C) 2016 Intel Corporation
*
* Licensed under the Apache License,  Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 	http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law  or agreed  to  in  writing,  software
* distributed under  the License  is  distributed  on  an  "AS IS"  BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the  specific  language  governing  permissions  and
* limitations under the License.
*************************************************************************/

/* 
// 
//  Purpose:
//     Cryptography Primitive.
//     HMAC General Functionality
// 
//  Contents:
//        ippsHMACUnpack_rmf()
//
*/

#include "owndefs.h"
#include "owncp.h"
#include "pcphmac.h"
#include "pcphmac_rmf.h"
#include "pcptool.h"

/*F*
//    Name: ippsHMACUnpack_rmf
//
// Purpose: Unpack buffer content into the initialized context.
//
// Returns:                Reason:
//    ippStsNullPtrErr        pBuffer == NULL
//                            pCtx == NULL
//    ippStsContextMatchErr   pCtx->idCtx != idCtxHash
//    ippStsNoErr             no errors
//
// Parameters:
//    pBuffer     pointer to the source buffer
//    pSize       pointer to the packed spec size
//
*F*/
IPPFUN(IppStatus, ippsHMACUnpack_rmf, (const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx))
{
    /* test pointers */
    IPP_BAD_PTR2_RET(pCtx, pBuffer);
    IPP_BADARG_RET(!HASH_VALID_ID(HASH_CTX(pCtx), idCtxHash), ippStsContextMatchErr);

    const IppsHashMethod* pMethod = HASH_METHOD(HASH_CTX(pCtx));
    CopyBlock(pBuffer, pCtx, sizeof(IppsHMACState_rmf));
    HASH_METHOD(HASH_CTX(pCtx)) = pMethod;

    /* Set IppsHMACState_rmf context id */
    HMAC_SET_CTX_ID(pCtx);
    /* Set context id for IppsHashState_rmf, which is the part of IppsHMACState_rmf */
    HASH_SET_ID(HASH_CTX(pCtx), idCtxHash);
    /* setup pointers to buffer and hash in IppsHashState_rmf structure */
    HASH_SETUP_POINTERS(HASH_CTX(pCtx));

    return ippStsNoErr;
}
