Fix for wc_CryptoCb_AesCbcEncrypt
with improper find device logic. Fix for HMAC scan-build with ret
. Cleanup of HMAC formatting.
This commit is contained in:
parent
d5f3fa2ff8
commit
58fe2781f1
@ -382,7 +382,6 @@ int wc_CryptoCb_AesCbcEncrypt(Aes* aes, byte* out,
|
||||
dev = wc_CryptoCb_FindDeviceByIndex(0);
|
||||
}
|
||||
|
||||
dev = wc_CryptoCb_FindDevice(aes->devId);
|
||||
if (dev && dev->cb) {
|
||||
wc_CryptoInfo cryptoInfo;
|
||||
XMEMSET(&cryptoInfo, 0, sizeof(cryptoInfo));
|
||||
|
@ -252,26 +252,26 @@ int _InitHmac(Hmac* hmac, int type, void* heap)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
ret = wc_InitSha3_224(&hmac->hash.sha3, heap, INVALID_DEVID);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
ret = wc_InitSha3_256(&hmac->hash.sha3, heap, INVALID_DEVID);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
ret = wc_InitSha3_384(&hmac->hash.sha3, heap, INVALID_DEVID);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
ret = wc_InitSha3_512(&hmac->hash.sha3, heap, INVALID_DEVID);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
default:
|
||||
@ -377,7 +377,6 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case WC_SHA224:
|
||||
{
|
||||
hmac_block_size = WC_SHA224_BLOCK_SIZE;
|
||||
if (length <= WC_SHA224_BLOCK_SIZE) {
|
||||
if (key != NULL) {
|
||||
@ -394,13 +393,11 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
|
||||
length = WC_SHA224_DIGEST_SIZE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case WC_SHA256:
|
||||
hmac_block_size = WC_SHA256_BLOCK_SIZE;
|
||||
hmac_block_size = WC_SHA256_BLOCK_SIZE;
|
||||
if (length <= WC_SHA256_BLOCK_SIZE) {
|
||||
if (key != NULL) {
|
||||
XMEMCPY(ip, key, length);
|
||||
@ -482,7 +479,7 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
hmac_block_size = WC_SHA3_224_BLOCK_SIZE;
|
||||
if (length <= WC_SHA3_224_BLOCK_SIZE) {
|
||||
@ -501,8 +498,8 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
length = WC_SHA3_224_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
hmac_block_size = WC_SHA3_256_BLOCK_SIZE;
|
||||
if (length <= WC_SHA3_256_BLOCK_SIZE) {
|
||||
@ -521,8 +518,8 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
length = WC_SHA3_256_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
hmac_block_size = WC_SHA3_384_BLOCK_SIZE;
|
||||
if (length <= WC_SHA3_384_BLOCK_SIZE) {
|
||||
@ -541,8 +538,8 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
length = WC_SHA3_384_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
hmac_block_size = WC_SHA3_512_BLOCK_SIZE;
|
||||
if (length <= WC_SHA3_512_BLOCK_SIZE) {
|
||||
@ -561,7 +558,7 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
||||
length = WC_SHA3_512_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
default:
|
||||
@ -609,7 +606,7 @@ static int HmacKeyInnerHash(Hmac* hmac)
|
||||
#ifndef NO_MD5
|
||||
case WC_MD5:
|
||||
ret = wc_Md5Update(&hmac->hash.md5, (byte*)hmac->ipad,
|
||||
WC_MD5_BLOCK_SIZE);
|
||||
WC_MD5_BLOCK_SIZE);
|
||||
break;
|
||||
#endif /* !NO_MD5 */
|
||||
|
||||
@ -623,27 +620,26 @@ static int HmacKeyInnerHash(Hmac* hmac)
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case WC_SHA224:
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->ipad,
|
||||
WC_SHA224_BLOCK_SIZE);
|
||||
WC_SHA224_BLOCK_SIZE);
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case WC_SHA256:
|
||||
ret = wc_Sha256Update(&hmac->hash.sha256, (byte*)hmac->ipad,
|
||||
WC_SHA256_BLOCK_SIZE);
|
||||
WC_SHA256_BLOCK_SIZE);
|
||||
break;
|
||||
#endif /* !NO_SHA256 */
|
||||
|
||||
#ifdef WOLFSSL_SHA384
|
||||
case WC_SHA384:
|
||||
ret = wc_Sha384Update(&hmac->hash.sha384, (byte*)hmac->ipad,
|
||||
WC_SHA384_BLOCK_SIZE);
|
||||
WC_SHA384_BLOCK_SIZE);
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA384 */
|
||||
#ifdef WOLFSSL_SHA512
|
||||
case WC_SHA512:
|
||||
ret = wc_Sha512Update(&hmac->hash.sha512, (byte*)hmac->ipad,
|
||||
WC_SHA512_BLOCK_SIZE);
|
||||
WC_SHA512_BLOCK_SIZE);
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
@ -655,30 +651,30 @@ static int HmacKeyInnerHash(Hmac* hmac)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
ret = wc_Sha3_224_Update(&hmac->hash.sha3, (byte*)hmac->ipad,
|
||||
WC_SHA3_224_BLOCK_SIZE);
|
||||
WC_SHA3_224_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
ret = wc_Sha3_256_Update(&hmac->hash.sha3, (byte*)hmac->ipad,
|
||||
WC_SHA3_256_BLOCK_SIZE);
|
||||
WC_SHA3_256_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
ret = wc_Sha3_384_Update(&hmac->hash.sha3, (byte*)hmac->ipad,
|
||||
WC_SHA3_384_BLOCK_SIZE);
|
||||
WC_SHA3_384_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
ret = wc_Sha3_512_Update(&hmac->hash.sha3, (byte*)hmac->ipad,
|
||||
WC_SHA3_512_BLOCK_SIZE);
|
||||
WC_SHA3_512_BLOCK_SIZE);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
default:
|
||||
@ -771,26 +767,26 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
ret = wc_Sha3_224_Update(&hmac->hash.sha3, msg, length);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
ret = wc_Sha3_256_Update(&hmac->hash.sha3, msg, length);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
ret = wc_Sha3_384_Update(&hmac->hash.sha3, msg, length);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
ret = wc_Sha3_512_Update(&hmac->hash.sha3, msg, length);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
default:
|
||||
@ -815,7 +811,6 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
if (ret != CRYPTOCB_UNAVAILABLE)
|
||||
return ret;
|
||||
/* fall-through when unavailable */
|
||||
ret = 0; /* reset error code */
|
||||
}
|
||||
#endif
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_HMAC)
|
||||
@ -848,11 +843,11 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Md5Update(&hmac->hash.md5, (byte*)hmac->opad,
|
||||
WC_MD5_BLOCK_SIZE);
|
||||
WC_MD5_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Md5Update(&hmac->hash.md5, (byte*)hmac->innerHash,
|
||||
WC_MD5_DIGEST_SIZE);
|
||||
WC_MD5_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Md5Final(&hmac->hash.md5, hash);
|
||||
@ -878,36 +873,33 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case WC_SHA224:
|
||||
{
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->opad,
|
||||
WC_SHA224_BLOCK_SIZE);
|
||||
WC_SHA224_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, (byte*)hmac->innerHash,
|
||||
WC_SHA224_DIGEST_SIZE);
|
||||
WC_SHA224_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, hash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case WC_SHA256:
|
||||
ret = wc_Sha256Final(&hmac->hash.sha256, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha256Update(&hmac->hash.sha256, (byte*)hmac->opad,
|
||||
WC_SHA256_BLOCK_SIZE);
|
||||
WC_SHA256_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha256Update(&hmac->hash.sha256, (byte*)hmac->innerHash,
|
||||
WC_SHA256_DIGEST_SIZE);
|
||||
WC_SHA256_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha256Final(&hmac->hash.sha256, hash);
|
||||
@ -920,11 +912,11 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha384Update(&hmac->hash.sha384, (byte*)hmac->opad,
|
||||
WC_SHA384_BLOCK_SIZE);
|
||||
WC_SHA384_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha384Update(&hmac->hash.sha384, (byte*)hmac->innerHash,
|
||||
WC_SHA384_DIGEST_SIZE);
|
||||
WC_SHA384_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha384Final(&hmac->hash.sha384, hash);
|
||||
@ -936,11 +928,11 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha512Update(&hmac->hash.sha512, (byte*)hmac->opad,
|
||||
WC_SHA512_BLOCK_SIZE);
|
||||
WC_SHA512_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha512Update(&hmac->hash.sha512, (byte*)hmac->innerHash,
|
||||
WC_SHA512_DIGEST_SIZE);
|
||||
WC_SHA512_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha512Final(&hmac->hash.sha512, hash);
|
||||
@ -966,70 +958,70 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
ret = wc_Sha3_224_Final(&hmac->hash.sha3, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_224_Update(&hmac->hash.sha3, (byte*)hmac->opad,
|
||||
WC_SHA3_224_BLOCK_SIZE);
|
||||
WC_SHA3_224_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_224_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
|
||||
WC_SHA3_224_DIGEST_SIZE);
|
||||
WC_SHA3_224_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_224_Final(&hmac->hash.sha3, hash);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
ret = wc_Sha3_256_Final(&hmac->hash.sha3, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_256_Update(&hmac->hash.sha3, (byte*)hmac->opad,
|
||||
WC_SHA3_256_BLOCK_SIZE);
|
||||
WC_SHA3_256_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_256_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
|
||||
WC_SHA3_256_DIGEST_SIZE);
|
||||
WC_SHA3_256_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_256_Final(&hmac->hash.sha3, hash);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
ret = wc_Sha3_384_Final(&hmac->hash.sha3, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_384_Update(&hmac->hash.sha3, (byte*)hmac->opad,
|
||||
WC_SHA3_384_BLOCK_SIZE);
|
||||
WC_SHA3_384_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_384_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
|
||||
WC_SHA3_384_DIGEST_SIZE);
|
||||
WC_SHA3_384_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_384_Final(&hmac->hash.sha3, hash);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
ret = wc_Sha3_512_Final(&hmac->hash.sha3, (byte*)hmac->innerHash);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_512_Update(&hmac->hash.sha3, (byte*)hmac->opad,
|
||||
WC_SHA3_512_BLOCK_SIZE);
|
||||
WC_SHA3_512_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_512_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
|
||||
WC_SHA3_512_DIGEST_SIZE);
|
||||
WC_SHA3_512_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
break;
|
||||
ret = wc_Sha3_512_Final(&hmac->hash.sha3, hash);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
default:
|
||||
@ -1127,7 +1119,6 @@ void wc_HmacFree(Hmac* hmac)
|
||||
wc_Sha224Free(&hmac->hash.sha224);
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case WC_SHA256:
|
||||
wc_Sha256Free(&hmac->hash.sha256);
|
||||
@ -1151,26 +1142,26 @@ void wc_HmacFree(Hmac* hmac)
|
||||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
#ifndef WOLFSSL_NOSHA3_224
|
||||
case WC_SHA3_224:
|
||||
wc_Sha3_224_Free(&hmac->hash.sha3);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_256
|
||||
case WC_SHA3_256:
|
||||
wc_Sha3_256_Free(&hmac->hash.sha3);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_384
|
||||
case WC_SHA3_384:
|
||||
wc_Sha3_384_Free(&hmac->hash.sha3);
|
||||
break;
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
#endif
|
||||
#ifndef WOLFSSL_NOSHA3_512
|
||||
case WC_SHA3_512:
|
||||
wc_Sha3_512_Free(&hmac->hash.sha3);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA3 */
|
||||
|
||||
default:
|
||||
@ -1199,7 +1190,6 @@ void wc_HmacFree(Hmac* hmac)
|
||||
wc_Sha224Free(&hmac->hash.sha224);
|
||||
break;
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case WC_SHA256:
|
||||
wc_Sha256Free(&hmac->hash.sha256);
|
||||
|
Loading…
x
Reference in New Issue
Block a user