diff --git a/tests/api/test_hmac.c b/tests/api/test_hmac.c index b2c83f2794..5c628f0086 100644 --- a/tests/api/test_hmac.c +++ b/tests/api/test_hmac.c @@ -305,6 +305,9 @@ int test_wc_Md5HmacUpdate(void) b.inLen = XSTRLEN(b.input); ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0); + /* update before setkey results in err. */ + ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys, (word32)XSTRLEN(keys)), 0); ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0); @@ -346,6 +349,9 @@ int test_wc_ShaHmacUpdate(void) b.inLen = XSTRLEN(b.input); ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0); + /* update before setkey results in err. */ + ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys, (word32)XSTRLEN(keys)), 0); ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0); @@ -387,6 +393,9 @@ int test_wc_Sha224HmacUpdate(void) b.inLen = XSTRLEN(b.input); ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0); + /* update before setkey results in err. */ + ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys, (word32)XSTRLEN(keys)), 0); ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0); @@ -428,6 +437,9 @@ int test_wc_Sha256HmacUpdate(void) b.inLen = XSTRLEN(b.input); ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0); + /* update before setkey results in err. */ + ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys, (word32)XSTRLEN(keys)), 0); ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0); @@ -469,6 +481,9 @@ int test_wc_Sha384HmacUpdate(void) b.inLen = XSTRLEN(b.input); ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0); + /* update before setkey results in err. */ + ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys, (word32)XSTRLEN(keys)), 0); ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0); diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index b18c0e0e49..963c4ab2b5 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -1135,6 +1135,7 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length) #endif default: + ret = BAD_FUNC_ARG; break; }