forked from wolfSSL/wolfssl
Merge pull request #932 from jrblixt/unitTest_api_addHmac-mergeWolfMaster
Add HMAC test functions to unit test.
This commit is contained in:
1067
tests/api.c
1067
tests/api.c
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wolfssl/wolfcrypt/settings.h>
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
|
|
||||||
#ifndef NO_HMAC
|
#ifndef NO_HMAC
|
||||||
|
|
||||||
@@ -43,14 +44,28 @@
|
|||||||
/* does init */
|
/* does init */
|
||||||
int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 keySz)
|
int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 keySz)
|
||||||
{
|
{
|
||||||
|
if (hmac == NULL || (key == NULL && keySz != 0) ||
|
||||||
|
!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|
||||||
|
|| type == SHA512 || type == BLAKE2B_ID)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return HmacSetKey_fips(hmac, type, key, keySz);
|
return HmacSetKey_fips(hmac, type, key, keySz);
|
||||||
}
|
}
|
||||||
int wc_HmacUpdate(Hmac* hmac, const byte* in, word32 sz)
|
int wc_HmacUpdate(Hmac* hmac, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
|
if (hmac == NULL || in == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return HmacUpdate_fips(hmac, in, sz);
|
return HmacUpdate_fips(hmac, in, sz);
|
||||||
}
|
}
|
||||||
int wc_HmacFinal(Hmac* hmac, byte* out)
|
int wc_HmacFinal(Hmac* hmac, byte* out)
|
||||||
{
|
{
|
||||||
|
if (hmac == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return HmacFinal_fips(hmac, out);
|
return HmacFinal_fips(hmac, out);
|
||||||
}
|
}
|
||||||
int wolfSSL_GetHmacMaxSize(void)
|
int wolfSSL_GetHmacMaxSize(void)
|
||||||
@@ -88,9 +103,6 @@
|
|||||||
#else /* else build without fips */
|
#else /* else build without fips */
|
||||||
|
|
||||||
|
|
||||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
#define wc_InitMd5 wc_InitMd5_sw
|
#define wc_InitMd5 wc_InitMd5_sw
|
||||||
#define wc_Md5Update wc_Md5Update_sw
|
#define wc_Md5Update wc_Md5Update_sw
|
||||||
@@ -510,6 +522,10 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (hmac == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||||
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
||||||
#if defined(HAVE_CAVIUM)
|
#if defined(HAVE_CAVIUM)
|
||||||
@@ -581,6 +597,10 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (hmac == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||||
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
if (hmac->asyncDev.marker == WOLFSSL_ASYNC_MARKER_HMAC) {
|
||||||
int hashLen = wc_HmacSizeByType(hmac->macType);
|
int hashLen = wc_HmacSizeByType(hmac->macType);
|
||||||
|
Reference in New Issue
Block a user