use hash grow function with cmac

This commit is contained in:
Jacob Barthelmeh
2022-04-06 15:08:19 -06:00
parent 2a0b726c15
commit e9aae8b571
5 changed files with 10 additions and 35 deletions

View File

@ -28,6 +28,9 @@
#ifdef WOLFSSL_QNX_CAAM
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
#endif
#if defined(WOLFSSL_HASH_KEEP)
#include <wolfssl/wolfcrypt/hash.h>
#endif
#if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
@ -62,37 +65,9 @@
* data to be hashed at once.
* returns 0 on success
*/
static int _wc_CMAC_Grow(byte** msg, word32* used, word32* len, const byte* in,
int inSz, void* heap)
{
if (*len < *used + inSz) {
if (*msg == NULL) {
*msg = (byte*)XMALLOC(*used + inSz, heap, DYNAMIC_TYPE_TMP_BUFFER);
}
else {
byte* pt = (byte*)XMALLOC(*used + inSz, heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (pt == NULL) {
return MEMORY_E;
}
XMEMCPY(pt, *msg, *used);
XFREE(*msg, heap, DYNAMIC_TYPE_TMP_BUFFER);
*msg = pt;
}
if (*msg == NULL) {
return MEMORY_E;
}
*len = *used + inSz;
}
XMEMCPY(*msg + *used, in, inSz);
*used += inSz;
return 0;
}
int wc_CMAC_Grow(Cmac* cmac, const byte* in, int inSz)
{
return _wc_CMAC_Grow(&cmac->msg, &cmac->used, &cmac->len, in, inSz, NULL);
return _wc_Hash_Grow(&cmac->msg, &cmac->used, &cmac->len, in, inSz, NULL);
}
#endif /* WOLFSSL_HASH_KEEP */

View File

@ -1707,7 +1707,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
#endif /* !NO_HASH_WRAPPER */
#ifdef WOLFSSL_HASH_KEEP
int _wc_Sha_Grow(byte** msg, word32* used, word32* len, const byte* in,
int _wc_Hash_Grow(byte** msg, word32* used, word32* len, const byte* in,
int inSz, void* heap)
{
if (*len < *used + inSz) {

View File

@ -1713,13 +1713,13 @@ void wc_Sha256Free(wc_Sha256* sha256)
*/
int wc_Sha256_Grow(wc_Sha256* sha256, const byte* in, int inSz)
{
return _wc_Sha_Grow(&(sha256->msg), &(sha256->used), &(sha256->len), in,
return _wc_Hash_Grow(&(sha256->msg), &(sha256->used), &(sha256->len), in,
inSz, sha256->heap);
}
#ifdef WOLFSSL_SHA224
int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz)
{
return _wc_Sha_Grow(&(sha224->msg), &(sha224->used), &(sha224->len), in,
return _wc_Hash_Grow(&(sha224->msg), &(sha224->used), &(sha224->len), in,
inSz, sha224->heap);
}
#endif /* WOLFSSL_SHA224 */

View File

@ -1829,13 +1829,13 @@ int wc_Sha384GetFlags(wc_Sha384* sha384, word32* flags)
*/
int wc_Sha512_Grow(wc_Sha512* sha512, const byte* in, int inSz)
{
return _wc_Sha_Grow(&(sha512->msg), &(sha512->used), &(sha512->len), in,
return _wc_Hash_Grow(&(sha512->msg), &(sha512->used), &(sha512->len), in,
inSz, sha512->heap);
}
#ifdef WOLFSSL_SHA384
int wc_Sha384_Grow(wc_Sha384* sha384, const byte* in, int inSz)
{
return _wc_Sha_Grow(&(sha384->msg), &(sha384->used), &(sha384->len), in,
return _wc_Hash_Grow(&(sha384->msg), &(sha384->used), &(sha384->len), in,
inSz, sha384->heap);
}
#endif /* WOLFSSL_SHA384 */

View File

@ -223,7 +223,7 @@ WOLFSSL_API int wc_Shake256Hash(const byte* data, word32 len, byte* hash, word32
#endif /* !NO_HASH_WRAPPER */
#if defined(WOLFSSL_HASH_KEEP)
WOLFSSL_LOCAL int _wc_Sha_Grow(byte** msg, word32* used, word32* len,
WOLFSSL_LOCAL int _wc_Hash_Grow(byte** msg, word32* used, word32* len,
const byte* in, int inSz, void* heap);
#endif