我正在尝试在英特尔 SGX 飞地内使用 SHA512 计算 HMAC。我让代码工作,但收到错误的结果。我有一个使用静态预定义密钥和随机数计算 HMAC 的示例,但是在验证接收到的结果时,它与正确的结果不匹配。
显然有两种不同的变体来计算 HMAC(根据这里的输入链接描述,我都试过了。
这是飞地的功能:
int calculateHMAC(uint8_t *key, uint8_t *nonce, uint8_t *res_hmac) {
IppsHMACState *ctx;
IppStatus status;
int psize = 0;
//VARIANT 1
status = ippsHMAC_GetSize(&psize);
if (status == ippStsNullPtrErr)
return 1;
ctx = (IppsHMACState*) malloc(psize);
status = ippsHMAC_Init(key, 16, ctx, ippHashAlg_SHA512);
if (status != ippStsNoErr)
return 1;
status = ippsHMAC_Update(nonce, 16, ctx);
if (status != ippStsNoErr)
return 1;
uint8_t hmac[64];
memset(hmac, '\0', 64);
status = ippsHMAC_Final(hmac, 64, ctx);
if (status != ippStsNoErr)
return 1;
memcpy(res_hmac, hmac, 64);
//VARIANT 2
// uint8_t test_hmac[HMAC_LENGTH];
// status = ippsHMAC_Message(nonce, 16, key, 16, test_hmac, 64, ippHashAlg_SHA512);
// if (status != ippStsNoErr)
// return 1;
// memcpy(res_hmac, test_hmac, 64);
return 0;
}
这是更新的电话:
uint8_t ba_nonce[16] = {
0x7d, 0x93, 0x09, 0x9f, 0x7f, 0xed, 0x16, 0x21,
0x58, 0x36, 0xf7, 0xba, 0xd4, 0xdb, 0x0e, 0x48
};
uint8_t ba_key[16] = {
0xa5, 0xb1, 0x15, 0x53, 0x6d, 0x5b, 0xf3, 0x50,
0xc5, 0xb0, 0xfa, 0x6f, 0x69, 0x24, 0x2f, 0x18
};
uint8_t t_hmac[64];
memset(t_hmac, '\0', 64);
int error = calculateHMAC(ba_key, ba_nonce, t_hmac);
我看不出我做错了什么!?
这将导致 7d2f2e3d57c84a58945b9016fb37e2df03afdde313c9d79c31ec1e6612d6d6b20456a8fcf799ef74d16f60c7f283e621400004422885f33fb3d2bb7ae7a1daa3
根据这个计算器这里是错误的