From 772651c17abb25679dc8cdd9b1c7cbfa965052e5 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 16 Feb 2018 13:30:02 -0700 Subject: [PATCH] update tests and benchmark for HAVE_AES_DECRYPT --- wolfcrypt/benchmark/benchmark.c | 5 +++++ wolfcrypt/test/test.c | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 3a84cc84a..a4655c09f 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1694,6 +1694,7 @@ exit_aes_dec: #endif /* HAVE_AES_DECRYPT */ + (void)decLabel; exit: for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -1781,6 +1782,7 @@ static void bench_aesgcm_internal(int doAsync, const byte* key, word32 keySz, exit_aes_gcm: bench_stats_sym_finish(encLabel, doAsync, count, bench_size, start, ret); +#ifdef HAVE_AES_DECRYPT /* GCM uses same routine in backend for both encrypt and decrypt */ bench_stats_start(&count, &start); do { @@ -1804,6 +1806,9 @@ exit_aes_gcm: } while (bench_stats_sym_check(start)); exit_aes_gcm_dec: bench_stats_sym_finish(decLabel, doAsync, count, bench_size, start, ret); +#endif /* HAVE_AES_DECRYPT */ + + (void)decLabel; exit: diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 4e1ff46c5..f9d58ed21 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -5312,22 +5312,26 @@ static int aes_cbc_test(void) ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL); if (ret != BAD_FUNC_ARG) return -4100; +#ifdef HAVE_AES_DECRYPT ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL); if (ret != BAD_FUNC_ARG) return -4101; +#endif ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, AES_BLOCK_SIZE, iv); if (ret != 0) return -4102; +#ifdef HAVE_AES_DECRYPT ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, AES_BLOCK_SIZE, iv); if (ret != 0) return -4103; - if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0) return -4104; +#endif /* HAVE_AES_DECRYPT */ + (void)plain; return 0; } #endif @@ -5781,9 +5785,9 @@ int aes_test(void) wc_AesFree(&enc); #ifdef HAVE_AES_DECRYPT wc_AesFree(&dec); + (void)plain; #endif - (void)plain; (void)cipher; return ret; @@ -6162,6 +6166,7 @@ int aesgcm_test(void) if (XMEMCMP(t1, resultT, sizeof(resultT))) return -4304; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(resultC), iv1, sizeof(iv1), resultT, sizeof(resultT), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6171,6 +6176,7 @@ int aesgcm_test(void) return -4305; if (XMEMCMP(p, resultP, sizeof(resultP))) return -4306; +#endif /* HAVE_AES_DECRYPT */ /* Large buffer test */ #ifdef BENCH_AESGCM_LARGE @@ -6188,6 +6194,7 @@ int aesgcm_test(void) if (result != 0) return -4307; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, large_outdec, large_output, BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT, sizeof(resultT), a, sizeof(a)); @@ -6198,6 +6205,7 @@ int aesgcm_test(void) return -4308; if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) return -4309; +#endif /* HAVE_AES_DECRYPT */ #endif /* BENCH_AESGCM_LARGE */ #ifdef ENABLE_NON_12BYTE_IV_TEST /* Variable IV length test */ @@ -6210,6 +6218,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4310; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(resultC), k1, (word32)ivlen, resultT, sizeof(resultT), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6217,6 +6226,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4311; +#endif /* HAVE_AES_DECRYPT */ } #endif @@ -6230,6 +6240,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4312; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(resultC), iv1, sizeof(iv1), resultT, sizeof(resultT), p, (word32)alen); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6237,6 +6248,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4313; +#endif /* HAVE_AES_DECRYPT */ } #ifdef BENCH_AESGCM_LARGE @@ -6252,6 +6264,7 @@ int aesgcm_test(void) if (result != 0) return -4314; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, large_outdec, large_output, plen, iv1, sizeof(iv1), resultT, sizeof(resultT), a, sizeof(a)); @@ -6260,6 +6273,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4315; +#endif /* HAVE_AES_DECRYPT */ } #else /* Variable plain text length test */ @@ -6272,6 +6286,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4314; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, (word32)plen, iv1, sizeof(iv1), resultT, sizeof(resultT), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6279,6 +6294,7 @@ int aesgcm_test(void) #endif if (result != 0) return -4315; +#endif /* HAVE_AES_DECRYPT */ } #endif /* BENCH_AESGCM_LARGE */ #endif /* WOLFSSL_AES_256 */ @@ -6304,6 +6320,7 @@ int aesgcm_test(void) if (XMEMCMP(t2, resultT, sizeof(resultT))) return -4318; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(resultC), iv2, sizeof(iv2), resultT, sizeof(resultT), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6313,6 +6330,7 @@ int aesgcm_test(void) return -4319; if (XMEMCMP(p, resultP, sizeof(resultP))) return -4320; +#endif /* HAVE_AES_DECRYPT */ XMEMSET(resultT, 0, sizeof(resultT)); XMEMSET(resultC, 0, sizeof(resultC)); @@ -6333,6 +6351,7 @@ int aesgcm_test(void) if (XMEMCMP(t3, resultT, sizeof(t3))) return -8211; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(c3), iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6342,6 +6361,7 @@ int aesgcm_test(void) return -8212; if (XMEMCMP(p3, resultP, sizeof(p3))) return -8213; +#endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_128 */ #endif /* ENABLE_NON_12BYTE_IV_TEST */ @@ -6364,6 +6384,7 @@ int aesgcm_test(void) if (XMEMCMP(t1, resultT + 1, sizeof(resultT) - 1)) return -4323; +#ifdef HAVE_AES_DECRYPT result = wc_AesGcmDecrypt(&enc, resultP, resultC, sizeof(resultC), iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1, a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) @@ -6373,6 +6394,7 @@ int aesgcm_test(void) return -4324; if (XMEMCMP(p, resultP, sizeof(resultP))) return -4325; +#endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_256 */ wc_AesFree(&enc);