level 3
一只阿北Dy
楼主
/* Get MK (To Generate the keys) */
ulRet = KMC_GetActiveMkWithHash(ulDomain,bMkBuf,&ulMkLen,&ulKeyId,bMkHash);
return_oper_if((ulRet != WSEC_SUCCESS), WSEC_LOG_E("[SDP] Get MK failed."), ulRet);
/* derive work key */
ulRet = CAC_Pbkdf2(WSEC_ALGID_PBKDF2_HMAC_SHA256, bMkBuf, ulMkLen,
pstCipherHead->aucSalt, SDP_SALT_LEN_SHORT, ulTempIterCount, ulKeyLen, pucKey);
if(ulRet != WSEC_SUCCESS)
{
WSEC_LOG_E("[SDP] CAC pbkdf2 derive WK failed.");
/* destroy the Mk buffer*/
WSEC_DESTROY_KEY(bMkBuf, ulMkLen);
return WSEC_ERR_PBKDF2_FAIL;
}
/* derive the HmacKey*/
ulRet = CAC_Random(pstHmacHead->aucSalt, SDP_SALT_LEN_SHORT);
return_oper_if((ulRet != WSEC_SUCCESS), WSEC_LOG_E("[SDP] CAC calculate random failed."), WSEC_ERR_GET_RAND_FAIL);
ulRet = CAC_Pbkdf2(WSEC_ALGID_PBKDF2_HMAC_SHA256, bMkBuf, ulMkLen,
pstHmacHead->aucSalt, SDP_SALT_LEN_SHORT, ulTempIterCount, ulHmacKeyLen, pucHmacKey);
/* destroy the Mk buffer*/
WSEC_DESTROY_KEY(bMkBuf, ulMkLen);
return_oper_if((WSEC_SUCCESS != ulRet), WSEC_LOG_E("[SDP] CAC pbkdf2 derive WK failed."), WSEC_ERR_PBKDF2_FAIL);
/* optionally generate IV */
ulRet = CAC_Random(pstCipherHead->aucIV, ulIVLen);
return_oper_if((ulRet!= WSEC_SUCCESS), WSEC_LOG_E("[SDP] CAC calculate random failed."), WSEC_ERR_GET_RAND_FAIL);
/* fill header except pstCipherHead->ulCDLen */
pstCipherHead->ulVersion = SDP_CIPHER_TEXT_VER2;
pstCipherHead->bHmacFlag = WSEC_TRUE;
pstCipherHead->ulDomainId = ulDomain;
pstCipherHead->ulEncAlgId = ulEncAlgId;
pstCipherHead->ulKeyId = ulKeyId;
return_oper_if(WSEC_MEMCPY(pstCipherHead->aucKeyHash, WSEC_MK_HASH_REC_LEN, bMkHash, WSEC_MK_HASH_REC_LEN) != EOK,
WSEC_LOG_E4MEMCPY, WSEC_ERR_MEMCPY_FAIL);