diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index a949ea8fe..6c52b7aed 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -1124,7 +1124,7 @@ static void wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock) printf("sz = %d\n", AES_BLOCK_SIZE); #endif - /* check alignment, encrypt doesn't need alignment */ + /* check alignment, decrypt doesn't need alignment */ if ((wolfssl_word)inBlock % 16) { #ifndef NO_WOLFSSL_ALLOC_ALIGN byte* tmp = (byte*)XMALLOC(AES_BLOCK_SIZE, NULL, @@ -1746,24 +1746,26 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, int dir) { + #if defined(AES_MAX_KEY_SIZE) + const word32 max_key_len = (AES_MAX_KEY_SIZE / 8); + #endif if (!((keylen == 16) || (keylen == 24) || (keylen == 32))) return BAD_FUNC_ARG; + #if defined(AES_MAX_KEY_SIZE) /* Check key length */ - #if defined(AES_MAX_KEY_SIZE) - const word32 max_key_len = (AES_MAX_KEY_SIZE / 8); - if (keylen > max_key_len) { - return BAD_FUNC_ARG; - } - #endif + if (keylen > max_key_len) { + return BAD_FUNC_ARG; + } + #endif - #ifdef HAVE_CAVIUM + #ifdef HAVE_CAVIUM if (aes->magic == WOLFSSL_AES_CAVIUM_MAGIC) return wc_AesCaviumSetKey(aes, userKey, keylen, iv); - #endif + #endif - #ifdef WOLFSSL_AESNI + #ifdef WOLFSSL_AESNI if (checkAESNI == 0) { haveAESNI = Check_CPU_support_AES(); checkAESNI = 1; @@ -1779,7 +1781,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) return AES_set_decrypt_key(userKey, keylen * 8, aes); #endif } - #endif /* WOLFSSL_AESNI */ + #endif /* WOLFSSL_AESNI */ return wc_AesSetKeyLocal(aes, userKey, keylen, iv, dir); } @@ -2359,41 +2361,6 @@ int wc_AesSetIV(Aes* aes, const byte* iv) return 0 ; } #endif /* HAVE_AES_DECRYPT */ -#elif defined(WOLFSSL_NRF51_AES) - int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) - { - int i, ret; - int offset = 0; - int len = sz; - - byte *iv; - byte temp_block[AES_BLOCK_SIZE]; - - iv = (byte*)aes->reg; - - while (len > 0) - { - XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE); - - /* XOR block with IV for CBC */ - for (i = 0; i < AES_BLOCK_SIZE; i++) { - temp_block[i] ^= iv[i]; - } - - ret = wc_AesEncrypt(aes, temp_block, out + offset); - if (ret != 0) { - return ret; - } - - len -= AES_BLOCK_SIZE; - offset += AES_BLOCK_SIZE; - - /* store IV for next block */ - XMEMCPY(iv, out + offset - AES_BLOCK_SIZE, AES_BLOCK_SIZE); - } - - return 0; - } #else int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) diff --git a/wolfcrypt/src/port/nrf51.c b/wolfcrypt/src/port/nrf51.c index 9bc656b90..eaae360b2 100644 --- a/wolfcrypt/src/port/nrf51.c +++ b/wolfcrypt/src/port/nrf51.c @@ -68,7 +68,7 @@ int nrf51_random_generate(byte* output, word32 size) /* Make sure RNG is running */ err_code = nrf_drv_rng_init(NULL); - if (NRF_SUCCESS != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { + if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { return -1; } @@ -113,13 +113,17 @@ int nrf51_aes_set_key(const byte* key) int nrf51_aes_encrypt(const byte* in, const byte* key, word32 rounds, byte* out) { + int ret; uint32_t err_code = 0; #ifdef SOFTDEVICE_PRESENT nrf_ecb_hal_data_t ecb_hal_data; #endif /* Set key */ - nrf51_aes_set_key(key); + ret = nrf51_aes_set_key(key); + if (ret != 0) { + return ret; + } #ifdef SOFTDEVICE_PRESENT /* Define ECB record */ diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 1840ebd32..904dab67e 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1379,7 +1379,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) /* Make sure RNG is running */ err_code = nrf_drv_rng_init(NULL); - if (NRF_SUCCESS != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { + if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { return -1; } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index c667252fe..396109309 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -6369,7 +6369,7 @@ int ecc_test(void) return -1010; wc_ecc_free(&pubKey); wc_ecc_init(&pubKey); -#if HAVE_ECC_KEY_IMPORT +#ifdef HAVE_ECC_KEY_IMPORT ret = wc_ecc_import_x963(exportBuf, x, &pubKey); if (ret != 0) return -1011; @@ -6443,6 +6443,9 @@ int ecc_test(void) ecc192.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41"; ecc192.curveName = "ECC-192"; ret = ecc_test_raw_vector(&ecc192, &userA, sig, sizeof(sig)); + if (ret != 0) { + return ret; + } } #endif /* HAVE_ECC192 */ #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES) @@ -6472,6 +6475,9 @@ int ecc_test(void) ecc224.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b"; ecc224.curveName = "ECC-224"; ret = ecc_test_raw_vector(&ecc224, &userA, sig, sizeof(sig)); + if (ret != 0) { + return ret; + } } #endif /* HAVE_ECC192 */ #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES) @@ -6501,6 +6507,9 @@ int ecc_test(void) ecc256.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248"; ecc256.curveName = "nistp256"; ret = ecc_test_raw_vector(&ecc256, &userA, sig, sizeof(sig)); + if (ret != 0) { + return ret; + } } #endif /* !NO_ECC256 */ #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES) @@ -6530,6 +6539,9 @@ int ecc_test(void) ecc384.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907"; ecc384.curveName = "nistp384"; ret = ecc_test_raw_vector(&ecc384, &userA, sig, sizeof(sig)); + if (ret != 0) { + return ret; + } } #endif /* HAVE_ECC384 */ #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES) @@ -6559,11 +6571,11 @@ int ecc_test(void) ecc521.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c"; ecc521.curveName = "nistp521"; ret = ecc_test_raw_vector(&ecc521, &userA, sig, sizeof(sig)); + if (ret != 0) { + return ret; + } } #endif /* HAVE_ECC521 */ - if (ret != 0) { - return ret; - } #endif /* HAVE_ECC_VECTOR_TEST */ #ifdef WOLFSSL_KEY_GEN diff --git a/wolfssl/mem_track.h b/wolfssl/mem_track.h index 6d5ade303..32af33695 100644 --- a/wolfssl/mem_track.h +++ b/wolfssl/mem_track.h @@ -123,7 +123,7 @@ int ret = 0; ret = wolfSSL_SetAllocators(TrackMalloc, TrackFree, TrackRealloc); if (ret != 0) { - WOLFSSL_MSG("wolfSSL SetAllocators failed for track memory"); + printf("wolfSSL SetAllocators failed for track memory\n"); return ret; }