forked from wolfSSL/wolfssl
HMAC_CTX_copy, copy save_len, save_key
This commit is contained in:
committed by
Jacob Barthelmeh
parent
e93d7d3c93
commit
30e6ec5396
@@ -24729,6 +24729,8 @@ int wolfSSL_HMAC_CTX_copy(WOLFSSL_HMAC_CTX* des, WOLFSSL_HMAC_CTX* src)
|
|||||||
des->hmac.heap = src->hmac.heap;
|
des->hmac.heap = src->hmac.heap;
|
||||||
des->hmac.macType = src->hmac.macType;
|
des->hmac.macType = src->hmac.macType;
|
||||||
des->hmac.innerHashKeyed = src->hmac.innerHashKeyed;
|
des->hmac.innerHashKeyed = src->hmac.innerHashKeyed;
|
||||||
|
des->save_len = src->save_len;
|
||||||
|
XMEMCPY(des->save_key, src->save_key, src->save_len);
|
||||||
|
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
XMEMCPY(des->hmac.asyncDev, src->hmac.asyncDev, sizeof(WC_ASYNC_DEV));
|
XMEMCPY(des->hmac.asyncDev, src->hmac.asyncDev, sizeof(WC_ASYNC_DEV));
|
||||||
|
42
tests/api.c
42
tests/api.c
@@ -16058,6 +16058,48 @@ static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest)
|
|||||||
AssertIntEQ(digestSz, digestSz2);
|
AssertIntEQ(digestSz, digestSz2);
|
||||||
AssertIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
|
AssertIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
|
||||||
|
|
||||||
|
/* test HMAC_Init with NULL key */
|
||||||
|
printf("test HMAC_Init with NULL key (1)\n");
|
||||||
|
HMAC_CTX_init(&ctx1);
|
||||||
|
AssertIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Final(&ctx2, digest, &digestSz), SSL_SUCCESS);
|
||||||
|
|
||||||
|
HMAC_CTX_cleanup(&ctx2);
|
||||||
|
AssertIntEQ(digestSz, digestSz2);
|
||||||
|
AssertIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
|
||||||
|
|
||||||
|
printf("test HMAC_Init with NULL key (2)\n");
|
||||||
|
HMAC_CTX_init(&ctx1);
|
||||||
|
AssertIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
|
||||||
|
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
|
||||||
|
AssertIntEQ(HMAC_Final(&ctx2, digest, &digestSz), SSL_SUCCESS);
|
||||||
|
|
||||||
|
HMAC_CTX_cleanup(&ctx2);
|
||||||
|
AssertIntEQ(digestSz, digestSz2);
|
||||||
|
AssertIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
|
||||||
|
|
||||||
return digestSz;
|
return digestSz;
|
||||||
}
|
}
|
||||||
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
|
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
|
||||||
|
Reference in New Issue
Block a user