diff --git a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c index 9a832cc..a5ce440 100644 --- a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c +++ b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.c @@ -1,6 +1,6 @@ /* benchmark.c * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2023 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -27,15 +27,48 @@ #include #endif +/* Some common, optional user settings */ +/* these can also be set in wolfssl/options.h or user_settings.h */ +/* ------------------------------------------------------------- */ +/* make the binary always use CSV format: */ +/* #define WOLFSSL_BENCHMARK_FIXED_CSV */ +/* */ +/* choose to use the same units, regardless of scale. pick 1: */ +/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_GB */ +/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_MB */ +/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB */ +/* #define WOLFSSL_BENCHMARK_FIXED_UNITS_B */ +/* */ +/* when the output should be in machine-parseable format: */ +/* #define GENERATE_MACHINE_PARSEABLE_REPORT */ +/* */ + +/* define the max length for each string of metric reported */ +#define __BENCHMARK_MAXIMUM_LINE_LENGTH 150 + +/* some internal helpers to get values of settings */ +/* this first one gets the text name of the #define parameter */ +#define __BENCHMARK_VALUE_TO_STRING(x) #x + +/* this next one gets the text value of the assigned value of #define param */ +#define __BENCHMARK_VALUE(x) __BENCHMARK_VALUE_TO_STRING(x) + +#define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" /* may be re-set by fixed units */ + #ifndef WOLFSSL_USER_SETTINGS #include #endif -#include +#include /* also picks up user_settings.h */ #include #include #include #include +#ifdef WOLFSSL_ESPIDF + #include /* reminder Espressif RISC-V not yet implemented */ + #include +#endif + #ifdef HAVE_PTHREAD #include #endif @@ -44,7 +77,7 @@ !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \ !defined(BENCH_EMBEDDED)) #include - #ifndef WOLFSSL_ZEPHYR + #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32) #include #endif #endif @@ -72,11 +105,11 @@ #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT -static const char info_prefix[] = "###, "; -static const char err_prefix[] = "!!!, "; + static const char info_prefix[] = "###, "; + static const char err_prefix[] = "!!!, "; #else -static const char info_prefix[] = ""; -static const char err_prefix[] = ""; + static const char info_prefix[] = ""; + static const char err_prefix[] = ""; #endif @@ -109,7 +142,7 @@ static const char err_prefix[] = ""; static int printfk(const char *fmt, ...) { int ret; - char line[150]; + char line[__BENCHMARK_MAXIMUM_LINE_LENGTH]; va_list ap; va_start(ap, fmt); @@ -153,9 +186,9 @@ static const char err_prefix[] = ""; #include #define printf(...) \ - __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) + __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) #define fprintf(fp, ...) \ - __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) + __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__) #else #if defined(XMALLOC_USER) || defined(FREESCALE_MQX) @@ -225,6 +258,9 @@ static const char err_prefix[] = ""; #ifdef WOLFSSL_WC_KYBER #include #endif +#if defined(HAVE_LIBOQS) || defined(HAVE_PQM4) + #include +#endif #endif #ifdef WOLFCRYPT_HAVE_ECCSI #include @@ -232,11 +268,6 @@ static const char err_prefix[] = ""; #ifdef WOLFCRYPT_HAVE_SAKKE #include #endif -#ifdef HAVE_LIBOQS - #include - #include - #include -#endif #if defined(HAVE_PQC) #if defined(HAVE_FALCON) @@ -250,16 +281,6 @@ static const char err_prefix[] = ""; #endif #endif -#ifdef HAVE_PQM4 - #include - #define PQM4_PUBLIC_KEY_LENGTH CRYPTO_PUBLICKEYBYTES - #define PQM4_PRIVATE_KEY_LENGTH CRYPTO_SECRETKEYBYTES - #define PQM4_SHARED_SECRET_LENGTH CRYPTO_BYTES - #define PQM4_CIPHERTEXT_LENGTH CRYPTO_CIPHERTEXTBYTES - typedef char OQS_KEM; - #include -#endif - #include #include #include @@ -441,18 +462,9 @@ static const char err_prefix[] = ""; /* Post-Quantum Asymmetric algorithms. */ #define BENCH_FALCON_LEVEL1_SIGN 0x00000001 #define BENCH_FALCON_LEVEL5_SIGN 0x00000002 -#define BENCH_KYBER_LEVEL1_KEYGEN 0x00000004 -#define BENCH_KYBER_LEVEL1_ENCAP 0x00000008 -#define BENCH_KYBER_LEVEL3_KEYGEN 0x00000010 -#define BENCH_KYBER_LEVEL3_ENCAP 0x00000020 -#define BENCH_KYBER_LEVEL5_KEYGEN 0x00000040 -#define BENCH_KYBER_LEVEL5_ENCAP 0x00000080 #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000 #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000 #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000 -#define BENCH_DILITHIUM_AES_LEVEL2_SIGN 0x20000000 -#define BENCH_DILITHIUM_AES_LEVEL3_SIGN 0x40000000 -#define BENCH_DILITHIUM_AES_LEVEL5_SIGN 0x80000000 /* Post-Quantum Asymmetric algorithms. (Part 2) */ #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001 @@ -735,7 +747,7 @@ static const bench_alg bench_other_opt[] = { #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */ -#if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) +#if defined(HAVE_PQC) && defined(HAVE_LIBOQS) /* The post-quantum-specific mapping of command line option to bit values and * OQS name. */ typedef struct bench_pq_alg { @@ -750,10 +762,6 @@ typedef struct bench_pq_alg { * options. */ static const bench_pq_alg bench_pq_asym_opt[] = { { "-pq", 0xffffffff, NULL}, -#ifdef HAVE_PQM4 - { "-kyber_level1-kg", BENCH_KYBER_LEVEL1_KEYGEN, NULL }, - { "-kyber_level1-ed", BENCH_KYBER_LEVEL1_ENCAP, NULL }, -#endif #ifdef HAVE_LIBOQS { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN, OQS_SIG_alg_falcon_512 }, @@ -765,24 +773,6 @@ static const bench_pq_alg bench_pq_asym_opt[] = { OQS_SIG_alg_dilithium_3 }, { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN, OQS_SIG_alg_dilithium_5 }, - { "-dilithium_aes_level2", BENCH_DILITHIUM_AES_LEVEL2_SIGN, - OQS_SIG_alg_dilithium_2_aes }, - { "-dilithium_aes_level3", BENCH_DILITHIUM_AES_LEVEL3_SIGN, - OQS_SIG_alg_dilithium_3_aes }, - { "-dilithium_aes_level5", BENCH_DILITHIUM_AES_LEVEL5_SIGN, - OQS_SIG_alg_dilithium_5_aes }, - { "-kyber_level1-kg", BENCH_KYBER_LEVEL1_KEYGEN, - OQS_KEM_alg_kyber_512 }, - { "-kyber_level1-ed", BENCH_KYBER_LEVEL1_ENCAP, - OQS_KEM_alg_kyber_512 }, - { "-kyber_level3-kg", BENCH_KYBER_LEVEL3_KEYGEN, - OQS_KEM_alg_kyber_768 }, - { "-kyber_level3-ed", BENCH_KYBER_LEVEL3_ENCAP, - OQS_KEM_alg_kyber_768 }, - { "-kyber_level5-kg", BENCH_KYBER_LEVEL5_KEYGEN, - OQS_KEM_alg_kyber_1024 }, - { "-kyber_level5-ed", BENCH_KYBER_LEVEL5_ENCAP, - OQS_KEM_alg_kyber_1024 }, #endif /* HAVE_LIBOQS */ { NULL, 0, NULL } }; @@ -968,8 +958,92 @@ static const char* bench_desc_words[][15] = { #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.6f,\n", \ (float)total_cycles / (count*s)) +#elif defined(WOLFSSL_ESPIDF) + static THREAD_LS_T word64 begin_cycles; + static THREAD_LS_T word64 total_cycles; + + /* the return value */ + static THREAD_LS_T word64 _xthal_get_ccount_ex = 0; + + /* the last value seen, adjusted for an overflow */ + static THREAD_LS_T word64 _xthal_get_ccount_last = 0; + + /* TAG for ESP_LOGx() */ + static const char* TAG = "wolfssl_benchmark"; + + #define HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER + static WC_INLINE word64 get_xtensa_cycles(void); + + /* WARNING the hal UINT xthal_get_ccount() quietly rolls over. */ + #define BEGIN_ESP_CYCLES begin_cycles = (get_xtensa_cycles()); + + /* since it rolls over, we have something that will tolerate one */ + #define END_ESP_CYCLES \ + ESP_LOGV(TAG,"%llu - %llu", \ + get_xtensa_cycles(), \ + begin_cycles \ + ); \ + total_cycles = (get_xtensa_cycles() - begin_cycles); + + #define SHOW_ESP_CYCLES(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = %6.2f\n", \ + bench_result_words1[lng_index][2], \ + (float)total_cycles / (count*s) \ + ) + + #define SHOW_ESP_CYCLES_CSV(b, n, s) \ + (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.6f,\n", \ + (float)total_cycles / (count*s)) + + /* xthal_get_ccount_ex() is a single-overflow-tolerant extension to + ** the Espressif `unsigned xthal_get_ccount()` which is known to overflow + ** at least once during full benchmark tests. + */ + word64 xthal_get_ccount_ex() + { + /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */ + + /* the currently observed clock counter value */ + word64 thisVal = xthal_get_ccount(); + + /* if the current value is less than the previous value, + ** we likely overflowed at least once. + */ + if (thisVal < _xthal_get_ccount_last) + { + /* Warning: we assume the return type of xthal_get_ccount() + ** will always be unsigned int to add UINT_MAX. + ** + ** NOTE for long duration between calls with multiple overflows: + ** + ** WILL NOT BE DETECTED - the return value will be INCORRECT. + ** + ** At this time no single test overflows. This is currently only a + ** concern for cumulative counts over multiple tests. As long + ** as well call xthal_get_ccount_ex() with no more than one + ** overflow CPU tick count, all will be well. + */ + ESP_LOGV(TAG, "Alert: Detected xthal_get_ccount overflow, " + "adding %ull", UINT_MAX); + thisVal += (word64)UINT_MAX; + } + + /* adjust our actual returned value that takes into account overflow */ + _xthal_get_ccount_ex += (thisVal - _xthal_get_ccount_last); + + /* all of this took some time, so reset the "last seen" value */ + _xthal_get_ccount_last = xthal_get_ccount(); + + return _xthal_get_ccount_ex; + } + +/* implement other architecture cycle counters here */ #else + /* if we don't know the platform, it is unlikely we can count CPU cycles */ + #undef HAVE_GET_CYCLES + #define INIT_CYCLE_COUNTER #define BEGIN_INTEL_CYCLES #define END_INTEL_CYCLES @@ -1049,9 +1123,9 @@ static const char* bench_desc_words[][15] = { defined(HAVE_CURVE448) || defined(HAVE_ED448) || \ defined(WOLFSSL_HAVE_KYBER) static const char* bench_result_words2[][5] = { - { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */ + { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */ #ifndef NO_MULTIBYTE_PRINT - { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */ + { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */ #endif }; #endif @@ -1219,7 +1293,7 @@ static const char* bench_result_words2[][5] = { /* maximum runtime for each benchmark */ #ifndef BENCH_MIN_RUNTIME_SEC - #define BENCH_MIN_RUNTIME_SEC 1.0f + #define BENCH_MIN_RUNTIME_SEC 1.0F #endif #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) @@ -1249,10 +1323,12 @@ static const char* bench_result_words2[][5] = { if (options & AAD_SIZE_DEFAULT) { aesAuthAddSz = AES_AUTH_ADD_SZ; options &= ~AAD_SIZE_DEFAULT; - } else if (options & AAD_SIZE_ZERO) { + } + else if (options & AAD_SIZE_ZERO) { aesAuthAddSz = 0; options &= ~AAD_SIZE_ZERO; - } else if (options & AAD_SIZE_CUSTOM) { + } + else if (options & AAD_SIZE_CUSTOM) { aesAuthAddSz = aes_aad_size; options &= ~AAD_SIZE_CUSTOM; } @@ -1261,6 +1337,7 @@ static const char* bench_result_words2[][5] = { } } #endif + #ifndef BENCH_CIPHER_ADD #define BENCH_CIPHER_ADD 0 #endif @@ -1288,30 +1365,33 @@ static const char* bench_result_words2[][5] = { #define NUM_BLOCKS 5 #define BENCH_SIZE (1024*1024uL) #endif + static int numBlocks = NUM_BLOCKS; static word32 bench_size = BENCH_SIZE; static int base2 = 1; static int digest_stream = 1; + #ifndef NO_RSA -/* Don't measure RSA sign/verify by default */ -static int rsa_sign_verify = 0; + /* Don't measure RSA sign/verify by default */ + static int rsa_sign_verify = 0; #endif + #ifndef NO_DH -/* Use the FFDHE parameters */ -static int use_ffdhe = 0; + /* Use the FFDHE parameters */ + static int use_ffdhe = 0; #endif /* Don't print out in CSV format by default */ static int csv_format = 0; #ifdef WOLFSSL_XILINX_CRYPT_VERSAL -/* Versal PLM maybe prints an error message to the same console. - * In order to not mix those outputs up, sleep a little while - * before erroring out. - */ -#define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0) + /* Versal PLM maybe prints an error message to the same console. + * In order to not mix those outputs up, sleep a little while + * before erroring out. + */ + #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0) #else -#define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0) + #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0) #endif /* globals for cipher tests */ @@ -1382,9 +1462,9 @@ static void benchmark_static_init(int force) -/******************************************************************************/ -/* Begin Stats Functions */ -/******************************************************************************/ +/*****************************************************************************/ +/* Begin Stats Functions */ +/*****************************************************************************/ typedef enum bench_stat_type { BENCH_STAT_ASYM, BENCH_STAT_SYM, @@ -1569,7 +1649,15 @@ static WC_INLINE void bench_stats_start(int* count, double* start) { *count = 0; *start = current_time(1); + +#ifdef WOLFSSL_ESPIDF + ESP_LOGV(TAG, "finish total_cycles = %llu, start=%f", + total_cycles, *start ); + + BEGIN_ESP_CYCLES +#else BEGIN_INTEL_CYCLES +#endif } static WC_INLINE int bench_stats_check(double start) @@ -1577,21 +1665,116 @@ static WC_INLINE int bench_stats_check(double start) return ((current_time(0) - start) < BENCH_MIN_RUNTIME_SEC); } +/* return text for units and scale the value of blocks as needed for base2 */ +static const char* get_blocktype_base10(double* blocks) +{ + const char* rt; + +#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB)) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "GB/s" + *blocks /= (1000UL * 1000UL * 1000UL); + rt = "GiB"; +#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB)) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "MB/s" + *blocks /= (1024UL * 1024UL); + rt = "MiB"; +#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB)) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "KB/s" + *blocks /= 1024; + rt = "KiB"; +#elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B) + #undef WOLFSSL_FIXED_UNITS_PER_SEC + #define WOLFSSL_FIXED_UNITS_PER_SEC "bytes/s" + (void)(*blocks); /* no adjustment, just appease compiler for not used */ + rt = "bytes"; +#else + /* If no user-specified, auto-scale each metric (results vary). + * Determine if we should show as KB or MB or bytes. No GiB here. */ + if (*blocks > (1024UL * 1024UL)) { + *blocks /= (1024UL * 1024UL); + rt = "MiB"; + } + else if (*blocks > 1024) { + *blocks /= 1024; + rt = "KiB"; + } + else { + rt = "bytes"; + } +#endif + + return rt; +} + +/* return text for units and scale the value of blocks as needed */ +static const char* get_blocktype(double* blocks) +{ + const char* rt; + +#if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB)) + *blocks /= (1000UL * 1000UL * 1000UL); + rt = "GB"; +#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB)) + *blocks /= (1000UL * 1000UL); + rt = "MB"; +#elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \ + defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB)) + *blocks /= (1000UL); + rt = "KB"; +#elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B) + (void)(*blocks); /* no adjustment, just appease compiler */ + rt = "bytes"; +#else + /* If not user-specified, auto-scale each metric (results vary). + * Determine if we should show as KB or MB or bytes */ + if (*blocks > (1000UL * 1000UL)) { + *blocks /= (1000UL * 1000UL); + rt = "MB"; + } + else if (*blocks > 1000) { + *blocks /= 1000; /* make KB */ + rt = "KB"; + } + else { + rt = "bytes"; + } +#endif + + return rt; +} /* countSz is number of bytes that 1 count represents. Normally bench_size, * except for AES direct that operates on AES_BLOCK_SIZE blocks */ -static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, - int countSz, double start, int ret) +static void bench_stats_sym_finish(const char* desc, int useDeviceID, + int count, int countSz, + double start, int ret) { double total, persec = 0, blocks = (double)count; const char* blockType; - char msg[128] = {0}; + char msg[__BENCHMARK_MAXIMUM_LINE_LENGTH] = {0}; const char** word = bench_result_words1[lng_index]; static int sym_header_printed = 0; +#ifdef WOLFSSL_ESPIDF + END_ESP_CYCLES +#else END_INTEL_CYCLES +#endif + total = current_time(0) - start; +#ifdef WOLFSSL_ESPIDF + ESP_LOGV(TAG, "%s total_cycles = %llu", desc, total_cycles); +#endif + #ifdef LINUX_RUSAGE_UTIME check_for_excessive_stime(desc, ""); #endif @@ -1601,44 +1784,40 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, if (csv_format == 1) { /* only print out header once */ if (sym_header_printed == 0) { + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + /* machine parseable CSV */ + #ifdef HAVE_GET_CYCLES printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," - "MB/s,cycles_total,Cycles per byte,\n"); + WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,Cycles per byte,\n"); + #else + printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,seconds_total," + WOLFSSL_FIXED_UNITS_PER_SEC ",cycles_total,\n"); + #endif #else + /* normal CSV */ + #ifdef HAVE_GET_CYCLES printf("\n\nSymmetric Ciphers:\n\n"); - printf("Algorithm,MB/s,Cycles per byte,\n"); + printf("Algorithm," + WOLFSSL_FIXED_UNITS_PER_SEC ",Cycles per byte,\n"); + #else + printf("\n\nSymmetric Ciphers:\n\n"); + printf("Algorithm," + WOLFSSL_FIXED_UNITS_PER_SEC ", \n"); + #endif #endif sym_header_printed = 1; } } + /* determine if we have fixed units, or auto-scale bits or bytes for units. + * note that the blockType text is assigned AND the blocks param is scaled. + */ if (base2) { - /* determine if we should show as KiB or MiB */ - if (blocks > (1024UL * 1024UL)) { - blocks /= (1024UL * 1024UL); - blockType = "MiB"; - } - else if (blocks > 1024) { - blocks /= 1024; - blockType = "KiB"; - } - else { - blockType = "bytes"; - } + blockType = get_blocktype(&blocks); } else { - /* determine if we should show as KB or MB */ - if (blocks > (1000UL * 1000UL)) { - blocks /= (1000UL * 1000UL); - blockType = "MB"; - } - else if (blocks > 1000) { - blocks /= 1000; /* make KB */ - blockType = "KB"; - } - else { - blockType = "bytes"; - } + blockType = get_blocktype_base10(&blocks); } /* calculate blocks per second */ @@ -1649,44 +1828,85 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, SLEEP_ON_ERROR(ret); /* format and print to terminal */ if (csv_format == 1) { + #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - word64 bytes_processed; - if (blockType[0] == 'K') - bytes_processed = (word64)(blocks * (base2 ? 1024. : 1000.)); - else if (blockType[0] == 'M') - bytes_processed = - (word64)(blocks * (base2 ? (1024. * 1024.) : (1000. * 1000.))); - else - bytes_processed = (word64)blocks; -#endif - if (blockType[0] == 'K') - persec /= base2 ? 1024. : 1000.; - else if (blockType[0] == 'b') - persec /= base2 ? (1024. * 1024.) : (1000. * 1000.); -#ifdef GENERATE_MACHINE_PARSEABLE_REPORT - /* note this codepath brings in all the fields from the non-CSV case. */ - (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, - BENCH_DEVID_GET_NAME(useDeviceID), - bytes_processed, total, persec, total_cycles); + #ifdef WOLFSSL_ESPIDF + unsigned long bytes_processed = + (unsigned long)count * (unsigned long)countSz; + #else + word64 bytes_processed = (word64)count * (word64)countSz; + #endif + + /* note this codepath brings in all the fields from the non-CSV case. */ + #ifdef WOLFSSL_ESPIDF + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, + BENCH_DEVID_GET_NAME(useDeviceID), + bytes_processed, total, persec, + (long unsigned int) total_cycles); + #else + #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF" + #endif + + /* implement other architectures here */ + + #else + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,%lu,", desc, + BENCH_DEVID_GET_NAME(useDeviceID), + bytes_processed, total, persec, total_cycles); + #else + (void)XSNPRINTF(msg, sizeof(msg), "sym,%s,%s,%lu,%f,%f,", desc, + BENCH_ASYNC_GET_NAME(useDeviceID), + bytes_processed, total, persec); + #endif + #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s,%f,", desc, persec); #endif + + #ifdef WOLFSSL_ESPIDF + SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz); + ESP_LOGV(TAG, "finish total_cycles = %llu", total_cycles); + /* implement other cycle counters here */ + #else SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), countSz); - } else { + #endif + } /* if (csv_format == 1) */ + + else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES + (void)XSNPRINTF(msg, sizeof(msg), + "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s" + ", %lu cycles,", + desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, + word[0], total, word[1], persec, blockType, + (unsigned long) total_cycles); + #else (void)XSNPRINTF(msg, sizeof(msg), "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s" - ", %lu cycles,", - desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, - word[0], total, word[1], persec, blockType, total_cycles); + ",", + desc, BENCH_ASYNC_GET_NAME(useDeviceID), blocks, blockType, + word[0], total, word[1], persec, blockType); + #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), "%-24s%s %5.0f %s %s %5.3f %s, %8.3f %s/s", desc, BENCH_DEVID_GET_NAME(useDeviceID), blocks, blockType, word[0], total, word[1], persec, blockType); #endif + +#ifdef WOLFSSL_ESPIDF + SHOW_ESP_CYCLES(msg, sizeof(msg), countSz); + +/* implement other architecture cycle counters here */ + +#else SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz); - } +#endif + } /* not CSV format */ + printf("%s", msg); /* show errors */ @@ -1706,7 +1926,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID, int count, (void)ret; TEST_SLEEP(); -} +} /* bench_stats_sym_finish */ #ifdef BENCH_ASYM #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \ @@ -1730,12 +1950,29 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, #endif #ifdef GENERATE_MACHINE_PARSEABLE_REPORT - END_INTEL_CYCLES + #ifdef WOLFSSL_ESPIDF + END_ESP_CYCLES + #else + END_INTEL_CYCLES + #endif #endif - if (count > 0) + /* some sanity checks on the final numbers */ + if (count > 0) { each = total / count; /* per second */ - opsSec = count / total; /* ops second */ + } + else { + count = 0; + each = 0; + } + + if (total > 0) { + opsSec = count / total; /* ops second */ + } + else { + opsSec = 0; + } + milliEach = each * 1000; /* milliseconds */ SLEEP_ON_ERROR(ret); @@ -1744,8 +1981,13 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, /* only print out header once */ if (asym_header_printed == 0) { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/sec," "ops,secs,cycles,cycles/op\n"); + #else + printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/sec," + "ops,secs\n"); + #endif #else printf("\n%sAsymmetric Ciphers:\n\n", info_prefix); printf("%sAlgorithm,key size,operation,avg ms,ops/sec,\n", @@ -1754,23 +1996,41 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, asym_header_printed = 1; } #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "asym,%s,%d,%s%s,%.3f,%.3f,%d,%f,%lu,%.6f\n", algo, strength, desc, desc_extra, milliEach, opsSec, - count, total, total_cycles, + count, total, (unsigned long) total_cycles, (double)total_cycles / (double)count); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "asym,%s,%d,%s%s,%.3f,%.3f,%d,%f\n", + algo, strength, desc, desc_extra, milliEach, opsSec, + count, total); + #endif #else (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,%.3f,%.3f,\n", algo, strength, desc, desc_extra, milliEach, opsSec); #endif - } else { + } /* if (csv_format == 1) */ + + else { #ifdef GENERATE_MACHINE_PARSEABLE_REPORT + #ifdef HAVE_GET_CYCLES (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," " %.3f %s, %lu cycles\n", algo, strength, desc, desc_extra, BENCH_DEVID_GET_NAME(useDeviceID), count, word[0], total, word[1], word[2], milliEach, - opsSec, word[3], total_cycles); + opsSec, word[3], (unsigned long) total_cycles); + #else + (void)XSNPRINTF(msg, sizeof(msg), + "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," + " %.3f %s\n", algo, strength, desc, + desc_extra, BENCH_ASYNC_GET_NAME(useDeviceID), + count, word[0], total, word[1], word[2], milliEach, + opsSec, word[3]); + #endif /* HAVE_GET_CYCLES */ #else (void)XSNPRINTF(msg, sizeof(msg), "%-6s %5d %8s%-2s %s %6d %s %5.3f %s, %s %5.3f ms," @@ -1799,7 +2059,7 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength, (void)ret; TEST_SLEEP(); -} +} /* bench_stats_asym_finish_ex */ static void bench_stats_asym_finish(const char* algo, int strength, const char* desc, int useDeviceID, int count, double start, int ret) @@ -1808,84 +2068,6 @@ static void bench_stats_asym_finish(const char* algo, int strength, start, ret); } #endif - -#if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) -static void bench_stats_pq_asym_finish(const char* algo, int useDeviceID, int count, - double start, int ret) -{ - double total, each = 0, opsSec, milliEach; - const char **word = bench_result_words2[lng_index]; - const char* kOpsSec = "Ops/Sec"; - char msg[128] = {0}; - static int pqasym_header_printed = 0; - - total = current_time(0) - start; - -#ifdef LINUX_RUSAGE_UTIME - check_for_excessive_stime(algo, ""); -#endif - -#ifdef GENERATE_MACHINE_PARSEABLE_REPORT - END_INTEL_CYCLES -#endif - - if (count > 0) - each = total / count; /* per second */ - opsSec = count / total; /* ops second */ - milliEach = each * 1000; /* milliseconds */ - - /* format and print to terminal */ - if (csv_format == 1) { - /* only print out header once */ - if (pqasym_header_printed == 0) { -#ifdef GENERATE_MACHINE_PARSEABLE_REPORT - printf("%s", "\"pq_asym\",Algorithm,avg ms,ops/sec,ops,secs,cycles," - "cycles/op\n"); -#else - printf("\nPost Quantum Asymmetric Ciphers:\n\n"); - printf("Algorithm,avg ms,ops/sec,\n"); -#endif - pqasym_header_printed = 1; - } -#ifdef GENERATE_MACHINE_PARSEABLE_REPORT - (void)XSNPRINTF(msg, sizeof(msg), - "pq_asym,%s,%.3f,%.3f,%d,%f,%lu,%.6f,\n", - algo, milliEach, opsSec, count, total, total_cycles, - (double)total_cycles / (double)count); -#else - (void)XSNPRINTF(msg, sizeof(msg), "%s %.3f,%.3f,\n", algo, milliEach, - opsSec); -#endif - } else { -#ifdef GENERATE_MACHINE_PARSEABLE_REPORT - (void)XSNPRINTF(msg, sizeof(msg), - "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," - " %.3f %s, %lu cycles\n", - algo, BENCH_DEVID_GET_NAME(useDeviceID), - count, word[0], total, word[1], word[2], milliEach, - opsSec, word[3], total_cycles); -#else - (void)XSNPRINTF(msg, sizeof(msg), "%-18s %s %6d %s %5.3f %s, %s %5.3f ms," - " %.3f %s\n", algo, BENCH_DEVID_GET_NAME(useDeviceID), - count, word[0], total, word[1], word[2], milliEach, opsSec, word[3]); -#endif - } - printf("%s", msg); - - /* show errors */ - if (ret < 0) { - printf("%sBenchmark %s failed: %d\n", err_prefix, algo, ret); - } - - /* Add to thread stats */ - bench_stats_add(BENCH_STAT_ASYM, algo, 0, "", useDeviceID, opsSec, kOpsSec, ret); - - (void)useDeviceID; - (void)ret; - - TEST_SLEEP(); -} -#endif #endif /* BENCH_ASYM */ static WC_INLINE void bench_stats_free(void) @@ -1901,9 +2083,10 @@ static WC_INLINE void bench_stats_free(void) bench_stats_tail = NULL; #endif } -/******************************************************************************/ + +/*****************************************************************************/ /* End Stats Functions */ -/******************************************************************************/ +/*****************************************************************************/ static void* benchmarks_do(void* args) @@ -1979,8 +2162,10 @@ static void* benchmarks_do(void* args) bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); #else - bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); - bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16, + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); #endif if (bench_plain == NULL || bench_cipher == NULL) { XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); @@ -1994,8 +2179,11 @@ static void* benchmarks_do(void* args) XMEMSET(bench_cipher, 0, (size_t)bench_buf_size); #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC) - bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); - bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_key = (byte*)XMALLOC(sizeof(bench_key_buf), + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf), + HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); + if (bench_key == NULL || bench_iv == NULL) { XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT); @@ -2176,7 +2364,32 @@ static void* benchmarks_do(void* args) bench_sha512(1); #endif } -#endif + +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + if (bench_all || (bench_digest_algs & BENCH_SHA512)) { + #ifndef NO_SW_BENCH + bench_sha512_224(0); + #endif + #ifdef BENCH_DEVID + bench_sha512_224(1); + #endif + } +#endif /* WOLFSSL_NOSHA512_224 */ + +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + if (bench_all || (bench_digest_algs & BENCH_SHA512)) { + #ifndef NO_SW_BENCH + bench_sha512_256(0); + #endif + #ifdef BENCH_DEVID + bench_sha512_256(1); + #endif + } +#endif /* WOLFSSL_NOSHA512_256 */ +#endif /* WOLFSSL_SHA512 */ + #ifdef WOLFSSL_SHA3 #ifndef WOLFSSL_NOSHA3_224 if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) { @@ -2549,21 +2762,7 @@ static void* benchmarks_do(void* args) #endif #endif -#if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL1_KEYGEN)) - bench_pqcKemKeygen(BENCH_KYBER_LEVEL1_KEYGEN); - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL1_ENCAP)) - bench_pqcKemEncapDecap(BENCH_KYBER_LEVEL1_ENCAP); -#endif #if defined(HAVE_LIBOQS) - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL3_KEYGEN)) - bench_pqcKemKeygen(BENCH_KYBER_LEVEL3_KEYGEN); - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL3_ENCAP)) - bench_pqcKemEncapDecap(BENCH_KYBER_LEVEL3_ENCAP); - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL5_KEYGEN)) - bench_pqcKemKeygen(BENCH_KYBER_LEVEL5_KEYGEN); - if (bench_all || (bench_pq_asym_algs & BENCH_KYBER_LEVEL5_ENCAP)) - bench_pqcKemEncapDecap(BENCH_KYBER_LEVEL5_ENCAP); #ifdef HAVE_FALCON if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN)) bench_falconKeySign(1); @@ -2572,19 +2771,12 @@ static void* benchmarks_do(void* args) #endif #ifdef HAVE_DILITHIUM if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN)) - bench_dilithiumKeySign(2, SHAKE_VARIANT); + bench_dilithiumKeySign(2); if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN)) - bench_dilithiumKeySign(3, SHAKE_VARIANT); + bench_dilithiumKeySign(3); if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN)) - bench_dilithiumKeySign(5, SHAKE_VARIANT); - if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_AES_LEVEL2_SIGN)) - bench_dilithiumKeySign(2, AES_VARIANT); - if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_AES_LEVEL3_SIGN)) - bench_dilithiumKeySign(3, AES_VARIANT); - if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_AES_LEVEL5_SIGN)) - bench_dilithiumKeySign(5, AES_VARIANT); + bench_dilithiumKeySign(5); #endif - #ifdef HAVE_SPHINCS if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN)) bench_sphincsKeySign(1, FAST_VARIANT); @@ -2637,8 +2829,9 @@ int benchmark_init(void) benchmark_static_init(0); #ifdef WOLFSSL_STATIC_MEMORY - ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory, sizeof(gBenchMemory), - WOLFMEM_GENERAL, 1); + ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory, + sizeof(gBenchMemory), WOLFMEM_GENERAL, 1); + if (ret != 0) { printf("%sunable to load static memory %d\n", err_prefix, ret); } @@ -2648,6 +2841,7 @@ int benchmark_init(void) printf("%swolfCrypt_Init failed %d\n", err_prefix, ret); return EXIT_FAILURE; } + #ifdef WOLFSSL_SECO_CAAM if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID, SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE) @@ -2670,9 +2864,11 @@ int benchmark_init(void) printf("%swolfCrypt Benchmark (block bytes %d, min %.1f sec each)\n", info_prefix, (int)bench_size, BENCH_MIN_RUNTIME_SEC); + #ifndef GENERATE_MACHINE_PARSEABLE_REPORT if (csv_format == 1) { - printf("This format allows you to easily copy the output to a csv file."); + printf("This format allows you to easily copy " + "the output to a csv file."); } #endif @@ -2762,7 +2958,8 @@ static int benchmark_test_threaded(void* args) } for (i = 0; i < g_threadCount; i++) { - PTHREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id, NULL, run_bench, args)); + PTHREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id, + NULL, run_bench, args)); } for (i = 0; i < g_threadCount; i++) { @@ -2797,6 +2994,15 @@ int benchmark_test(void *args) #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING) { + /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT + ** + ** Chapter Two, Build Options: + ** + ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf + ** + ** asynchronous cryptography using hardware based adapters such as + ** the Intel QuickAssist or Marvell (Cavium) Nitrox V. + */ int i; if (g_threadCount == 0) { @@ -2879,7 +3085,8 @@ void bench_rng(void) len = remain; if (len > RNG_MAX_BLOCK_LEN) len = RNG_MAX_BLOCK_LEN; - ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos], (word32)len); + ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos], + (word32)len); if (ret < 0) goto exit_rng; @@ -2900,7 +3107,8 @@ exit_rng: #ifndef NO_AES #ifdef HAVE_AES_CBC -static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz, +static void bench_aescbc_internal(int useDeviceID, + const byte* key, word32 keySz, const byte* iv, const char* encLabel, const char* decLabel) { @@ -2934,12 +3142,12 @@ static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_AesCbcEncrypt(&enc[i], bench_plain, bench_cipher, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_enc; } } @@ -2947,8 +3155,10 @@ static void bench_aescbc_internal(int useDeviceID, const byte* key, word32 keySz } /* for times */ count += times; } while (bench_stats_check(start)); + exit_aes_enc: - bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(encLabel, useDeviceID, count, + bench_size, start, ret); if (ret < 0) { goto exit; @@ -2972,12 +3182,12 @@ exit_aes_enc: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_AesCbcDecrypt(&enc[i], bench_cipher, bench_plain, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_dec; } } @@ -2986,7 +3196,8 @@ exit_aes_enc: count += times; } while (bench_stats_check(start)); exit_aes_dec: - bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, + start, ret); #endif /* HAVE_AES_DECRYPT */ @@ -3017,8 +3228,9 @@ void bench_aescbc(int useDeviceID) #endif /* HAVE_AES_CBC */ #ifdef HAVE_AESGCM -static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz, - const byte* iv, word32 ivSz, +static void bench_aesgcm_internal(int useDeviceID, + const byte* key, word32 keySz, + const byte* iv, word32 ivSz, const char* encLabel, const char* decLabel) { int ret = 0, i, count = 0, times, pending = 0; @@ -3075,26 +3287,13 @@ static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { -#ifndef BENCHMARK_AESGCM_STREAM + ×, numBlocks, &pending)) { ret = wc_AesGcmEncrypt(&enc[i], bench_cipher, bench_plain, bench_size, iv, ivSz, bench_tag, AES_AUTH_TAG_SZ, bench_additional, aesAuthAddSz); -#else - ret = wc_AesGcmEncryptInit(&enc[i], NULL, 0, iv, ivSz); - if (ret == 0) { - ret = wc_AesGcmEncryptUpdate(&enc[i], bench_cipher, - bench_plain, bench_size, bench_additional, - aesAuthAddSz); - } - if (ret == 0) { - ret = wc_AesGcmEncryptFinal(&enc[i], bench_tag, - AES_AUTH_TAG_SZ); - } -#endif if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_gcm; } } @@ -3103,7 +3302,8 @@ static void bench_aesgcm_internal(int useDeviceID, const byte* key, word32 keySz count += times; } while (bench_stats_check(start)); exit_aes_gcm: - bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, + start, ret); #ifdef HAVE_AES_DECRYPT /* init keys */ @@ -3129,26 +3329,13 @@ exit_aes_gcm: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), 0, - ×, numBlocks, &pending)) { -#ifndef BENCHMARK_AESGCM_STREAM + ×, numBlocks, &pending)) { ret = wc_AesGcmDecrypt(&dec[i], bench_plain, bench_cipher, bench_size, iv, ivSz, bench_tag, AES_AUTH_TAG_SZ, bench_additional, aesAuthAddSz); -#else - ret = wc_AesGcmDecryptInit(&enc[i], NULL, 0, iv, ivSz); - if (ret == 0) { - ret = wc_AesGcmDecryptUpdate(&enc[i], bench_plain, - bench_cipher, bench_size, bench_additional, - aesAuthAddSz); - } - if (ret == 0) { - ret = wc_AesGcmDecryptFinal(&enc[i], bench_tag, - AES_AUTH_TAG_SZ); - } -#endif if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_gcm_dec; } } @@ -3156,8 +3343,10 @@ exit_aes_gcm: } /* for times */ count += times; } while (bench_stats_check(start)); + exit_aes_gcm_dec: - bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, + start, ret); #endif /* HAVE_AES_DECRYPT */ (void)decLabel; @@ -3180,11 +3369,166 @@ exit: WC_FREE_VAR(bench_tag, HEAP_HINT); } +#ifdef WOLFSSL_AESGCM_STREAM +static void bench_aesgcm_stream_internal(int useDeviceID, + const byte* key, word32 keySz, const byte* iv, word32 ivSz, + const char* encLabel, const char* decLabel) +{ + int ret = 0, i, count = 0, times, pending = 0; + Aes enc[BENCH_MAX_PENDING]; +#ifdef HAVE_AES_DECRYPT + Aes dec[BENCH_MAX_PENDING]; +#endif + double start; + + WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT); + WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT); +#ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC + if (bench_additional == NULL || bench_tag == NULL) { + printf("bench_aesgcm_internal malloc failed\n"); + goto exit; + } +#endif + + /* clear for done cleanup */ + XMEMSET(enc, 0, sizeof(enc)); +#ifdef HAVE_AES_DECRYPT + XMEMSET(dec, 0, sizeof(dec)); +#endif +#ifdef WOLFSSL_ASYNC_CRYPT + if (bench_additional) +#endif + XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ); +#ifdef WOLFSSL_ASYNC_CRYPT + if (bench_tag) +#endif + XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ); + + /* init keys */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if ((ret = wc_AesInit(&enc[i], HEAP_HINT, + useDeviceID ? devId: INVALID_DEVID)) != 0) { + printf("AesInit failed, ret = %d\n", ret); + goto exit; + } + + ret = wc_AesGcmSetKey(&enc[i], key, keySz); + if (ret != 0) { + printf("AesGcmSetKey failed, ret = %d\n", ret); + goto exit; + } + } + + /* GCM uses same routine in backend for both encrypt and decrypt */ + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks || pending > 0; ) { + bench_async_poll(&pending); + + /* while free pending slots in queue, submit ops */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, + ×, numBlocks, &pending)) { + ret = wc_AesGcmEncryptInit(&enc[i], NULL, 0, iv, ivSz); + if (ret == 0) { + ret = wc_AesGcmEncryptUpdate(&enc[i], bench_cipher, + bench_plain, bench_size, bench_additional, + aesAuthAddSz); + } + if (ret == 0) { + ret = wc_AesGcmEncryptFinal(&enc[i], bench_tag, + AES_AUTH_TAG_SZ); + } + if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), + 0, ×, &pending)) { + goto exit_aes_gcm; + } + } + } /* for i */ + } /* for times */ + count += times; + } while (bench_stats_check(start)); +exit_aes_gcm: + bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size, + start, ret); + +#ifdef HAVE_AES_DECRYPT + /* init keys */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if ((ret = wc_AesInit(&dec[i], HEAP_HINT, + useDeviceID ? devId: INVALID_DEVID)) != 0) { + printf("AesInit failed, ret = %d\n", ret); + goto exit; + } + + ret = wc_AesGcmSetKey(&dec[i], key, keySz); + if (ret != 0) { + printf("AesGcmSetKey failed, ret = %d\n", ret); + goto exit; + } + } + + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks || pending > 0; ) { + bench_async_poll(&pending); + + /* while free pending slots in queue, submit ops */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), 0, + ×, numBlocks, &pending)) { + ret = wc_AesGcmDecryptInit(&enc[i], NULL, 0, iv, ivSz); + if (ret == 0) { + ret = wc_AesGcmDecryptUpdate(&enc[i], bench_plain, + bench_cipher, bench_size, bench_additional, + aesAuthAddSz); + } + if (ret == 0) { + ret = wc_AesGcmDecryptFinal(&enc[i], bench_tag, + AES_AUTH_TAG_SZ); + } + if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&dec[i]), + 0, ×, &pending)) { + goto exit_aes_gcm_dec; + } + } + } /* for i */ + } /* for times */ + count += times; + } while (bench_stats_check(start)); + +exit_aes_gcm_dec: + bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size, + start, ret); +#endif /* HAVE_AES_DECRYPT */ + + (void)decLabel; + +exit: + + if (ret < 0) { + printf("bench_aesgcm failed: %d\n", ret); + } +#ifdef HAVE_AES_DECRYPT + for (i = 0; i < BENCH_MAX_PENDING; i++) { + wc_AesFree(&dec[i]); + } +#endif + for (i = 0; i < BENCH_MAX_PENDING; i++) { + wc_AesFree(&enc[i]); + } + + WC_FREE_VAR(bench_additional, HEAP_HINT); + WC_FREE_VAR(bench_tag, HEAP_HINT); +} +#endif + void bench_aesgcm(int useDeviceID) { #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir) #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \ - && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL) + && !defined(WOLFSSL_XILINX_CRYPT) \ + || defined(WOLFSSL_XILINX_CRYPT_VERSAL) bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12, AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec)); #endif @@ -3197,6 +3541,25 @@ void bench_aesgcm(int useDeviceID) bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12, AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec)); #endif +#ifdef WOLFSSL_AESGCM_STREAM +#undef AES_GCM_STRING +#define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir) +#if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \ + && !defined(WOLFSSL_XILINX_CRYPT) \ + || defined(WOLFSSL_XILINX_CRYPT_VERSAL) + bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12, + AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec)); +#endif +#if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \ + && !defined(WOLFSSL_XILINX_CRYPT) + bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12, + AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec)); +#endif +#ifdef WOLFSSL_AES_256 + bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12, + AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec)); +#endif +#endif /* WOLFSSL_AESGCM_STREAM */ #undef AES_GCM_STRING } @@ -3244,7 +3607,8 @@ void bench_gmac(void) #ifdef HAVE_AES_ECB -static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz, +static void bench_aesecb_internal(int useDeviceID, + const byte* key, word32 keySz, const char* encLabel, const char* decLabel) { int ret = 0, i, count = 0, times, pending = 0; @@ -3285,7 +3649,7 @@ static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifdef HAVE_FIPS wc_AesEncryptDirect(&enc[i], bench_cipher, bench_plain); #else @@ -3294,7 +3658,7 @@ static void bench_aesecb_internal(int useDeviceID, const byte* key, word32 keySz #endif ret = 0; if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_enc; } } @@ -3325,7 +3689,7 @@ exit_aes_enc: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { #ifdef HAVE_FIPS wc_AesDecryptDirect(&enc[i], bench_plain, bench_cipher); #else @@ -3334,7 +3698,7 @@ exit_aes_enc: #endif ret = 0; if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_aes_dec; } } @@ -3373,7 +3737,8 @@ void bench_aesecb(int useDeviceID) #endif /* HAVE_AES_ECB */ #ifdef WOLFSSL_AES_CFB -static void bench_aescfb_internal(const byte* key, word32 keySz, const byte* iv, +static void bench_aescfb_internal(const byte* key, + word32 keySz, const byte* iv, const char* label) { Aes enc; @@ -3416,7 +3781,8 @@ void bench_aescfb(void) #ifdef WOLFSSL_AES_OFB -static void bench_aesofb_internal(const byte* key, word32 keySz, const byte* iv, +static void bench_aesofb_internal(const byte* key, + word32 keySz, const byte* iv, const char* label) { Aes enc; @@ -3532,8 +3898,8 @@ void bench_aesxts(void) #ifdef WOLFSSL_AES_COUNTER -static void bench_aesctr_internal(const byte* key, word32 keySz, const byte* iv, - const char* label) +static void bench_aesctr_internal(const byte* key, word32 keySz, + const byte* iv, const char* label) { Aes enc; double start; @@ -3545,7 +3911,7 @@ static void bench_aesctr_internal(const byte* key, word32 keySz, const byte* iv, do { for (i = 0; i < numBlocks; i++) { if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher, - bench_size)) != 0) { + bench_size)) != 0) { printf("wc_AesCtrEncrypt failed, ret = %d\n", ret); return; } @@ -3810,11 +4176,12 @@ void bench_des(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { - ret = wc_Des3_CbcEncrypt(&enc[i], bench_cipher, bench_plain, - bench_size); + ×, numBlocks, &pending)) { + ret = wc_Des3_CbcEncrypt(&enc[i], + bench_cipher, + bench_plain, bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_3des; } } @@ -3867,11 +4234,11 @@ void bench_arc4(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), 0, - ×, numBlocks, &pending)) { + ×, numBlocks, &pending)) { ret = wc_Arc4Process(&enc[i], bench_cipher, bench_plain, - bench_size); + bench_size); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&enc[i]), - 0, ×, &pending)) { + 0, ×, &pending)) { goto exit_arc4; } } @@ -3944,8 +4311,10 @@ void bench_md5(int useDeviceID) wc_Md5 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MD5_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MD5_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MD5_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MD5_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -3972,11 +4341,12 @@ void bench_md5(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Md5Update(&hash[i], bench_plain, - bench_size); + bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, &pending)) { goto exit_md5; } } @@ -3990,10 +4360,11 @@ void bench_md5(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Md5Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_md5; } } @@ -4038,8 +4409,10 @@ void bench_sha(int useDeviceID) wc_Sha hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4066,11 +4439,12 @@ void bench_sha(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_ShaUpdate(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha; } } @@ -4084,10 +4458,11 @@ void bench_sha(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_ShaFinal(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha; } } @@ -4131,8 +4506,10 @@ void bench_sha224(int useDeviceID) wc_Sha224 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA224_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA224_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA224_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA224_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4156,11 +4533,12 @@ void bench_sha224(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha224Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha224; } } @@ -4173,10 +4551,11 @@ void bench_sha224(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha224Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha224; } } @@ -4201,7 +4580,8 @@ void bench_sha224(int useDeviceID) } while (bench_stats_check(start)); } exit_sha224: - bench_stats_sym_finish("SHA-224", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-224", useDeviceID, count, + bench_size, start, ret); exit: @@ -4219,8 +4599,10 @@ void bench_sha256(int useDeviceID) wc_Sha256 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA256_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA256_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA256_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA256_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4247,11 +4629,12 @@ void bench_sha256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha256Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha256; } } @@ -4264,10 +4647,11 @@ void bench_sha256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha256Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha256; } } @@ -4292,7 +4676,8 @@ void bench_sha256(int useDeviceID) } while (bench_stats_check(start)); } exit_sha256: - bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size, + start, ret); exit: @@ -4310,8 +4695,10 @@ void bench_sha384(int useDeviceID) wc_Sha384 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA384_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA384_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA384_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA384_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4335,11 +4722,12 @@ void bench_sha384(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha384Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha384; } } @@ -4352,10 +4740,11 @@ void bench_sha384(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha384Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha384; } } @@ -4380,7 +4769,8 @@ void bench_sha384(int useDeviceID) } while (bench_stats_check(start)); } exit_sha384: - bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size, + start, ret); exit: @@ -4398,8 +4788,10 @@ void bench_sha512(int useDeviceID) wc_Sha512 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA512_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4423,11 +4815,12 @@ void bench_sha512(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha512Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha512; } } @@ -4440,10 +4833,11 @@ void bench_sha512(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha512Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha512; } } @@ -4468,7 +4862,8 @@ void bench_sha512(int useDeviceID) } while (bench_stats_check(start)); } exit_sha512: - bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size, + start, ret); exit: @@ -4478,6 +4873,196 @@ exit: WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT); } + +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +void bench_sha512_224(int useDeviceID) +{ + wc_Sha512_224 hash[BENCH_MAX_PENDING]; + double start; + int ret = 0, i, count = 0, times, pending = 0; + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_224_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_224_DIGEST_SIZE, HEAP_HINT); + + /* clear for done cleanup */ + XMEMSET(hash, 0, sizeof(hash)); + + if (digest_stream) { + /* init keys */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + ret = wc_InitSha512_224_ex(&hash[i], HEAP_HINT, + useDeviceID ? devId : INVALID_DEVID); + if (ret != 0) { + printf("InitSha512_224_ex failed, ret = %d\n", ret); + goto exit; + } + } + + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks || pending > 0; ) { + bench_async_poll(&pending); + + /* while free pending slots in queue, submit ops */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, numBlocks, &pending)) { + ret = wc_Sha512_224Update(&hash[i], bench_plain, + bench_size); + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { + goto exit_sha512_224; + } + } + } /* for i */ + } /* for times */ + count += times; + + times = 0; + do { + bench_async_poll(&pending); + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, numBlocks, &pending)) { + ret = wc_Sha512_224Final(&hash[i], digest[i]); + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { + goto exit_sha512_224; + } + } + } /* for i */ + } while (pending > 0); + } while (bench_stats_check(start)); + } + else { + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks; times++) { + ret = wc_InitSha512_224_ex(hash, HEAP_HINT, + useDeviceID ? devId : INVALID_DEVID); + if (ret == 0) + ret = wc_Sha512_224Update(hash, bench_plain, bench_size); + if (ret == 0) + ret = wc_Sha512_224Final(hash, digest[0]); + if (ret != 0) + goto exit_sha512_224; + } /* for times */ + count += times; + } while (bench_stats_check(start)); + } +exit_sha512_224: + bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size, + start, ret); + +exit: + + for (i = 0; i < BENCH_MAX_PENDING; i++) { + wc_Sha512_224Free(&hash[i]); + } + + WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT); +} +#endif + +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +void bench_sha512_256(int useDeviceID) +{ + wc_Sha512_256 hash[BENCH_MAX_PENDING]; + double start; + int ret = 0, i, count = 0, times, pending = 0; + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_256_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA512_256_DIGEST_SIZE, HEAP_HINT); + + /* clear for done cleanup */ + XMEMSET(hash, 0, sizeof(hash)); + + if (digest_stream) { + /* init keys */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + ret = wc_InitSha512_256_ex(&hash[i], HEAP_HINT, + useDeviceID ? devId : INVALID_DEVID); + if (ret != 0) { + printf("InitSha512_256_ex failed, ret = %d\n", ret); + goto exit; + } + } + + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks || pending > 0; ) { + bench_async_poll(&pending); + + /* while free pending slots in queue, submit ops */ + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, numBlocks, &pending)) { + ret = wc_Sha512_256Update(&hash[i], bench_plain, + bench_size); + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { + goto exit_sha512_256; + } + } + } /* for i */ + } /* for times */ + count += times; + + times = 0; + do { + bench_async_poll(&pending); + for (i = 0; i < BENCH_MAX_PENDING; i++) { + if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), + 0, ×, numBlocks, &pending)) { + ret = wc_Sha512_256Final(&hash[i], digest[i]); + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { + goto exit_sha512_256; + } + } + } /* for i */ + } while (pending > 0); + } while (bench_stats_check(start)); + } + else { + bench_stats_start(&count, &start); + do { + for (times = 0; times < numBlocks; times++) { + ret = wc_InitSha512_256_ex(hash, HEAP_HINT, + useDeviceID ? devId : INVALID_DEVID); + if (ret == 0) + ret = wc_Sha512_256Update(hash, bench_plain, bench_size); + if (ret == 0) + ret = wc_Sha512_256Final(hash, digest[0]); + if (ret != 0) + goto exit_sha512_256; + } /* for times */ + count += times; + } while (bench_stats_check(start)); + } +exit_sha512_256: + bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size, + start, ret); + +exit: + + for (i = 0; i < BENCH_MAX_PENDING; i++) { + wc_Sha512_256Free(&hash[i]); + } + + WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT); +} + +#endif + #endif @@ -4488,8 +5073,10 @@ void bench_sha3_224(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_224_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4513,11 +5100,12 @@ void bench_sha3_224(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_224_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_224; } } @@ -4530,10 +5118,11 @@ void bench_sha3_224(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_224_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_224; } } @@ -4558,7 +5147,8 @@ void bench_sha3_224(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_224: - bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size, + start, ret); exit: @@ -4576,8 +5166,10 @@ void bench_sha3_256(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4601,11 +5193,12 @@ void bench_sha3_256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_256_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_256; } } @@ -4618,10 +5211,11 @@ void bench_sha3_256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_256_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_256; } } @@ -4646,7 +5240,8 @@ void bench_sha3_256(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_256: - bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size, + start, ret); exit: @@ -4664,8 +5259,10 @@ void bench_sha3_384(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_384_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4689,11 +5286,12 @@ void bench_sha3_384(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_384_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_384; } } @@ -4706,10 +5304,11 @@ void bench_sha3_384(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_384_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_384; } } @@ -4734,7 +5333,8 @@ void bench_sha3_384(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_384: - bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size, + start, ret); exit: @@ -4752,8 +5352,10 @@ void bench_sha3_512(int useDeviceID) wc_Sha3 hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_512_DIGEST_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4777,11 +5379,12 @@ void bench_sha3_512(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_512_Update(&hash[i], bench_plain, bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_512; } } @@ -4794,10 +5397,11 @@ void bench_sha3_512(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Sha3_512_Final(&hash[i], digest[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_sha3_512; } } @@ -4822,7 +5426,8 @@ void bench_sha3_512(int useDeviceID) } while (bench_stats_check(start)); } exit_sha3_512: - bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size, + start, ret); exit: @@ -4834,14 +5439,16 @@ exit: } #endif /* WOLFSSL_NOSHA3_512 */ -#ifndef WOLFSSL_NO_SHAKE128 +#ifdef WOLFSSL_SHAKE128 void bench_shake128(int useDeviceID) { wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_128_BLOCK_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4865,11 +5472,12 @@ void bench_shake128(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake128_Update(&hash[i], bench_plain, - BENCH_SIZE); + bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake128; } } @@ -4882,11 +5490,12 @@ void bench_shake128(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake128_Final(&hash[i], digest[i], WC_SHA3_128_BLOCK_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake128; } } @@ -4901,7 +5510,7 @@ void bench_shake128(int useDeviceID) ret = wc_InitShake128(hash, HEAP_HINT, useDeviceID ? devId : INVALID_DEVID); if (ret == 0) - ret = wc_Shake128_Update(hash, bench_plain, BENCH_SIZE); + ret = wc_Shake128_Update(hash, bench_plain, bench_size); if (ret == 0) ret = wc_Shake128_Final(hash, digest[0], WC_SHA3_128_BLOCK_SIZE); @@ -4912,7 +5521,8 @@ void bench_shake128(int useDeviceID) } while (bench_stats_check(start)); } exit_shake128: - bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size, + start, ret); exit: @@ -4922,7 +5532,7 @@ exit: WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT); } -#endif /* WOLFSSL_NO_SHAKE128 */ +#endif /* WOLFSSL_SHAKE128 */ #ifdef WOLFSSL_SHAKE256 void bench_shake256(int useDeviceID) @@ -4930,8 +5540,10 @@ void bench_shake256(int useDeviceID) wc_Shake hash[BENCH_MAX_PENDING]; double start; int ret = 0, i, count = 0, times, pending = 0; - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_SHA3_256_BLOCK_SIZE, HEAP_HINT); /* clear for done cleanup */ XMEMSET(hash, 0, sizeof(hash)); @@ -4955,11 +5567,12 @@ void bench_shake256(int useDeviceID) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake256_Update(&hash[i], bench_plain, - BENCH_SIZE); + bench_size); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake256; } } @@ -4972,11 +5585,12 @@ void bench_shake256(int useDeviceID) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hash[i]), - 0, ×, numBlocks, &pending)) { + 0, ×, numBlocks, &pending)) { ret = wc_Shake256_Final(&hash[i], digest[i], WC_SHA3_256_BLOCK_SIZE); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&hash[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&hash[i]), 0, + ×, &pending)) { goto exit_shake256; } } @@ -4991,7 +5605,7 @@ void bench_shake256(int useDeviceID) ret = wc_InitShake256(hash, HEAP_HINT, useDeviceID ? devId : INVALID_DEVID); if (ret == 0) - ret = wc_Shake256_Update(hash, bench_plain, BENCH_SIZE); + ret = wc_Shake256_Update(hash, bench_plain, bench_size); if (ret == 0) ret = wc_Shake256_Final(hash, digest[0], WC_SHA3_256_BLOCK_SIZE); @@ -5002,7 +5616,8 @@ void bench_shake256(int useDeviceID) } while (bench_stats_check(start)); } exit_shake256: - bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size, start, ret); + bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size, + start, ret); exit: @@ -5281,7 +5896,8 @@ void bench_scrypt(void) do { for (i = 0; i < scryptCnt; i++) { ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13, - (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(derived)); + (byte*)"SodiumChloride", 14, 14, 8, 1, + sizeof(derived)); if (ret != 0) { printf("scrypt failed, ret = %d\n", ret); goto exit; @@ -5304,8 +5920,10 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, double start; int ret = 0, i, count = 0, times, pending = 0; #ifdef WOLFSSL_ASYNC_CRYPT - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT); - WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_MAX_DIGEST_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MAX_DIGEST_SIZE, HEAP_HINT); + WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, + WC_MAX_DIGEST_SIZE, HEAP_HINT); #else byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE]; #endif @@ -5338,10 +5956,12 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), 0, + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, numBlocks, &pending)) { ret = wc_HmacUpdate(&hmac[i], bench_plain, bench_size); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, &pending)) { goto exit_hmac; } @@ -5355,10 +5975,12 @@ static void bench_hmac(int useDeviceID, int type, int digestSz, bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), 0, + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, numBlocks, &pending)) { ret = wc_HmacFinal(&hmac[i], digest[i]); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&hmac[i]), + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV(&hmac[i]), 0, ×, &pending)) { goto exit_hmac; } @@ -5416,7 +6038,8 @@ void bench_hmac_sha224(int useDeviceID) 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; - bench_hmac(useDeviceID, WC_SHA224, WC_SHA224_DIGEST_SIZE, key, sizeof(key), + bench_hmac(useDeviceID, WC_SHA224, + WC_SHA224_DIGEST_SIZE, key, sizeof(key), "HMAC-SHA224"); } @@ -5550,7 +6173,7 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), - 0, ×, genTimes, &pending)) { + 0, ×, genTimes, &pending)) { wc_FreeRsaKey(&genKey[i]); ret = wc_InitRsaKey_ex(&genKey[i], HEAP_HINT, devId); @@ -5560,7 +6183,8 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) ret = wc_MakeRsaKey(&genKey[i], keySz, rsa_e_val, &gRng); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&genKey[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&genKey[i]), 0, + ×, &pending)) { goto exit; } } @@ -5569,7 +6193,8 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz) count += times; } while (bench_stats_check(start)); exit: - bench_stats_asym_finish("RSA", keySz, desc[2], useDeviceID, count, start, ret); + bench_stats_asym_finish("RSA", keySz, desc[2], useDeviceID, count, + start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -5707,7 +6332,7 @@ static unsigned char rsa_3072_sig[] = { #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], - int rsaKeySz) + int rsaKeySz) { int ret = 0, i, times, count = 0, pending = 0; word32 idx = 0; @@ -5720,16 +6345,24 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], #ifndef WOLFSSL_RSA_VERIFY_ONLY WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT); #endif - WC_DECLARE_ARRAY_DYNAMIC_DEC(enc, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); - #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) - WC_DECLARE_ARRAY_DYNAMIC_DEC(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); + WC_DECLARE_ARRAY_DYNAMIC_DEC(enc, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); + + #if ( !defined(WOLFSSL_RSA_VERIFY_INLINE) \ + && !defined(WOLFSSL_RSA_PUBLIC_ONLY) ) + WC_DECLARE_ARRAY_DYNAMIC_DEC(out, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); #else byte* out[BENCH_MAX_PENDING]; #endif - WC_DECLARE_ARRAY_DYNAMIC_EXE(enc, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); - #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) - WC_DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT); + WC_DECLARE_ARRAY_DYNAMIC_EXE(enc, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); + + #if ( !defined(WOLFSSL_RSA_VERIFY_INLINE) \ + && !defined(WOLFSSL_RSA_PUBLIC_ONLY) ) + WC_DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, + rsaKeySz, HEAP_HINT); if (out[0] == NULL) { ret = MEMORY_E; goto exit; @@ -5760,13 +6393,16 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i], rsaKeySz/8, &rsaKey[i], GLOBAL_RNG); - if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV( - &rsaKey[i]), 1, ×, &pending)) { + if (!bench_async_handle(&ret, + BENCH_ASYNC_GET_DEV( + &rsaKey[i]), 1, ×, + &pending)) { goto exit_rsa_verify; } } @@ -5775,8 +6411,8 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING], count += times; } while (bench_stats_check(start)); exit_rsa_verify: - bench_stats_asym_finish("RSA", rsaKeySz, desc[0], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[0], + useDeviceID, count, start, ret); #endif /* !WOLFSSL_RSA_VERIFY_ONLY */ #ifndef WOLFSSL_RSA_PUBLIC_ONLY @@ -5795,12 +6431,13 @@ exit_rsa_verify: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i], - rsaKeySz/8, &rsaKey[i]); + rsaKeySz/8, &rsaKey[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), + BENCH_ASYNC_GET_DEV(&rsaKey[i]), 1, ×, &pending)) { goto exit_rsa_pub; } @@ -5810,8 +6447,8 @@ exit_rsa_verify: count += times; } while (bench_stats_check(start)); exit_rsa_pub: - bench_stats_asym_finish("RSA", rsaKeySz, desc[1], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[1], + useDeviceID, count, start, ret); #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */ } else { @@ -5824,13 +6461,14 @@ exit_rsa_pub: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { ret = wc_RsaSSL_Sign(message, len, enc[i], rsaKeySz/8, &rsaKey[i], &gRng); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, &pending)) { goto exit_rsa_sign; } } @@ -5839,8 +6477,8 @@ exit_rsa_pub: count += times; } while (bench_stats_check(start)); exit_rsa_sign: - bench_stats_asym_finish("RSA", rsaKeySz, desc[4], useDeviceID, count, start, - ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[4], useDeviceID, + count, start, ret); if (ret < 0) { goto exit; @@ -5858,8 +6496,9 @@ exit_rsa_sign: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, ntimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, ntimes, &pending)) { #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \ !defined(WOLFSSL_RSA_PUBLIC_ONLY) ret = wc_RsaSSL_Verify(enc[i], idx, out[i], @@ -5868,22 +6507,24 @@ exit_rsa_sign: XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig)); idx = sizeof(rsa_2048_sig); out[i] = NULL; - ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i], - &rsaKey[i]); - if (ret > 0) + ret = wc_RsaSSL_VerifyInline(enc[i], idx, + &out[i], &rsaKey[i]); + if (ret > 0) { ret = 0; + } + #elif defined(USE_CERT_BUFFERS_3072) XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig)); idx = sizeof(rsa_3072_sig); out[i] = NULL; - ret = wc_RsaSSL_VerifyInline(enc[i], idx, &out[i], - &rsaKey[i]); + ret = wc_RsaSSL_VerifyInline(enc[i], idx, + &out[i], &rsaKey[i]); if (ret > 0) ret = 0; #endif if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&rsaKey[i]), - 1, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&rsaKey[i]), + 1, ×, &pending)) { goto exit_rsa_verifyinline; } } @@ -5891,9 +6532,10 @@ exit_rsa_sign: } /* for times */ count += times; } while (bench_stats_check(start)); + exit_rsa_verifyinline: - bench_stats_asym_finish("RSA", rsaKeySz, desc[5], useDeviceID, count, - start, ret); + bench_stats_asym_finish("RSA", rsaKeySz, desc[5], + useDeviceID, count, start, ret); } exit: @@ -5962,8 +6604,8 @@ void bench_rsa(int useDeviceID) #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY) /* decode the private key */ idx = 0; - if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx, &rsaKey[i], - (word32)bytes)) != 0) { + if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx, + &rsaKey[i], (word32)bytes)) != 0) { printf("wc_RsaPrivateKeyDecode failed! %d\n", ret); goto exit_bench_rsa; } @@ -6104,7 +6746,7 @@ void bench_dh(int useDeviceID) word32 pubSz2 = BENCH_DH_KEY_SIZE; word32 privSz2 = BENCH_DH_PRIV_SIZE; word32 agreeSz[BENCH_MAX_PENDING]; -#if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) +#if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096) #ifdef HAVE_PUBLIC_FFDHE const DhParams *params = NULL; #else @@ -6112,15 +6754,23 @@ void bench_dh(int useDeviceID) #endif #endif - WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); - WC_DECLARE_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_VAR(pub2, byte, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING, + BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING, + BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_DECLARE_VAR(priv2, byte, + BENCH_DH_PRIV_SIZE, HEAP_HINT); - WC_INIT_ARRAY(pub, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_INIT_ARRAY(agree, byte, BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); - WC_INIT_ARRAY(priv, byte, BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); + WC_INIT_ARRAY(pub, byte, + BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_INIT_ARRAY(agree, byte, + BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT); + WC_INIT_ARRAY(priv, byte, + BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT); #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC if (pub[0] == NULL || pub2 == NULL || agree[0] == NULL || priv[0] == NULL || priv2 == NULL) { @@ -6200,8 +6850,8 @@ void bench_dh(int useDeviceID) /* setup key */ if (!use_ffdhe) { #ifdef NO_ASN - ret = wc_DhSetKey(&dhKey[i], dh_p, sizeof(dh_p), dh_g, - sizeof(dh_g)); + ret = wc_DhSetKey(&dhKey[i], dh_p, + sizeof(dh_p), dh_g, sizeof(dh_g)); #else idx = 0; ret = wc_DhKeyDecode(tmp, &idx, &dhKey[i], (word32)bytes); @@ -6210,8 +6860,8 @@ void bench_dh(int useDeviceID) #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) #ifdef HAVE_PUBLIC_FFDHE else if (params != NULL) { - ret = wc_DhSetKey(&dhKey[i], params->p, params->p_len, params->g, - params->g_len); + ret = wc_DhSetKey(&dhKey[i], params->p, params->p_len, + params->g, params->g_len); } #else else if (paramName != 0) { @@ -6235,13 +6885,15 @@ void bench_dh(int useDeviceID) for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), - 0, ×, genTimes, &pending)) { + 0, ×, genTimes, &pending)) { privSz[i] = BENCH_DH_PRIV_SIZE; pubSz[i] = BENCH_DH_KEY_SIZE; - ret = wc_DhGenerateKeyPair(&dhKey[i], &gRng, priv[i], &privSz[i], - pub[i], &pubSz[i]); + ret = wc_DhGenerateKeyPair(&dhKey[i], &gRng, + priv[i], &privSz[i], + pub[i], &pubSz[i]); if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&dhKey[i]), 0, ×, &pending)) { + BENCH_ASYNC_GET_DEV(&dhKey[i]), + 0, ×, &pending)) { goto exit_dh_gen; } } @@ -6251,7 +6903,8 @@ void bench_dh(int useDeviceID) } while (bench_stats_check(start)); PRIVATE_KEY_LOCK(); exit_dh_gen: - bench_stats_asym_finish("DH", dhKeySz, desc[2], useDeviceID, count, start, ret); + bench_stats_asym_finish("DH", dhKeySz, desc[2], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6259,7 +6912,8 @@ exit_dh_gen: /* Generate key to use as other public */ PRIVATE_KEY_UNLOCK(); - ret = wc_DhGenerateKeyPair(&dhKey[0], &gRng, priv2, &privSz2, pub2, &pubSz2); + ret = wc_DhGenerateKeyPair(&dhKey[0], &gRng, + priv2, &privSz2, pub2, &pubSz2); PRIVATE_KEY_LOCK(); #ifdef WOLFSSL_ASYNC_CRYPT ret = wc_AsyncWait(ret, &dhKey[0].asyncDev, WC_ASYNC_FLAG_NONE); @@ -6275,9 +6929,9 @@ exit_dh_gen: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), - 0, ×, agreeTimes, &pending)) { + 0, ×, agreeTimes, &pending)) { ret = wc_DhAgree(&dhKey[i], agree[i], &agreeSz[i], priv[i], - privSz[i], pub2, pubSz2); + privSz[i], pub2, pubSz2); if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&dhKey[i]), 0, ×, &pending)) { goto exit; @@ -6288,8 +6942,10 @@ exit_dh_gen: count += times; } while (bench_stats_check(start)); PRIVATE_KEY_LOCK(); + exit: - bench_stats_asym_finish("DH", dhKeySz, desc[3], useDeviceID, count, start, ret); + bench_stats_asym_finish("DH", dhKeySz, desc[3], + useDeviceID, count, start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -6481,8 +7137,9 @@ void bench_eccMakeKey(int useDeviceID, int curveId) bench_async_poll(&pending); for (i = 0; i < BENCH_MAX_PENDING; i++) { - if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 0, - ×, agreeTimes, &pending)) { + if (bench_async_check(&ret, + BENCH_ASYNC_GET_DEV(&genKey[i]), 0, + ×, agreeTimes, &pending)) { wc_ecc_free(&genKey[i]); ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID); @@ -6502,11 +7159,12 @@ void bench_eccMakeKey(int useDeviceID, int curveId) } /* for times */ count += times; } while (bench_stats_check(start)); + exit: (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count, start, - ret); + bench_stats_asym_finish(name, keySize * 8, desc[2], + useDeviceID, count, start, ret); /* cleanup */ for (i = 0; i < BENCH_MAX_PENDING; i++) { @@ -6525,26 +7183,34 @@ void bench_ecc(int useDeviceID, int curveId) #ifdef HAVE_ECC_DHE ecc_key genKey2[BENCH_MAX_PENDING]; #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) -#ifdef HAVE_ECC_VERIFY - int verify[BENCH_MAX_PENDING]; -#endif + #ifdef HAVE_ECC_VERIFY + int verify[BENCH_MAX_PENDING]; + #endif #endif + word32 x[BENCH_MAX_PENDING]; double start = 0; const char**desc = bench_desc_words[lng_index]; #ifdef HAVE_ECC_DHE - WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_DECLARE_ARRAY(shared, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) - WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); - WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_DECLARE_ARRAY(sig, byte, + BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); + WC_DECLARE_ARRAY(digest, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif #ifdef HAVE_ECC_DHE - WC_INIT_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); + WC_INIT_ARRAY(shared, byte, + BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); #endif + #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) WC_INIT_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); WC_INIT_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT); @@ -6602,7 +7268,7 @@ void bench_ecc(int useDeviceID, int curveId) /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { + ×, agreeTimes, &pending)) { x[i] = (word32)keySize; ret = wc_ecc_shared_secret(&genKey[i], &genKey2[i], shared[i], &x[i]); @@ -6618,10 +7284,11 @@ void bench_ecc(int useDeviceID, int curveId) } while (bench_stats_check(start)); PRIVATE_KEY_UNLOCK(); exit_ecdhe: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", wc_ecc_get_name(curveId)); + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]", + wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count, start, - ret); + bench_stats_asym_finish(name, keySize * 8, desc[3], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6646,26 +7313,32 @@ exit_ecdhe: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { - if (genKey[i].state == 0) + ×, agreeTimes, &pending)) { + + if (genKey[i].state == 0) { x[i] = ECC_MAX_SIG_SIZE; + } + ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i], - &x[i], &gRng, &genKey[i]); + &x[i], &gRng, &genKey[i]); + if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, ×, &pending)) { goto exit_ecdsa_sign; } - } + } /* bench_async_check */ } /* for i */ } /* for times */ count += times; } while (bench_stats_check(start)); -exit_ecdsa_sign: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count, start, - ret); +exit_ecdsa_sign: + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", + wc_ecc_get_name(curveId)); + + bench_stats_asym_finish(name, keySize * 8, desc[4], + useDeviceID, count, start, ret); if (ret < 0) { goto exit; @@ -6682,26 +7355,33 @@ exit_ecdsa_sign: /* while free pending slots in queue, submit ops */ for (i = 0; i < BENCH_MAX_PENDING; i++) { if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 1, - ×, agreeTimes, &pending)) { - if (genKey[i].state == 0) + ×, agreeTimes, &pending)) { + if (genKey[i].state == 0) { verify[i] = 0; + } + ret = wc_ecc_verify_hash(sig[i], x[i], digest[i], - (word32)keySize, &verify[i], &genKey[i]); + (word32)keySize, &verify[i], + &genKey[i]); + if (!bench_async_handle(&ret, - BENCH_ASYNC_GET_DEV(&genKey[i]), 1, ×, - &pending)) { + BENCH_ASYNC_GET_DEV(&genKey[i]), + 1, ×, + &pending)) { goto exit_ecdsa_verify; } - } + } /* if bench_async_check */ } /* for i */ } /* for times */ count += times; } while (bench_stats_check(start)); -exit_ecdsa_verify: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", wc_ecc_get_name(curveId)); - bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count, start, - ret); +exit_ecdsa_verify: + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]", + wc_ecc_get_name(curveId)); + + bench_stats_asym_finish(name, keySize * 8, desc[5], + useDeviceID, count, start, ret); #endif /* HAVE_ECC_VERIFY */ #endif /* !NO_ASN && HAVE_ECC_SIGN */ @@ -6795,8 +7475,8 @@ void bench_eccEncrypt(int curveId) do { for (i = 0; i < ntimes; i++) { /* encrypt msg to B */ - ret = wc_ecc_encrypt(&userA, &userB, msg, sizeof(msg), out, &outSz, - NULL); + ret = wc_ecc_encrypt(&userA, &userB, msg, sizeof(msg), + out, &outSz, NULL); if (ret != 0) { printf("wc_ecc_encrypt failed! %d\n", ret); goto exit_enc; @@ -6804,8 +7484,10 @@ void bench_eccEncrypt(int curveId) } count += i; } while (bench_stats_check(start)); + exit_enc: - (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", wc_ecc_get_name(curveId)); + (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]", + wc_ecc_get_name(curveId)); bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret); bench_stats_start(&count, &start); @@ -7313,6 +7995,7 @@ void bench_eccsi(void) for (i = 0; i < genTimes; i++) { ret = wc_VerifyEccsiHash(&genKey, WC_HASH_TYPE_SHA256, msg, sizeof(msg), sig, sigSz, &verified); + if (ret != 0 || !verified) { printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret, verified); @@ -7455,15 +8138,17 @@ void bench_sakke(void) bench_stats_start(&count, &start); do { for (i = 0; i < genTimes; i++) { - ret = wc_MakeSakkeEncapsulatedSSV(&genKey, WC_HASH_TYPE_SHA256, ssv, - sizeof(ssv), auth, &authSz); + ret = wc_MakeSakkeEncapsulatedSSV(&genKey, + WC_HASH_TYPE_SHA256, + ssv, sizeof(ssv), auth, &authSz); if (ret != 0) { printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; } - } + } /* for */ count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1", 0, count, start, 0); @@ -7498,8 +8183,9 @@ void bench_sakke(void) bench_stats_start(&count, &start); do { for (i = 0; i < genTimes; i++) { - ret = wc_MakeSakkeEncapsulatedSSV(&genKey, WC_HASH_TYPE_SHA256, ssv, - sizeof(ssv), auth, &authSz); + ret = wc_MakeSakkeEncapsulatedSSV(&genKey, + WC_HASH_TYPE_SHA256, ssv, + sizeof(ssv), auth, &authSz); if (ret != 0) { printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret); break; @@ -7507,6 +8193,7 @@ void bench_sakke(void) } count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0, count, start, 0); @@ -7527,6 +8214,7 @@ void bench_sakke(void) if (ret != 0) break; count += i; } while (bench_stats_check(start)); + bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0, count, start, 0); @@ -7581,215 +8269,7 @@ void bench_sakke(void) #endif /* WOLFCRYPT_SAKKE_CLIENT */ #endif /* WOLFCRYPT_HAVE_SAKKE */ -#if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) -static void bench_pqcKemInit(word32 alg, byte **priv_key, byte **pub_key, - const char **wolf_name, OQS_KEM **kem) -{ - int i; - const char *pqc_name = NULL; - - *pub_key = NULL; - *priv_key = NULL; - - for (i=0; bench_pq_asym_opt[i].str != NULL; i++) { - if (alg == bench_pq_asym_opt[i].val) { -#ifdef HAVE_LIBOQS - pqc_name = bench_pq_asym_opt[i].pqc_name; -#endif - *wolf_name = bench_pq_asym_opt[i].str; - break; - } - } - -#ifdef HAVE_LIBOQS - if (pqc_name == NULL) { - printf("Bad OQS Alg specified\n"); - return; - } - - *kem = OQS_KEM_new(pqc_name); - if (*kem == NULL) { - printf("OQS_KEM_new() failed\n"); - return; - } - - *pub_key = (byte*)XMALLOC((*kem)->length_public_key, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - - *priv_key = (byte*)XMALLOC((*kem)->length_secret_key, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - -#endif -#ifdef HAVE_PQM4 - *pub_key = (byte*)XMALLOC(PQM4_PUBLIC_KEY_LENGTH, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - - *priv_key = (byte*)XMALLOC(PQM4_PRIVATE_KEY_LENGTH, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - (void)pqc_name; -#endif -} - -void bench_pqcKemKeygen(word32 alg) -{ - const char *wolf_name = NULL; - OQS_KEM* kem = NULL; - double start; - int i, count, ret; - byte *priv_key; - byte *pub_key; - - bench_pqcKemInit(alg, &priv_key, &pub_key, &wolf_name, &kem); - - if (wolf_name == NULL || pub_key == NULL || -#ifdef HAVE_LIBOQS - kem == NULL || -#endif - priv_key == NULL) { - printf("bench_pqcKemInit() failed\n"); - goto exit; - } - - bench_stats_start(&count, &start); - do { - for (i = 0; i < genTimes; i++) { -#ifdef HAVE_LIBOQS - ret = OQS_KEM_keypair(kem, pub_key, priv_key); - if (ret != OQS_SUCCESS) { - printf("OQS_KEM_keypair() failed: %d\n", ret); - goto exit; - } -#endif -#ifdef HAVE_PQM4 - ret = crypto_kem_keypair(pub_key, priv_key); - if (ret != 0) { - printf("crypto_kem_keypair() failed: %d\n", ret); - goto exit; - } -#endif - } - count += i; - } while (bench_stats_check(start)); - - /* + 1 gets rid of the leading dash (-) */ - bench_stats_pq_asym_finish(wolf_name + 1, 0, count, start, 0); - -exit: - XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); -#ifdef HAVE_LIBOQS - OQS_KEM_free(kem); -#endif -} - -void bench_pqcKemEncapDecap(word32 alg) -{ - const char *wolf_name = NULL; - OQS_KEM* kem = NULL; - double start; - int i, count, ret; - byte *priv_key; - byte *pub_key; - byte *ciphertext = NULL; - byte *shared_secret = NULL; - - bench_pqcKemInit(alg, &priv_key, &pub_key, &wolf_name, &kem); - - if (wolf_name == NULL || pub_key == NULL || -#ifdef HAVE_LIBOQS - kem == NULL || -#endif - priv_key == NULL) { - printf("bench_pqcKemInit() failed\n"); - goto exit; - } - -#ifdef HAVE_LIBOQS - ret = OQS_KEM_keypair(kem, pub_key, priv_key); - if (ret != OQS_SUCCESS) { - printf("OQS_KEM_keypair() failed: %d\n", ret); - goto exit; - } - - shared_secret = (byte*)XMALLOC(kem->length_shared_secret, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - - ciphertext = (byte*)XMALLOC(kem->length_ciphertext, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); -#endif -#ifdef HAVE_PQM4 - ret = crypto_kem_keypair(pub_key, priv_key); - if (ret != 0) { - printf("crypto_kem_keypair() failed: %d\n", ret); - goto exit; - } - - shared_secret = (byte*)XMALLOC(PQM4_SHARED_SECRET_LENGTH, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - - ciphertext = (byte*)XMALLOC(PQM4_CIPHERTEXT_LENGTH, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); -#endif - - if (shared_secret == NULL || ciphertext == NULL) { - printf("XMALLOC() failed\n"); - goto exit; - } - -#ifdef HAVE_LIBOQS - if (ret == OQS_SUCCESS) -#endif -#ifdef HAVE_PQM4 - if (ret == 0) -#endif - { - bench_stats_start(&count, &start); - do { - for (i = 0; i < agreeTimes; i++) { -#ifdef HAVE_LIBOQS - ret = OQS_KEM_encaps(kem, ciphertext, shared_secret, pub_key); - if (ret != OQS_SUCCESS) { - printf("OQS_KEM_encaps() failed: %d\n", ret); - goto exit; - } - - ret = OQS_KEM_decaps(kem, shared_secret, ciphertext, priv_key); - if (ret != OQS_SUCCESS) { - printf("OQS_KEM_decaps() failed: %d\n", ret); - goto exit; - } -#endif -#ifdef HAVE_PQM4 - ret = crypto_kem_enc(ciphertext, shared_secret, pub_key); - if (ret != 0){ - printf("crypto_kem_enc() failed: %d\n", ret); - goto exit; - } - - ret = crypto_kem_dec(shared_secret, ciphertext, priv_key); - if (ret != 0){ - printf("crypto_kem_dec() failed: %d\n", ret); - goto exit; - } -#endif - } - count += i; - } while (bench_stats_check(start)); - - /* + 1 gets rid of the leading dash (-) */ - bench_stats_pq_asym_finish(wolf_name + 1, 0, count, start, ret); - } - -exit: - XFREE(ciphertext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(shared_secret, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); -#ifdef HAVE_LIBOQS - OQS_KEM_free(kem); -#endif -} - +#if defined(HAVE_PQC) && defined(HAVE_LIBOQS) #ifdef HAVE_FALCON void bench_falconKeySign(byte level) { @@ -7856,7 +8336,8 @@ void bench_falconKeySign(byte level) } while (bench_stats_check(start)); if (ret == 0) { - bench_stats_asym_finish("FALCON", level, desc[4], 0, count, start, ret); + bench_stats_asym_finish("FALCON", level, desc[4], 0, + count, start, ret); } bench_stats_start(&count, &start); @@ -7877,7 +8358,8 @@ void bench_falconKeySign(byte level) } while (bench_stats_check(start)); if (ret == 0) { - bench_stats_asym_finish("FALCON", level, desc[5], 0, count, start, ret); + bench_stats_asym_finish("FALCON", level, desc[5], + 0, count, start, ret); } wc_falcon_free(&key); @@ -7885,7 +8367,7 @@ void bench_falconKeySign(byte level) #endif /* HAVE_FALCON */ #ifdef HAVE_DILITHIUM -void bench_dilithiumKeySign(byte level, byte sym) +void bench_dilithiumKeySign(byte level) { int ret = 0; dilithium_key key; @@ -7902,40 +8384,25 @@ void bench_dilithiumKeySign(byte level, byte sym) return; } - ret = wc_dilithium_set_level_and_sym(&key, level, sym); + ret = wc_dilithium_set_level(&key, level); if (ret != 0) { - printf("wc_dilithium_set_level_and_sym() failed %d\n", ret); + printf("wc_dilithium_set_level() failed %d\n", ret); } if (ret == 0) { ret = -1; - if ((level == 2) && (sym == SHAKE_VARIANT)) { + if (level == 2) { ret = wc_dilithium_import_private_key(bench_dilithium_level2_key, sizeof_bench_dilithium_level2_key, NULL, 0, &key); } - else if ((level == 3) && (sym == SHAKE_VARIANT)) { + else if (level == 3) { ret = wc_dilithium_import_private_key(bench_dilithium_level3_key, sizeof_bench_dilithium_level3_key, NULL, 0, &key); } - else if ((level == 5) && (sym == SHAKE_VARIANT)) { + else if (level == 5) { ret = wc_dilithium_import_private_key(bench_dilithium_level5_key, sizeof_bench_dilithium_level5_key, NULL, 0, &key); } - else if ((level == 2) && (sym == AES_VARIANT)) { - ret = wc_dilithium_import_private_key( - bench_dilithium_aes_level2_key, - sizeof_bench_dilithium_level2_key, NULL, 0, &key); - } - else if ((level == 3) && (sym == AES_VARIANT)) { - ret = wc_dilithium_import_private_key( - bench_dilithium_aes_level3_key, - sizeof_bench_dilithium_level3_key, NULL, 0, &key); - } - else if ((level == 5) && (sym == AES_VARIANT)) { - ret = wc_dilithium_import_private_key( - bench_dilithium_aes_level5_key, - sizeof_bench_dilithium_level5_key, NULL, 0, &key); - } if (ret != 0) { printf("wc_dilithium_import_private_key failed %d\n", ret); @@ -7971,14 +8438,8 @@ void bench_dilithiumKeySign(byte level, byte sym) } while (bench_stats_check(start)); if (ret == 0) { - if (sym == SHAKE_VARIANT) { - bench_stats_asym_finish("DILITHIUM", level, desc[4], 0, count, - start, ret); - } - else { - bench_stats_asym_finish("DILITHIUM-AES", level, desc[4], 0, count, - start, ret); - } + bench_stats_asym_finish("DILITHIUM", level, desc[4], 0, count, start, + ret); } bench_stats_start(&count, &start); @@ -7986,8 +8447,8 @@ void bench_dilithiumKeySign(byte level, byte sym) for (i = 0; i < agreeTimes; i++) { if (ret == 0) { int verify = 0; - ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg), &verify, - &key); + ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg), + &verify, &key); if (ret != 0 || verify != 1) { printf("wc_dilithium_verify_msg failed %d, verify %d\n", @@ -8000,14 +8461,8 @@ void bench_dilithiumKeySign(byte level, byte sym) } while (bench_stats_check(start)); if (ret == 0) { - if (sym == SHAKE_VARIANT) { - bench_stats_asym_finish("DILITHIUM", level, desc[5], 0, count, - start, ret); - } - else { - bench_stats_asym_finish("DILITHIUM-AES", level, desc[5], 0, count, - start, ret); - } + bench_stats_asym_finish("DILITHIUM", level, desc[5], 0, count, start, + ret); } wc_dilithium_free(&key); @@ -8210,13 +8665,17 @@ void bench_sphincsKeySign(byte level, byte optim) #include "task.h" #if defined(WOLFSSL_ESPIDF) - /* proto type definition */ + /* prototype definition */ int construct_argv(); extern char* __argv[22]; #endif double current_time(int reset) { + #if ESP_IDF_VERSION_MAJOR >= 4 + TickType_t tickCount; + #else portTickType tickCount; + #endif (void) reset; @@ -8267,7 +8726,9 @@ void bench_sphincsKeySign(byte level, byte optim) #elif defined(WOLFSSL_DEOS) double current_time(int reset) { - const uint32_t systemTickTimeInHz = 1000000 / systemTickInMicroseconds(); + const uint32_t systemTickTimeInHz + = 1000000 / systemTickInMicroseconds(); + const volatile uint32_t *systemTickPtr = systemTickPointer(); (void)reset; @@ -8334,9 +8795,11 @@ void bench_sphincsKeySign(byte level, byte optim) #elif defined(WOLFSSL_XILINX) #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ - #define COUNTS_PER_SECOND XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ + #define COUNTS_PER_SECOND \ + XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ #else - #define COUNTS_PER_SECOND XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ + #define COUNTS_PER_SECOND \ + XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ #endif double current_time(int reset) @@ -8418,17 +8881,27 @@ void bench_sphincsKeySign(byte level, byte optim) #if defined(HAVE_GET_CYCLES) -static WC_INLINE word64 get_intel_cycles(void) -{ - unsigned int lo_c, hi_c; - __asm__ __volatile__ ( - "cpuid\n\t" - "rdtsc" - : "=a"(lo_c), "=d"(hi_c) /* out */ - : "a"(0) /* in */ - : "%ebx", "%ecx"); /* clobber */ - return ((word64)lo_c) | (((word64)hi_c) << 32); -} + #if defined(WOLFSSL_ESPIDF) + static WC_INLINE word64 get_xtensa_cycles(void) + { + return xthal_get_ccount_ex(); + } + + /* implement other architectures here */ + + #else + static WC_INLINE word64 get_intel_cycles(void) + { + unsigned int lo_c, hi_c; + __asm__ __volatile__ ( + "cpuid\n\t" + "rdtsc" + : "=a"(lo_c), "=d"(hi_c) /* out */ + : "a"(0) /* in */ + : "%ebx", "%ecx"); /* clobber */ + return ((word64)lo_c) | (((word64)hi_c) << 32); + } + #endif #endif /* HAVE_GET_CYCLES */ @@ -8451,19 +8924,24 @@ void benchmark_configure(int block_size) * str Algorithm string to print. * line Length of line used so far. */ +#ifndef BENCH_MAX_LINE +#define BENCH_MAX_LINE 80 +#endif static void print_alg(const char* str, int* line) { - int optLen; - - optLen = (int)XSTRLEN(str) + 1; - if (optLen + *line > 80) { - printf("\n "); - *line = 13; + const char* const ident = " "; + if (*line == 0) { + fputs(ident, stdout); + *line = (int)XSTRLEN(ident); } - *line += optLen; printf(" %s", str); + *line += (int)XSTRLEN(str) + 1; + if (*line > BENCH_MAX_LINE) { + printf("\n"); + *line = 0; + } } -#endif +#endif /* WOLFSSL_BENCHMARK_ALL */ /* Display the usage options of the benchmark program. */ static void Usage(void) @@ -8521,42 +8999,31 @@ static void Usage(void) e++; #ifndef WOLFSSL_BENCHMARK_ALL printf("%s", bench_Usage_msg1[lng_index][e]); /* option - */ - printf(" "); - line = 13; + line = 0; for (i=0; bench_cipher_opt[i].str != NULL; i++) - print_alg(bench_cipher_opt[i].str + 1, &line); - printf("\n "); - line = 13; + print_alg(bench_cipher_opt[i].str, &line); for (i=0; bench_digest_opt[i].str != NULL; i++) - print_alg(bench_digest_opt[i].str + 1, &line); - printf("\n "); - line = 13; + print_alg(bench_digest_opt[i].str, &line); for (i=0; bench_mac_opt[i].str != NULL; i++) - print_alg(bench_mac_opt[i].str + 1, &line); - printf("\n "); - line = 13; + print_alg(bench_mac_opt[i].str, &line); for (i=0; bench_asym_opt[i].str != NULL; i++) - print_alg(bench_asym_opt[i].str + 1, &line); - printf("\n "); - line = 13; + print_alg(bench_asym_opt[i].str, &line); for (i=0; bench_other_opt[i].str != NULL; i++) - print_alg(bench_other_opt[i].str + 1, &line); - printf("\n "); -#if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) - line = 13; + print_alg(bench_other_opt[i].str, &line); +#if defined(HAVE_PQC) && defined(HAVE_LIBOQS) for (i=0; bench_pq_asym_opt[i].str != NULL; i++) - print_alg(bench_pq_asym_opt[i].str + 1, &line); + print_alg(bench_pq_asym_opt[i].str, &line); #if defined(HAVE_LIBOQS) for (i=0; bench_pq_asym_opt2[i].str != NULL; i++) - print_alg(bench_pq_asym_opt2[i].str + 1, &line); - printf("\n"); + print_alg(bench_pq_asym_opt2[i].str, &line); #endif /* HAVE_LIBOQS */ #endif /* HAVE_PQC */ + printf("\n"); #endif /* !WOLFSSL_BENCHMARK_ALL */ e++; - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */ - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option */ - printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option */ + printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks */ #ifdef WC_ENABLE_BENCH_THREADING printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads */ #endif @@ -8577,19 +9044,34 @@ static int string_matches(const char* arg, const char* str) } #endif /* MAIN_NO_ARGS */ +/* +** ---------------------------------------------------------------------------- +** determine how the benchmarks are called, the function name varies: +** ---------------------------------------------------------------------------- +*/ #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION) -#if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE) -int wolf_benchmark_task(void) -#elif defined(MAIN_NO_ARGS) -int main() -#else -int main(int argc, char** argv) -#endif + #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE) + + /* for some environments, we'll call a function wolf_benchmark_task: */ + int wolf_benchmark_task(void) + + #elif defined(MAIN_NO_ARGS) + + /* otherwise we'll use main() with no arguments as desired: */ + int main() + + #else + + /* else we'll be calling main with default arg parameters */ + int main(int argc, char** argv) + + #endif { -#ifdef WOLFSSL_ESPIDF - int argc = construct_argv(); - char** argv = (char**)__argv; -#endif + #ifdef WOLFSSL_ESPIDF + int argc = construct_argv(); + char** argv = (char**)__argv; + #endif + return wolfcrypt_benchmark_main(argc, argv); } #endif /* NO_MAIN_DRIVER && NO_MAIN_FUNCTION */ @@ -8597,11 +9079,12 @@ int main(int argc, char** argv) int wolfcrypt_benchmark_main(int argc, char** argv) { int ret = 0; + #ifndef MAIN_NO_ARGS int optMatched; -#ifndef WOLFSSL_BENCHMARK_ALL - int i; -#endif + #ifndef WOLFSSL_BENCHMARK_ALL + int i; + #endif #endif benchmark_static_init(1); @@ -8615,9 +9098,9 @@ int wolfcrypt_benchmark_main(int argc, char** argv) #ifndef MAIN_NO_ARGS while (argc > 1) { if (string_matches(argv[1], "-?")) { - if(--argc>1){ + if (--argc > 1) { lng_index = XATOI((++argv)[1]); - if(lng_index<0||lng_index>1) { + if (lng_index<0 || lng_index>1) { lng_index = 0; } } @@ -8627,11 +9110,11 @@ int wolfcrypt_benchmark_main(int argc, char** argv) else if (string_matches(argv[1], "-lng")) { argc--; argv++; - if(argc>1) { + if (argc > 1) { lng_index = XATOI(argv[1]); - if(lng_index<0||lng_index>1){ + if (lng_index<0 || lng_index>1) { printf("invalid number(%d) is specified. [ :0-1]\n", - lng_index); + lng_index); lng_index = 0; } } @@ -8687,6 +9170,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv) csv_format = 1; } #endif + #ifdef WC_ENABLE_BENCH_THREADING else if (string_matches(argv[1], "-threads")) { argc--; @@ -8746,7 +9230,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv) optMatched = 1; } } - #if defined(HAVE_PQC) && (defined(HAVE_LIBOQS) || defined(HAVE_PQM4)) + #if defined(HAVE_PQC) && defined(HAVE_LIBOQS) /* Known asymmetric post-quantum algorithms */ for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) { if (string_matches(argv[1], bench_pq_asym_opt[i].str)) { @@ -8755,7 +9239,6 @@ int wolfcrypt_benchmark_main(int argc, char** argv) optMatched = 1; } } - #if defined(HAVE_LIBOQS) /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for * -pq, so we need to do a special case for -pq since optMatched * was set to 1 just above. */ @@ -8771,7 +9254,6 @@ int wolfcrypt_benchmark_main(int argc, char** argv) optMatched = 1; } } - #endif /* HAVE_LIBOQS*/ #endif /* HAVE_PQC */ /* Other known cryptographic algorithms */ for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) { @@ -8797,6 +9279,13 @@ int wolfcrypt_benchmark_main(int argc, char** argv) } #endif /* MAIN_NO_ARGS */ +#if defined(WOLFSSL_BENCHMARK_FIXED_CSV) + /* when defined, we'll always output CSV regardless of params. + ** this is typically convenient in embedded environments. + */ + csv_format = 1; +#endif + #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT) if (g_threadCount > 1) { ret = benchmark_test_threaded(NULL); diff --git a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h index eb89fd6..1e859e1 100644 --- a/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h +++ b/recipes-examples/wolfcrypt/wolfcryptbenchmark/benchmark.h @@ -1,6 +1,6 @@ /* wolfcrypt/benchmark/benchmark.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2023 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -67,6 +67,14 @@ void bench_sha224(int useDeviceID); void bench_sha256(int useDeviceID); void bench_sha384(int useDeviceID); void bench_sha512(int useDeviceID); +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +void bench_sha512_224(int useDeviceID); +#endif +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +void bench_sha512_256(int useDeviceID); +#endif void bench_sha3_224(int useDeviceID); void bench_sha3_256(int useDeviceID); void bench_sha3_384(int useDeviceID); @@ -114,10 +122,8 @@ void bench_blake2b(void); void bench_blake2s(void); void bench_pbkdf2(void); void bench_falconKeySign(byte level); -void bench_dilithiumKeySign(byte level, byte sym); +void bench_dilithiumKeySign(byte level); void bench_sphincsKeySign(byte level, byte optim); -void bench_pqcKemKeygen(word32 alg); -void bench_pqcKemEncapDecap(word32 alg); void bench_stats_print(void); diff --git a/recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb b/recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb index 607f9a5..ae0f2b4 100644 --- a/recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb +++ b/recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb @@ -8,7 +8,7 @@ SECTION = "x11/applications" FILESEXTRAPATHS_prepend := "${THISDIR}:" LICENSE = "GPLv2" -LIC_FILES_CHKSUM = "file://benchmark.c;beginline=1;endline=20;md5=0e91b118566c76b2fb4ff7757b8f21a2" +LIC_FILES_CHKSUM = "file://benchmark.c;beginline=1;endline=20;md5=aca0c406899b7421c67598ba3f55d1a5" DEPENDS += "wolfssl" diff --git a/recipes-examples/wolfcrypt/wolfcrypttest/test.c b/recipes-examples/wolfcrypt/wolfcrypttest/test.c index d29d9ae..5f80924 100644 --- a/recipes-examples/wolfcrypt/wolfcrypttest/test.c +++ b/recipes-examples/wolfcrypt/wolfcrypttest/test.c @@ -1,6 +1,6 @@ /* test.c * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2023 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -66,7 +66,7 @@ #else static ssize_t max_relative_heap_bytes = -1; #endif -#define PRINT_HEAP_CHECKPOINT() { \ +#define PRINT_HEAP_CHECKPOINT() { \ const ssize_t _rha = wolfCrypt_heap_peakAllocs_checkpoint() - heap_baselineAllocs; \ const ssize_t _rhb = wolfCrypt_heap_peakBytes_checkpoint() - heap_baselineBytes; \ printf(" relative heap peak usage: %ld alloc%s, %ld bytes\n", \ @@ -74,9 +74,11 @@ _rha == 1 ? "" : "s", \ (long int)_rhb); \ if ((max_relative_heap_allocs > 0) && (_rha > max_relative_heap_allocs)) \ - return err_sys("heap allocs exceed designated max.", -1); \ + return err_sys("heap allocs exceed designated max.", \ + WC_TEST_RET_ENC_NC); \ if ((max_relative_heap_bytes > 0) && (_rhb > max_relative_heap_bytes)) \ - return err_sys("heap bytes exceed designated max.", -1); \ + return err_sys("heap bytes exceed designated max.", \ + WC_TEST_RET_ENC_NC); \ heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint(); \ heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint(); \ } @@ -253,6 +255,9 @@ #ifdef HAVE_ECC #include #endif +#ifdef HAVE_HPKE + #include +#endif #ifdef HAVE_CURVE25519 #include #endif @@ -413,6 +418,14 @@ WOLFSSL_TEST_SUBROUTINE int sha_test(void); WOLFSSL_TEST_SUBROUTINE int sha224_test(void); WOLFSSL_TEST_SUBROUTINE int sha256_test(void); WOLFSSL_TEST_SUBROUTINE int sha512_test(void); +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +WOLFSSL_TEST_SUBROUTINE int sha512_224_test(void); +#endif +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +WOLFSSL_TEST_SUBROUTINE int sha512_256_test(void); +#endif WOLFSSL_TEST_SUBROUTINE int sha384_test(void); WOLFSSL_TEST_SUBROUTINE int sha3_test(void); WOLFSSL_TEST_SUBROUTINE int shake128_test(void); @@ -434,6 +447,7 @@ WOLFSSL_TEST_SUBROUTINE int sshkdf_test(void); WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void); #endif WOLFSSL_TEST_SUBROUTINE int x963kdf_test(void); +WOLFSSL_TEST_SUBROUTINE int hpke_test(void); WOLFSSL_TEST_SUBROUTINE int arc4_test(void); #ifdef WC_RC2 WOLFSSL_TEST_SUBROUTINE int rc2_test(void); @@ -558,7 +572,8 @@ WOLFSSL_TEST_SUBROUTINE int certext_test(void); WOLFSSL_TEST_SUBROUTINE int decodedCertCache_test(void); #endif WOLFSSL_TEST_SUBROUTINE int memory_test(void); -#ifdef HAVE_VALGRIND +#if defined(WOLFSSL_PUBLIC_MP) && \ + (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) WOLFSSL_TEST_SUBROUTINE int mp_test(void); #endif #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN) @@ -573,11 +588,15 @@ WOLFSSL_TEST_SUBROUTINE int logging_test(void); #if !defined(NO_ASN) && !defined(NO_ASN_TIME) WOLFSSL_TEST_SUBROUTINE int time_test(void); #endif +#if defined(__INCLUDE_NUTTX_CONFIG_H) +WOLFSSL_TEST_SUBROUTINE int wolfcrypt_mutex_test(void); +#else WOLFSSL_TEST_SUBROUTINE int mutex_test(void); +#endif #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS) WOLFSSL_TEST_SUBROUTINE int memcb_test(void); #endif -#ifdef WOLFSSL_IMX6_CAAM_BLOB +#ifdef WOLFSSL_CAAM_BLOB WOLFSSL_TEST_SUBROUTINE int blob_test(void); #endif @@ -597,20 +616,90 @@ WOLFSSL_TEST_SUBROUTINE int aes_siv_test(void); #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0) +static void render_error_message(const char* msg, int es) +{ + (void)msg; + (void)es; + +#ifdef WOLFSSL_LINUXKM + #define err_sys_printf lkm_printf +#else + #define err_sys_printf printf +#endif + + switch (WC_TEST_RET_DEC_TAG(es)) { + case WC_TEST_RET_TAG_NC: + err_sys_printf("%s error L=%d\n", msg, WC_TEST_RET_DEC_LN(es)); + break; + case WC_TEST_RET_TAG_EC: +#ifdef NO_ERROR_STRINGS + err_sys_printf("%s error L=%d code=%d\n", msg, + WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es)); +#else + err_sys_printf("%s error L=%d code=%d (%s)\n", msg, + WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es), + wc_GetErrorString(-WC_TEST_RET_DEC_I(es))); +#endif + break; + case WC_TEST_RET_TAG_ERRNO: + { + +/* strerror_r() comes in two mutually incompatible flavors, a native glibc + * flavor that always returns a non-null char pointer that must be used + * directly, and a POSIX flavor that returns an error int, and iff success, + * stores an error string in the supplied buffer. this is all most + * infelicitous... + */ +#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \ + ((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \ + (defined(__USE_XOPEN2K) && \ + defined(_POSIX_C_SOURCE) && \ + (_POSIX_C_SOURCE >= 200112L))) + + char errno_buf[64], *errno_string; + /* precisely mirror the gate used in glibc string.h */ +#if defined __USE_XOPEN2K && !defined __USE_GNU + if (strerror_r(WC_TEST_RET_DEC_I(es), + errno_buf, sizeof(errno_buf)) != 0) + XSTRLCPY(errno_buf, "?", sizeof(errno_buf)); + errno_string = errno_buf; +#else + errno_string = strerror_r(WC_TEST_RET_DEC_I(es), + errno_buf, sizeof(errno_buf)); +#endif + err_sys_printf("%s error L=%d errno=%d (%s)\n", msg, + WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es), + errno_string); + +#else /* can't figure out how to strerror_r(), or don't want error strings */ + err_sys_printf("%s error L=%d errno=%d\n", msg, + WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es)); +#endif + break; + } + case WC_TEST_RET_TAG_I: + err_sys_printf("%s error L=%d i=%d\n", msg, + WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es)); + break; + } + +#undef err_sys_printf +} + +static void print_fiducials(void); + #ifdef HAVE_STACK_SIZE static THREAD_RETURN err_sys(const char* msg, int es) #else static int err_sys(const char* msg, int es) #endif { - (void)msg; - (void)es; - + render_error_message(msg, es); + print_fiducials(); #ifdef WOLFSSL_LINUXKM - lkm_printf("%s error = %d\n", msg, es); EXIT_TEST(es); #else - printf("%s error = %d\n", msg, es); EXIT_TEST(-1); #endif } @@ -694,7 +783,7 @@ static int wolfssl_pb_print(const char* msg, ...) #define TEST_PASS(...) { \ if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \ (max_relative_stack, printf(__VA_ARGS__)) < 0) { \ - return err_sys("post-test check failed", -1); \ + return err_sys("post-test check failed", WC_TEST_RET_ENC_NC);\ } \ PRINT_HEAP_CHECKPOINT(); \ ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \ @@ -737,28 +826,28 @@ int wolfcrypt_test(void* args) max_relative_stack = (ssize_t)atoi(myoptarg); break; #else - return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", -1); + return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", WC_TEST_RET_ENC_NC); #endif case 'm': #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE max_relative_heap_bytes = (ssize_t)atoi(myoptarg); break; #else - return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", -1); + return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC); #endif case 'a': #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE max_relative_heap_allocs = (ssize_t)atoi(myoptarg); break; #else - return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", -1); + return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC); #endif case 'h': return err_sys("\ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ [-a max_relative_heap_allocs] [-h]\n", 0); default: - return err_sys("unknown test option. try -h.", -1); + return err_sys("unknown test option. try -h.", WC_TEST_RET_ENC_NC); } } #endif @@ -788,14 +877,14 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ if (CheckCtcSettings() != 1) { printf("Sizeof mismatch (build) %x != (run) %lx\n", CTC_SETTINGS, (unsigned long)CheckRunTimeSettings()); - return err_sys("Build vs runtime math mismatch\n", -1000); + return err_sys("Build vs runtime math mismatch\n", WC_TEST_RET_ENC_NC); } #if defined(USE_FAST_MATH) && \ (!defined(NO_RSA) || !defined(NO_DH) || defined(HAVE_ECC)) if (CheckFastMathSettings() != 1) return err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n", - -1001); + WC_TEST_RET_ENC_NC); #endif /* USE_FAST_MATH */ #endif /* !NO_BIG_INT */ @@ -922,11 +1011,32 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif #ifdef WOLFSSL_SHA512 - if ( (ret = sha512_test()) != 0) + if ((ret = sha512_test()) != 0) { return err_sys("SHA-512 test failed!\n", ret); - else + } + else { TEST_PASS("SHA-512 test passed!\n"); -#endif + } + +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + if ((ret = sha512_224_test()) != 0) { + return err_sys("SHA-512/224 test failed!\n", ret); + } + else + TEST_PASS("SHA-512/224 test passed!\n"); +#endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */ + +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + if ((ret = sha512_256_test()) != 0) { + return err_sys("SHA-512/256 test failed!\n", ret); + } + else + TEST_PASS("SHA-512/256 test passed!\n"); +#endif /* !defined(WOLFSSL_NOSHA512_256) & !FIPS ... */ + +#endif /* WOLFSSL_SHA512 */ #ifdef WOLFSSL_SHA3 if ( (ret = sha3_test()) != 0) @@ -1064,6 +1174,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ TEST_PASS("X963-KDF test passed!\n"); #endif +#if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM) + if ( (ret = hpke_test()) != 0) + return err_sys("HPKE test failed!\n", ret); + else + TEST_PASS("HPKE test passed!\n"); +#endif + #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \ !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) if ( (ret = gmac_test()) != 0) @@ -1428,7 +1545,8 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif #endif -#ifdef HAVE_VALGRIND +#if defined(WOLFSSL_PUBLIC_MP) && \ + (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) if ( (ret = mp_test()) != 0) return err_sys("mp test failed!\n", ret); else @@ -1463,7 +1581,11 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ TEST_PASS("time test passed!\n"); #endif - if ( (ret = mutex_test()) != 0) +#if defined(__INCLUDE_NUTTX_CONFIG_H) + if ((ret = wolfcrypt_mutex_test()) != 0) +#else + if ((ret = mutex_test()) != 0) +#endif return err_sys("mutex test failed!\n", ret); else TEST_PASS("mutex test passed!\n"); @@ -1475,7 +1597,7 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ TEST_PASS("memcb test passed!\n"); #endif -#ifdef WOLFSSL_IMX6_CAAM_BLOB +#ifdef WOLFSSL_CAAM_BLOB if ( (ret = blob_test()) != 0) return err_sys("blob test failed!\n", ret); else @@ -1601,9 +1723,10 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif #ifdef HAVE_WNR - if (wc_InitNetRandom(wnrConfigFile, NULL, 5000) != 0) { - err_sys("Whitewood netRandom global config failed", -1001); - return -1002; + if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) { + err_sys("Whitewood netRandom global config failed", + WC_TEST_RET_ENC_EC(ret)); + return WC_TEST_RET_ENC_EC(ret); } #endif #ifndef WOLFSSL_ESPIDF @@ -1612,7 +1735,7 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif if ((ret = wolfCrypt_Init()) != 0) { printf("wolfCrypt_Init failed %d\n", ret); - err_sys("Error with wolfCrypt_Init!\n", -1003); + err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret)); } #ifdef WC_RNG_SEED_CB @@ -1627,12 +1750,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ if ((ret = wolfCrypt_Cleanup()) != 0) { printf("wolfCrypt_Cleanup failed %d\n", ret); - err_sys("Error with wolfCrypt_Cleanup!\n", -1004); + err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret)); } #ifdef HAVE_WNR - if (wc_FreeNetRandom() < 0) - err_sys("Failed to free netRandom context", -1005); + if ((ret = wc_FreeNetRandom()) < 0) + err_sys("Failed to free netRandom context", + WC_TEST_RET_ENC_EC(ret)); #endif /* HAVE_WNR */ #ifdef DOLPHIN_EMULATOR /* Returning from main panics the emulator. Just hang @@ -1664,13 +1788,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ && !defined(WOLF_CRYPTO_CB_ONLY_ECC) #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) -#define SaveDerAndPem(d, dSz, fD, fP, pT, eB) _SaveDerAndPem(d, dSz, fD, fP, pT, eB) +#define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN) #else -#define SaveDerAndPem(d, dSz, fD, fP, pT, eB) _SaveDerAndPem(d, dSz, NULL, NULL, pT, eB) +#define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, NULL, NULL, pT, WC_TEST_RET_LN) #endif static int _SaveDerAndPem(const byte* der, int derSz, - const char* fileDer, const char* filePem, int pemType, int errBase) + const char* fileDer, const char* filePem, int pemType, int calling_line) { #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) int ret; @@ -1678,12 +1802,12 @@ static int _SaveDerAndPem(const byte* der, int derSz, derFile = XFOPEN(fileDer, "wb"); if (!derFile) { - return errBase + 0; + return WC_TEST_RET_ENC(calling_line, 0, WC_TEST_RET_TAG_I); } ret = (int)XFWRITE(der, 1, derSz, derFile); XFCLOSE(derFile); if (ret != derSz) { - return errBase + 1; + return WC_TEST_RET_ENC(calling_line, 1, WC_TEST_RET_TAG_I); } #endif @@ -1698,29 +1822,29 @@ static int _SaveDerAndPem(const byte* der, int derSz, /* calculate PEM size */ pemSz = wc_DerToPem(der, derSz, NULL, 0, pemType); if (pemSz < 0) { - return pemSz; + return WC_TEST_RET_ENC(calling_line, 2, WC_TEST_RET_TAG_I); } pem = (byte*)XMALLOC(pemSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (pem == NULL) { - return MEMORY_E; + return WC_TEST_RET_ENC(calling_line, 3, WC_TEST_RET_TAG_I); } /* Convert to PEM */ pemSz = wc_DerToPem(der, derSz, pem, pemSz, pemType); if (pemSz < 0) { XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return errBase + 2; + return WC_TEST_RET_ENC(calling_line, 4, WC_TEST_RET_TAG_I); } #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) pemFile = XFOPEN(filePem, "wb"); if (!pemFile) { XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return errBase + 3; + return WC_TEST_RET_ENC(calling_line, 5, WC_TEST_RET_TAG_I); } ret = (int)XFWRITE(pem, 1, pemSz, pemFile); XFCLOSE(pemFile); if (ret != pemSz) { XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return errBase + 4; + return WC_TEST_RET_ENC(calling_line, 6, WC_TEST_RET_TAG_I); } #endif XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -1733,7 +1857,7 @@ static int _SaveDerAndPem(const byte* der, int derSz, (void)filePem; (void)fileDer; (void)pemType; - (void)errBase; + (void)calling_line; return 0; } @@ -1752,9 +1876,9 @@ WOLFSSL_TEST_SUBROUTINE int error_test(void) errStr = wc_GetErrorString(OPEN_RAN_E); wc_ErrorString(OPEN_RAN_E, out); if (XSTRCMP(errStr, unknownStr) != 0) - return -1100; + return WC_TEST_RET_ENC_NC; if (XSTRCMP(out, unknownStr) != 0) - return -1101; + return WC_TEST_RET_ENC_NC; #else int i; int j = 0; @@ -1773,20 +1897,20 @@ WOLFSSL_TEST_SUBROUTINE int error_test(void) if (i != missing[j]) { if (XSTRCMP(errStr, unknownStr) == 0) - return -1102; + return WC_TEST_RET_ENC_NC; if (XSTRCMP(out, unknownStr) == 0) - return -1103; + return WC_TEST_RET_ENC_NC; if (XSTRCMP(errStr, out) != 0) - return -1104; + return WC_TEST_RET_ENC_NC; if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) - return -1105; + return WC_TEST_RET_ENC_NC; } else { j++; if (XSTRCMP(errStr, unknownStr) != 0) - return -1106; + return WC_TEST_RET_ENC_NC; if (XSTRCMP(out, unknownStr) != 0) - return -1107; + return WC_TEST_RET_ENC_NC; } } @@ -1794,9 +1918,9 @@ WOLFSSL_TEST_SUBROUTINE int error_test(void) errStr = wc_GetErrorString(i); wc_ErrorString(i, out); if (XSTRCMP(errStr, unknownStr) != 0) - return -1108; + return WC_TEST_RET_ENC_NC; if (XSTRCMP(out, unknownStr) != 0) - return -1109; + return WC_TEST_RET_ENC_NC; #endif return 0; @@ -1834,45 +1958,45 @@ WOLFSSL_TEST_SUBROUTINE int base64_test(void) outLen = sizeof(out); ret = Base64_Decode(good, sizeof(good), out, &outLen); if (ret != 0) - return -1200; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen); if (ret != 0) - return -1201; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(goodChar); ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen); if (ret != 0) - return -1235; + return WC_TEST_RET_ENC_EC(ret); if (outLen != 64 / 4 * 3) - return -1236; + return WC_TEST_RET_ENC_NC; outLen = sizeof(out); ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen); if (ret != 0) - return -1201; + return WC_TEST_RET_ENC_EC(ret); /* Bad parameters. */ outLen = 1; ret = Base64_Decode(good, sizeof(good), out, &outLen); if (ret != BAD_FUNC_ARG) - return -1202; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen); if (ret != ASN_INPUT_E) - return -1203; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen); if (ret != ASN_INPUT_E) - return -1203; + return WC_TEST_RET_ENC_EC(ret); /* Bad character at each offset 0-3. */ for (i = 0; i < 4; i++) { outLen = sizeof(out); ret = Base64_Decode(badSmall + i, 4, out, &outLen); if (ret != ASN_INPUT_E) - return -1204 - i; + return WC_TEST_RET_ENC_I(i); ret = Base64_Decode(badLarge + i, 4, out, &outLen); if (ret != ASN_INPUT_E) - return -1214 - i; + return WC_TEST_RET_ENC_I(i); } /* Invalid character less than 0x2b */ for (i = 1; i < 0x2b; i++) { @@ -1880,7 +2004,7 @@ WOLFSSL_TEST_SUBROUTINE int base64_test(void) charTest[0] = (byte)i; ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen); if (ret != ASN_INPUT_E) - return -1240 - i; + return WC_TEST_RET_ENC_I(i); } /* Bad characters in range 0x2b - 0x7a. */ for (i = 0; i < (int)sizeof(badChar) - 1; i++) { @@ -1888,7 +2012,7 @@ WOLFSSL_TEST_SUBROUTINE int base64_test(void) charTest[0] = badChar[i]; ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen); if (ret != ASN_INPUT_E) - return -1270 - i; + return WC_TEST_RET_ENC_I(i); } /* Invalid character greater than 0x7a */ for (i = 0x7b; i < 0x100; i++) { @@ -1896,7 +2020,7 @@ WOLFSSL_TEST_SUBROUTINE int base64_test(void) charTest[0] = (byte)i; ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen); if (ret != ASN_INPUT_E) - return -1290 - i; + return WC_TEST_RET_ENC_I(i); } @@ -1905,46 +2029,46 @@ WOLFSSL_TEST_SUBROUTINE int base64_test(void) dataLen = sizeof(data); ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen); if (ret != 0) - return -1224; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Encode(data, dataLen, NULL, &outLen); if (ret != LENGTH_ONLY_E) - return -1225; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Encode(data, dataLen, out, &outLen); if (ret != 0) - return -1226; + return WC_TEST_RET_ENC_EC(ret); outLen = 7; ret = Base64_EncodeEsc(data, dataLen, out, &outLen); if (ret != BUFFER_E) - return -1227; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen); if (ret != LENGTH_ONLY_E) - return -1228; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_EncodeEsc(data, dataLen, out, &outLen); if (ret != 0) - return -1229; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Encode_NoNl(data, dataLen, out, &outLen); if (ret != 0) - return -1230; + return WC_TEST_RET_ENC_EC(ret); /* Data that results in an encoding longer than one line. */ outLen = sizeof(out); dataLen = sizeof(longData); ret = Base64_Encode(longData, dataLen, out, &outLen); if (ret != 0) - return -1231; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_EncodeEsc(longData, dataLen, out, &outLen); if (ret != 0) - return -1232; + return WC_TEST_RET_ENC_EC(ret); outLen = sizeof(out); ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen); if (ret != 0) - return -1233; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -1965,23 +2089,23 @@ WOLFSSL_TEST_SUBROUTINE int base16_test(void) encodedLen = sizeof(encoded); ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen); if (ret != 0) - return -1300; + return WC_TEST_RET_ENC_EC(ret); len = (word32)XSTRLEN((char*)encoded); if (len != encodedLen - 1) - return -1301; + return WC_TEST_RET_ENC_NC; len = sizeof(plain); ret = Base16_Decode(encoded, encodedLen - 1, plain, &len); if (ret != 0) - return -1302; + return WC_TEST_RET_ENC_EC(ret); if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0) - return -1303; + return WC_TEST_RET_ENC_NC; if (encodedLen != sizeof(encodedTestData) || XMEMCMP(encoded, encodedTestData, encodedLen) != 0) { - return -1304; + return WC_TEST_RET_ENC_NC; } return 0; @@ -2007,27 +2131,27 @@ WOLFSSL_TEST_SUBROUTINE int asn_test(void) ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format, &length); if (ret != 0) - return -1400; + return WC_TEST_RET_ENC_EC(ret); #ifndef NO_ASN_TIME /* Parameter Validation tests. */ - if (wc_GetTime(NULL, sizeof(now)) != BAD_FUNC_ARG) - return -1401; - if (wc_GetTime(&now, 0) != BUFFER_E) - return -1402; + if ((ret = wc_GetTime(NULL, sizeof(now))) != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + if ((ret = wc_GetTime(&now, 0)) != BUFFER_E) + return WC_TEST_RET_ENC_EC(ret); now = 0; - if (wc_GetTime(&now, sizeof(now)) != 0) { - return -1403; + if ((ret = wc_GetTime(&now, sizeof(now))) != 0) { + return WC_TEST_RET_ENC_EC(ret); } if (now == 0) { printf("RTC/Time not set!\n"); - return -1404; + return WC_TEST_RET_ENC_NC; } ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg); if (ret != 0) - return -1405; + return WC_TEST_RET_ENC_EC(ret); #endif /* !NO_ASN_TIME */ return 0; @@ -2104,19 +2228,18 @@ WOLFSSL_TEST_SUBROUTINE int md2_test(void) wc_Md2Final(&md2, hash); if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) - return -1500 - i; + return WC_TEST_RET_ENC_I(i); } for (i = 0; i < times; ++i) { ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash); - if (ret != 0) { - return -1507 - i; + if (ret != 0) { + return WC_TEST_RET_ENC_I(i); } if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) { - return -1507 - i; + return WC_TEST_RET_ENC_I(i); } - } return 0; @@ -2181,38 +2304,38 @@ WOLFSSL_TEST_SUBROUTINE int md5_test(void) ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId); if (ret != 0) - return -1600; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId); if (ret != 0) { wc_Md5Free(&md5); - return -1601; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_Md5Update(&md5, (byte*)test_md5[i].input, (word32)test_md5[i].inLen); if (ret != 0) - ERROR_OUT(-1602 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Md5GetHash(&md5, hashcopy); if (ret != 0) - ERROR_OUT(-1603 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Md5Copy(&md5, &md5Copy); if (ret != 0) - ERROR_OUT(-1604 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Md5Final(&md5, hash); if (ret != 0) - ERROR_OUT(-1605 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_Md5Free(&md5Copy); if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0) - ERROR_OUT(-1606 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0) - ERROR_OUT(-1607 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -2232,13 +2355,13 @@ WOLFSSL_TEST_SUBROUTINE int md5_test(void) ret = wc_Md5Update(&md5, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-1608, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Md5Final(&md5, hash); if (ret != 0) - ERROR_OUT(-1609, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0) - ERROR_OUT(-1610, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -2322,7 +2445,7 @@ WOLFSSL_TEST_SUBROUTINE int md4_test(void) wc_Md4Final(&md4, hash); if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0) - return -1700 - i; + return WC_TEST_RET_ENC_I(i); } return 0; @@ -2383,33 +2506,33 @@ WOLFSSL_TEST_SUBROUTINE int sha_test(void) ret = wc_InitSha_ex(&sha, HEAP_HINT, devId); if (ret != 0) - return -1800; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId); if (ret != 0) { wc_ShaFree(&sha); - return -1801; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-1802 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_ShaGetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-1803 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_ShaCopy(&sha, &shaCopy); if (ret != 0) - ERROR_OUT(-1804 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_ShaFinal(&sha, hash); if (ret != 0) - ERROR_OUT(-1805 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_ShaFree(&shaCopy); if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0) - ERROR_OUT(-1806 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0) - ERROR_OUT(-1807 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -2441,13 +2564,13 @@ WOLFSSL_TEST_SUBROUTINE int sha_test(void) ret = wc_ShaUpdate(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-1808, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_ShaFinal(&sha, hash); if (ret != 0) - ERROR_OUT(-1809, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0) - ERROR_OUT(-1810, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -2504,23 +2627,23 @@ WOLFSSL_TEST_SUBROUTINE int ripemd_test(void) ret = wc_InitRipeMd(&ripemd); if (ret != 0) { - return -1900; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input, (word32)test_ripemd[i].inLen); if (ret != 0) { - return -1901 - i; + return WC_TEST_RET_ENC_I(i); } ret = wc_RipeMdFinal(&ripemd, hash); if (ret != 0) { - return -1911 - i; + return WC_TEST_RET_ENC_I(i); } if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0) - return -1921 - i; + return WC_TEST_RET_ENC_I(i); } return 0; @@ -2582,18 +2705,18 @@ WOLFSSL_TEST_SUBROUTINE int blake2b_test(void) for (i = 0; i < BLAKE2B_TESTS; i++) { ret = wc_InitBlake2b(&b2b, 64); if (ret != 0) - return -2000 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_Blake2bUpdate(&b2b, input, i); if (ret != 0) - return -2010 - 1; + return WC_TEST_RET_ENC_I(i); ret = wc_Blake2bFinal(&b2b, digest, 64); if (ret != 0) - return -2020 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) { - return -2030 - i; + return WC_TEST_RET_ENC_I(i); } } @@ -2643,18 +2766,18 @@ WOLFSSL_TEST_SUBROUTINE int blake2s_test(void) for (i = 0; i < BLAKE2S_TESTS; i++) { ret = wc_InitBlake2s(&b2s, 32); if (ret != 0) - return -2100 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_Blake2sUpdate(&b2s, input, i); if (ret != 0) - return -2110 - 1; + return WC_TEST_RET_ENC_I(i); ret = wc_Blake2sFinal(&b2s, digest, 32); if (ret != 0) - return -2120 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) { - return -2130 - i; + return WC_TEST_RET_ENC_I(i); } } @@ -2699,33 +2822,33 @@ WOLFSSL_TEST_SUBROUTINE int sha224_test(void) ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId); if (ret != 0) - return -2200; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId); if (ret != 0) { wc_Sha224Free(&sha); - return -2201; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2202 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha224GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2203 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha224Copy(&sha, &shaCopy); if (ret != 0) - ERROR_OUT(-2204 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha224Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2205 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_Sha224Free(&shaCopy); if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0) - ERROR_OUT(-2206 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0) - ERROR_OUT(-2207 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } exit: @@ -2776,34 +2899,34 @@ WOLFSSL_TEST_SUBROUTINE int sha256_test(void) ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId); if (ret != 0) - return -2300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId); if (ret != 0) { wc_Sha256Free(&sha); - return -2301; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) { - ERROR_OUT(-2302 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } ret = wc_Sha256GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2303 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha256Copy(&sha, &shaCopy); if (ret != 0) - ERROR_OUT(-2304 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha256Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2305 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_Sha256Free(&shaCopy); if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) - ERROR_OUT(-2306 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) - ERROR_OUT(-2307 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -2833,13 +2956,13 @@ WOLFSSL_TEST_SUBROUTINE int sha256_test(void) ret = wc_Sha256Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2308, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha256Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2309, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0) - ERROR_OUT(-2310, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -2856,6 +2979,9 @@ exit: #ifdef WOLFSSL_SHA512 WOLFSSL_TEST_SUBROUTINE int sha512_test(void) { + /* + ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf + */ wc_Sha512 sha, shaCopy; byte hash[WC_SHA512_DIGEST_SIZE]; byte hashcopy[WC_SHA512_DIGEST_SIZE]; @@ -2899,33 +3025,33 @@ WOLFSSL_TEST_SUBROUTINE int sha512_test(void) ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId); if (ret != 0) - return -2400; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId); if (ret != 0) { wc_Sha512Free(&sha); - return -2401; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2402 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha512GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2403 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha512Copy(&sha, &shaCopy); if (ret != 0) - ERROR_OUT(-2404 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha512Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2405 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_Sha512Free(&shaCopy); if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) - ERROR_OUT(-2406 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) - ERROR_OUT(-2407 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -2957,13 +3083,13 @@ WOLFSSL_TEST_SUBROUTINE int sha512_test(void) ret = wc_Sha512Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2408, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha512Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2409, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0) - ERROR_OUT(-2410, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); #ifndef NO_UNALIGNED_MEMORY_TEST /* Unaligned memory access test */ @@ -2971,7 +3097,7 @@ WOLFSSL_TEST_SUBROUTINE int sha512_test(void) ret = wc_Sha512Update(&sha, (byte*)large_input + i, (word32)sizeof(large_input) - i); if (ret != 0) - ERROR_OUT(-2411, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Sha512Final(&sha, hash); } #endif @@ -2984,8 +3110,311 @@ exit: return ret; } + +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) +WOLFSSL_TEST_SUBROUTINE int sha512_224_test(void) +{ + /* + ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values + ** + ** NIST SHA512/224 Document Example: + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf + */ + wc_Sha512 sha, shaCopy; + byte hash[WC_SHA512_224_DIGEST_SIZE]; + byte hashcopy[WC_SHA512_224_DIGEST_SIZE]; + int ret = 0; + + testVector a, b, c; + testVector test_sha[3]; + int times = sizeof(test_sha) / sizeof(struct testVector), i; + + a.input = ""; + a.output = "\x6e\xd0\xdd\x02" + "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c" + "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6" + "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4"; + a.inLen = XSTRLEN(a.input); + a.outLen = WC_SHA512_224_DIGEST_SIZE; + + /* + ** See page 1 in above document for the SHA512/224 "abc" test: + */ + b.input = "abc"; + /* + ** See page 1 in above document for the SHA512/224 "abc" test digest: + */ + b.output = "\x46\x34\x27\x0f" + "\x70\x7b\x6a\x54" "\xda\xae\x75\x30" + "\x46\x08\x42\xe2" "\x0e\x37\xed\x26" + "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa"; + b.inLen = XSTRLEN(b.input); + b.outLen = WC_SHA512_224_DIGEST_SIZE; + /* + ** See page 4 in above for the 2-block test: + */ + c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" + "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + /* + ** see page 9 in above document for the 2-block test message digest: + */ + c.output = "\x23\xfe\xc5\xbb" + "\x94\xd6\x0b\x23" "\x30\x81\x92\x64" + "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73" + "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9"; + c.inLen = XSTRLEN(c.input); + c.outLen = WC_SHA512_224_DIGEST_SIZE; + + test_sha[0] = a; + test_sha[1] = b; + test_sha[2] = c; + + ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId); + if (ret != 0) { + wc_Sha512_224Free(&sha); + return WC_TEST_RET_ENC_EC(ret); + } + + for (i = 0; i < times; ++i) { + ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input, + (word32)test_sha[i].inLen); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_224GetHash(&sha, hashcopy); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_224Copy(&sha, &shaCopy); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_224Final(&sha, hash); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + wc_Sha512_224Free(&shaCopy); + + if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + + + if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + } + +#ifndef NO_LARGE_HASH_TEST + /* BEGIN LARGE HASH TEST */ { + byte large_input[1024]; +#ifdef HASH_SIZE_LIMIT + const char* large_digest = + "\x98\x68\xc3\xd9\xb9\xef\x17\x53" + "\x43\x66\x0e\x60\xdf\x29\xf8\xef" + "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb" + "\x14\x6c\xcf\x6a"; +#else + const char* large_digest = + "\x26\x5f\x98\xd1\x76\x49\x71\x4e" + "\x82\xb7\x9d\x52\x32\x67\x9d\x56" + "\x91\xf5\x88\xc3\x05\xbb\x3f\x90" + "\xe2\x4e\x85\x05"; #endif + for (i = 0; i < (int)sizeof(large_input); i++) { + large_input[i] = (byte)(i & 0xFF); + } +#ifdef HASH_SIZE_LIMIT + times = 20; +#else + times = 100; +#endif + for (i = 0; i < times; ++i) { + ret = wc_Sha512_224Update(&sha, (byte*)large_input, + (word32)sizeof(large_input)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + } + ret = wc_Sha512_224Final(&sha, hash); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); + +#ifndef NO_UNALIGNED_MEMORY_TEST + /* Unaligned memory access test */ + for (i = 1; i < 16; i++) { + ret = wc_Sha512_224Update(&sha, (byte*)large_input + i, + (word32)sizeof(large_input) - i); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + ret = wc_Sha512_224Final(&sha, hash); + } +#endif + } /* END LARGE HASH TEST */ +#endif /* NO_LARGE_HASH_TEST */ + +exit: + wc_Sha512_224Free(&sha); + wc_Sha512_224Free(&shaCopy); + + return ret; +} /* sha512_224_test */ +#endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */ + + +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + +WOLFSSL_TEST_SUBROUTINE int sha512_256_test(void) +{ + /* + ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values + ** NIST SHA512/256 Document Example: + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf + */ + wc_Sha512 sha, shaCopy; + byte hash[WC_SHA512_256_DIGEST_SIZE]; + byte hashcopy[WC_SHA512_256_DIGEST_SIZE]; + int ret = 0; + + testVector a, b, c; + testVector test_sha[3]; + int times = sizeof(test_sha) / sizeof(struct testVector), i; + + a.input = ""; + a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28" + "\xab\x87\xc3\x62" "\x2c\x51\x14\x06" + "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74" + "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a"; + a.inLen = XSTRLEN(a.input); + a.outLen = WC_SHA512_256_DIGEST_SIZE; + + /* + ** See page 1 of above document for "abc" example: + */ + b.input = "abc"; + /* + ** See page 4 of above document for "abc" example digest: + */ + b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9" + "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab" + "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46" + "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23"; + b.inLen = XSTRLEN(b.input); + b.outLen = WC_SHA512_256_DIGEST_SIZE; + + /* + ** See page 4 of above document for Two Block Message Sample: + */ + c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" + "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + /* + ** See page 10 of above document for Two Block Message Sample digest: + */ + c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8" + "\x40\xda\x39\x88" "\x12\x1d\x31\xbe" + "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14" + "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a"; + c.inLen = XSTRLEN(c.input); + c.outLen = WC_SHA512_256_DIGEST_SIZE; + + test_sha[0] = a; + test_sha[1] = b; + test_sha[2] = c; + + ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId); + if (ret != 0) { + wc_Sha512_256Free(&sha); + return WC_TEST_RET_ENC_EC(ret); + } + + for (i = 0; i < times; ++i) { + ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input, + (word32)test_sha[i].inLen); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_256GetHash(&sha, hashcopy); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_256Copy(&sha, &shaCopy); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + ret = wc_Sha512_256Final(&sha, hash); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + wc_Sha512_256Free(&shaCopy); + + if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + + + if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); + } + +#ifndef NO_LARGE_HASH_TEST + /* BEGIN LARGE HASH TEST */ { + byte large_input[1024]; +#ifdef HASH_SIZE_LIMIT + const char* large_digest = + "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8" + "\xad\x9a\x46\x51\x00\x1f\x13\x80" + "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8" + "\x41\xd4\x06\x8b\x1d\x19\xad\x72"; +#else + const char* large_digest = + "\x7a\xe3\x84\x05\xcb\x06\x22\x08" + "\x7e\x2c\x65\x89\x1f\x26\x45\xfd" + "\xad\xbc\x2e\x29\x83\x12\x84\x4b" + "\xf2\xa0\xde\xbe\x06\x11\xd7\x44"; +#endif + + for (i = 0; i < (int)sizeof(large_input); i++) { + large_input[i] = (byte)(i & 0xFF); + } +#ifdef HASH_SIZE_LIMIT + times = 20; +#else + times = 100; +#endif + for (i = 0; i < times; ++i) { + ret = wc_Sha512_256Update(&sha, (byte*)large_input, + (word32)sizeof(large_input)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + } + ret = wc_Sha512_256Final(&sha, hash); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); + +#ifndef NO_UNALIGNED_MEMORY_TEST + /* Unaligned memory access test */ + for (i = 1; i < 16; i++) { + ret = wc_Sha512_256Update(&sha, (byte*)large_input + i, + (word32)sizeof(large_input) - i); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + ret = wc_Sha512_256Final(&sha, hash); + } +#endif + } /* END LARGE HASH TEST */ +#endif /* NO_LARGE_HASH_TEST */ + +exit: + wc_Sha512_256Free(&sha); + wc_Sha512_256Free(&shaCopy); + + return ret; +} /* sha512_256_test */ +#endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */ + +#endif /* WOLFSSL_SHA512 */ + #ifdef WOLFSSL_SHA384 WOLFSSL_TEST_SUBROUTINE int sha384_test(void) @@ -3031,33 +3460,33 @@ WOLFSSL_TEST_SUBROUTINE int sha384_test(void) ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId); if (ret != 0) - return -2500; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId); if (ret != 0) { wc_Sha384Free(&sha); - return -2501; + return WC_TEST_RET_ENC_EC(ret); } for (i = 0; i < times; ++i) { ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2502 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha384GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2503 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha384Copy(&sha, &shaCopy); if (ret != 0) - ERROR_OUT(-2504 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha384Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2505 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); wc_Sha384Free(&shaCopy); if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0) - ERROR_OUT(-2506 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0) - ERROR_OUT(-2507 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -3087,13 +3516,13 @@ WOLFSSL_TEST_SUBROUTINE int sha384_test(void) ret = wc_Sha384Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2508, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha384Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2509, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0) - ERROR_OUT(-2510, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3143,24 +3572,24 @@ static int sha3_224_test(void) ret = wc_InitSha3_224(&sha, HEAP_HINT, devId); if (ret != 0) - return -2600; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2601 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_224_GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2602 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_224_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2603 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0) - ERROR_OUT(-2604 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0) - ERROR_OUT(-2605 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -3178,13 +3607,13 @@ static int sha3_224_test(void) ret = wc_Sha3_224_Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2606, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_224_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2607, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0) - ERROR_OUT(-2608, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3219,6 +3648,9 @@ static int sha3_256_test(void) "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70"; #endif + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf + */ a.input = ""; a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6" "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8" @@ -3246,24 +3678,24 @@ static int sha3_256_test(void) ret = wc_InitSha3_256(&sha, HEAP_HINT, devId); if (ret != 0) - return -2700; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2701 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_256_GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2702 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_256_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2703 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0) - ERROR_OUT(-2704 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0) - ERROR_OUT(-2705 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -3276,13 +3708,13 @@ static int sha3_256_test(void) ret = wc_Sha3_256_Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2706, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_256_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2707, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0) - ERROR_OUT(-2708, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3291,18 +3723,18 @@ static int sha3_256_test(void) /* Test for Keccak256 */ ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256); if (ret != 0) { - ERROR_OUT(-2709, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_256_Update(&sha, (byte*)"", 0); if (ret != 0) { - ERROR_OUT(-2710, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_256_Final(&sha, hash); if (ret != 0) { - ERROR_OUT(-2711, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) { - ERROR_OUT(-2712, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */ @@ -3328,6 +3760,9 @@ static int sha3_384_test(void) int ret; int times = sizeof(test_sha) / sizeof(struct testVector), i; + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf + */ a.input = ""; a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24" "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98" @@ -3373,28 +3808,28 @@ static int sha3_384_test(void) ret = wc_InitSha3_384(&sha, HEAP_HINT, devId); if (ret != 0) - return -2800; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen); ret = wc_Sha3_384_Update(&sha, buf, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2801 - (i * 10), exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); #ifndef NO_INTM_HASH_TEST ret = wc_Sha3_384_GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2802 - (i * 10), exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); #endif ret = wc_Sha3_384_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2803 - (i * 10), exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0) - ERROR_OUT(-2804 - (i * 10), exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); #ifndef NO_INTM_HASH_TEST if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0) - ERROR_OUT(-2805 - (i * 10), exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); #endif } @@ -3414,13 +3849,13 @@ static int sha3_384_test(void) ret = wc_Sha3_384_Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2806, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_384_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2807, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0) - ERROR_OUT(-2808, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3443,6 +3878,9 @@ static int sha3_512_test(void) int ret; int times = sizeof(test_sha) / sizeof(struct testVector), i; + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf + */ a.input = ""; a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75" "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c" @@ -3476,24 +3914,24 @@ static int sha3_512_test(void) ret = wc_InitSha3_512(&sha, HEAP_HINT, devId); if (ret != 0) - return -2900; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-2901 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_512_GetHash(&sha, hashcopy); if (ret != 0) - ERROR_OUT(-2902 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Sha3_512_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2903 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0) - ERROR_OUT(-2904 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0) - ERROR_OUT(-2905 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -3513,13 +3951,13 @@ static int sha3_512_test(void) ret = wc_Sha3_512_Update(&sha, (byte*)large_input, (word32)sizeof(large_input)); if (ret != 0) - ERROR_OUT(-2906, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Sha3_512_Final(&sha, hash); if (ret != 0) - ERROR_OUT(-2907, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0) - ERROR_OUT(-2908, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3558,17 +3996,15 @@ WOLFSSL_TEST_SUBROUTINE int sha3_test(void) #endif /* WOLFSSL_SHA3 */ #ifdef WOLFSSL_SHAKE128 -static int shake128_absorb_test(wc_Shake* sha) +static int shake128_absorb_test(wc_Shake* sha, byte *large_input_buf, + size_t large_input_buf_size) { - byte hash[WC_SHA3_128_BLOCK_SIZE*2]; - testVector a, b, c, d, e; testVector test_sha[5]; int ret = 0; int times = sizeof(test_sha) / sizeof(struct testVector), i; - byte large_input[1024]; - const char* large_digest = + static const char large_digest[] = "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe" "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61" "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43" @@ -3591,6 +4027,11 @@ static int shake128_absorb_test(wc_Shake* sha) "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26" "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5"; + byte hash[sizeof(large_digest) - 1]; + + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf + */ a.input = ""; a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85" "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66" @@ -3696,43 +4137,43 @@ static int shake128_absorb_test(wc_Shake* sha) for (i = 0; i < times; ++i) { ret = wc_InitShake128(sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-3100 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-3101 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake128_SqueezeBlocks(sha, hash, (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE); if (ret != 0) - ERROR_OUT(-3102 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0) - ERROR_OUT(-3103 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST /* BEGIN LARGE HASH TEST */ { - for (i = 0; i < (int)sizeof(large_input); i++) { - large_input[i] = (byte)(i & 0xFF); + for (i = 0; i < (int)large_input_buf_size; i++) { + large_input_buf[i] = (byte)(i & 0xFF); } ret = wc_InitShake128(sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-3104, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* Absorb is non-incremental. */ - ret = wc_Shake128_Absorb(sha, (byte*)large_input, - (word32)sizeof(large_input)); + ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf, + (word32)large_input_buf_size); if (ret != 0) - ERROR_OUT(-3105, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* Able to squeeze out blocks incrementally. */ ret = wc_Shake128_SqueezeBlocks(sha, hash, 1); if (ret != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Shake128_SqueezeBlocks(sha, hash, ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1); if (ret != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0) - ERROR_OUT(-3107, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -3750,8 +4191,13 @@ WOLFSSL_TEST_SUBROUTINE int shake128_test(void) int ret = 0; int times = sizeof(test_sha) / sizeof(struct testVector), i; - byte large_input[1024]; - const char* large_digest = +#define SHAKE128_LARGE_INPUT_BUFSIZ 1024 +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + byte *large_input = NULL; +#else + byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ]; +#endif + static const char large_digest[] = "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35" "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf" "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8" @@ -3761,6 +4207,10 @@ WOLFSSL_TEST_SUBROUTINE int shake128_test(void) "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa" "\xfa\x1b"; + + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf + */ a.input = ""; a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85" "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66" @@ -3845,46 +4295,58 @@ WOLFSSL_TEST_SUBROUTINE int shake128_test(void) ret = wc_InitShake128(&sha, HEAP_HINT, devId); if (ret != 0) - return -3100; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-3101 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen); if (ret != 0) - ERROR_OUT(-3102 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0) - ERROR_OUT(-3103 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (large_input == NULL) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); +#endif + #ifndef NO_LARGE_HASH_TEST /* BEGIN LARGE HASH TEST */ { - for (i = 0; i < (int)sizeof(large_input); i++) { + for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) { large_input[i] = (byte)(i & 0xFF); } times = 100; for (i = 0; i < times; ++i) { ret = wc_Shake128_Update(&sha, (byte*)large_input, - (word32)sizeof(large_input)); + SHAKE128_LARGE_INPUT_BUFSIZ); if (ret != 0) - ERROR_OUT(-3104, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash)); if (ret != 0) - ERROR_OUT(-3105, exit); - if (XMEMCMP(hash, large_digest, 114) != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); + if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ - ret = shake128_absorb_test(&sha); + ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ); exit: wc_Shake128_Free(&sha); +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + if (large_input != NULL) + XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif + return ret; } #endif @@ -3893,14 +4355,12 @@ exit: static int shake256_absorb_test(wc_Shake* sha, byte *large_input_buf, size_t large_input_buf_size) { - byte hash[WC_SHA3_256_BLOCK_SIZE*2]; - testVector a, b, c, d, e; testVector test_sha[5]; int ret = 0; int times = sizeof(test_sha) / sizeof(struct testVector), i; - const char* large_digest = + static const char large_digest[] = "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69" "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65" "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd" @@ -3919,6 +4379,11 @@ static int shake256_absorb_test(wc_Shake* sha, byte *large_input_buf, "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6" "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44"; + byte hash[sizeof(large_digest) - 1]; + + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf + */ a.input = ""; a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb" "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5" @@ -4012,18 +4477,18 @@ static int shake256_absorb_test(wc_Shake* sha, byte *large_input_buf, for (i = 0; i < times; ++i) { ret = wc_InitShake256(sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-3100 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-3101 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake256_SqueezeBlocks(sha, hash, (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE); if (ret != 0) - ERROR_OUT(-3102 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0) - ERROR_OUT(-3103 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #ifndef NO_LARGE_HASH_TEST @@ -4033,22 +4498,22 @@ static int shake256_absorb_test(wc_Shake* sha, byte *large_input_buf, } ret = wc_InitShake256(sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-3104, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* Absorb is non-incremental. */ ret = wc_Shake256_Absorb(sha, large_input_buf, (word32)large_input_buf_size); if (ret != 0) - ERROR_OUT(-3105, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* Able to squeeze out blocks incrementally. */ ret = wc_Shake256_SqueezeBlocks(sha, hash, 1); if (ret != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_Shake256_SqueezeBlocks(sha, hash, ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1); if (ret != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0) - ERROR_OUT(-3107, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -4081,7 +4546,9 @@ WOLFSSL_TEST_SUBROUTINE int shake256_test(void) "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38" "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9" "\xea\x26"; - + /* + ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf + */ a.input = ""; a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb" "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5" @@ -4166,26 +4633,26 @@ WOLFSSL_TEST_SUBROUTINE int shake256_test(void) ret = wc_InitShake256(&sha, HEAP_HINT, devId); if (ret != 0) - return -3100; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < times; ++i) { ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen); if (ret != 0) - ERROR_OUT(-3101 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen); if (ret != 0) - ERROR_OUT(-3102 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0) - ERROR_OUT(-3103 - i, exit); + ERROR_OUT(WC_TEST_RET_ENC_I(i), exit); } #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (large_input == NULL) - ERROR_OUT(-3107, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); #endif #ifndef NO_LARGE_HASH_TEST @@ -4198,13 +4665,13 @@ WOLFSSL_TEST_SUBROUTINE int shake256_test(void) ret = wc_Shake256_Update(&sha, (byte*)large_input, SHAKE256_LARGE_INPUT_BUFSIZ); if (ret != 0) - ERROR_OUT(-3104, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash)); if (ret != 0) - ERROR_OUT(-3105, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(hash, large_digest, 114) != 0) - ERROR_OUT(-3106, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* END LARGE HASH TEST */ #endif /* NO_LARGE_HASH_TEST */ @@ -4283,37 +4750,37 @@ WOLFSSL_TEST_SUBROUTINE int hash_test(void) /* Parameter Validation testing. */ ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256); if (ret != BAD_FUNC_ARG) - return -3200; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data)); if (ret != BAD_FUNC_ARG) - return -3201; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashUpdate(&hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data)); if (ret != BAD_FUNC_ARG) - return -3202; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data)); if (ret != BAD_FUNC_ARG) - return -3203; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL); if (ret != BAD_FUNC_ARG) - return -3204; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashFinal(&hash, WC_HASH_TYPE_SHA256, NULL); if (ret != BAD_FUNC_ARG) - return -3205; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out); if (ret != BAD_FUNC_ARG) - return -3206; + return WC_TEST_RET_ENC_EC(ret); /* Try invalid hash algorithms. */ for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) { ret = wc_HashInit(&hash, typesBad[i]); if (ret != BAD_FUNC_ARG) - return -3207 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_HashUpdate(&hash, typesBad[i], data, sizeof(data)); if (ret != BAD_FUNC_ARG) - return -3217 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_HashFinal(&hash, typesBad[i], out); if (ret != BAD_FUNC_ARG) - return -3227 - i; + return WC_TEST_RET_ENC_I(i); wc_HashFree(&hash, typesBad[i]); } @@ -4327,201 +4794,201 @@ WOLFSSL_TEST_SUBROUTINE int hash_test(void) } ret = wc_HashInit(&hash, typesGood[i]); if (ret != exp_ret) - return -3237 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_HashUpdate(&hash, typesGood[i], data, sizeof(data)); if (ret != exp_ret) - return -3247 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_HashFinal(&hash, typesGood[i], out); if (ret != exp_ret) - return -3257 - i; + return WC_TEST_RET_ENC_I(i); wc_HashFree(&hash, typesGood[i]); digestSz = wc_HashGetDigestSize(typesGood[i]); if (exp_ret < 0 && digestSz != exp_ret) - return -3267 - i; + return WC_TEST_RET_ENC_I(i); if (exp_ret == 0 && digestSz < 0) - return -3277 - i; + return WC_TEST_RET_ENC_I(i); if (exp_ret == 0) { ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, digestSz - 1); if (ret != BUFFER_E) - return -3287 - i; + return WC_TEST_RET_ENC_I(i); } ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, digestSz); if (ret != exp_ret) - return -3297 - i; + return WC_TEST_RET_ENC_I(i); if (exp_ret == 0 && XMEMCMP(out, hashOut, digestSz) != 0) - return -3307 -i; + return WC_TEST_RET_ENC_I(i); ret = wc_HashGetBlockSize(typesGood[i]); if (exp_ret < 0 && ret != exp_ret) - return -3308 - i; + return WC_TEST_RET_ENC_I(i); if (exp_ret == 0 && ret < 0) - return -3318 - i; + return WC_TEST_RET_ENC_I(i); #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) ret = wc_HashGetOID(typesGood[i]); if (ret == BAD_FUNC_ARG || (exp_ret == 0 && ret == HASH_TYPE_E) || (exp_ret != 0 && ret != HASH_TYPE_E)) { - return -3328 - i; + return WC_TEST_RET_ENC_I(i); } hashType = wc_OidGetHash(ret); if (exp_ret == 0 && hashType != typesGood[i]) - return -3338 - i; + return WC_TEST_RET_ENC_I(i); #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */ } for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) { ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out)); if (ret != BAD_FUNC_ARG && ret != BUFFER_E) - return -3348 - i; + return WC_TEST_RET_ENC_I(i); } #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) ret = wc_HashGetOID(WC_HASH_TYPE_MD2); #ifdef WOLFSSL_MD2 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3358; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3359; + return WC_TEST_RET_ENC_EC(ret); #endif hashType = wc_OidGetHash(646); /* Md2h */ #ifdef WOLFSSL_MD2 if (hashType != WC_HASH_TYPE_MD2) - return -3360; + return WC_TEST_RET_ENC_NC; #else if (hashType != WC_HASH_TYPE_NONE) - return -3361; + return WC_TEST_RET_ENC_NC; #endif ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA); #ifndef NO_MD5 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3362; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3363; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetOID(WC_HASH_TYPE_MD4); if (ret != BAD_FUNC_ARG) - return -3364; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashGetOID(WC_HASH_TYPE_NONE); if (ret != BAD_FUNC_ARG) - return -3365; + return WC_TEST_RET_ENC_EC(ret); hashType = wc_OidGetHash(0); if (hashType != WC_HASH_TYPE_NONE) - return -3366; + return WC_TEST_RET_ENC_NC; #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */ ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2); #ifdef WOLFSSL_MD2 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3367; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3368; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2); #ifdef WOLFSSL_MD2 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3369; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3370; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4); #ifndef NO_MD4 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3371; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3372; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4); #ifndef NO_MD4 if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3373; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3374; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA); #if !defined(NO_MD5) && !defined(NO_SHA) if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3375; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3376; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B); #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S) if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3377; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3378; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B); #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S) if (ret == HASH_TYPE_E || ret == BAD_FUNC_ARG) - return -3379; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != HASH_TYPE_E) - return -3380; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE); if (ret != BAD_FUNC_ARG) - return -3381; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE); if (ret != BAD_FUNC_ARG) - return -3382; + return WC_TEST_RET_ENC_EC(ret); #if !defined(NO_CERTS) && !defined(NO_ASN) #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) ret = wc_GetCTC_HashOID(MD2); if (ret == 0) - return -3383; + return WC_TEST_RET_ENC_EC(ret); #endif #ifndef NO_MD5 ret = wc_GetCTC_HashOID(WC_MD5); if (ret == 0) - return -3384; + return WC_TEST_RET_ENC_EC(ret); #endif #ifndef NO_SHA ret = wc_GetCTC_HashOID(WC_SHA); if (ret == 0) - return -3385; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SHA224 ret = wc_GetCTC_HashOID(WC_SHA224); if (ret == 0) - return -3386; + return WC_TEST_RET_ENC_EC(ret); #endif #ifndef NO_SHA256 ret = wc_GetCTC_HashOID(WC_SHA256); if (ret == 0) - return -3387; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SHA384 ret = wc_GetCTC_HashOID(WC_SHA384); if (ret == 0) - return -3388; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SHA512 ret = wc_GetCTC_HashOID(WC_SHA512); if (ret == 0) - return -3389; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_GetCTC_HashOID(-1); if (ret != 0) - return -3390; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -4581,31 +5048,31 @@ WOLFSSL_TEST_SUBROUTINE int hmac_md5_test(void) } #endif - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) { - return -3400; - } + ret = wc_HmacInit(&hmac, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3401; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3402; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3403; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0) - return -3404 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_MD5) != WC_MD5_DIGEST_SIZE) - return -3414; + if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -4664,30 +5131,30 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha_test(void) continue; /* cavium can't handle short keys, fips not allowed */ #endif - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -3500; + if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3501; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3502; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3503; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0) - return -3504 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_SHA) != WC_SHA_DIGEST_SIZE) - return -3514; + if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -4759,30 +5226,30 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha224_test(void) continue; /* cavium can't handle short keys, fips not allowed */ #endif - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -3600; + if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3601; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3602; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3603; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0) - return -3604 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_SHA224) != WC_SHA224_DIGEST_SIZE) - return -3614; + if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -4860,36 +5327,36 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha256_test(void) #endif if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -3700 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3710 - i; + return WC_TEST_RET_ENC_I(i); if (test_hmac[i].input != NULL) { ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3720 - i; + return WC_TEST_RET_ENC_I(i); } ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3730 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0) - return -3740 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_SHA256) != WC_SHA256_DIGEST_SIZE) - return -3750; - if (wc_HmacSizeByType(20) != BAD_FUNC_ARG) - return -3751; + if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); + if ((ret = wc_HmacSizeByType(20)) != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); #endif - if (wolfSSL_GetHmacMaxSize() != WC_MAX_DIGEST_SIZE) - return -3752; + if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -4972,30 +5439,30 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha384_test(void) continue; /* fips not allowed */ #endif - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -3800; + if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3801; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3802; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3803; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0) - return -3804 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_SHA384) != WC_SHA384_DIGEST_SIZE) - return -3814; + if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -5083,30 +5550,30 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha512_test(void) continue; /* fips not allowed */ #endif - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -3900; + if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i], (word32)XSTRLEN(keys[i])); if (ret != 0) - return -3901; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, (word32)test_hmac[i].inLen); if (ret != 0) - return -3902; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -3903; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0) - return -3904 - i; + return WC_TEST_RET_ENC_I(i); wc_HmacFree(&hmac); } #ifndef HAVE_FIPS - if (wc_HmacSizeByType(WC_SHA512) != WC_SHA512_DIGEST_SIZE) - return -3914; + if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE) + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -5253,22 +5720,22 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha3_test(void) #endif for (; i < iMax; i++) { for (j = 0; j < jMax; j++) { - if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0) - return -4000; + if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0) + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i], (word32)XSTRLEN(key[i])); if (ret != 0) - return -4001; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacUpdate(&hmac, (byte*)input[i], (word32)XSTRLEN(input[i])); if (ret != 0) - return -4002; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HmacFinal(&hmac, hash); if (ret != 0) - return -4003; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(hash, output[(i*jMax) + j], hashSz[j]) != 0) - return -4004; + return WC_TEST_RET_ENC_NC; wc_HmacFree(&hmac); @@ -5278,7 +5745,7 @@ WOLFSSL_TEST_SUBROUTINE int hmac_sha3_test(void) #ifndef HAVE_FIPS ret = wc_HmacSizeByType(hashType[j]); if (ret != hashSz[j]) - return -4005; + return WC_TEST_RET_ENC_EC(ret); #endif } } @@ -5401,28 +5868,28 @@ static int rc2_ecb_test(void) ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen, NULL, test_rc2[i].effectiveKeyBits); if (ret != 0) { - return -4100; + return WC_TEST_RET_ENC_EC(ret); } /* ECB encrypt */ ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input, (word32)test_rc2[i].outLen); if (ret != 0) { - return -4101; + return WC_TEST_RET_ENC_EC(ret); } if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) { - return -4102; + return WC_TEST_RET_ENC_NC; } /* ECB decrypt */ ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE); if (ret != 0) { - return -4103; + return WC_TEST_RET_ENC_EC(ret); } if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) { - return -4104; + return WC_TEST_RET_ENC_NC; } } @@ -5578,32 +6045,32 @@ static int rc2_cbc_test(void) ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen, (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits); if (ret != 0) { - return -4200; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input, test_rc2[j].inLen); if (ret != 0) { - return -4201; + return WC_TEST_RET_ENC_EC(ret); } if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) { - return -4202; + return WC_TEST_RET_ENC_NC; } /* reset IV for decrypt, since overriden by encrypt operation */ ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv); if (ret != 0) { - return -4203; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen); if (ret != 0) { - return -4204; + return WC_TEST_RET_ENC_EC(ret); } if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) { - return -4205; + return WC_TEST_RET_ENC_NC; } } @@ -5629,6 +6096,7 @@ WOLFSSL_TEST_SUBROUTINE int arc4_test(void) { byte cipher[16]; byte plain[16]; + int ret; const char* keys[] = { @@ -5675,23 +6143,33 @@ WOLFSSL_TEST_SUBROUTINE int arc4_test(void) if (i == 3) keylen = 4; - if (wc_Arc4Init(&enc, HEAP_HINT, devId) != 0) - return -4400; - if (wc_Arc4Init(&dec, HEAP_HINT, devId) != 0) - return -4401; + ret = wc_Arc4Init(&enc, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_Arc4Init(&dec, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - wc_Arc4SetKey(&enc, (byte*)keys[i], keylen); - wc_Arc4SetKey(&dec, (byte*)keys[i], keylen); + ret = wc_Arc4SetKey(&enc, (byte*)keys[i], keylen); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_Arc4SetKey(&dec, (byte*)keys[i], keylen); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input, + ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input, (word32)test_arc4[i].outLen); - wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen)) - return -4402 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen)) - return -4412 - i; + return WC_TEST_RET_ENC_I(i); wc_Arc4Free(&enc); wc_Arc4Free(&dec); @@ -5946,10 +6424,10 @@ WOLFSSL_TEST_SUBROUTINE int chacha_test(void) return ret; if (XMEMCMP(test_chacha[i], cipher, 8)) - return -4700 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(plain, input, 8)) - return -4710 - i; + return WC_TEST_RET_ENC_I(i); } /* test of starting at a different counter @@ -5975,7 +6453,7 @@ WOLFSSL_TEST_SUBROUTINE int chacha_test(void) return ret; if (XMEMCMP(plain + 64, sliver, 64)) - return -4720; + return WC_TEST_RET_ENC_NC; #ifndef BENCH_EMBEDDED /* test of encrypting more data */ @@ -5998,10 +6476,10 @@ WOLFSSL_TEST_SUBROUTINE int chacha_test(void) return ret; if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE)) - return -4721; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE)) - return -4722; + return WC_TEST_RET_ENC_NC; for (i = 0; i < 18; ++i) { /* this will test all paths @@ -6027,10 +6505,10 @@ WOLFSSL_TEST_SUBROUTINE int chacha_test(void) return ret; if (XMEMCMP(plain_big, input_big, block_size)) - return -4740-i*2; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(cipher_big, cipher_big_result, block_size)) - return -4741-i*2; + return WC_TEST_RET_ENC_I(i); } /* Streaming test */ @@ -6039,40 +6517,40 @@ WOLFSSL_TEST_SUBROUTINE int chacha_test(void) ret = wc_Chacha_SetKey(&enc, keys[0], keySz); if (ret != 0) - return -4725; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Chacha_SetKey(&dec, keys[0], keySz); if (ret != 0) - return -4726; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Chacha_SetIV(&enc, ivs[2], 0); if (ret != 0) - return -4727; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Chacha_SetIV(&dec, ivs[2], 0); if (ret != 0) - return -4728; + return WC_TEST_RET_ENC_EC(ret); for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) { ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, i); if (ret != 0) - return -4729; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, i); if (ret != 0) - return -4730; + return WC_TEST_RET_ENC_EC(ret); } rem = CHACHA_BIG_TEST_SIZE - j; ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, rem); if (ret != 0) - return -4731; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, rem); if (ret != 0) - return -4732; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE)) - return -4733; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE)) - return -4734; + return WC_TEST_RET_ENC_NC; } #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -6253,33 +6731,33 @@ WOLFSSL_TEST_SUBROUTINE int poly1305_test(void) for (i = 0; i < 6; i++) { ret = wc_Poly1305SetKey(&enc, keys[i], 32); if (ret != 0) - return -4800 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_Poly1305Update(&enc, msgs[i], szm[i]); if (ret != 0) - return -4810 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_Poly1305Final(&enc, tag); if (ret != 0) - return -4820 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(tag, tests[i], sizeof(tag))) - return -4830 - i; + return WC_TEST_RET_ENC_I(i); } /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */ XMEMSET(tag, 0, sizeof(tag)); ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4)); if (ret != 0) - return -4840; + return WC_TEST_RET_ENC_EC(ret); ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional), (byte*)msg4, sizeof(msg4), tag, sizeof(tag)); if (ret != 0) - return -4841; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(tag, correct4, sizeof(tag))) - return -4842; + return WC_TEST_RET_ENC_NC; /* Check fail of TLS MAC function if altering additional data */ XMEMSET(tag, 0, sizeof(tag)); @@ -6287,10 +6765,10 @@ WOLFSSL_TEST_SUBROUTINE int poly1305_test(void) ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional), (byte*)msg4, sizeof(msg4), tag, sizeof(tag)); if (ret != 0) - return -4843; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(tag, correct4, sizeof(tag)) == 0) - return -4844; + return WC_TEST_RET_ENC_NC; return 0; @@ -6486,53 +6964,53 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1, sizeof(plaintext1), generatedCiphertext, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4900; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1), plaintext1, sizeof(plaintext1), generatedCiphertext, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4901; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL, sizeof(plaintext1), generatedCiphertext, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4902; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1, sizeof(plaintext1), NULL, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4903; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1, sizeof(plaintext1), generatedCiphertext, NULL); if (err != BAD_FUNC_ARG) - return -4904; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL, sizeof(plaintext1), generatedCiphertext, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4905; + return WC_TEST_RET_ENC_EC(err); /* Decrypt */ err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2, sizeof(cipher2), authTag2, generatedPlaintext); if (err != BAD_FUNC_ARG) - return -4906; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2, sizeof(cipher2), authTag2, generatedPlaintext); if (err != BAD_FUNC_ARG) - return -4907; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL, sizeof(cipher2), authTag2, generatedPlaintext); if (err != BAD_FUNC_ARG) - return -4908; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2, sizeof(cipher2), NULL, generatedPlaintext); if (err != BAD_FUNC_ARG) - return -4909; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2, sizeof(cipher2), authTag2, NULL); if (err != BAD_FUNC_ARG) - return -4910; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL, sizeof(cipher2), authTag2, generatedPlaintext); if (err != BAD_FUNC_ARG) - return -4911; + return WC_TEST_RET_ENC_EC(err); /* Test #1 */ @@ -6541,15 +7019,15 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) plaintext1, sizeof(plaintext1), generatedCiphertext, generatedAuthTag); if (err) { - return err; + return WC_TEST_RET_ENC_EC(err); } /* -- Check the ciphertext and authtag */ if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) { - return -4912; + return WC_TEST_RET_ENC_NC; } if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) { - return -4913; + return WC_TEST_RET_ENC_NC; } /* -- Verify decryption works */ @@ -6561,7 +7039,7 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) return err; } if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) { - return -4914; + return WC_TEST_RET_ENC_NC; } @@ -6580,10 +7058,10 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) /* -- Check the ciphertext and authtag */ if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) { - return -4915; + return WC_TEST_RET_ENC_NC; } if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) { - return -4916; + return WC_TEST_RET_ENC_NC; } /* -- Verify decryption works */ @@ -6596,7 +7074,7 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) } if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) { - return -4917; + return WC_TEST_RET_ENC_NC; } @@ -6604,39 +7082,39 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1, CHACHA20_POLY1305_AEAD_DECRYPT); if (err != BAD_FUNC_ARG) - return -4918; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1, CHACHA20_POLY1305_AEAD_DECRYPT); if (err != BAD_FUNC_ARG) - return -4919; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL, CHACHA20_POLY1305_AEAD_DECRYPT); if (err != BAD_FUNC_ARG) - return -4920; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1)); if (err != BAD_FUNC_ARG) - return -4921; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1)); if (err != BAD_FUNC_ARG) - return -4922; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext, generatedPlaintext, sizeof(plaintext1)); if (err != BAD_FUNC_ARG) - return -4923; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL, sizeof(plaintext1)); if (err != BAD_FUNC_ARG) - return -4924; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext, sizeof(plaintext1)); if (err != BAD_FUNC_ARG) - return -4925; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag); if (err != BAD_FUNC_ARG) - return -4926; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_Final(&aead, NULL); if (err != BAD_FUNC_ARG) - return -4927; + return WC_TEST_RET_ENC_EC(err); /* AEAD init/update/final - bad state tests */ /* clear struct - make valgrind happy to resolve @@ -6647,24 +7125,24 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) aead.state = CHACHA20_POLY1305_STATE_INIT; err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1)); if (err != BAD_STATE_E) - return -4928; + return WC_TEST_RET_ENC_EC(err); aead.state = CHACHA20_POLY1305_STATE_DATA; err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1)); if (err != BAD_STATE_E) - return -4929; + return WC_TEST_RET_ENC_EC(err); aead.state = CHACHA20_POLY1305_STATE_INIT; err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, generatedPlaintext, sizeof(plaintext1)); if (err != BAD_STATE_E) - return -4930; + return WC_TEST_RET_ENC_EC(err); aead.state = CHACHA20_POLY1305_STATE_INIT; err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag); if (err != BAD_STATE_E) - return -4931; + return WC_TEST_RET_ENC_EC(err); aead.state = CHACHA20_POLY1305_STATE_READY; err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag); if (err != BAD_STATE_E) - return -4932; + return WC_TEST_RET_ENC_EC(err); XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext)); XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag)); @@ -6674,10 +7152,10 @@ WOLFSSL_TEST_SUBROUTINE int chacha20_poly1305_aead_test(void) err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1, CHACHA20_POLY1305_AEAD_ENCRYPT); if (err != 0) - return -4933; + return WC_TEST_RET_ENC_EC(err); err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1)); if (err != 0) - return -4934; + return WC_TEST_RET_ENC_EC(err); #ifdef TEST_SMALL_CHACHA_CHUNKS /* test doing data in smaller chunks */ for (testLen=0; testLenrounds */ @@ -8360,7 +8849,7 @@ static int aes_key_size_test(void) aes->rounds = 16; ret = wc_AesGetKeySize(aes, &keySize); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-5308, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif #endif @@ -8370,11 +8859,11 @@ static int aes_key_size_test(void) #else if (ret != BAD_FUNC_ARG) #endif - ERROR_OUT(-5309, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128) ret = wc_AesGetKeySize(aes, &keySize); if (ret != 0 || keySize != sizeof(key16)) - ERROR_OUT(-5310, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif #ifndef WOLFSSL_CRYPTOCELL /* Cryptocell only supports AES-128 key size */ @@ -8384,11 +8873,11 @@ static int aes_key_size_test(void) #else if (ret != BAD_FUNC_ARG) #endif - ERROR_OUT(-5311, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192) ret = wc_AesGetKeySize(aes, &keySize); if (ret != 0 || keySize != sizeof(key24)) - ERROR_OUT(-5312, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION); @@ -8397,11 +8886,11 @@ static int aes_key_size_test(void) #else if (ret != BAD_FUNC_ARG) #endif - ERROR_OUT(-5313, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256) ret = wc_AesGetKeySize(aes, &keySize); if (ret != 0 || keySize != sizeof(key32)) - ERROR_OUT(-5314, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif #endif /* !WOLFSSL_CRYPTOCELL */ ret = 0; /* success */ @@ -8427,8 +8916,8 @@ static int aes_xts_128_test(void) #endif int aes_inited = 0; int ret = 0; - unsigned char buf[AES_BLOCK_SIZE * 2]; - unsigned char cipher[AES_BLOCK_SIZE * 2]; + unsigned char buf[AES_BLOCK_SIZE * 2 + 8]; + unsigned char cipher[AES_BLOCK_SIZE * 2 + 8]; /* 128 key tests */ WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = { @@ -8486,9 +8975,38 @@ static int aes_xts_128_test(void) 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22 }; +#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3) + + WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = { + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + }; + WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = { + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + }; + WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = { + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 + }; + WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = { + 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23, + 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12, + 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36, + 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF, + 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD + }; + +#endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-5417, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \ @@ -8501,9 +9019,10 @@ static int aes_xts_128_test(void) #endif XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5400, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; @@ -8512,24 +9031,25 @@ static int aes_xts_128_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5401, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, buf, sizeof(c2))) - ERROR_OUT(-5402, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); XMEMSET(buf, 0, sizeof(buf)); wc_AesXtsFree(aes); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5403, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5404, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5405, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* partial block encryption test */ XMEMSET(cipher, 0, sizeof(cipher)); @@ -8538,22 +9058,23 @@ static int aes_xts_128_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5406, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_AesXtsFree(aes); /* partial block decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5407, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5408, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(pp, buf, sizeof(pp))) - ERROR_OUT(-5409, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* NIST decrypt test vector */ XMEMSET(buf, 0, sizeof(buf)); @@ -8562,9 +9083,9 @@ static int aes_xts_128_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5410, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5411, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* fail case with decrypting using wrong key */ XMEMSET(buf, 0, sizeof(buf)); @@ -8573,25 +9094,65 @@ static int aes_xts_128_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5412, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */ - ERROR_OUT(-5413, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); /* set correct key and retest */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5414, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5415, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p2, buf, sizeof(p2))) - ERROR_OUT(-5416, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + wc_AesXtsFree(aes); + +#if !defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3) + + /* Test ciphertext stealing in-place. */ + XMEMCPY(buf, p3, sizeof(p3)); + ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + else + aes_inited = 1; + + ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(c3, buf, sizeof(c3))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + + wc_AesXtsFree(aes); + + ret = wc_AesXtsSetKey(aes, k3, sizeof(k3), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3)); +#if defined(WOLFSSL_ASYNC_CRYPT) + ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); +#endif + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + if (XMEMCMP(p3, buf, sizeof(p3))) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + +#endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ out: @@ -8695,7 +9256,7 @@ static int aes_xts_256_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-5515, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \ @@ -8708,9 +9269,10 @@ static int aes_xts_256_test(void) #endif XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5500, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2)); @@ -8718,23 +9280,24 @@ static int aes_xts_256_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5501, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, buf, sizeof(c2))) - ERROR_OUT(-5502, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5503, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5504, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5505, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* partial block encryption test */ XMEMSET(cipher, 0, sizeof(cipher)); @@ -8743,22 +9306,23 @@ static int aes_xts_256_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5506, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_AesXtsFree(aes); /* partial block decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5507, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5508, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(pp, buf, sizeof(pp))) - ERROR_OUT(-5509, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* NIST decrypt test vector */ XMEMSET(buf, 0, sizeof(buf)); @@ -8767,23 +9331,24 @@ static int aes_xts_256_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5510, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5511, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5512, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2)); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5513, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p2, buf, sizeof(p2))) - ERROR_OUT(-5514, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); out: @@ -8861,13 +9426,14 @@ static int aes_xts_sector_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-5612, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5600, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1); @@ -8875,54 +9441,57 @@ static int aes_xts_sector_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5601, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5602, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); /* decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5603, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5604, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p1, buf, AES_BLOCK_SIZE)) - ERROR_OUT(-5605, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); /* 256 bit key tests */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5606, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5607, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, buf, sizeof(c2))) - ERROR_OUT(-5608, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); /* decrypt test */ XMEMSET(buf, 0, sizeof(buf)); - if (wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5609, out); + ret = wc_AesXtsSetKey(aes, k2, sizeof(k2), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5610, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p2, buf, sizeof(p2))) - ERROR_OUT(-5611, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); out: @@ -8973,20 +9542,21 @@ static int aes_xts_args_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-5708, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif if (wc_AesXtsSetKey(NULL, k1, sizeof(k1), AES_ENCRYPTION, HEAP_HINT, devId) == 0) - ERROR_OUT(-5700, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (wc_AesXtsSetKey(aes, NULL, sizeof(k1), AES_ENCRYPTION, HEAP_HINT, devId) == 0) - ERROR_OUT(-5701, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* encryption operations */ - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5702, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else aes_inited = 1; ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1); @@ -8994,33 +9564,34 @@ static int aes_xts_args_test(void) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret == 0) - ERROR_OUT(-5703, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret == 0) - ERROR_OUT(-5704, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesXtsFree(aes); /* decryption operations */ - if (wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, - HEAP_HINT, devId) != 0) - ERROR_OUT(-5705, out); + ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION, + HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret == 0) - ERROR_OUT(-5706, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret == 0) - ERROR_OUT(-5707, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = 0; @@ -9059,24 +9630,24 @@ static int aes_cbc_test(void) /* Parameter Validation testing. */ ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL); if (ret != BAD_FUNC_ARG) - return -5800; + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_AES_DECRYPT ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL); if (ret != BAD_FUNC_ARG) - return -5801; + return WC_TEST_RET_ENC_EC(ret); #endif ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, AES_BLOCK_SIZE, iv); if (ret != 0) - return -5802; + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_AES_DECRYPT ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, AES_BLOCK_SIZE, iv); if (ret != 0) - return -5803; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0) - return -5804; + return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ (void)plain; @@ -9092,6 +9663,7 @@ static int aesecb_test(void) #else Aes enc[1]; #endif + int enc_inited = 0; byte cipher[AES_BLOCK_SIZE * 4]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -9099,6 +9671,7 @@ static int aesecb_test(void) #else Aes dec[1]; #endif + int dec_inited = 0; byte plain [AES_BLOCK_SIZE * 4]; #endif /* HAVE_AES_DECRYPT */ int ret = 0; @@ -9125,47 +9698,61 @@ static int aesecb_test(void) 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 }; - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) - ERROR_OUT(-5900, out); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + enc_inited = 1; #if defined(HAVE_AES_DECRYPT) - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) - ERROR_OUT(-5901, out); + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + dec_inited = 1; #endif XMEMSET(cipher, 0, AES_BLOCK_SIZE); ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-5923, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5924, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5925, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-5926, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5927, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE); if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5928, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } - wc_AesFree(enc); -#ifdef HAVE_AES_DECRYPT - wc_AesFree(dec); -#endif out: #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - if (enc) + if (enc) { + if (enc_inited) + wc_AesFree(enc); XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); + } #ifdef HAVE_AES_DECRYPT - if (dec) + if (dec) { + if (dec_inited) + wc_AesFree(dec); XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES); + } +#endif +#else + if (enc_inited) + wc_AesFree(enc); +#ifdef HAVE_AES_DECRYPT + if (dec_inited) + wc_AesFree(dec); #endif #endif + #endif /* WOLFSSL_AES_256 */ return ret; @@ -9175,7 +9762,7 @@ static int aesecb_test(void) #ifdef WOLFSSL_AES_COUNTER static int aesctr_test(Aes* enc, Aes* dec, byte* cipher, byte* plain) { - int ret; + int ret = 0; /* test vectors from "Recommendation for Block Cipher Modes of * Operation" NIST Special Publication 800-38A */ @@ -9743,31 +10330,31 @@ static int aesctr_test(Aes* enc, Aes* dec, byte* cipher, byte* plain) ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv, AES_ENCRYPTION); if (ret != 0) { - ERROR_OUT(-5930 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } /* Ctr only uses encrypt, even on key setup */ ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv, AES_ENCRYPTION); if (ret != 0) { - ERROR_OUT(-5931 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(i), out); } } ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len); if (ret != 0) { - ERROR_OUT(-5932 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len); if (ret != 0) { - ERROR_OUT(-5933 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } if (XMEMCMP(plain, ctrPlain, testVec[i].len)) { - ERROR_OUT(-5934 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM)) if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) { - ERROR_OUT(-5935 - i * 10, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } #endif } @@ -9786,6 +10373,7 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) #else Aes enc[1]; #endif + int enc_inited = 0; byte cipher[AES_BLOCK_SIZE * 4]; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -9793,6 +10381,7 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) #else Aes dec[1]; #endif + int dec_inited = 0; byte plain [AES_BLOCK_SIZE * 4]; #endif /* HAVE_AES_DECRYPT */ #endif /* HAVE_AES_CBC || WOLFSSL_AES_COUNTER || WOLFSSL_AES_DIRECT */ @@ -9818,28 +10407,32 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT) if (enc == NULL) - ERROR_OUT(-5990, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT) if (dec == NULL) - ERROR_OUT(-5991, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #endif - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) - ERROR_OUT(-5900, out); /* note this error code is used programmatically in cleanup. */ + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + enc_inited = 1; #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER) - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) - ERROR_OUT(-5901, out); /* note this error code is used programmatically in cleanup. */ + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + dec_inited = 1; #endif ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-5902, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER) ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-5903, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4); @@ -9848,7 +10441,7 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5904, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT XMEMSET(plain, 0, AES_BLOCK_SIZE * 4); ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE); @@ -9856,13 +10449,13 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5905, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - ERROR_OUT(-5906, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - ERROR_OUT(-5907, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* WOLFSSL_AES_128 */ #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT) @@ -9928,7 +10521,7 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) (bigPlain == NULL)) { if (bigCipher != NULL) XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ERROR_OUT(-5992, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #else byte bigCipher[sizeof(bigMsg)]; @@ -9946,12 +10539,12 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) XMEMSET(bigPlain, 0, sizeof(bigMsg)); ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION); if (ret != 0) { - ret = -5908; + ret = WC_TEST_RET_ENC_EC(ret); break; } ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION); if (ret != 0) { - ret = -5909; + ret = WC_TEST_RET_ENC_EC(ret); break; } @@ -9960,7 +10553,7 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { - ret = -5910; + ret = WC_TEST_RET_ENC_EC(ret); break; } @@ -9969,12 +10562,12 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { - ret = -5911; + ret = WC_TEST_RET_ENC_EC(ret); break; } if (XMEMCMP(bigPlain, bigMsg, msgSz)) { - ret = -5912; + ret = WC_TEST_RET_ENC_NC; break; } } @@ -10025,16 +10618,16 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-5913, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2); ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5914, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE)) - ERROR_OUT(-5915, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); @@ -10042,24 +10635,24 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5916, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE)) - ERROR_OUT(-5917, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if defined(HAVE_AES_DECRYPT) ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-5918, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); XMEMSET(plain, 0, AES_BLOCK_SIZE * 2); ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5919, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE)) - ERROR_OUT(-5920, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE); @@ -10067,10 +10660,10 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-5921, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE)) - ERROR_OUT(-5922, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ } @@ -10108,34 +10701,36 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) XMEMSET(cipher, 0, AES_BLOCK_SIZE); ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-5994, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(HAVE_SELFTEST) && \ (defined(WOLFSSL_LINUXKM) || \ !defined(HAVE_FIPS) || \ (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))) - if (wc_AesEncryptDirect(enc, cipher, niPlain) != 0) - ERROR_OUT(-5995, out); + ret = wc_AesEncryptDirect(enc, cipher, niPlain); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #else wc_AesEncryptDirect(enc, cipher, niPlain); #endif if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5996, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-5997, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(HAVE_SELFTEST) && \ (defined(WOLFSSL_LINUXKM) || \ !defined(HAVE_FIPS) || \ (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))) - if (wc_AesDecryptDirect(dec, plain, niCipher) != 0) - ERROR_OUT(-5998, out); + ret = wc_AesDecryptDirect(dec, plain, niCipher); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #else wc_AesDecryptDirect(dec, plain, niCipher); #endif if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-5999, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */ @@ -10198,29 +10793,24 @@ WOLFSSL_TEST_SUBROUTINE int aes_test(void) #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (enc) { - if (ret != -5900) /* note this must match ERRROR_OUT() code - * for wc_AesInit(enc, ...) failure above. - */ + if (enc_inited) wc_AesFree(enc); XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); } #else - if (ret != -5900) + if (enc_inited) wc_AesFree(enc); #endif (void)cipher; #ifdef HAVE_AES_DECRYPT #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (dec) { - if ((ret != -5900) && (ret != -5901)) - /* note these codes must match the ERRROR_OUT() codes for - * wc_AesInit() failures above. - */ + if (dec_inited) wc_AesFree(dec); XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES); } #else - if ((ret != -5900) && (ret != -5901)) + if (dec_inited) wc_AesFree(dec); #endif (void)plain; @@ -10278,27 +10868,29 @@ WOLFSSL_TEST_SUBROUTINE int aes192_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6008, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #ifdef HAVE_AES_DECRYPT if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6009, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #endif - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) - ERROR_OUT(-6000, out); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) - ERROR_OUT(-6001, out); + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-6002, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-6003, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif XMEMSET(cipher, 0, AES_BLOCK_SIZE); @@ -10307,7 +10899,7 @@ WOLFSSL_TEST_SUBROUTINE int aes192_test(void) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-6004, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); @@ -10315,14 +10907,14 @@ WOLFSSL_TEST_SUBROUTINE int aes192_test(void) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-6005, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(plain, msg, (int) sizeof(plain))) { - ERROR_OUT(-6006, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) - ERROR_OUT(-6007, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesFree(enc); #ifdef HAVE_AES_DECRYPT @@ -10392,27 +10984,29 @@ WOLFSSL_TEST_SUBROUTINE int aes256_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6108, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #ifdef HAVE_AES_DECRYPT if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6109, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif #endif - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) - ERROR_OUT(-6100, out); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) - ERROR_OUT(-6101, out); + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION); if (ret != 0) - ERROR_OUT(-6102, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION); if (ret != 0) - ERROR_OUT(-6103, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif XMEMSET(cipher, 0, AES_BLOCK_SIZE); @@ -10421,7 +11015,7 @@ WOLFSSL_TEST_SUBROUTINE int aes256_test(void) ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-6104, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT XMEMSET(plain, 0, AES_BLOCK_SIZE); ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher)); @@ -10429,14 +11023,14 @@ WOLFSSL_TEST_SUBROUTINE int aes256_test(void) ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-6105, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(plain, msg, (int) sizeof(plain))) { - ERROR_OUT(-6106, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif if (XMEMCMP(cipher, verify, (int) sizeof(cipher))) - ERROR_OUT(-6107, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesFree(enc); #ifdef HAVE_AES_DECRYPT @@ -10478,64 +11072,65 @@ static int aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz, byte resultT[AES_BLOCK_SIZE]; byte resultP[AES_BLOCK_SIZE * 3]; byte resultC[AES_BLOCK_SIZE * 3]; - int result; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6118, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6119, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif XMEMSET(resultT, 0, sizeof(resultT)); XMEMSET(resultC, 0, sizeof(resultC)); XMEMSET(resultP, 0, sizeof(resultP)); - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) - ERROR_OUT(-6110, out); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else enc_inited = 1; - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) - ERROR_OUT(-6111, out); + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); else dec_inited = 1; - result = wc_AesGcmSetKey(enc, key, keySz); - if (result != 0) - ERROR_OUT(-6112, out); + ret = wc_AesGcmSetKey(enc, key, keySz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz, - resultT, tagSz, aad, aadSz); + ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz, + resultT, tagSz, aad, aadSz); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6113, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (cipher != NULL) { if (XMEMCMP(cipher, resultC, cipherSz)) - ERROR_OUT(-6114, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } if (XMEMCMP(tag, resultT, tagSz)) - ERROR_OUT(-6115, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmSetKey(dec, key, keySz); - if (result != 0) - ERROR_OUT(-6116, out); + ret = wc_AesGcmSetKey(dec, key, keySz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz, - iv, ivSz, resultT, tagSz, aad, aadSz); + ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz, + iv, ivSz, resultT, tagSz, aad, aadSz); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6117, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (plain != NULL) { if (XMEMCMP(plain, resultP, plainSz)) - ERROR_OUT(-6118, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* HAVE_AES_DECRYPT */ @@ -10544,16 +11139,22 @@ static int aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz, out: +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + if (enc) { + if (enc_inited) + wc_AesFree(enc); + XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); + } + if (dec) { + if (dec_inited) + wc_AesFree(dec); + XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES); + } +#else if (enc_inited) wc_AesFree(enc); if (dec_inited) wc_AesFree(dec); - -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) - if (enc) - XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); - if (dec) - XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES); #endif return ret; @@ -10832,8 +11433,7 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) byte resultT[sizeof(t1) + AES_BLOCK_SIZE]; byte resultP[sizeof(p) + AES_BLOCK_SIZE]; byte resultC[sizeof(p) + AES_BLOCK_SIZE]; - int result = 0; - int ret; + int ret = 0; #ifdef WOLFSSL_AES_256 #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC)) int alen; @@ -10874,56 +11474,54 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6342, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - ERROR_OUT(-6343, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif - (void)result; - XMEMSET(resultT, 0, sizeof(resultT)); XMEMSET(resultC, 0, sizeof(resultC)); XMEMSET(resultP, 0, sizeof(resultP)); - if (wc_AesInit(enc, HEAP_HINT, devId) != 0) { - ERROR_OUT(-6300, out); - } - if (wc_AesInit(dec, HEAP_HINT, devId) != 0) { - ERROR_OUT(-6301, out); - } + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesInit(dec, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef WOLFSSL_AES_256 - result = wc_AesGcmSetKey(enc, k1, sizeof(k1)); - if (result != 0) - ERROR_OUT(-6302, out); + ret = wc_AesGcmSetKey(enc, k1, sizeof(k1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6303, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, resultC, sizeof(c1))) - ERROR_OUT(-6304, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t1, resultT, sizeof(t1))) - ERROR_OUT(-6305, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmSetKey(dec, k1, sizeof(k1)); - if (result != 0) - ERROR_OUT(-6306, out); + ret = wc_AesGcmSetKey(dec, k1, sizeof(k1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), + ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6307, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, resultP, sizeof(p))) - ERROR_OUT(-6308, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ /* Large buffer test */ @@ -10933,47 +11531,47 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) large_input[alen] = (byte)alen; /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, large_output, large_input, + ret = wc_AesGcmEncrypt(enc, large_output, large_input, BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6309, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, large_outdec, large_output, + ret = wc_AesGcmDecrypt(dec, large_outdec, large_output, BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6310, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) - ERROR_OUT(-6311, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* BENCH_AESGCM_LARGE */ #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256) /* Variable IV length test */ for (ivlen=1; ivlen<(int)sizeof(k1); ivlen++) { /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1, + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1, (word32)ivlen, resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6312, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1, + ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1, (word32)ivlen, resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6313, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ } #endif @@ -10982,21 +11580,21 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) /* Variable authenticated data length test */ for (alen=0; alen<(int)sizeof(p); alen++) { /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), resultT, sizeof(t1), p, (word32)alen); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6314, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1, + ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1, sizeof(iv1), resultT, sizeof(t1), p, (word32)alen); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6315, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ } #if defined(WOLFSSL_XILINX_CRYPT_VERSAL) @@ -11006,46 +11604,46 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) /* Variable authenticated data length test */ for (alen=0; alen<=1024; alen+=16) { /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen); - if (result != 0) - ERROR_OUT(-6316, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1, + ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1, sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen); - if (result != 0) - ERROR_OUT(-6317, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ } /* Test unaligned memory of all potential arguments */ - result = wc_AesGcmSetKey(enc, k1, sizeof(k1)); - if (result != 0) - ERROR_OUT(-6318, out); + ret = wc_AesGcmSetKey(enc, k1, sizeof(k1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ XMEMCPY(&buf[1], p, sizeof(p)); XMEMCPY(&bufA[1], a, sizeof(a)); - result = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1), + ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a)); - if (result != 0) - ERROR_OUT(-6319, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, &resultC[1], sizeof(c1))) - ERROR_OUT(-6320, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t1, &resultT[1], sizeof(t1))) - ERROR_OUT(-6321, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmSetKey(dec, k1, sizeof(k1)); - if (result != 0) - ERROR_OUT(-6322, out); + ret = wc_AesGcmSetKey(dec, k1, sizeof(k1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1), + ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1), iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a)); - if (result != 0) - ERROR_OUT(-6323, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, &resultP[1], sizeof(p))) - ERROR_OUT(-6324, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* Xilinx Versal */ @@ -11056,45 +11654,45 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) /* Variable plain text length test */ for (plen=1; plenasyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6316, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, large_outdec, large_output, + ret = wc_AesGcmDecrypt(dec, large_outdec, large_output, plen, iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6317, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ } #else /* BENCH_AESGCM_LARGE */ /* Variable plain text length test */ for (plen=1; plen<(int)sizeof(p); plen++) { /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1, + ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6318, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1, + ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6319, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_AES_DECRYPT */ } #endif /* BENCH_AESGCM_LARGE */ @@ -11110,28 +11708,28 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) #ifdef WOLFSSL_AES_192 wc_AesGcmSetKey(enc, k2, sizeof(k2)); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2), + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6320, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c2, resultC, sizeof(c2))) - ERROR_OUT(-6321, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t2, resultT, sizeof(t1))) - ERROR_OUT(-6322, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1), + ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1), iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6323, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, resultP, sizeof(p))) - ERROR_OUT(-6324, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ XMEMSET(resultT, 0, sizeof(resultT)); @@ -11141,28 +11739,28 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) #ifdef WOLFSSL_AES_128 wc_AesGcmSetKey(enc, k3, sizeof(k3)); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3), + ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6325, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c3, resultC, sizeof(c3))) - ERROR_OUT(-6326, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t3, resultT, sizeof(t3))) - ERROR_OUT(-6327, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3), + ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3), iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6328, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p3, resultP, sizeof(p3))) - ERROR_OUT(-6329, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_128 */ #endif /* ENABLE_NON_12BYTE_IV_TEST */ @@ -11177,28 +11775,28 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) wc_AesGcmSetKey(enc, k1, sizeof(k1)); /* AES-GCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), + ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6330, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c1, resultC, sizeof(c1))) - ERROR_OUT(-6331, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1)) - ERROR_OUT(-6332, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p), + ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p), iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6333, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, resultP, sizeof(p))) - ERROR_OUT(-6334, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* WOLFSSL_AES_256 */ @@ -11211,9 +11809,9 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) WC_RNG rng; byte randIV[12]; - result = wc_InitRng_ex(&rng, HEAP_HINT, devId); - if (result != 0) - ERROR_OUT(-6335, out); + ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); XMEMSET(randIV, 0, sizeof(randIV)); XMEMSET(resultT, 0, sizeof(resultT)); @@ -11221,20 +11819,20 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) XMEMSET(resultP, 0, sizeof(resultP)); wc_AesGcmSetKey(enc, k1, sizeof(k1)); - result = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng); - if (result != 0) - ERROR_OUT(-6336, out); + ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesGcmEncrypt_ex(enc, + ret = wc_AesGcmEncrypt_ex(enc, resultC, p, sizeof(p), randIV, sizeof(randIV), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &enc->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6337, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* Check the IV has been set. */ { @@ -11243,27 +11841,27 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) for (i = 0; i < sizeof(randIV); i++) ivSum += randIV[i]; if (ivSum == 0) - ERROR_OUT(-6338, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef HAVE_AES_DECRYPT wc_AesGcmSetKey(dec, k1, sizeof(k1)); - result = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng); - if (result != 0) - ERROR_OUT(-6339, out); + ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesGcmDecrypt(dec, + ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), randIV, sizeof(randIV), resultT, sizeof(t1), a, sizeof(a)); #if defined(WOLFSSL_ASYNC_CRYPT) - result = wc_AsyncWait(result, &dec->asyncDev, WC_ASYNC_FLAG_NONE); + ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (result != 0) - ERROR_OUT(-6340, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, resultP, sizeof(p))) - ERROR_OUT(-6341, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ wc_FreeRng(&rng); @@ -11274,121 +11872,121 @@ WOLFSSL_TEST_SUBROUTINE int aesgcm_test(void) #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) #ifdef WOLFSSL_AES_256 #ifdef WOLFSSL_AESGCM_STREAM - result = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6360, out); - result = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6361, out); - result = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6362, out); + ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(resultC, c1, sizeof(c1)) != 0) - ERROR_OUT(-6363, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(resultT, t1, sizeof(t1)) != 0) - ERROR_OUT(-6364, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6370, out); - result = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6371, out); - result = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6372, out); + ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(resultP, p, sizeof(p)) != 0) - ERROR_OUT(-6373, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* alen is the size to pass in with each update. */ for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) { - result = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6380, out); + ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* plen is the offset into AAD to update with. */ for (plen = 0; plen < (int)sizeof(a); plen += alen) { int len = sizeof(a) - plen; if (len > alen) len = alen; - result = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, len); - if (result != 0) - ERROR_OUT(-6381, out); + ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, len); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* plen is the offset into plaintext to update with. */ for (plen = 0; plen < (int)sizeof(p); plen += alen) { int len = sizeof(p) - plen; if (len > alen) len = alen; - result = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, len, + ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, len, NULL, 0); - if (result != 0) - ERROR_OUT(-6382, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - result = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6383, out); + ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(resultC, c1, sizeof(c1)) != 0) - ERROR_OUT(-6384, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(resultT, t1, sizeof(t1)) != 0) - ERROR_OUT(-6385, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef HAVE_AES_DECRYPT for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) { - result = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6390, out); + ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* plen is the offset into AAD to update with. */ for (plen = 0; plen < (int)sizeof(a); plen += alen) { int len = sizeof(a) - plen; if (len > alen) len = alen; - result = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, len); - if (result != 0) - ERROR_OUT(-6391, out); + ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, len); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* plen is the offset into cipher text to update with. */ for (plen = 0; plen < (int)sizeof(c1); plen += alen) { int len = sizeof(c1) - plen; if (len > alen) len = alen; - result = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, len, + ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, len, NULL, 0); - if (result != 0) - ERROR_OUT(-6392, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - result = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6393, out); + ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(resultP, p, sizeof(p)) != 0) - ERROR_OUT(-6394, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* HAVE_AES_DECRYPT */ #ifdef BENCH_AESGCM_LARGE /* setup test buffer */ - result = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6360, out); - result = wc_AesGcmEncryptUpdate(enc, large_output, large_input, + ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input, BENCH_AESGCM_LARGE, a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6361, out); - result = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6362, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifdef HAVE_AES_DECRYPT - result = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); - if (result != 0) - ERROR_OUT(-6363, out); - result = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output, + ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output, BENCH_AESGCM_LARGE, a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6364, out); - result = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1)); - if (result != 0) - ERROR_OUT(-6365, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE)) - ERROR_OUT(-6366, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* HAVE_AES_DECRYPT */ #endif /* BENCH_AESGCM_LARGE */ #endif /* WOLFSSL_AESGCM_STREAM */ @@ -11485,7 +12083,7 @@ WOLFSSL_TEST_SUBROUTINE int gmac_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - return -6409; + return WC_TEST_RET_ENC_ERRNO; #endif XMEMSET(gmac, 0, sizeof *gmac); /* clear context */ @@ -11494,7 +12092,7 @@ WOLFSSL_TEST_SUBROUTINE int gmac_test(void) wc_GmacSetKey(gmac, k1, sizeof(k1)); wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1)); if (XMEMCMP(t1, tag, sizeof(t1)) != 0) - ERROR_OUT(-6400, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if (!defined(HAVE_FIPS) || \ (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) ) @@ -11503,7 +12101,7 @@ WOLFSSL_TEST_SUBROUTINE int gmac_test(void) wc_GmacSetKey(gmac, k2, sizeof(k2)); wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2)); if (XMEMCMP(t2, tag, sizeof(t2)) != 0) - ERROR_OUT(-6401, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT) { @@ -11517,31 +12115,38 @@ WOLFSSL_TEST_SUBROUTINE int gmac_test(void) byte iv[12]; #ifndef HAVE_FIPS - if (wc_InitRng_ex(&rng, HEAP_HINT, devId) != 0) - ERROR_OUT(-6402, out); + ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #else - if (wc_InitRng(&rng) != 0) - ERROR_OUT(-6403, out); + ret = wc_InitRng(&rng); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - if (wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1), - t1, sizeof(t1)) != 0) - ERROR_OUT(-6404, out); - if (wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1), - badT, sizeof(badT)) != AES_GCM_AUTH_E) - ERROR_OUT(-6405, out); - if (wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2), - t2, sizeof(t2)) != 0) - ERROR_OUT(-6406, out); + ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1), + t1, sizeof(t1)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1), + badT, sizeof(badT)); + if (ret != AES_GCM_AUTH_E) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2), + t2, sizeof(t2)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); XMEMSET(tag, 0, sizeof(tag)); XMEMSET(iv, 0, sizeof(iv)); - if (wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1), - tag, sizeof(tag), &rng) != 0) - ERROR_OUT(-6407, out); - if (wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1), - tag, sizeof(tag)) != 0) - ERROR_OUT(-6408, out); + ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1), + tag, sizeof(tag), &rng); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1), + tag, sizeof(tag)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_FreeRng(&rng); } #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */ @@ -11610,7 +12215,7 @@ static int aesccm_256_test(void) if (ret == 0 && (XMEMCMP(output, exp_ciphertext, sizeof(output)) || XMEMCMP(atag, exp_tag, sizeof(atag)))) { - ret = -1; + ret = WC_TEST_RET_ENC_NC; } if (ret == 0) { @@ -11624,7 +12229,7 @@ static int aesccm_256_test(void) /* Verify decryption was successful */ if (ret == 0 && XMEMCMP(output, in_plaintext, sizeof(output))) { - ret = -1; + ret = WC_TEST_RET_ENC_NC; } wc_AesFree(aes); @@ -11738,11 +12343,9 @@ static int aesccm_128_test(void) byte tl2[sizeof(tl)]; byte t_empty2[sizeof(t_empty)]; - int result; - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL) - return -6521; + return WC_TEST_RET_ENC_ERRNO; #endif XMEMSET(enc, 0, sizeof *enc); /* clear context */ @@ -11750,43 +12353,43 @@ static int aesccm_128_test(void) XMEMSET(c2, 0, sizeof(c2)); XMEMSET(p2, 0, sizeof(p2)); - result = wc_AesInit(enc, HEAP_HINT, devId); - if (result != 0) - ERROR_OUT(-6499, out); + ret = wc_AesInit(enc, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - result = wc_AesCcmSetKey(enc, k, sizeof(k)); - if (result != 0) - ERROR_OUT(-6500, out); + ret = wc_AesCcmSetKey(enc, k, sizeof(k)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-CCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv), + ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv), t2, sizeof(t2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6501, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(c, c2, sizeof(c2))) - ERROR_OUT(-6502, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t, t2, sizeof(t2))) - ERROR_OUT(-6503, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); - result = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv), + ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv), t2, sizeof(t2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6504, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(p, p2, sizeof(p2))) - ERROR_OUT(-6505, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* Test the authentication failure */ t2[0]++; /* Corrupt the authentication tag. */ - result = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv), + ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv), t2, sizeof(t2), a, sizeof(a)); - if (result == 0) - ERROR_OUT(-6506, out); + if (ret == 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* Clear c2 to compare against p2. p2 should be set to zero in case of * authentication fail. */ XMEMSET(c2, 0, sizeof(c2)); if (XMEMCMP(p2, c2, sizeof(p2))) - ERROR_OUT(-6507, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_AesFree(enc); XMEMSET(enc, 0, sizeof(Aes)); /* clear context */ @@ -11798,108 +12401,111 @@ static int aesccm_128_test(void) #ifndef HAVE_SELFTEST /* selftest build does not have wc_AesCcmSetNonce() or * wc_AesCcmEncrypt_ex() */ - if (wc_AesCcmSetKey(enc, k, sizeof(k)) != 0) - ERROR_OUT(-6508, out); + ret = wc_AesCcmSetKey(enc, k, sizeof(k)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (wc_AesCcmSetNonce(enc, iv, sizeof(iv)) != 0) - ERROR_OUT(-6509, out); - if (wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2), - t2, sizeof(t2), a, sizeof(a)) != 0) - ERROR_OUT(-6510, out); + ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2), + t2, sizeof(t2), a, sizeof(a)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(iv, iv2, sizeof(iv2))) - ERROR_OUT(-6511, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(c, c2, sizeof(c2))) - ERROR_OUT(-6512, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(t, t2, sizeof(t2))) - ERROR_OUT(-6513, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) /* test fail on invalid IV sizes */ - result = wc_AesCcmSetKey(enc, k, sizeof(k)); - if (result != 0) - ERROR_OUT(-6514, out); + ret = wc_AesCcmSetKey(enc, k, sizeof(k)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* AES-CCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv), + ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv), t2, 1, a, sizeof(a)); - if (result == 0) { - ERROR_OUT(-6515, out); + if (ret == 0) { + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* AES-CCM encrypt and decrypt both use AES encrypt internally */ - result = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv), + ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv), tl2, sizeof(tl2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6516, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(cl, cl2, sizeof(cl2))) - ERROR_OUT(-6517, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(tl, tl2, sizeof(tl2))) - ERROR_OUT(-6518, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); - result = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv), + ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv), tl2, sizeof(tl2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6519, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(pl, pl2, sizeof(pl2))) - ERROR_OUT(-6520, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* test empty message as null input or output with nonzero inSz. */ - result = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */, + ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != BAD_FUNC_ARG) - ERROR_OUT(-6527, out); - result = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */, + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != BAD_FUNC_ARG) - ERROR_OUT(-6528, out); - result = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */, + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != BAD_FUNC_ARG) - ERROR_OUT(-6529, out); - result = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */, + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != BAD_FUNC_ARG) - ERROR_OUT(-6530, out); + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* test empty message as null input and output with zero inSz -- * must either succeed, or fail early with BAD_FUNC_ARG. */ - result = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */, + ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != BAD_FUNC_ARG) { - if (result != 0) - ERROR_OUT(-6521, out); + if (ret != BAD_FUNC_ARG) { + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2))) - ERROR_OUT(-6522, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); - result = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */, + ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6523, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* test empty message as zero-length string -- must work. */ - result = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv, + ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6524, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2))) - ERROR_OUT(-6525, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); - result = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */, + ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv, sizeof(iv), t_empty2, sizeof(t_empty2), a, sizeof(a)); - if (result != 0) - ERROR_OUT(-6526, out); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_AesFree(enc); @@ -12112,20 +12718,20 @@ WOLFSSL_TEST_SUBROUTINE int aeskeywrap_test(void) output, sizeof(output), NULL); if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) ) - return -6600; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0) - return -6601; + return WC_TEST_RET_ENC_NC; plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen, output, wrapSz, plain, sizeof(plain), NULL); if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) ) - return -6602; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0) - return -6603 - i; + return WC_TEST_RET_ENC_I(i); } return 0; @@ -12317,25 +12923,29 @@ WOLFSSL_TEST_SUBROUTINE int camellia_test(void) /* Setting the IV and checking it was actually set. */ ret = wc_CamelliaSetIV(&cam, ivc); - if (ret != 0 || XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE)) - return -6700; + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0) + return WC_TEST_RET_ENC_NC; /* Setting the IV to NULL should be same as all zeros IV */ - if (wc_CamelliaSetIV(&cam, NULL) != 0 || - XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE)) - return -6701; + ret = wc_CamelliaSetIV(&cam, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0) + return WC_TEST_RET_ENC_NC; /* First parameter should never be null */ if (wc_CamelliaSetIV(NULL, NULL) == 0) - return -6702; + return WC_TEST_RET_ENC_NC; /* First parameter should never be null, check it fails */ if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0) - return -6703; + return WC_TEST_RET_ENC_NC; /* Key should have a size of 16, 24, or 32 */ if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0) - return -6704; + return WC_TEST_RET_ENC_NC; return 0; } @@ -12343,7 +12953,7 @@ WOLFSSL_TEST_SUBROUTINE int camellia_test(void) #ifdef HAVE_XCHACHA WOLFSSL_TEST_SUBROUTINE int XChaCha_test(void) { - int ret = -6830; + int ret; WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = { 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */ @@ -12404,7 +13014,7 @@ WOLFSSL_TEST_SUBROUTINE int XChaCha_test(void) { byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL)) - ERROR_OUT(MEMORY_E, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #else struct ChaCha chacha[1]; byte buf1[sizeof Plaintext]; @@ -12413,25 +13023,25 @@ WOLFSSL_TEST_SUBROUTINE int XChaCha_test(void) { ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0); if (ret < 0) - ERROR_OUT(-6831, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext); if (ret < 0) - ERROR_OUT(-6832, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext)) - ERROR_OUT(-6833, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0); if (ret < 0) - ERROR_OUT(-6834, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext); if (ret < 0) - ERROR_OUT(-6835, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(buf2, Plaintext, sizeof Plaintext)) - ERROR_OUT(-6836, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); out: @@ -12492,7 +13102,7 @@ WOLFSSL_TEST_SUBROUTINE int XChaCha20Poly1305_test(void) { byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if ((buf1 == NULL) || (buf2 == NULL)) - ERROR_OUT(-6480, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #else byte buf1[sizeof Ciphertext + sizeof Tag]; byte buf2[sizeof Plaintext]; @@ -12505,13 +13115,13 @@ WOLFSSL_TEST_SUBROUTINE int XChaCha20Poly1305_test(void) { Key, sizeof Key); if (ret < 0) - ERROR_OUT(-6841, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext)) - ERROR_OUT(-6842, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE)) - ERROR_OUT(-6843, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext, buf1, sizeof Ciphertext + sizeof Tag, @@ -12520,10 +13130,10 @@ WOLFSSL_TEST_SUBROUTINE int XChaCha20Poly1305_test(void) { Key, sizeof Key); if (ret < 0) - ERROR_OUT(-6844, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(buf2, Plaintext, sizeof Plaintext)) - ERROR_OUT(-6845, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); out: @@ -12548,7 +13158,7 @@ static int _rng_test(WC_RNG* rng, int errorOffset) ret = wc_RNG_GenerateBlock(rng, block, sizeof(block)); if (ret != 0) { - ret = -6850; + ret = 1; goto exit; } @@ -12560,36 +13170,36 @@ static int _rng_test(WC_RNG* rng, int errorOffset) } /* All zeros count check */ if (ret >= (int)sizeof(block)) { - ret = -6851; + ret = 2; goto exit; } ret = wc_RNG_GenerateByte(rng, block); if (ret != 0) { - ret = -6852; + ret = 3; goto exit; } /* Parameter validation testing. */ ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block)); if (ret != BAD_FUNC_ARG) { - ret = -6853; + ret = 4; goto exit; } ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block)); if (ret != BAD_FUNC_ARG) { - ret = -6854; + ret = 5; goto exit; } ret = wc_RNG_GenerateByte(NULL, block); if (ret != BAD_FUNC_ARG) { - ret = -6855; + ret = 6; goto exit; } ret = wc_RNG_GenerateByte(rng, NULL); if (ret != BAD_FUNC_ARG) { - ret = -6856; + ret = 7; goto exit; } @@ -12597,7 +13207,7 @@ static int _rng_test(WC_RNG* rng, int errorOffset) exit: if (ret != 0) - ret += errorOffset; + ret = errorOffset - (ret * 1000000); return ret; } @@ -12616,23 +13226,26 @@ static int random_rng_test(void) #else ret = wc_InitRng(rng); #endif - if (ret != 0) return -6900; + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - ret = _rng_test(rng, -6300); + ret = _rng_test(rng, WC_TEST_RET_ENC_NC); /* Make sure and free RNG */ wc_FreeRng(rng); - if (ret != 0) return ret; + if (ret != 0) + return ret; #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) { byte nonce[8] = { 0 }; /* Test dynamic RNG. */ rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT); - if (rng == NULL) return -6901; + if (rng == NULL) + return WC_TEST_RET_ENC_ERRNO; - ret = _rng_test(rng, -6310); + ret = _rng_test(rng, WC_TEST_RET_ENC_NC); wc_rng_free(rng); } @@ -12680,35 +13293,30 @@ static int rng_seed_test(void) ret = wc_SetSeed_Cb(seed_cb); if (ret != 0) { - ret = -7007; - goto exit; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = wc_InitRng(&rng); if (ret != 0) { - ret = -7008; - goto exit; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output)); if (ret != 0) { - ret = -7009; - goto exit; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = XMEMCMP(output, check, sizeof(output)); if (ret != 0) { - ret = -7010; - goto exit; + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } ret = wc_FreeRng(&rng); if (ret != 0) { - ret = -7011; - goto exit; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = wc_SetSeed_Cb(wc_GenerateSeed); if (ret != 0) { - ret = -7012; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } -exit: +out: return ret; } #endif @@ -12771,19 +13379,19 @@ WOLFSSL_TEST_SUBROUTINE int random_test(void) ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0, output, sizeof(output)); if (ret != 0) - return -7000; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(test1Output, output, sizeof(output)) != 0) - return -7001; + return WC_TEST_RET_ENC_NC; ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA), test2EntropyB, sizeof(test2EntropyB), output, sizeof(output)); if (ret != 0) - return -7002; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(test2Output, output, sizeof(output)) != 0) - return -7003; + return WC_TEST_RET_ENC_NC; /* Basic RNG generate block test */ if ((ret = random_rng_test()) != 0) @@ -12800,7 +13408,7 @@ WOLFSSL_TEST_SUBROUTINE int random_test(void) XMEMSET(output, 1, outputSz); ret = wc_RNG_TestSeed(output, outputSz); if (ret == 0) - return -7004; + return WC_TEST_RET_ENC_NC; /* Every byte of the entropy scratch is different, * entropy is a single byte that shouldn't match. */ @@ -12809,14 +13417,14 @@ WOLFSSL_TEST_SUBROUTINE int random_test(void) output[i] = (byte)i; ret = wc_RNG_TestSeed(output, outputSz); if (ret != 0) - return -7005; + return WC_TEST_RET_ENC_EC(ret); outputSz = sizeof(output); for (i = 0; i < outputSz; i++) output[i] = (byte)i; ret = wc_RNG_TestSeed(output, outputSz); if (ret != 0) - return -7006; + return WC_TEST_RET_ENC_EC(ret); } #endif @@ -12853,7 +13461,7 @@ static int simple_mem_test(int sz) b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (b == NULL) { - return -7110; + return WC_TEST_RET_ENC_NC; } /* utilize memory */ for (i = 0; i < sz; i++) { @@ -12862,7 +13470,7 @@ static int simple_mem_test(int sz) /* read back and verify */ for (i = 0; i < sz; i++) { if (b[i] != (byte)i) { - ret = -7111; + ret = WC_TEST_RET_ENC_NC; break; } } @@ -12889,84 +13497,89 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) #ifdef WOLFSSL_STATIC_MEMORY /* check macro settings */ if (sizeof(size)/sizeof(word32) != WOLFMEM_MAX_BUCKETS) { - return -7200; + return WC_TEST_RET_ENC_NC; } if (sizeof(dist)/sizeof(word32) != WOLFMEM_MAX_BUCKETS) { - return -7201; + return WC_TEST_RET_ENC_NC; } for (i = 0; i < WOLFMEM_MAX_BUCKETS; i++) { if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) { /* each element in array should be divisible by alignment size */ - return -7202; + return WC_TEST_RET_ENC_NC; } } for (i = 1; i < WOLFMEM_MAX_BUCKETS; i++) { if (size[i - 1] >= size[i]) { - return -7203; /* sizes should be in increasing order */ + return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */ } } /* check that padding size returned is possible */ if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) { - return -7204; /* no room for wc_Memory struct */ + return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */ } - if (wolfSSL_MemoryPaddingSz() < 0) { - return -7205; + ret = wolfSSL_MemoryPaddingSz(); + if (ret < 0) { + return WC_TEST_RET_ENC_EC(ret); } if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) { - return -7206; /* not aligned! */ + return WC_TEST_RET_ENC_NC; /* not aligned! */ } /* check function to return optimum buffer size (rounded down) */ ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL); - if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) { - return -7207; /* not aligned! */ - } - if (ret < 0) { - return -7208; + return WC_TEST_RET_ENC_EC(ret); + } + if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) { + return WC_TEST_RET_ENC_NC; /* not aligned! */ } if ((unsigned int)ret > sizeof(buffer)) { - return -7209; /* did not round down as expected */ + return WC_TEST_RET_ENC_NC; /* did not round down as expected */ } if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) { - return -7210; /* return value changed when using suggested value */ + return WC_TEST_RET_ENC_NC; /* return value changed when using suggested + * value + */ } ret = wolfSSL_MemoryPaddingSz(); ret += pad; /* add space that is going to be needed if buffer not aligned */ if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) != (ret + (int)size[0])) { - return -7211; /* did not round down to nearest bucket value */ + return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket + * value + */ } ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL); if ((ret - pad) < 0) { - return -7212; + return WC_TEST_RET_ENC_NC; } if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) { - return -7213; /* not even chunks of memory for IO size */ + return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */ } if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) { - return -7214; /* memory not aligned */ + return WC_TEST_RET_ENC_NC; /* memory not aligned */ } /* check for passing bad or unknown arguments to functions */ if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) { - return -7215; + return WC_TEST_RET_ENC_NC; } if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) { - return -7216; /* should round to 0 since struct + bucket will not fit */ + return WC_TEST_RET_ENC_NC; /* should round to 0 + since struct + bucket will not fit */ } (void)dist; /* avoid static analysis warning of variable not used */ @@ -12988,22 +13601,28 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) } #endif -#if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) +#if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC) /* realloc test */ { byte *c = NULL; byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + #ifndef WOLFSSL_NO_REALLOC if (b) { c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (c) b = c; } + #endif if (b) XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if ((b == NULL) || (c == NULL)) { - return -7217; + if ((b == NULL) + #ifndef WOLFSSL_NO_REALLOC + || (c == NULL) + #endif + ) { + return WC_TEST_RET_ENC_ERRNO; } } #endif @@ -13097,13 +13716,15 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) #ifndef NO_RSA static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der"; #endif - static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der"; - static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem"; - #ifdef ENABLE_ECC384_CERT_GEN_TEST - static const char* eccCaKey384File = - CERT_ROOT "ca-ecc384-key.der"; - static const char* eccCaCert384File = - CERT_ROOT "ca-ecc384-cert.pem"; + #ifndef NO_ASN_TIME + static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der"; + static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem"; + #ifdef ENABLE_ECC384_CERT_GEN_TEST + static const char* eccCaKey384File = + CERT_ROOT "ca-ecc384-key.der"; + static const char* eccCaCert384File = + CERT_ROOT "ca-ecc384-cert.pem"; + #endif #endif #endif #if defined(HAVE_PKCS7) && defined(HAVE_ECC) @@ -13140,7 +13761,7 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) #ifndef NO_WRITE_TEMP_FILES #ifdef HAVE_ECC - #ifdef WOLFSSL_CERT_GEN + #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem"; static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der"; #endif @@ -13149,7 +13770,7 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der"; #endif #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \ - !defined(WOLF_CRYPTO_CB_ONLY_ECC) + !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT) static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem"; static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der"; static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der"; @@ -13161,7 +13782,7 @@ WOLFSSL_TEST_SUBROUTINE int memory_test(void) #endif /* HAVE_ECC */ #ifndef NO_RSA - #ifdef WOLFSSL_CERT_GEN + #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der"; static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der"; static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem"; @@ -13230,20 +13851,20 @@ static void initDefaultName(void) n = &certDefaultName.name[0]; n->id = ASN_ORGUNIT_NAME; n->type = CTC_UTF8; - n->sz = sizeof("Development-2"); + n->sz = XSTRLEN("Development-2"); XMEMCPY(n->value, "Development-2", sizeof("Development-2")); #if CTC_MAX_ATTRIB > 3 n = &certDefaultName.name[1]; n->id = ASN_DOMAIN_COMPONENT; n->type = CTC_UTF8; - n->sz = sizeof("com"); + n->sz = XSTRLEN("com"); XMEMCPY(n->value, "com", sizeof("com")); n = &certDefaultName.name[2]; n->id = ASN_DOMAIN_COMPONENT; n->type = CTC_UTF8; - n->sz = sizeof("wolfssl"); + n->sz = XSTRLEN("wolfssl"); XMEMCPY(n->value, "wolfssl", sizeof("wolfssl")); #endif #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */ @@ -13350,9 +13971,8 @@ static int cert_asn1_test(void) InitDecodedCert(&cert, certData, len[0], 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); FreeDecodedCert(&cert); - if (ret != 0) { - ERROR_OUT(-7300, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); /* Bad issuer name */ len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial)); @@ -13372,7 +13992,7 @@ static int cert_asn1_test(void) ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); FreeDecodedCert(&cert); if (ret != ASN_PARSE_E) { - ERROR_OUT(-7301, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); badCert = NULL; @@ -13395,52 +14015,55 @@ WOLFSSL_TEST_SUBROUTINE int cert_test(void) tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) - return -7400; + return WC_TEST_RET_ENC_ERRNO; /* Certificate with Name Constraints extension. */ file = XFOPEN(certExtNc, "rb"); if (!file) { - ERROR_OUT(-7401, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-7402, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); FreeDecodedCert(&cert); /* Certificate with Inhibit Any Policy extension. */ file = XFOPEN(certExtIa, "rb"); if (!file) { - ERROR_OUT(-7403, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-7404, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); FreeDecodedCert(&cert); /* Certificate with Netscape Certificate Type extension. */ file = XFOPEN(certExtNct, "rb"); if (!file) { - ERROR_OUT(-7405, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); #ifndef IGNORE_NETSCAPE_CERT_TYPE - if (ret != 0) { - ERROR_OUT(-7406, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #else if (ret != ASN_CRIT_EXT_E) { - ERROR_OUT(-7407, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } ret = 0; #endif @@ -13494,50 +14117,52 @@ WOLFSSL_TEST_SUBROUTINE int certext_test(void) tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) - return -7500; + return WC_TEST_RET_ENC_ERRNO; /* load othercert.der (Cert signed by an authority) */ file = XFOPEN(otherCertDerFile, "rb"); if (!file) { - XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - return -7501; + XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + return WC_TEST_RET_ENC_ERRNO; } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + return WC_TEST_RET_ENC_ERRNO; InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) - return -7502; + return WC_TEST_RET_ENC_EC(ret); /* check the SKID from a RSA certificate */ if (XMEMCMP(skid_rsa, cert.extSubjKeyId, sizeof(cert.extSubjKeyId))) - return -7503; + return WC_TEST_RET_ENC_NC; /* check the AKID from an RSA certificate */ if (XMEMCMP(akid_rsa, cert.extAuthKeyId, sizeof(cert.extAuthKeyId))) - return -7504; + return WC_TEST_RET_ENC_NC; /* check the Key Usage from an RSA certificate */ if (!cert.extKeyUsageSet) - return -7505; + return WC_TEST_RET_ENC_NC; if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE)) - return -7506; + return WC_TEST_RET_ENC_NC; /* check the CA Basic Constraints from an RSA certificate */ if (cert.isCA) - return -7507; + return WC_TEST_RET_ENC_NC; #ifndef WOLFSSL_SEP /* test only if not using SEP policies */ /* check the Certificate Policies Id */ if (cert.extCertPoliciesNb != 1) - return -7508; + return WC_TEST_RET_ENC_NC; if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23)) - return -7509; + return WC_TEST_RET_ENC_NC; #endif FreeDecodedCert(&cert); @@ -13546,46 +14171,48 @@ WOLFSSL_TEST_SUBROUTINE int certext_test(void) /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */ file = XFOPEN(certEccDerFile, "rb"); if (!file) { - XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - return -7510; + XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + return WC_TEST_RET_ENC_ERRNO; } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + return WC_TEST_RET_ENC_ERRNO; InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) - return -7511; + return WC_TEST_RET_ENC_EC(ret); /* check the SKID from a ECC certificate - generated dynamically */ /* check the AKID from an ECC certificate */ if (XMEMCMP(akid_ecc, cert.extAuthKeyId, sizeof(cert.extAuthKeyId))) - return -7512; + return WC_TEST_RET_ENC_NC; /* check the Key Usage from an ECC certificate */ if (!cert.extKeyUsageSet) - return -7513; + return WC_TEST_RET_ENC_NC; if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT)) - return -7514; + return WC_TEST_RET_ENC_NC; /* check the CA Basic Constraints from an ECC certificate */ if (cert.isCA) - return -7515; + return WC_TEST_RET_ENC_NC; #ifndef WOLFSSL_SEP /* test only if not using SEP policies */ /* check the Certificate Policies Id */ if (cert.extCertPoliciesNb != 2) - return -7516; + return WC_TEST_RET_ENC_NC; if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32)) - return -7517; + return WC_TEST_RET_ENC_NC; if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22)) - return -7518; + return WC_TEST_RET_ENC_NC; #endif FreeDecodedCert(&cert); @@ -13594,52 +14221,54 @@ WOLFSSL_TEST_SUBROUTINE int certext_test(void) /* load cert.der (self signed certificate) */ file = XFOPEN(certDerFile, "rb"); if (!file) { - XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - return -7519; + XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + return WC_TEST_RET_ENC_ERRNO; } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + return WC_TEST_RET_ENC_ERRNO; InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) - return -7520; + return WC_TEST_RET_ENC_EC(ret); /* check the SKID from a CA certificate */ if (XMEMCMP(kid_ca, cert.extSubjKeyId, sizeof(cert.extSubjKeyId))) - return -7521; + return WC_TEST_RET_ENC_NC; /* check the AKID from an CA certificate */ if (XMEMCMP(kid_ca, cert.extAuthKeyId, sizeof(cert.extAuthKeyId))) - return -7522; + return WC_TEST_RET_ENC_NC; /* check the Key Usage from CA certificate */ if (!cert.extKeyUsageSet) - return -7523; + return WC_TEST_RET_ENC_NC; if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN)) - return -7524; + return WC_TEST_RET_ENC_NC; /* check the CA Basic Constraints CA certificate */ if (!cert.isCA) - return -7525; + return WC_TEST_RET_ENC_NC; #ifndef WOLFSSL_SEP /* test only if not using SEP policies */ /* check the Certificate Policies Id */ if (cert.extCertPoliciesNb != 2) - return -7526; + return WC_TEST_RET_ENC_NC; if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23)) - return -7527; + return WC_TEST_RET_ENC_NC; if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25)) - return -7528; + return WC_TEST_RET_ENC_NC; #endif FreeDecodedCert(&cert); - XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return 0; } @@ -13659,7 +14288,7 @@ WOLFSSL_TEST_SUBROUTINE int decodedCertCache_test(void) derSz = FOURK_BUF; der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) - ret = -7600; + ret = WC_TEST_RET_ENC_NC; if (ret == 0) { /* load cert.der */ @@ -13667,95 +14296,127 @@ WOLFSSL_TEST_SUBROUTINE int decodedCertCache_test(void) if (file != NULL) { derSz = (word32)XFREAD(der, 1, FOURK_BUF, file); XFCLOSE(file); + if (derSz == 0) + ret = WC_TEST_RET_ENC_ERRNO; + } else - ret = -7601; + ret = WC_TEST_RET_ENC_ERRNO; } if (ret == 0) { - if (wc_InitCert_ex(&cert, HEAP_HINT, devId)) { - ret = -7602; - } + ret = wc_InitCert_ex(&cert, HEAP_HINT, devId); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_SetSubjectBuffer(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetSubjectBuffer(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7603; + ret = wc_SetSubjectBuffer(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if (wc_SetSubjectRaw(&cert, der, derSz) != 0) - ret = -7604; + ret = wc_SetSubjectRaw(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetSubjectRaw(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7605; + ret = wc_SetSubjectRaw(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetIssuerBuffer(&cert, der, derSz) != 0) - ret = -7606; + ret = wc_SetIssuerBuffer(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetIssuerBuffer(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7607; + ret = wc_SetIssuerBuffer(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetIssuerRaw(&cert, der, derSz) != 0) - ret = -7608; + ret = wc_SetIssuerRaw(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetIssuerRaw(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7609; + ret = wc_SetIssuerRaw(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } #ifdef WOLFSSL_ALT_NAMES if (ret == 0) { - if(wc_SetAltNamesBuffer(&cert, der, derSz) != 0) - ret = -7610; + ret = wc_SetAltNamesBuffer(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetAltNamesBuffer(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7611; + ret = wc_SetAltNamesBuffer(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetDatesBuffer(&cert, der, derSz) != 0) - ret = -7612; + ret = wc_SetDatesBuffer(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetDatesBuffer(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7613; + ret = wc_SetDatesBuffer(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_EC(ret); } #endif if (ret == 0) { - if(wc_SetAuthKeyIdFromCert(&cert, der, derSz) != 0) - ret = -7614; + ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { - if(wc_SetAuthKeyIdFromCert(NULL, der, derSz) != BAD_FUNC_ARG) - ret = -7615; + ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz); + if (ret == BAD_FUNC_ARG) + ret = 0; + else + ret = WC_TEST_RET_ENC_NC; } wc_SetCert_Free(&cert); if (ret == 0) { if(cert.decodedCert != NULL) - ret = -7616; + ret = WC_TEST_RET_ENC_NC; } - XFREE(der, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return ret; } @@ -13784,7 +14445,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != BAD_FUNC_ARG) #endif - return -7620; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz); #ifdef HAVE_USER_RSA /* Implementation using IPP Libraries returns: @@ -13794,7 +14455,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != BAD_FUNC_ARG) #endif - return -7621; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz); #ifdef HAVE_USER_RSA /* Implementation using IPP Libraries returns: @@ -13804,7 +14465,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != BAD_FUNC_ARG) #endif - return -7622; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz); #ifdef HAVE_USER_RSA /* Implementation using IPP Libraries returns: @@ -13814,7 +14475,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != BAD_FUNC_ARG) #endif - return -7623; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL); #ifdef HAVE_USER_RSA /* Implementation using IPP Libraries returns: @@ -13824,10 +14485,10 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != BAD_FUNC_ARG) #endif - return -7624; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz); if (ret != 0) - return -7625; + return WC_TEST_RET_ENC_EC(ret); eSz = 0; ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz); #ifdef HAVE_USER_RSA @@ -13841,7 +14502,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != RSA_BUFFER_E) #endif - return -7626; + return WC_TEST_RET_ENC_EC(ret); eSz = sizeof(e); nSz = 0; ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz); @@ -13853,7 +14514,7 @@ static int rsa_flatten_test(RsaKey* key) #else if (ret != RSA_BUFFER_E) #endif - return -7627; + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -13878,59 +14539,59 @@ static int rsa_export_key_test(RsaKey* key) ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7630; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7631; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7632; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7633; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7634; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7635; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7636; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7637; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz); if (ret != BAD_FUNC_ARG) - return -7638; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz); if (ret != BAD_FUNC_ARG) - return -7639; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL); if (ret != BAD_FUNC_ARG) - return -7640; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != RSA_BUFFER_E) - return -7641; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz); if (ret != RSA_BUFFER_E) - return -7642; + return WC_TEST_RET_ENC_EC(ret); #ifndef WOLFSSL_RSA_PUBLIC_ONLY ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz); if (ret != RSA_BUFFER_E) - return -7643; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz); if (ret != RSA_BUFFER_E) - return -7644; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero); if (ret != RSA_BUFFER_E) - return -7645; + return WC_TEST_RET_ENC_EC(ret); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz); if (ret != 0) - return -7646; + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -13964,36 +14625,36 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng) /* Parameter Validation testing. */ ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen); if (ret != BAD_FUNC_ARG) - return -7650; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0); if (ret != BAD_FUNC_ARG) - return -7651; + return WC_TEST_RET_ENC_EC(ret); sigSz = (word32)modLen; ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL, inLen, out, &sigSz, key, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7652; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, 0, out, &sigSz, key, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7653; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, NULL, &sigSz, key, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7654; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, NULL, key, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7655; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, NULL, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7656; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, 0, rng); if (ret != BAD_FUNC_ARG) - return -7657; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, keyLen, NULL); #ifdef HAVE_USER_RSA @@ -14022,42 +14683,42 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng) #else if (ret != MISSING_RNG_E) #endif - return -7658; + return WC_TEST_RET_ENC_EC(ret); sigSz = 0; ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, keyLen, rng); if (ret != BAD_FUNC_ARG) - return -7659; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL, inLen, out, (word32)modLen, key, keyLen); if (ret != BAD_FUNC_ARG) - return -7660; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, 0, out, (word32)modLen, key, keyLen); if (ret != BAD_FUNC_ARG) - return -7661; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, NULL, (word32)modLen, key, keyLen); if (ret != BAD_FUNC_ARG) - return -7662; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, 0, key, keyLen); if (ret != BAD_FUNC_ARG) - return -7663; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, (word32)modLen, NULL, keyLen); if (ret != BAD_FUNC_ARG) - return -7664; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, (word32)modLen, key, 0); if (ret != BAD_FUNC_ARG) - return -7665; + return WC_TEST_RET_ENC_EC(ret); #ifndef HAVE_ECC ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen); if (ret != SIG_TYPE_E) - return -7666; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLF_CRYPTO_CB_ONLY_RSA) return 0; @@ -14065,10 +14726,10 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng) /* Use APIs. */ ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen); if (ret != modLen) - return -7667; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen); if (ret != modLen) - return -7668; + return WC_TEST_RET_ENC_EC(ret); sigSz = (word32)ret; #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY) @@ -14076,52 +14737,52 @@ static int rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng) ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, keyLen, rng); if (ret != 0) - return -7669; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, (word32)modLen, key, keyLen); if (ret != 0) - return -7670; + return WC_TEST_RET_ENC_EC(ret); sigSz = (word32)sizeof(out); ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC, in, inLen, out, &sigSz, key, keyLen, rng); if (ret != 0) - return -7671; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC, in, inLen, out, (word32)modLen, key, keyLen); if (ret != 0) - return -7672; + return WC_TEST_RET_ENC_EC(ret); /* Wrong signature type. */ ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, (word32)modLen, key, keyLen); if (ret == 0) - return -7673; + return WC_TEST_RET_ENC_EC(ret); /* check hash functions */ sigSz = (word32)sizeof(out); ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng); if (ret != 0) - return -7674; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen); if (ret != 0) - return -7675; + return WC_TEST_RET_ENC_EC(ret); sigSz = (word32)sizeof(out); ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC, hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng); if (ret != 0) - return -7676; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC, hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen); if (ret != 0) - return -7677; + return WC_TEST_RET_ENC_EC(ret); #else (void)hash; (void)hashEnc; @@ -14163,7 +14824,7 @@ static int rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out, if (ret < 0) { return ret; } -#ifdef DEBUG_WOLFSSL +#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) printf("RSA non-block sign: %d times\n", count); #endif signSz = ret; @@ -14181,7 +14842,7 @@ static int rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out, if (ret < 0) { return ret; } -#ifdef DEBUG_WOLFSSL +#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) printf("RSA non-block verify: %d times\n", count); #endif @@ -14201,7 +14862,7 @@ static int rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out, if (ret < 0) { return ret; } -#ifdef DEBUG_WOLFSSL +#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) printf("RSA non-block inline verify: %d times\n", count); #endif @@ -14270,22 +14931,22 @@ static int rsa_decode_test(RsaKey* keyPub) ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7690; + return WC_TEST_RET_ENC_EC(ret); /* Parameter Validation testing. */ ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub); if (ret != BAD_FUNC_ARG) { - ret = -7691; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub); if (ret != BAD_FUNC_ARG) { - ret = -7692; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL); if (ret != BAD_FUNC_ARG) { - ret = -7693; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub); @@ -14294,53 +14955,53 @@ static int rsa_decode_test(RsaKey* keyPub) #else if (ret != ASN_GETINT_E) { #endif - ret = -7694; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7695; + return WC_TEST_RET_ENC_EC(ret); ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub); #if !defined(WOLFSSL_SP_MATH) & !defined(WOLFSSL_SP_MATH_ALL) if (ret != 0) { #else if (ret != ASN_GETINT_E) { #endif - ret = -7696; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7697; + return WC_TEST_RET_ENC_EC(ret); /* Use API. */ ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub); if (ret != 0) { - ret = -7698; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7699; + return WC_TEST_RET_ENC_EC(ret); /* Parameter Validation testing. */ inSz = sizeof(good); ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz); if (ret != BAD_FUNC_ARG) { - ret = -7700; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz); if (ret != BAD_FUNC_ARG) { - ret = -7701; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz); if (ret != BAD_FUNC_ARG) { - ret = -7702; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -14349,14 +15010,14 @@ static int rsa_decode_test(RsaKey* keyPub) inSz = sizeof(good) - inOutIdx; ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz); if (ret != ASN_PARSE_E) { - ret = -7703; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inOutIdx = 2; inSz = sizeof(goodAlgId) - inOutIdx; ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz); if (ret != ASN_PARSE_E) { - ret = -7704; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inOutIdx = 2; @@ -14368,7 +15029,7 @@ static int rsa_decode_test(RsaKey* keyPub) if (ret != ASN_RSA_KEY_E) #endif { - ret = -7705; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } /* Try different bad data. */ @@ -14376,49 +15037,49 @@ static int rsa_decode_test(RsaKey* keyPub) inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz); if (ret != ASN_EXPECT_0_E) { - ret = -7706; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNotBitString); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz); if (ret != ASN_BITSTR_E) { - ret = -7707; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badBitStringLen); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz); if (ret != ASN_PARSE_E) { - ret = -7708; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNoSeq); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz); if (ret != ASN_PARSE_E) { - ret = -7709; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNoObj); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz); if (ret != ASN_PARSE_E && ret != ASN_OBJECT_ID_E) { - ret = -7710; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badIntN); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz); if (ret != ASN_RSA_KEY_E && ret != ASN_PARSE_E) { - ret = -7711; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNotIntE); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz); if (ret != ASN_RSA_KEY_E && ret != ASN_PARSE_E) { - ret = -7712; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } /* TODO: Shouldn't pass as the sequence length is too small. */ @@ -14431,69 +15092,69 @@ static int rsa_decode_test(RsaKey* keyPub) if (ret != ASN_PARSE_E) #endif { - ret = -7713; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } /* TODO: Shouldn't ignore object id's data. */ wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7714; + return WC_TEST_RET_ENC_EC(ret); inSz = sizeof(badBitStrNoZero); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz); if (ret != ASN_EXPECT_0_E && ret != ASN_PARSE_E) { - ret = -7715; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7716; + return WC_TEST_RET_ENC_EC(ret); /* Valid data cases. */ inSz = sizeof(good); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz); if (ret != 0) { - ret = -7717; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } if (inOutIdx != inSz) { - ret = -7718; + ret = WC_TEST_RET_ENC_NC; goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7719; + return WC_TEST_RET_ENC_EC(ret); inSz = sizeof(goodAlgId); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz); if (ret != 0) { - ret = -7720; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } if (inOutIdx != inSz) { - ret = -7721; + ret = WC_TEST_RET_ENC_NC; goto done; } wc_FreeRsaKey(keyPub); ret = wc_InitRsaKey(keyPub, NULL); if (ret != 0) - return -7722; + return WC_TEST_RET_ENC_EC(ret); inSz = sizeof(goodAlgIdNull); inOutIdx = 0; ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz); if (ret != 0) { - ret = -7723; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } if (inOutIdx != inSz) { - ret = -7724; + ret = WC_TEST_RET_ENC_NC; goto done; } @@ -14570,7 +15231,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) /* Calculate hash of message. */ ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest)); if (ret != 0) - ERROR_OUT(-7730, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); digestSz = wc_HashGetDigestSize(hash[j]); #ifdef WOLFSSL_SE050 @@ -14591,7 +15252,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret <= 0) - ERROR_OUT(-7731, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); outSz = ret; XMEMCPY(sig, out, outSz); @@ -14609,7 +15270,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret <= 0) - ERROR_OUT(-7732, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); plainSz = ret; TEST_SLEEP(); @@ -14625,7 +15286,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT); #endif if (ret != 0) - ERROR_OUT(-7733, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); #ifdef RSA_PSS_TEST_WRONG_PARAMS for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) { @@ -14646,7 +15307,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret >= 0) - ERROR_OUT(-7734, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); } } #endif @@ -14671,7 +15332,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret <= 0) - ERROR_OUT(-7735, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); outSz = ret; TEST_SLEEP(); @@ -14686,7 +15347,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret <= 0) - ERROR_OUT(-7736, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); plainSz = ret; TEST_SLEEP(); @@ -14710,7 +15371,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-7737, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); XMEMCPY(sig, out, outSz); plain = NULL; @@ -14725,7 +15386,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret <= 0) - ERROR_OUT(-7738, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); plainSz = ret; TEST_SLEEP(); @@ -14741,7 +15402,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) 0, 0, HEAP_HINT); #endif if (ret != 0) - ERROR_OUT(-7739, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); /* Test bad salt lengths in various APIs. */ digestSz = wc_HashGetDigestSize(hash[0]); @@ -14762,7 +15423,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7740, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); do { #if defined(WOLFSSL_ASYNC_CRYPT) @@ -14775,7 +15436,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7741, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); TEST_SLEEP(); do { @@ -14789,7 +15450,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7742, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); TEST_SLEEP(); do { @@ -14803,7 +15464,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) } } while (ret == WC_PENDING_E); if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7743, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); TEST_SLEEP(); #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER @@ -14823,7 +15484,7 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) len, 0, HEAP_HINT); #endif if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7744, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); #ifndef WOLFSSL_PSS_LONG_SALT len = digestSz + 1; #else @@ -14833,15 +15494,19 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[0], len); + if (ret != PSS_SALTLEN_E) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[0], len, 0); + if (ret != BAD_PADDING_E) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); #else ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0], len, 0, HEAP_HINT); -#endif if (ret != PSS_SALTLEN_E) - ERROR_OUT(-7745, exit_rsa_pss); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss); +#endif ret = 0; #endif /* WOLFSSL_SE050 */ @@ -14901,7 +15566,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) || out == NULL || plain == NULL #endif ) { - ERROR_OUT(-7800, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding); } #ifdef USE_CERT_BUFFERS_1024 @@ -14915,24 +15580,27 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) #elif !defined(NO_FILESYSTEM) file = XFOPEN(clientKey, "rb"); if (!file) { - err_sys("can't open clientKey, Please run from wolfSSL home dir", -40); - ERROR_OUT(-7801, exit_rsa_nopadding); + err_sys("can't open clientKey, Please run from wolfSSL home dir", + WC_TEST_RET_ENC_ERRNO); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding); #else /* No key to use. */ - ERROR_OUT(-7802, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId); if (ret != 0) { - ERROR_OUT(-7803, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); if (ret != 0) { - ERROR_OUT(-7804, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } /* after loading in key use tmp as the test buffer */ @@ -14943,7 +15611,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) { - ERROR_OUT(-7805, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } #ifndef WOLFSSL_RSA_VERIFY_ONLY @@ -14961,12 +15629,12 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) } } while (ret == WC_PENDING_E); if (ret <= 0) { - ERROR_OUT(-7806, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } /* encrypted result should not be the same as input */ if (XMEMCMP(out, tmp, inLen) == 0) { - ERROR_OUT(-7807, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding); } TEST_SLEEP(); @@ -14981,11 +15649,11 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) } } while (ret == WC_PENDING_E); if (ret <= 0) { - ERROR_OUT(-7808, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } if (XMEMCMP(plain, tmp, inLen) != 0) { - ERROR_OUT(-7809, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding); } TEST_SLEEP(); #endif @@ -14993,12 +15661,12 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) #ifdef WC_RSA_BLINDING ret = wc_RsaSetRNG(NULL, &rng); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-7810, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } ret = wc_RsaSetRNG(key, &rng); if (ret < 0) { - ERROR_OUT(-7811, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } #endif @@ -15014,7 +15682,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) } } while (ret == WC_PENDING_E); if (ret < 0) { - ERROR_OUT(-7812, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_VERIFY_ONLY */ @@ -15030,11 +15698,11 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) } } while (ret == WC_PENDING_E); if (ret < 0) { - ERROR_OUT(-7813, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } if (XMEMCMP(plain, tmp, inLen) != 0) { - ERROR_OUT(-7814, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -15043,25 +15711,25 @@ WOLFSSL_TEST_SUBROUTINE int rsa_no_pad_test(void) ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1, &rng); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-7815, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT, &rng); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-7816, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT, &rng); if (ret != LENGTH_ONLY_E || plainSz != inLen) { - ERROR_OUT(-7817, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key, RSA_PUBLIC_DECRYPT, &rng); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-7818, exit_rsa_nopadding); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding); } /* if making it to this point of code without hitting an ERROR_OUT then @@ -15126,7 +15794,7 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) || out == NULL || plain == NULL #endif ) { - ERROR_OUT(-7800, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod); } #if defined(USE_CERT_BUFFERS_2048) @@ -15139,31 +15807,33 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) file = XFOPEN(clientKey, "rb"); if (!file) { err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", -40); - ERROR_OUT(-7801, exit_rsa_even_mod); + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod); #else /* No key to use. */ - ERROR_OUT(-7802, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod); #endif /* USE_CERT_BUFFERS */ #ifndef NO_ASN ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); if (ret != 0) { - ERROR_OUT(-7804, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #else #ifdef USE_CERT_BUFFERS_2048 ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256); if (ret != 0) { - ERROR_OUT(-7804, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } ret = mp_set_int(&key->e, WC_RSA_EXPONENT); if (ret != 0) { - ERROR_OUT(-7804, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #ifndef NO_SIG_WRAPPER modLen = 2048; @@ -15175,7 +15845,7 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) key->n.dp[0] &= (mp_digit)-2; if (ret != 0) { - ERROR_OUT(-7804, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } /* after loading in key use tmp as the test buffer */ @@ -15192,19 +15862,19 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) XMEMSET(tmp, 7, plainSz); ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng); if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_INVMOD_E) { - ERROR_OUT(-7806, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key); if (ret != MP_VAL && ret != MP_EXPTMOD_E) { - ERROR_OUT(-7808, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #endif #ifdef WC_RSA_BLINDING ret = wc_RsaSetRNG(key, rng); if (ret < 0) { - ERROR_OUT(-7811, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #endif @@ -15212,14 +15882,14 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng); if (ret != MP_VAL && ret != MP_EXPTMOD_E) { - ERROR_OUT(-7812, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #endif /* WOLFSSL_RSA_VERIFY_ONLY */ #ifndef WOLFSSL_RSA_PUBLIC_ONLY ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key); if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_INVMOD_E) { - ERROR_OUT(-7813, exit_rsa_even_mod); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod); } #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */ @@ -15247,7 +15917,7 @@ exit_rsa_even_mod: } #endif /* WOLFSSL_HAVE_SP_RSA */ -#ifdef WOLFSSL_CERT_GEN +#if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) { #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -15292,16 +15962,17 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { - ERROR_OUT(-7820, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (myCert == NULL) { - ERROR_OUT(-7821, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } /* self signed */ - if (wc_InitCert_ex(myCert, HEAP_HINT, devId)) { - ERROR_OUT(-7822, exit_rsa); + ret = wc_InitCert_ex(myCert, HEAP_HINT, devId); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName)); @@ -15323,31 +15994,34 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) myCert->certPoliciesNb = 2; /* add SKID from the Public Key */ - if (wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL) != 0) { - ERROR_OUT(-7823, exit_rsa); + ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } /* add AKID from the Public Key */ - if (wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL) != 0) { - ERROR_OUT(-7824, exit_rsa); + ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } /* add Key Usage */ - if (wc_SetKeyUsage(myCert,"cRLSign,keyCertSign") != 0) { - ERROR_OUT(-7825, exit_rsa); + ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign"); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } #ifdef WOLFSSL_EKU_OID { const char unique[] = "2.16.840.1.111111.100.1.10.1"; - if (wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0, - HEAP_HINT) != 0) { - ERROR_OUT(-7826, exit_rsa); + ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0, + HEAP_HINT); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } } #endif /* WOLFSSL_EKU_OID */ #endif /* WOLFSSL_CERT_EXT */ - ret = 0; do { #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); @@ -15357,7 +16031,7 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) } } while (ret == WC_PENDING_E); if (ret < 0) { - ERROR_OUT(-7827, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } certSz = ret; @@ -15366,20 +16040,21 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) { FreeDecodedCert(decode); - ERROR_OUT(-7828, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } FreeDecodedCert(decode); #endif ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile, - CERT_TYPE, -5578); + CERT_TYPE); if (ret != 0) { goto exit_rsa; } /* Setup Certificate */ - if (wc_InitCert_ex(myCert, HEAP_HINT, devId)) { - ERROR_OUT(-7829, exit_rsa); + ret = wc_InitCert_ex(myCert, HEAP_HINT, devId); + if (ret < 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } #ifdef WOLFSSL_ALT_NAMES @@ -15393,36 +16068,34 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) #else file3 = XFOPEN(rsaCaCertDerFile, "rb"); if (!file3) { - ERROR_OUT(-7830, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); XFCLOSE(file3); + if (bytes3 == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif /* USE_CERT_BUFFERS */ #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \ !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN) ret = wc_SetAltNames(myCert, rsaCaCertFile); - if (ret != 0) { - ERROR_OUT(-7831, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif /* get alt names from der */ ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3); - if (ret != 0) { - ERROR_OUT(-7832, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* get dates from der */ ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3); - if (ret != 0) { - ERROR_OUT(-7833, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_ASN_TIME ret = wc_GetCertDates(myCert, &beforeTime, &afterTime); - if (ret < 0) { - ERROR_OUT(-7834, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif #endif /* WOLFSSL_ALT_NAMES */ @@ -15436,21 +16109,21 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) #else file3 = XFOPEN(rsaCaKeyFile, "rb"); if (!file3) { - ERROR_OUT(-7835, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); XFCLOSE(file3); + if (bytes3 == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(caKey, HEAP_HINT); - if (ret != 0) { - ERROR_OUT(-7836, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3); - if (ret != 0) { - ERROR_OUT(-7837, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_SHA256 myCert->sigType = CTC_SHA256wRSA; @@ -15467,9 +16140,9 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) myCert->certPoliciesNb =1; /* add SKID from the Public Key */ - if (wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL) != 0) { - ERROR_OUT(-7838, exit_rsa); - } + ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add AKID from the CA certificate */ #if defined(USE_CERT_BUFFERS_2048) @@ -15481,14 +16154,13 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) #else ret = wc_SetAuthKeyId(myCert, rsaCaCertFile); #endif - if (ret != 0) { - ERROR_OUT(-7839, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add Key Usage */ - if (wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement") != 0) { - ERROR_OUT(-7840, exit_rsa); - } + ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement"); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif /* WOLFSSL_CERT_EXT */ #if defined(USE_CERT_BUFFERS_2048) @@ -15500,13 +16172,12 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) #else ret = wc_SetIssuer(myCert, rsaCaCertFile); #endif - if (ret < 0) { - ERROR_OUT(-7841, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng); if (certSz < 0) { - ERROR_OUT(-7842, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa); } ret = 0; @@ -15519,9 +16190,8 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) caKey, NULL, rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7843, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); certSz = ret; #ifdef WOLFSSL_TEST_CERT @@ -15529,13 +16199,13 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) { FreeDecodedCert(decode); - ERROR_OUT(-7844, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } FreeDecodedCert(decode); #endif ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile, - CERT_TYPE, -5598); + CERT_TYPE); if (ret != 0) { goto exit_rsa; } @@ -15607,11 +16277,11 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { - ERROR_OUT(-7850, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (myCert == NULL) { - ERROR_OUT(-7851, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } /* Get CA Key */ @@ -15624,21 +16294,21 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) #else file3 = XFOPEN(rsaCaKeyFile, "rb"); if (!file3) { - ERROR_OUT(-7852, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); XFCLOSE(file3); + if (bytes3 == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(caKey, HEAP_HINT); - if (ret != 0) { - ERROR_OUT(-7853, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3); - if (ret != 0) { - ERROR_OUT(-7854, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* Get Cert Key */ #ifdef USE_CERT_BUFFERS_256 @@ -15647,28 +16317,28 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) #else file3 = XFOPEN(eccKeyPubFileDer, "rb"); if (!file3) { - ERROR_OUT(-7855, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); XFCLOSE(file3); + if (bytes3 == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-7856, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); idx3 = 0; ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3); - if (ret != 0) { - ERROR_OUT(-7857, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* Setup Certificate */ - if (wc_InitCert_ex(myCert, HEAP_HINT, devId)) { - ERROR_OUT(-7858, exit_rsa); - } + ret = wc_InitCert_ex(myCert, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_SHA256 myCert->sigType = CTC_SHA256wRSA; @@ -15687,9 +16357,9 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) myCert->certPoliciesNb = 2; /* add SKID from the Public Key */ - if (wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub) != 0) { - ERROR_OUT(-7859, exit_rsa); - } + ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add AKID from the CA certificate */ #if defined(USE_CERT_BUFFERS_2048) @@ -15701,14 +16371,13 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) #else ret = wc_SetAuthKeyId(myCert, rsaCaCertFile); #endif - if (ret != 0) { - ERROR_OUT(-7860, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add Key Usage */ - if (wc_SetKeyUsage(myCert, certKeyUsage) != 0) { - ERROR_OUT(-7861, exit_rsa); - } + ret = wc_SetKeyUsage(myCert, certKeyUsage); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif /* WOLFSSL_CERT_EXT */ #if defined(USE_CERT_BUFFERS_2048) @@ -15720,13 +16389,12 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) #else ret = wc_SetIssuer(myCert, rsaCaCertFile); #endif - if (ret < 0) { - ERROR_OUT(-7862, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng); if (certSz < 0) { - ERROR_OUT(-7863, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa); } ret = 0; @@ -15739,9 +16407,8 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) FOURK_BUF, caKey, NULL, rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7864, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); certSz = ret; #ifdef WOLFSSL_TEST_CERT @@ -15749,14 +16416,13 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) { FreeDecodedCert(decode); - ERROR_OUT(-7865, exit_rsa); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } FreeDecodedCert(decode); #endif ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile, - CERT_TYPE, -5616); + CERT_TYPE); if (ret != 0) { goto exit_rsa; } @@ -15825,9 +16491,8 @@ static int rsa_keygen_test(WC_RNG* rng) XMEMSET(genKey, 0, sizeof *genKey); ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-7870, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifdef HAVE_FIPS for (;;) { @@ -15843,46 +16508,42 @@ static int rsa_keygen_test(WC_RNG* rng) } #endif - if (ret != 0) { - ERROR_OUT(-7871, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); #ifdef WOLFSSL_RSA_KEY_CHECK ret = wc_CheckRsaKey(genKey); - if (ret != 0) { - ERROR_OUT(-7872, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { - ERROR_OUT(-7873, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } derSz = wc_RsaKeyToDer(genKey, der, FOURK_BUF); if (derSz < 0) { - ERROR_OUT(-7874, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa); } ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile, - PRIVATEKEY_TYPE, -5555); + PRIVATEKEY_TYPE); if (ret != 0) { goto exit_rsa; } wc_FreeRsaKey(genKey); ret = wc_InitRsaKey(genKey, HEAP_HINT); - if (ret != 0) { - ERROR_OUT(-7875, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef WOLFSSL_CRYPTOCELL idx = 0; /* The private key part of the key gen pairs from cryptocell can't be exported */ ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, derSz); - if (ret != 0) { - ERROR_OUT(-7876, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif /* WOLFSSL_CRYPTOCELL */ exit_rsa: @@ -15943,9 +16604,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7918, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); #ifndef WOLFSSL_RSA_PUBLIC_ONLY @@ -15959,12 +16619,11 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7919, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7920, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* NO_SHA */ @@ -15981,9 +16640,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7921, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); idx = (word32)ret; @@ -15997,12 +16655,11 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7922, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7923, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -16017,14 +16674,13 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7924, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (ret != (int)inLen) { - ERROR_OUT(-7925, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } if (XMEMCMP(res, in, inLen)) { - ERROR_OUT(-7926, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -16040,9 +16696,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7927, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */ @@ -16061,7 +16716,7 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) } } while (ret == WC_PENDING_E); if (ret > 0) { /* in this case decrypt should fail */ - ERROR_OUT(-7928, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } ret = 0; TEST_SLEEP(); @@ -16078,9 +16733,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7929, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); idx = (word32)ret; @@ -16094,12 +16748,11 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7930, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7931, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -16116,9 +16769,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7932, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */ @@ -16136,7 +16788,7 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) } } while (ret == WC_PENDING_E); if (ret > 0) { /* should fail */ - ERROR_OUT(-7933, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } ret = 0; TEST_SLEEP(); @@ -16160,9 +16812,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7934, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); idx = ret; @@ -16176,12 +16827,11 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7935, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7936, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -16199,9 +16849,8 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7937, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); idx = (word32)ret; @@ -16215,12 +16864,11 @@ static int rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng) WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7938, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7939, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif /* WOLFSSL_RSA_PUBLIC_ONLY */ @@ -16354,7 +17002,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) - ERROR_OUT(-7900, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif #ifdef USE_CERT_BUFFERS_1024 @@ -16369,39 +17017,37 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) file = XFOPEN(clientKey, "rb"); if (!file) { err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", -40); - ERROR_OUT(-7901, exit_rsa); + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #else /* No key to use. */ - ERROR_OUT(-7902, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-7903, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_ASN ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); - if (ret != 0) { - ERROR_OUT(-7904, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_SIG_WRAPPER modLen = wc_RsaEncryptSize(key); #endif #else #ifdef USE_CERT_BUFFERS_2048 ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256); - if (ret != 0) { - ERROR_OUT(-7905, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); ret = mp_set_int(&key->e, WC_RSA_EXPONENT); - if (ret != 0) { - ERROR_OUT(-7906, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifndef NO_SIG_WRAPPER modLen = 2048; #endif @@ -16416,9 +17062,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #else ret = wc_InitRng(&rng); #endif - if (ret != 0) { - ERROR_OUT(-7907, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif #ifndef NO_SIG_WRAPPER @@ -16443,18 +17088,16 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7908, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); #ifdef WC_RSA_BLINDING { int tmpret = ret; ret = wc_RsaSetRNG(key, &rng); - if (ret < 0) { - ERROR_OUT(-7909, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); ret = tmpret; } #endif @@ -16468,12 +17111,11 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7910, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, inLen)) { - ERROR_OUT(-7911, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); @@ -16485,14 +17127,13 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ret = wc_RsaPrivateDecryptInline(out, idx, &res, key); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7912, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (ret != (int)inLen) { - ERROR_OUT(-7913, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } if (XMEMCMP(res, in, inLen)) { - ERROR_OUT(-7914, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); @@ -16504,9 +17145,8 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7915, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); TEST_SLEEP(); #elif defined(WOLFSSL_PUBLIC_MP) @@ -16586,12 +17226,11 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #endif } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7916, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); if (XMEMCMP(plain, in, (size_t)ret)) { - ERROR_OUT(-7917, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); } TEST_SLEEP(); #endif @@ -16650,14 +17289,16 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #elif !defined(NO_FILESYSTEM) file2 = XFOPEN(clientCert, "rb"); if (!file2) { - ERROR_OUT(-7940, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes = XFREAD(tmp, 1, FOURK_BUF, file2); XFCLOSE(file2); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #else /* No certificate to use. */ - ERROR_OUT(-7941, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa); #endif #ifdef sizeof @@ -16668,7 +17309,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL); if (ret != 0) { FreeDecodedCert(cert); - ERROR_OUT(-7942, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } #ifndef NO_ASN_TIME @@ -16676,12 +17317,12 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) &dateFormat, &dateLength); if (ret != 0) { FreeDecodedCert(cert); - ERROR_OUT(-7943, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg); if (ret != 0) { FreeDecodedCert(cert); - ERROR_OUT(-7944, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } #endif @@ -16706,24 +17347,24 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) file = XFOPEN(clientKeyPub, "rb"); if (!file) { err_sys("can't open ./certs/client-keyPub.der, " - "Please run from wolfSSL home dir", -40); - ERROR_OUT(-7945, exit_rsa); + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(keypub, HEAP_HINT); - if (ret != 0) { - ERROR_OUT(-7946, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); idx = 0; ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes); - if (ret != 0) { - ERROR_OUT(-7947, exit_rsa); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #endif /* WOLFSSL_CERT_EXT */ #ifdef WOLFSSL_KEY_GEN @@ -16732,7 +17373,7 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) goto exit_rsa; #endif -#ifdef WOLFSSL_CERT_GEN +#if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) /* Make Cert / Sign example for RSA cert and RSA CA */ ret = rsa_certgen_test(key, keypub, &rng, tmp); if (ret != 0) @@ -16757,12 +17398,12 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) ERROR_OUT(MEMORY_E, exit_rsa); der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { - ERROR_OUT(-7964, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa); } - if (wc_InitCert_ex(req, HEAP_HINT, devId)) { - ERROR_OUT(-7965, exit_rsa); - } + ret = wc_InitCert_ex(req, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); req->version = 0; req->isCA = 1; @@ -16777,44 +17418,46 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) #ifdef WOLFSSL_CERT_EXT /* add SKID from the Public Key */ - if (wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL) != 0) { - ERROR_OUT(-7966, exit_rsa); - } + ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add Key Usage */ - if (wc_SetKeyUsage(req, certKeyUsage2) != 0) { - ERROR_OUT(-7967, exit_rsa); - } + ret = wc_SetKeyUsage(req, certKeyUsage2); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); /* add Extended Key Usage */ - if (wc_SetExtKeyUsage(req, "serverAuth,clientAuth,codeSigning," - "emailProtection,timeStamping,OCSPSigning") != 0) { - ERROR_OUT(-7968, exit_rsa); - } + ret = wc_SetExtKeyUsage(req, + "serverAuth,clientAuth,codeSigning," + "emailProtection,timeStamping,OCSPSigning"); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); #ifdef WOLFSSL_EKU_OID { - WOLFSSL_SMALL_STACK_STATIC const char unique[] = "2.16.840.1.111111.100.1.10.1"; - if (wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0, - HEAP_HINT) != 0) { - ERROR_OUT(-7969, exit_rsa); - } + WOLFSSL_SMALL_STACK_STATIC const char unique[] = + "2.16.840.1.111111.100.1.10.1"; + ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0, + HEAP_HINT); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); } #endif /* WOLFSSL_EKU_OID */ #endif /* WOLFSSL_CERT_EXT */ derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL); if (derSz < 0) { - ERROR_OUT(-7970, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa); } #ifdef WOLFSSL_CERT_EXT /* Try again with "any" flag set, will override all others */ - if (wc_SetExtKeyUsage(req, "any") != 0) { - ERROR_OUT(-7971, exit_rsa); - } + ret = wc_SetExtKeyUsage(req, "any"); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL); if (derSz < 0) { - ERROR_OUT(-7972, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa); } #endif /* WOLFSSL_CERT_EXT */ @@ -16828,27 +17471,26 @@ WOLFSSL_TEST_SUBROUTINE int rsa_test(void) key, NULL, &rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-7973, exit_rsa); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa); derSz = ret; ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile, - CERTREQ_TYPE, -5650); + CERTREQ_TYPE); if (ret != 0) { goto exit_rsa; } derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key); if (derSz < 0) { - ERROR_OUT(-7974, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa); } /* Test getting the size of the buffer without providing the buffer. * derSz is set to the "largest buffer" we are willing to allocate. */ derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL); if (derSz < 0) { - ERROR_OUT(-7975, exit_rsa); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa); } XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -17039,95 +17681,87 @@ static int dh_fips_generate_test(WC_RNG *rng) /* Parameter Validation testing. */ ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7980, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7981, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7982, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7983, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7984, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL); if (ret != BAD_FUNC_ARG) - ERROR_OUT(-7985, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-7986, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0)); - if (ret != 0) { - ERROR_OUT(-7987, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); wc_FreeDhKey(key); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-7988, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q)); - if (ret != 0) { - ERROR_OUT(-7989, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); /* Use API. */ ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-7990, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0)); - if (ret != 0) { - ERROR_OUT(-7991, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); wc_FreeDhKey(key); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-7992, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g)); - if (ret != 0) { - ERROR_OUT(-7993, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q)); - if (ret != 0) { - ERROR_OUT(-7994, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); #ifndef HAVE_SELFTEST ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz); - if (ret != 0) { - ERROR_OUT(-7995, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); /* Taint the public key so the check fails. */ pub[0]++; ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz); if (ret != MP_CMP_E) { - ERROR_OUT(-7996, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } #ifdef WOLFSSL_KEY_GEN wc_FreeDhKey(key); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-7997, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateParams(rng, 2048, key); - if (ret != 0) { - ERROR_OUT(-7998, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); privSz = sizeof(priv); pubSz = sizeof(pub); @@ -17136,9 +17770,8 @@ static int dh_fips_generate_test(WC_RNG *rng) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-7999, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); #endif /* WOLFSSL_KEY_GEN */ #endif /* HAVE_SELFTEST */ @@ -17184,44 +17817,43 @@ static int dh_generate_test(WC_RNG *rng) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) - return -8019; + return WC_TEST_RET_ENC_ERRNO; #endif ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-8010, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); smallKey_inited = 1; /* Parameter Validation testing. */ ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId); if (ret != BAD_FUNC_ARG) - return -8011; + return WC_TEST_RET_ENC_EC(ret); wc_FreeDhKey(NULL); ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g)); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-8012, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g)); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-8013, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g)); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-8014, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g)); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-8015, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0); if (ret != BAD_FUNC_ARG) { - ERROR_OUT(-8016, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g)); - if (ret != 0) { - ERROR_OUT(-8017, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE) /* Use API. */ @@ -17230,7 +17862,7 @@ static int dh_generate_test(WC_RNG *rng) ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) { - ret = -8018; + ret = WC_TEST_RET_ENC_EC(ret); } #else (void)rng; @@ -17250,12 +17882,11 @@ static int dh_generate_test(WC_RNG *rng) wc_FreeDhKey(smallKey); ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-8019, exit_gen_test); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); ret = wc_DhGenerateParams(rng, 2056, smallKey); - if (ret != 0) { - ERROR_OUT(-8020, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); privSz = sizeof(priv); pubSz = sizeof(pub); @@ -17264,9 +17895,8 @@ static int dh_generate_test(WC_RNG *rng) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8021, exit_gen_test); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test); } #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */ @@ -17333,14 +17963,14 @@ static int dh_test_check_pubvalue(void) ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data, dh_pubval_fail[i].len); if (ret != MP_VAL) - return -8020 - (int)i; + return WC_TEST_RET_ENC_I(i); } for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) { ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data, dh_pubval_pass[i].len); if (ret != 0) - return -8030 - (int)i; + return WC_TEST_RET_ENC_I(i); } return 0; @@ -17404,7 +18034,7 @@ static int dh_ffdhe_test(WC_RNG *rng, int name) (agree2 == NULL) || (key == NULL) || (key2 == NULL)) - ERROR_OUT(-8050, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif pubSz = MAX_DH_KEY_SZ; @@ -17421,22 +18051,19 @@ static int dh_ffdhe_test(WC_RNG *rng, int name) XMEMSET(key2, 0, sizeof(*key2)); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8051, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8052, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_PUBLIC_FFDHE ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len); #else ret = wc_DhSetNamedKey(key, name); #endif - if (ret != 0) { - ERROR_OUT(-8053, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_PUBLIC_FFDHE ret = wc_DhSetKey(key2, params->p, params->p_len, params->g, @@ -17444,59 +18071,53 @@ static int dh_ffdhe_test(WC_RNG *rng, int name) #else ret = wc_DhSetNamedKey(key2, name); #endif - if (ret != 0) { - ERROR_OUT(-8054, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8055, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8056, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8057, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8058, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) { - ERROR_OUT(-8059, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #if defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH) /* Make p even */ key->p.dp[0] &= (mp_digit)-2; - if (ret != 0) { - ERROR_OUT(-8058, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != MP_VAL && ret != MP_EXPTMOD_E) { - ERROR_OUT(-8058, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2); @@ -17504,14 +18125,14 @@ static int dh_ffdhe_test(WC_RNG *rng, int name) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != ASYNC_OP_E) { - ERROR_OUT(-8057, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #ifndef HAVE_SELFTEST ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz); if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_CMP_E && ret != ASYNC_OP_E) { - ERROR_OUT(-8057, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif @@ -17596,7 +18217,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL || agree == NULL || agree2 == NULL) { - ERROR_OUT(-8100, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #else byte priv[DH_TEST_BUF_SIZE]; @@ -17610,7 +18231,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (key == NULL || key2 == NULL || tmp == NULL) { - ERROR_OUT(-8100, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #endif @@ -17632,14 +18253,16 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) { XFILE file = XFOPEN(dhParamsFile, "rb"); if (! file) - ERROR_OUT(-8101, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #else /* No DH key to use. */ - ERROR_OUT(-8102, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif /* USE_CERT_BUFFERS */ (void)idx; @@ -17657,57 +18280,48 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) /* Use API for coverage. */ ret = wc_InitDhKey(key); - if (ret != 0) { - ERROR_OUT(-8103, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); wc_FreeDhKey(key); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8104, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); keyInit = 1; ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8105, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); key2Init = 1; #ifdef NO_ASN #ifndef WOLFSSL_SP_MATH ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g)); - if (ret != 0) { - ERROR_OUT(-8106, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g)); - if (ret != 0) { - ERROR_OUT(-8107, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #else ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g, sizeof(dh2048_g)); - if (ret != 0) { - ERROR_OUT(-8106, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g, sizeof(dh2048_g)); - if (ret != 0) { - ERROR_OUT(-8107, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #else ret = wc_DhKeyDecode(tmp, &idx, key, bytes); - if (ret != 0) { - ERROR_OUT(-8108, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); idx = 0; ret = wc_DhKeyDecode(tmp, &idx, key2, bytes); - if (ret != 0) { - ERROR_OUT(-8109, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #ifndef WC_NO_RNG @@ -17716,61 +18330,60 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) #else ret = wc_InitRng(&rng); #endif - if (ret != 0) { - ERROR_OUT(-8110, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); rngInit = 1; ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8111, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8112, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8113, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-8114, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) { - ERROR_OUT(-8115, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif /* !WC_NO_RNG */ #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) - if (wc_DhCheckPrivKey(NULL, NULL, 0) != BAD_FUNC_ARG) - ERROR_OUT(-8116, done); + ret = wc_DhCheckPrivKey(NULL, NULL, 0); + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); - if (wc_DhCheckPrivKey(key, priv, privSz) != 0) - ERROR_OUT(-8117, done); + ret = wc_DhCheckPrivKey(key, priv, privSz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); - if (wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL) != BAD_FUNC_ARG) - ERROR_OUT(-8118, done); + ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL); + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); { word32 pSz, qSz, gSz; - if (wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz) != LENGTH_ONLY_E) - ERROR_OUT(-8119, done); + ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz); + if (ret != LENGTH_ONLY_E) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif @@ -17780,9 +18393,8 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) wc_FreeDhKey(key); ret = wc_InitDhKey_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8120, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifndef NO_ASN { @@ -17794,14 +18406,16 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) #endif XFILE file = XFOPEN(dhKeyFile, "rb"); if (!file) - ERROR_OUT(-8130, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp2 == NULL) - ERROR_OUT(-8131, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #endif idx = 0; XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE); @@ -17816,16 +18430,18 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) /* Verify export matches original */ if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) { - ERROR_OUT(-8132, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } /* DH Public Key - Export / Import */ file = XFOPEN(dhKeyPubFile, "rb"); if (!file) - ERROR_OUT(-8133, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); /* for HAVE_WOLF_BIGINT prevent leak */ wc_FreeDhKey(key); @@ -17844,7 +18460,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) /* Verify export matches original */ if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) { - ERROR_OUT(-8134, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -17853,37 +18469,34 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) } #else ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g)); - if (ret != 0) { - ERROR_OUT(-8121, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif /* !NO_ASN */ privSz = DH_TEST_BUF_SIZE; pubSz = DH_TEST_BUF_SIZE; ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz); - if (ret != 0) { - ERROR_OUT(-8122, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz); - if (ret != 0) { - ERROR_OUT(-8125, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */ #ifndef WC_NO_RNG ret = dh_generate_test(&rng); if (ret != 0) - ERROR_OUT(-8123, done); + ERROR_OUT(ret, done); ret = dh_fips_generate_test(&rng); if (ret != 0) - ERROR_OUT(-8124, done); + ERROR_OUT(ret, done); #endif /* !WC_NO_RNG */ #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) ret = dh_test_check_pubvalue(); if (ret != 0) - ERROR_OUT(-8125, done); + ERROR_OUT(ret, done); #endif #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \ @@ -17899,7 +18512,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) ret = dh_ffdhe_test(&rng, WC_FFDHE_2048); #endif if (ret != 0) - ERROR_OUT(-8126, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #ifdef HAVE_FFDHE_3072 #ifdef HAVE_PUBLIC_FFDHE @@ -17908,7 +18521,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) ret = dh_ffdhe_test(&rng, WC_FFDHE_3072); #endif if (ret != 0) - ERROR_OUT(-8127, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #ifdef HAVE_FFDHE_4096 #ifdef HAVE_PUBLIC_FFDHE @@ -17917,7 +18530,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) ret = dh_ffdhe_test(&rng, WC_FFDHE_4096); #endif if (ret != 0) - ERROR_OUT(-8128, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #endif /* !WC_NO_RNG */ #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */ @@ -17931,7 +18544,7 @@ WOLFSSL_TEST_SUBROUTINE int dh_test(void) ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g), NULL, 0, 0, &rng); if (ret != 0) - ERROR_OUT(-8129, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); keyInit = 1; /* DhSetCheckKey also initializes the key, free it */ #endif @@ -18016,7 +18629,7 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) || (genKey == NULL) #endif ) { - ret = -8216; + ret = WC_TEST_RET_ENC_NC; goto out; } #else @@ -18038,27 +18651,29 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) { XFILE file = XFOPEN(dsaKey, "rb"); if (!file) - ERROR_OUT(-8200, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } #endif /* USE_CERT_BUFFERS */ ret = wc_InitSha_ex(&sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-8201, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_ShaUpdate(&sha, tmp, bytes); wc_ShaFinal(&sha, hash); wc_ShaFree(&sha); ret = wc_InitDsaKey(key); if (ret != 0) - ERROR_OUT(-8202, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes); if (ret != 0) - ERROR_OUT(-8203, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifndef HAVE_FIPS ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); @@ -18066,17 +18681,17 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - ERROR_OUT(-8204, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_DsaSign(hash, signature, key, &rng); if (ret != 0) - ERROR_OUT(-8205, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_DsaVerify(hash, signature, key, &answer); if (ret != 0) - ERROR_OUT(-8206, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (answer != 1) - ERROR_OUT(-8207, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_FreeDsaKey(key); @@ -18086,34 +18701,34 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) ret = wc_InitDsaKey(genKey); if (ret != 0) - ERROR_OUT(-8208, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_MakeDsaParameters(&rng, 1024, genKey); if (ret != 0) { wc_FreeDsaKey(genKey); - ERROR_OUT(-8209, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = wc_MakeDsaKey(&rng, genKey); if (ret != 0) { wc_FreeDsaKey(genKey); - ERROR_OUT(-8210, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { wc_FreeDsaKey(genKey); - ERROR_OUT(-8211, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF); if (derSz < 0) { XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - ERROR_OUT(-8212, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out); } ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile, - DSA_PRIVATEKEY_TYPE, -5814); + DSA_PRIVATEKEY_TYPE); if (ret != 0) { XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_FreeDsaKey(genKey); @@ -18124,7 +18739,7 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) if (ret != 0) { XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_FreeDsaKey(genKey); - ERROR_OUT(-8213, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } idx = 0; @@ -18133,7 +18748,7 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_FreeDsaKey(derIn); wc_FreeDsaKey(genKey); - ERROR_OUT(-8214, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } @@ -18144,8 +18759,9 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (key) { #endif - if (wc_InitDsaKey_h(key, NULL) != 0) - ret = -8215; + ret = wc_InitDsaKey_h(key, NULL); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) } #endif @@ -18191,11 +18807,11 @@ WOLFSSL_TEST_SUBROUTINE int dsa_test(void) static int generate_random_salt(byte *buf, word32 size) { - int ret = -8220; + int ret = WC_TEST_RET_ENC_NC; WC_RNG rng; if(NULL == buf || !size) - return -8221; + return WC_TEST_RET_ENC_NC; if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) { ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size); @@ -18271,7 +18887,7 @@ static int srp_test_digest(SrpType dgstType) (srv == NULL) || (clientProof == NULL) || (serverProof == NULL)) { - r = -8222; + r = WC_TEST_RET_ENC_NC; goto out; } #else @@ -18428,25 +19044,25 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8400; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0) - return -8401; + return WC_TEST_RET_ENC_NC; if (outlen != 0) - return -8402; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0) - return -8403; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8404; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0) - return -8405; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8406; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != 32) return 3408; @@ -18455,107 +19071,107 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8407; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0) - return -8408; + return WC_TEST_RET_ENC_NC; if (outlen != 0) - return -8409; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0) - return -8410; + return WC_TEST_RET_ENC_NC; if (outlen != 0) total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0) - return -8411; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8412; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0) - return -8413; + return WC_TEST_RET_ENC_NC; if (outlen != 2) - return -8414; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != 18) return 3427; if (XMEMCMP(plain, cbcPlain, 18)) - return -8415; + return WC_TEST_RET_ENC_NC; /* test with encrypting/decrypting more than 16 bytes at once */ total = 0; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8416; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 17) == 0) - return -8417; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8418; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[17] , 1) == 0) - return -8419; + return WC_TEST_RET_ENC_NC; if (outlen != 0) - return -8420; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0) - return -8421; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8422; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != 32) - return -8423; + return WC_TEST_RET_ENC_NC; total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8424; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0) - return -8425; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8426; + return WC_TEST_RET_ENC_NC; total += outlen; /* final call on non block size should fail */ if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0) - return -8427; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[17], 1) == 0) - return -8428; + return WC_TEST_RET_ENC_NC; if (outlen != 0) total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[17+1], 14) == 0) - return -8429; + return WC_TEST_RET_ENC_NC; if (outlen != 0) - return -8430; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0) - return -8431; + return WC_TEST_RET_ENC_NC; if (outlen != 2) - return -8432; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != 18) - return -8433; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, cbcPlain, 18)) - return -8434; + return WC_TEST_RET_ENC_NC; /* test byte by byte decrypt */ for (i = 0; i < AES_BLOCK_SIZE * 3; i++) { @@ -18566,32 +19182,32 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8435; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)plain, AES_BLOCK_SIZE * 3) == 0) - return -8436; + return WC_TEST_RET_ENC_NC; if (outlen != AES_BLOCK_SIZE * 3) - return -8437; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0) - return -8438; + return WC_TEST_RET_ENC_NC; if (outlen != AES_BLOCK_SIZE) - return -8439; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != sizeof(plain)) - return -8440; + return WC_TEST_RET_ENC_NC; total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8441; + return WC_TEST_RET_ENC_NC; for (i = 0; i < AES_BLOCK_SIZE * 4; i++) { if (EVP_CipherUpdate(de, (byte*)plain + total, &outlen, (byte*)cipher + i, 1) == 0) - return -8442; + return WC_TEST_RET_ENC_NC; if (outlen > 0) { int j; @@ -18599,21 +19215,21 @@ static int openssl_aes_test(void) total += outlen; for (j = 0; j < total; j++) { if (plain[j] != j) { - return -8443; + return WC_TEST_RET_ENC_NC; } } } } if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0) - return -8444; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != AES_BLOCK_SIZE * 3) { - return -8445; + return WC_TEST_RET_ENC_NC; } for (i = 0; i < AES_BLOCK_SIZE * 3; i++) { if (plain[i] != i) { - return -8446; + return WC_TEST_RET_ENC_NC; } } @@ -18666,40 +19282,40 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8447; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(en, 0) != 1) - return -8448; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0) - return -8449; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8450; + return WC_TEST_RET_ENC_NC; total += outlen; /* should fail here */ if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0) - return -8451; + return WC_TEST_RET_ENC_NC; /* turn padding back on and do successful encrypt */ total = 0; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8452; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(en, 1) != 1) - return -8453; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)padded, &outlen, (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0) - return -8454; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8455; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0) - return -8456; + return WC_TEST_RET_ENC_NC; total += outlen; if (total != 32) - return -8457; + return WC_TEST_RET_ENC_NC; XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ); /* test out of bounds read on buffers w/o padding during decryption */ @@ -18707,39 +19323,39 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8458; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(de, 0) != 1) - return -8459; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, EVP_TEST_BUF_SZ) == 0) - return -8460; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8461; + return WC_TEST_RET_ENC_NC; total += outlen; /* should fail since not using padding */ if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0) - return -8462; + return WC_TEST_RET_ENC_NC; total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8463; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(de, 1) != 1) - return -8464; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded, EVP_TEST_BUF_PAD) == 0) - return -8465; + return WC_TEST_RET_ENC_NC; if (outlen != 16) - return -8466; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0) - return -8467; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ)) - return -8468; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); @@ -18781,23 +19397,23 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(ctx); if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1) == 0) - return -8469; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16) - return -8470; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - return -8471; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(ctx); if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0) == 0) - return -8472; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(ctx, plain, cipher, 16) != 16) - return -8473; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - return -8474; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); @@ -18844,23 +19460,23 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(ctx); if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0) - return -8475; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16) - return -8476; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - return -8477; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(ctx); if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0) - return -8478; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(ctx, plain, cipher, 16) != 16) - return -8479; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - return -8480; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); @@ -18924,11 +19540,11 @@ static int openssl_aes_test(void) #ifdef HAVE_AES_DECRYPT AES_decrypt(cipher, plain, dec); if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - return -8481; + return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - return -8482; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); @@ -19073,132 +19689,132 @@ static int openssl_aes_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8483; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8484; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8485; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8486; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) - return -8487; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) - return -8488; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) p_en = wolfSSL_EVP_CIPHER_CTX_new(); if (p_en == NULL) - return -8489; + return WC_TEST_RET_ENC_ERRNO; p_de = wolfSSL_EVP_CIPHER_CTX_new(); if (p_de == NULL) - return -8490; + return WC_TEST_RET_ENC_ERRNO; if (EVP_CipherInit(p_en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8491; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8492; + return WC_TEST_RET_ENC_NC; if (EVP_CipherInit(p_de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8493; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8494; + return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_free(p_en); wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) - return -8495; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) - return -8496; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8497; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9) - return -8498; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8499; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9) - return -8500; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, 9)) - return -8501; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, ctrCipher, 9)) - return -8502; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9) - return -8503; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9) - return -8504; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, 9)) - return -8505; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, oddCipher, 9)) - return -8506; + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_128 */ #ifdef WOLFSSL_AES_192 EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_192_ctr(), (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) - return -8507; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8508; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_192_ctr(), (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) - return -8509; + return WC_TEST_RET_ENC_NC; XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8510; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain))) - return -8511; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher))) - return -8512; + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_192 */ #ifdef WOLFSSL_AES_256 EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_256_ctr(), (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) - return -8513; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8514; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_256_ctr(), (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) - return -8515; + return WC_TEST_RET_ENC_NC; XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8516; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain))) - return -8517; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher))) - return -8518; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); @@ -19263,20 +19879,20 @@ static int openssl_aes_test(void) &num, AES_ENCRYPT); if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1)) - return -8519; + return WC_TEST_RET_ENC_NC; if (num != 15) /* should have used 15 of the 16 bytes */ - return -8520; + return WC_TEST_RET_ENC_NC; wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1, cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv, &num, AES_ENCRYPT); if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2)) - return -8521; + return WC_TEST_RET_ENC_NC; if (num != 0) - return -8522; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); @@ -19314,7 +19930,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) p = (byte*)CRYPTO_malloc(10, "", 0); if (p == NULL) { - return -8600; + return WC_TEST_RET_ENC_NC; } XMEMSET(p, 0, 10); CRYPTO_free(p, "", 0); @@ -19338,9 +19954,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS) - return -18601; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0) - return -8601; + return WC_TEST_RET_ENC_NC; #endif /* NO_MD5 */ #ifndef NO_SHA @@ -19361,9 +19977,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS) - return -18602; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(hash, b.output, WC_SHA_DIGEST_SIZE) != 0) - return -8602; + return WC_TEST_RET_ENC_NC; #endif /* NO_SHA */ #ifdef WOLFSSL_SHA224 @@ -19384,7 +20000,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, WC_SHA224_DIGEST_SIZE) != 0) { - return -8603; + return WC_TEST_RET_ENC_NC; } #endif /* WOLFSSL_SHA224 */ @@ -19406,7 +20022,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, WC_SHA256_DIGEST_SIZE) != 0) { - return -8604; + return WC_TEST_RET_ENC_NC; } #endif /* !NO_SHA256 */ @@ -19430,7 +20046,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, WC_SHA384_DIGEST_SIZE) != 0) { - return -8605; + return WC_TEST_RET_ENC_NC; } #endif /* WOLFSSL_SHA384 */ @@ -19455,12 +20071,12 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, WC_SHA512_DIGEST_SIZE) != 0) { - return -8606; + return WC_TEST_RET_ENC_NC; } -#endif /* WOLFSSL_SHA512 */ -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) +#if !defined(WOLFSSL_NOSHA512_224) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) + f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45" @@ -19478,13 +20094,12 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, WC_SHA512_224_DIGEST_SIZE) != 0) { - return -8722; + return WC_TEST_RET_ENC_NC; } -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ +#endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */ -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) -#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) +#if !defined(WOLFSSL_NOSHA512_256) && \ + (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST) f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31" @@ -19503,10 +20118,10 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, WC_SHA512_256_DIGEST_SIZE) != 0) { - return -8723; + return WC_TEST_RET_ENC_NC; } -#endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */ -#endif /* !HAVE_FIPS && !HAVE_SELFTEST */ +#endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */ +#endif /* WOLFSSL_SHA512 */ #ifdef WOLFSSL_SHA3 #ifndef WOLFSSL_NOSHA3_224 @@ -19527,7 +20142,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, WC_SHA3_224_DIGEST_SIZE) != 0) { - return -8607; + return WC_TEST_RET_ENC_NC; } #endif /* WOLFSSL_NOSHA3_224 */ @@ -19550,7 +20165,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, WC_SHA3_256_DIGEST_SIZE) != 0) { - return -8608; + return WC_TEST_RET_ENC_NC; } #endif /* WOLFSSL_NOSHA3_256 */ @@ -19573,7 +20188,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, WC_SHA3_384_DIGEST_SIZE) != 0) { - return -8609; + return WC_TEST_RET_ENC_NC; } #ifndef WOLFSSL_NOSHA3_512 @@ -19597,14 +20212,14 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_MD_CTX_cleanup(&md_ctx); if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, WC_SHA3_512_DIGEST_SIZE) != 0) { - return -8610; + return WC_TEST_RET_ENC_NC; } #endif /* WOLFSSL_NOSHA3_512 */ #endif /* WOLFSSL_SHA3 */ #ifndef WC_NO_RNG if (RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS) - return -8611; + return WC_TEST_RET_ENC_NC; #endif #ifndef NO_MD5 @@ -19624,7 +20239,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) XMEMCMP(hash, c.output, WC_MD5_DIGEST_SIZE) != 0) #endif { - return -8612; + return WC_TEST_RET_ENC_NC; } #endif /* NO_MD5 */ @@ -19656,17 +20271,17 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT); if (XMEMCMP(plain, vector, sizeof(vector)) != 0) - return -8613; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher, verify, sizeof(verify)) != 0) - return -8614; + return WC_TEST_RET_ENC_NC; /* test changing iv */ DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT); DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT); if (XMEMCMP(cipher, verify, sizeof(verify)) != 0) - return -8615; + return WC_TEST_RET_ENC_NC; } /* end des test */ #endif /* NO_DES3 */ @@ -19727,9 +20342,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } EVP_CIPHER_CTX_cleanup(ctx); if (ret != WOLFSSL_SUCCESS) - return -8617; + return WC_TEST_RET_ENC_NC; if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz)) - return -8618; + return WC_TEST_RET_ENC_NC; /* check partial decrypt (not enough padding for full block) */ plainSz = 0; @@ -19746,10 +20361,10 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) if (plainSz == 0 && ret != WOLFSSL_SUCCESS) ret = WOLFSSL_SUCCESS; else - ret = -8619; + ret = WC_TEST_RET_ENC_NC; } else - ret = -8620; + ret = WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_cleanup(ctx); if (ret != WOLFSSL_SUCCESS) return ret; @@ -19769,9 +20384,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } EVP_CIPHER_CTX_cleanup(ctx); if (ret != WOLFSSL_SUCCESS) - return -8621; + return WC_TEST_RET_ENC_NC; if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg))) - return -8622; + return WC_TEST_RET_ENC_NC; cipherSz = 0; EVP_CIPHER_CTX_init(ctx); @@ -19788,9 +20403,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } EVP_CIPHER_CTX_cleanup(ctx); if (ret != WOLFSSL_SUCCESS) - return -8623; + return WC_TEST_RET_ENC_NC; if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz)) - return -8624; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); @@ -19833,9 +20448,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) ret = EVP_Cipher(ctx, cipher, (byte*)msg, 16); EVP_CIPHER_CTX_cleanup(ctx); if (ret != 16) - return -8625; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - return -8626; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(ctx); ret = EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0); @@ -19843,9 +20458,9 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) ret = EVP_Cipher(ctx, plain, cipher, 16); EVP_CIPHER_CTX_cleanup(ctx); if (ret != 16) - return -8627; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - return -8628; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(ctx); @@ -19853,9 +20468,6 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) } /* end evp_cipher test */ #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */ -#define OPENSSL_TEST_ERROR (-10000) - - #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256) /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */ { @@ -19915,11 +20527,11 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) #ifdef HAVE_AES_DECRYPT AES_decrypt(cipher, plain, dec); if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) - return OPENSSL_TEST_ERROR-60; + return WC_TEST_RET_ENC_NC; #endif /* HAVE_AES_DECRYPT */ if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) - return OPENSSL_TEST_ERROR-61; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES); @@ -20063,132 +20675,132 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8629; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8630; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8631; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8632; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) - return -8633; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) - return -8634; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) p_en = wolfSSL_EVP_CIPHER_CTX_new(); if (p_en == NULL) - return -8635; + return WC_TEST_RET_ENC_ERRNO; p_de = wolfSSL_EVP_CIPHER_CTX_new(); if (p_de == NULL) - return -8636; + return WC_TEST_RET_ENC_ERRNO; if (EVP_CipherInit(p_en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8637; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8638; + return WC_TEST_RET_ENC_NC; if (EVP_CipherInit(p_de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8639; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4) - return -8640; + return WC_TEST_RET_ENC_NC; wolfSSL_EVP_CIPHER_CTX_free(p_en); wolfSSL_EVP_CIPHER_CTX_free(p_de); #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4)) - return -8641; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4)) - return -8642; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8643; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9) - return -8644; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_ctr(), (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0) - return -8645; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9) - return -8646; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, 9)) - return -8647; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, ctrCipher, 9)) - return -8648; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9) - return -8649; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9) - return -8650; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctrPlain, 9)) - return -8651; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(cipherBuff, oddCipher, 9)) - return -8652; + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_128 */ #ifdef WOLFSSL_AES_192 EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_192_ctr(), (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) - return -8653; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8654; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_192_ctr(), (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0) - return -8655; + return WC_TEST_RET_ENC_NC; XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8656; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain))) - return -8657; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher))) - return -8658; + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_192 */ #ifdef WOLFSSL_AES_256 EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_256_ctr(), (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) - return -8659; + return WC_TEST_RET_ENC_NC; if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8660; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_256_ctr(), (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0) - return -8661; + return WC_TEST_RET_ENC_NC; XMEMSET(plainBuff, 0, sizeof(plainBuff)); if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, AES_BLOCK_SIZE) != AES_BLOCK_SIZE) - return -8662; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain))) - return -8663; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher))) - return -8664; + return WC_TEST_RET_ENC_NC; #endif /* WOLFSSL_AES_256 */ #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -20238,206 +20850,228 @@ WOLFSSL_TEST_SUBROUTINE int openssl_test(void) EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8665; + return WC_TEST_RET_ENC_NC; /* openSSL compatibility, if(inlen == 0)return 1; */ if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 0) != 1) - return -8666; + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 1) == 0) - return -8667; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0) - return -8668; + return WC_TEST_RET_ENC_NC; if(outlen != 0) - return -8669; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0) - return -8670; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8671; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0) - return -8672; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8673; + return WC_TEST_RET_ENC_NC; total += outlen; if(total != 32) - return -8674; + return WC_TEST_RET_ENC_NC; total = 0; EVP_CIPHER_CTX_init(de); if (EVP_CipherInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8675; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0) - return -8676; + return WC_TEST_RET_ENC_NC; if(outlen != 0) - return -8677; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0) - return -8678; + return WC_TEST_RET_ENC_NC; if(outlen != 0) total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0) - return -8679; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8680; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0) - return -8681; + return WC_TEST_RET_ENC_NC; if(outlen != 2) - return -8682; + return WC_TEST_RET_ENC_NC; total += outlen; if(total != 18) - return -8683; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(plain, cbcPlain, 18)) - return -8684; + return WC_TEST_RET_ENC_NC; total = 0; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_EncryptInit(en, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv) == 0) - return -8685; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0) - return -8686; + return WC_TEST_RET_ENC_NC; if(outlen != 0) - return -8687; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0) - return -8688; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8689; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0) - return -8690; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8691; + return WC_TEST_RET_ENC_NC; total += outlen; if(total != 32) return 3438; total = 0; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_DecryptInit(de, EVP_aes_128_cbc(), (unsigned char*)key, (unsigned char*)iv) == 0) - return -8692; + return WC_TEST_RET_ENC_NC; if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0) - return -8693; + return WC_TEST_RET_ENC_NC; if(outlen != 0) - return -8694; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0) - return -8695; + return WC_TEST_RET_ENC_NC; if(outlen != 0) total += outlen; if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0) - return -8696; + return WC_TEST_RET_ENC_NC; if(outlen != 16) - return -8697; + return WC_TEST_RET_ENC_NC; total += outlen; if (EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0) - return -8698; + return WC_TEST_RET_ENC_NC; if(outlen != 2) - return -8699; + return WC_TEST_RET_ENC_NC; total += outlen; if(total != 18) return 3447; if (XMEMCMP(plain, cbcPlain, 18)) - return -8700; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_key_length(NULL) != 0) - return -8701; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_key_length(EVP_aes_128_cbc()) != 16) - return -8702; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_mode(NULL) != 0) - return -8703; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE)) - return -8704; + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_CipherInit_ex(en, EVP_aes_128_cbc(), NULL, (unsigned char*)key, (unsigned char*)iv, 0) == 0) - return -8705; + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); if (EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL, (unsigned char*)key, (unsigned char*)iv) == 0) - return -8706; + return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL) != WOLFSSL_FAILURE) - return -8707; + return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL) != WOLFSSL_FAILURE) - return -8708; + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(de); if (EVP_DecryptInit_ex(de, EVP_aes_128_cbc(), NULL, (unsigned char*)key, (unsigned char*)iv) == 0) - return -8709; + return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL) != WOLFSSL_FAILURE) - return -8710; + return WC_TEST_RET_ENC_NC; if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL) != WOLFSSL_FAILURE) - return -8711; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_block_size(NULL) != BAD_FUNC_ARG) - return -8712; + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_init(en); EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL, (unsigned char*)key, (unsigned char*)iv); if (EVP_CIPHER_CTX_block_size(en) != en->block_size) - return -8713; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_block_size(NULL) != BAD_FUNC_ARG) - return -8714; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_block_size(EVP_aes_128_cbc()) != AES_BLOCK_SIZE) - return -8715; + return WC_TEST_RET_ENC_NC; if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0) - return -8716; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_flags(EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE) - return -8717; + return WC_TEST_RET_ENC_NC; EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF); EVP_CIPHER_CTX_set_flags(en, 42); if (en->flags != 42) - return -8718; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(NULL, 0) != BAD_FUNC_ARG) - return -8719; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS) - return -8720; + return WC_TEST_RET_ENC_NC; if (EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS) - return -8721; + return WC_TEST_RET_ENC_NC; + + if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; + if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS) + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wolfSSL_EVP_CIPHER_CTX_free(en); @@ -20461,60 +21095,60 @@ WOLFSSL_TEST_SUBROUTINE int openSSL_evpMD_test(void) ret = EVP_DigestInit(ctx, EVP_sha256()); if (ret != SSL_SUCCESS) { - ret = -8800; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } ret = EVP_MD_CTX_copy(ctx2, ctx); if (ret != SSL_SUCCESS) { - ret = -8801; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) { - ret = -8802; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } ret = EVP_DigestInit(ctx, EVP_sha1()); if (ret != SSL_SUCCESS) { - ret = -8803; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) { - ret = -8804; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } ret = EVP_MD_CTX_copy_ex(ctx2, ctx); if (ret != SSL_SUCCESS) { - ret = -8805; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_MD_type(EVP_sha256()) == EVP_MD_CTX_type(ctx2)) { - ret = -8806; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_MD_type(EVP_sha1()) != EVP_MD_CTX_type(ctx2)) { - ret = -8807; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_DigestInit_ex(ctx, EVP_sha1(), NULL) != SSL_SUCCESS) { - ret = -8808; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (EVP_add_digest(NULL) != 0) { - ret = -8809; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } if (wolfSSL_EVP_add_cipher(NULL) != 0) { - ret = -8810; + ret = WC_TEST_RET_ENC_NC; goto openSSL_evpMD_test_done; } @@ -20543,7 +21177,6 @@ static void show(const char *title, const char *p, unsigned int s) { #define FOURK_BUFF 4096 -#define ERR_BASE_PKEY (-5000) WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) { int ret = 0; @@ -20574,11 +21207,11 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (prvTmp == NULL) - return ERR_BASE_PKEY-1; + return WC_TEST_RET_ENC_ERRNO; pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (pubTmp == NULL) { - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - return ERR_BASE_PKEY-2; + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + return WC_TEST_RET_ENC_NC; } #ifdef USE_CERT_BUFFERS_1024 @@ -20594,45 +21227,49 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) #else keyFile = XFOPEN(cliKey, "rb"); if (!keyFile) { - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", ERR_BASE_PKEY-3); - return ERR_BASE_PKEY-3; + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + return WC_TEST_RET_ENC_ERRNO; } prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile); XFCLOSE(keyFile); + if (prvBytes == 0) + return WC_TEST_RET_ENC_ERRNO; keypubFile = XFOPEN(cliKeypub, "rb"); if (!keypubFile) { - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); err_sys("can't open ./certs/client-cert.der, " - "Please run from wolfSSL home dir", -4); - return ERR_BASE_PKEY-4; + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + return WC_TEST_RET_ENC_ERRNO; } pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile); XFCLOSE(keypubFile); + if (pubBytes == 0) + return WC_TEST_RET_ENC_ERRNO; #endif /* USE_CERT_BUFFERS */ prvRsa = wolfSSL_RSA_new(); pubRsa = wolfSSL_RSA_new(); if((prvRsa == NULL) || (pubRsa == NULL)){ printf("error with RSA_new\n"); - ret = ERR_BASE_PKEY-10; + ret = WC_TEST_RET_ENC_ERRNO; goto openssl_pkey0_test_done; } ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE); if(ret != SSL_SUCCESS){ printf("error with RSA_LoadDer_ex\n"); - ret = ERR_BASE_PKEY-11; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey0_test_done; } ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC); if(ret != SSL_SUCCESS){ printf("error with RSA_LoadDer_ex\n"); - ret = ERR_BASE_PKEY-12; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey0_test_done; } keySz = (size_t)RSA_size(pubRsa); @@ -20641,14 +21278,14 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) pubPkey = wolfSSL_EVP_PKEY_new(); if((prvPkey == NULL) || (pubPkey == NULL)){ printf("error with PKEY_new\n"); - ret = ERR_BASE_PKEY-13; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa); ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa); if(ret != 2){ printf("error with PKEY_set1_RSA\n"); - ret = ERR_BASE_PKEY-14; + ret = WC_TEST_RET_ENC_I(ret); goto openssl_pkey0_test_done; } @@ -20656,27 +21293,27 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) enc = EVP_PKEY_CTX_new(pubPkey, NULL); if((dec == NULL)||(enc==NULL)){ printf("error with EVP_PKEY_CTX_new\n"); - ret = ERR_BASE_PKEY-15; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } ret = EVP_PKEY_decrypt_init(dec); if (ret != 1) { printf("error with decrypt init\n"); - ret = ERR_BASE_PKEY-16; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } ret = EVP_PKEY_encrypt_init(enc); if (ret != 1) { printf("error with encrypt init\n"); - ret = ERR_BASE_PKEY-17; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } XMEMSET(out, 0, sizeof(out)); ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in)); if (ret != 1) { printf("error encrypting msg\n"); - ret = ERR_BASE_PKEY-18; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } @@ -20686,7 +21323,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz); if (ret != 1) { printf("error decrypting msg\n"); - ret = ERR_BASE_PKEY-19; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } show("decrypted msg", plain, outlen); @@ -20695,32 +21332,32 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) ret = EVP_PKEY_decrypt_init(dec); if (ret != 1) { printf("error with decrypt init\n"); - ret = ERR_BASE_PKEY-30; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } ret = EVP_PKEY_encrypt_init(enc); if (ret != 1) { printf("error with encrypt init\n"); - ret = ERR_BASE_PKEY-31; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) { printf("first set rsa padding error\n"); - ret = ERR_BASE_PKEY-32; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey0_test_done; } #ifndef HAVE_FIPS if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){ printf("second set rsa padding error\n"); - ret = ERR_BASE_PKEY-33; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey0_test_done; } if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) { printf("third set rsa padding error\n"); - ret = ERR_BASE_PKEY-34; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey0_test_done; } #endif @@ -20729,7 +21366,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in)); if (ret != 1) { printf("error encrypting msg\n"); - ret = ERR_BASE_PKEY-35; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } @@ -20739,7 +21376,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey0_test(void) ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz); if (ret != 1) { printf("error decrypting msg\n"); - ret = ERR_BASE_PKEY-36; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey0_test_done; } @@ -20786,7 +21423,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey1_test(void) if ((tmp == NULL) || (cipher == NULL) || (plain == NULL)) { - ret = -9015; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } #else @@ -20830,13 +21467,15 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey1_test(void) if (!f) { err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", -41); - ret = -9000; + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + ret = WC_TEST_RET_ENC_ERRNO; goto openssl_pkey1_test_done; } cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f); XFCLOSE(f); + if (cliKeySz == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done); } /* using existing wolfSSL api to get public and private key */ @@ -20845,70 +21484,70 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey1_test(void) clikey = tmp; if ((prvKey = EVP_PKEY_new()) == NULL) { - ret = -9001; + ret = WC_TEST_RET_ENC_ERRNO; goto openssl_pkey1_test_done; } EVP_PKEY_free(prvKey); prvKey = NULL; if (x509 == NULL) { - ret = -9002; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } pubKey = X509_get_pubkey(x509); if (pubKey == NULL) { - ret = -9003; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } prvKey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &clikey, cliKeySz); if (prvKey == NULL) { - ret = -9004; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } /* phase 2 API to create EVP_PKEY_CTX and encrypt/decrypt */ if (EVP_PKEY_bits(prvKey) != keyLenBits) { - ret = -9005; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } if (EVP_PKEY_size(prvKey) != keyLenBits/8) { - ret = -9006; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } dec = EVP_PKEY_CTX_new(prvKey, NULL); enc = EVP_PKEY_CTX_new(pubKey, NULL); if (dec == NULL || enc == NULL) { - ret = -9007; + ret = WC_TEST_RET_ENC_ERRNO; goto openssl_pkey1_test_done; } if (EVP_PKEY_decrypt_init(dec) != 1) { - ret = -9008; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } if (EVP_PKEY_encrypt_init(enc) != 1) { - ret = -9009; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) { - ret = -9010; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } #ifndef HAVE_FIPS if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){ - ret = -9011; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey1_test_done; } if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) { - ret = -9012; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey1_test_done; } #endif @@ -20916,13 +21555,13 @@ WOLFSSL_TEST_SUBROUTINE int openssl_pkey1_test(void) XMEMSET(cipher, 0, RSA_TEST_BYTES); outlen = keyLenBits/8; if (EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) { - ret = -9013; + ret = WC_TEST_RET_ENC_EC(ret); goto openssl_pkey1_test_done; } XMEMSET(plain, 0, RSA_TEST_BYTES); if (EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) { - ret = -9014; + ret = WC_TEST_RET_ENC_NC; goto openssl_pkey1_test_done; } @@ -20957,8 +21596,6 @@ openssl_pkey1_test_done: } -#define ERR_BASE_EVPSIG (-5100) - WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) { #if !defined(NO_RSA) && !defined(NO_SHA) && !defined(HAVE_USER_RSA) @@ -20989,11 +21626,11 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (prvTmp == NULL) - return ERR_BASE_EVPSIG-1; + return WC_TEST_RET_ENC_ERRNO; pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (pubTmp == NULL) { XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return ERR_BASE_EVPSIG-2; + return WC_TEST_RET_ENC_NC; } #ifdef USE_CERT_BUFFERS_1024 @@ -21009,57 +21646,61 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) #else keyFile = XFOPEN(cliKey, "rb"); if (!keyFile) { - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", -40); - return ERR_BASE_EVPSIG-3; + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + return WC_TEST_RET_ENC_ERRNO; } prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile); XFCLOSE(keyFile); + if (prvBytes == 0) + return WC_TEST_RET_ENC_ERRNO; keypubFile = XFOPEN(cliKeypub, "rb"); if (!keypubFile) { - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); err_sys("can't open ./certs/client-cert.der, " - "Please run from wolfSSL home dir", -41); - return ERR_BASE_EVPSIG-4; + "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO); + return WC_TEST_RET_ENC_ERRNO; } pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile); XFCLOSE(keypubFile); + if (pubBytes == 0) + return WC_TEST_RET_ENC_ERRNO; #endif /* USE_CERT_BUFFERS */ prvRsa = wolfSSL_RSA_new(); pubRsa = wolfSSL_RSA_new(); if((prvRsa == NULL) || (pubRsa == NULL)){ - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - err_sys("ERROR with RSA_new", -9100); - return ERR_BASE_EVPSIG-5; + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC); + return WC_TEST_RET_ENC_NC; } ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE); ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC); if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){ printf("error with RSA_LoadDer_ex\n"); - return ERR_BASE_EVPSIG-6; + return WC_TEST_RET_ENC_NC; } prvPkey = wolfSSL_EVP_PKEY_new(); pubPkey = wolfSSL_EVP_PKEY_new(); if((prvPkey == NULL) || (pubPkey == NULL)){ - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); printf("error with KEY_new\n"); - return ERR_BASE_EVPSIG-7; + return WC_TEST_RET_ENC_NC; } ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa); ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa); if((ret1 != 1) || (ret2 != 1)){ - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); printf("error with EVP_PKEY_set1_RSA\n"); - return ERR_BASE_EVPSIG-8; + return WC_TEST_RET_ENC_NC; } /****************** sign and verify *******************/ @@ -21069,7 +21710,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) printf("error with EVP_MD_CTX_create\n"); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); - return ERR_BASE_EVPSIG-10; + return WC_TEST_RET_ENC_NC; } ret = EVP_SignInit(sign, EVP_sha1()); @@ -21077,7 +21718,7 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) printf("error with EVP_SignInit\n"); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); - return ERR_BASE_EVPSIG-11; + return WC_TEST_RET_ENC_NC; } count = sizeof(msg); @@ -21089,12 +21730,12 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) ret1 = EVP_SignUpdate(sign, pt, count); ret2 = EVP_SignFinal(sign, sig, &sigSz, prvPkey); if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){ - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); printf("error with EVP_MD_CTX_create\n"); - return ERR_BASE_EVPSIG-12; + return WC_TEST_RET_ENC_NC; } show("signature = ", (char *)sig, sigSz); @@ -21103,35 +21744,35 @@ WOLFSSL_TEST_SUBROUTINE int openssl_evpSig_test(void) ret1 = EVP_VerifyInit(verf, EVP_sha1()); ret2 = EVP_VerifyUpdate(verf, pt, count); if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){ - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); printf("error with EVP_Verify\n"); - return ERR_BASE_EVPSIG-13; + return WC_TEST_RET_ENC_NC; } if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) { - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); printf("error with EVP_VerifyFinal\n"); - return ERR_BASE_EVPSIG-14; + return WC_TEST_RET_ENC_NC; } /* expect fail without update */ EVP_VerifyInit(verf, EVP_sha1()); if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) { - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); printf("EVP_VerifyInit without update not detected\n"); - return ERR_BASE_EVPSIG-15; + return WC_TEST_RET_ENC_NC; } - XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); + XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); EVP_MD_CTX_destroy(sign); EVP_MD_CTX_destroy(verf); @@ -21207,48 +21848,48 @@ WOLFSSL_TEST_SUBROUTINE int scrypt_test(void) ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1)); if (ret != 0) - return -9200; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0) - return -9201; + return WC_TEST_RET_ENC_NC; ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16, sizeof(verify2)); if (ret != 0) - return -9202; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0) - return -9203; + return WC_TEST_RET_ENC_NC; /* Test case with parallel overflowing */ ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608, sizeof(verify2)); if (ret != BAD_FUNC_ARG) - return -9210; + return WC_TEST_RET_ENC_EC(ret); /* Don't run these test on embedded, since they use large mallocs */ #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA) ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13, (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3)); if (ret != 0) - return -9204; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0) - return -9205; + return WC_TEST_RET_ENC_NC; #ifdef SCRYPT_TEST_ALL ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13, (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4)); if (ret != 0) - return -9206; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0) - return -9207; + return WC_TEST_RET_ENC_NC; #endif #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */ ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10, 8, 16, sizeof(verify2)); if (ret != 0) - return -9208; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0) - return -9209; + return WC_TEST_RET_ENC_NC; #endif /* !HAVE_FIPS */ @@ -21287,24 +21928,24 @@ WOLFSSL_TEST_SUBROUTINE int pkcs12_test(void) iterations, kLen, WC_SHA256, id); if (ret < 0) - return -9300; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify, kLen) != 0) - return -9301; + return WC_TEST_RET_ENC_NC; iterations = 1000; ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8, iterations, kLen, WC_SHA256, id); if (ret < 0) - return -9302; + return WC_TEST_RET_ENC_EC(ret); ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8, iterations, kLen, WC_SHA256, id, HEAP_HINT); if (ret < 0) - return -9303; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(derived, verify2, 24) != 0) - return -9304; + return WC_TEST_RET_ENC_NC; return 0; } @@ -21330,7 +21971,7 @@ WOLFSSL_TEST_SUBROUTINE int pbkdf2_test(void) return ret; if (XMEMCMP(derived, verify, sizeof(verify)) != 0) - return -9400; + return WC_TEST_RET_ENC_NC; return 0; @@ -21358,7 +21999,7 @@ WOLFSSL_TEST_SUBROUTINE int pbkdf1_test(void) return ret; if (XMEMCMP(derived, verify, sizeof(verify)) != 0) - return -9500; + return WC_TEST_RET_ENC_NC; return 0; } @@ -21452,10 +22093,10 @@ static int hkdf_test(void) ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0, okm1, L); if (ret != 0) - return -9700; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(okm1, res1, L) != 0) - return -9701; + return WC_TEST_RET_ENC_NC; #ifndef HAVE_FIPS /* fips can't have key size under 14 bytes, salt is key too */ @@ -21463,10 +22104,10 @@ static int hkdf_test(void) ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, L); if (ret != 0) - return -9702; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(okm1, res2, L) != 0) - return -9703; + return WC_TEST_RET_ENC_NC; #endif /* HAVE_FIPS */ #endif /* !NO_SHA */ @@ -21474,20 +22115,20 @@ static int hkdf_test(void) ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0, okm1, L); if (ret != 0) - return -9704; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(okm1, res3, L) != 0) - return -9705; + return WC_TEST_RET_ENC_NC; #ifndef HAVE_FIPS /* fips can't have key size under 14 bytes, salt is key too */ ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, L); if (ret != 0) - return -9706; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(okm1, res4, L) != 0) - return -9707; + return WC_TEST_RET_ENC_NC; #endif /* HAVE_FIPS */ #endif /* !NO_SHA256 */ #endif /* !NO_SHA || !NO_SHA256 */ @@ -21641,12 +22282,12 @@ int sshkdf_test(void) if (result != 0) { printf("KDF: Could not derive key.\n"); - result = -101; + result = WC_TEST_RET_ENC_EC(result); } else { if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) { printf("KDF: Calculated Key does not match Expected Key.\n"); - result = -102; + result = WC_TEST_RET_ENC_EC(result); } } @@ -22199,16 +22840,16 @@ static const Tls13KdfTestVector tls13KdfTestVectors[] = { #endif /* WOLFSSL_SHA384 */ }; -const char protocolLabel[] = "tls13 "; -const char ceTrafficLabel[] = "c e traffic"; -const char eExpMasterLabel[] = "e exp master"; -const char cHsTrafficLabel[] = "c hs traffic"; -const char sHsTrafficLabel[] = "s hs traffic"; -const char cAppTrafficLabel[] = "c ap traffic"; -const char sAppTrafficLabel[] = "s ap traffic"; -const char expMasterLabel[] = "exp master"; -const char resMasterLabel[] = "res master"; -const char derivedLabel[] = "derived"; +static const char protocolLabel[] = "tls13 "; +static const char ceTrafficLabel[] = "c e traffic"; +static const char eExpMasterLabel[] = "e exp master"; +static const char cHsTrafficLabel[] = "c hs traffic"; +static const char sHsTrafficLabel[] = "s hs traffic"; +static const char cAppTrafficLabel[] = "c ap traffic"; +static const char sAppTrafficLabel[] = "s ap traffic"; +static const char expMasterLabel[] = "exp master"; +static const char resMasterLabel[] = "res master"; +static const char derivedLabel[] = "derived"; WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) @@ -22240,8 +22881,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)ceTrafficLabel, (word32)strlen(ceTrafficLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel), tv->hashHello1, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22250,8 +22891,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)eExpMasterLabel, (word32)strlen(eExpMasterLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel), tv->hashHello1, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22260,8 +22901,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(salt, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)derivedLabel, (word32)strlen(derivedLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel), hashZero, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22272,8 +22913,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)cHsTrafficLabel, (word32)strlen(cHsTrafficLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel), tv->hashHello2, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22283,8 +22924,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)sHsTrafficLabel, (word32)strlen(sHsTrafficLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel), tv->hashHello2, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22293,8 +22934,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(salt, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)derivedLabel, (word32)strlen(derivedLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel), hashZero, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22304,8 +22945,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)cAppTrafficLabel, (word32)strlen(cAppTrafficLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel), tv->hashFinished1, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22314,8 +22955,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)sAppTrafficLabel, (word32)strlen(sAppTrafficLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel), tv->hashFinished1, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22324,8 +22965,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)expMasterLabel, (word32)strlen(expMasterLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel), tv->hashFinished1, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22334,8 +22975,8 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) ret = wc_Tls13_HKDF_Expand_Label(output, hashAlgSz, secret, hashAlgSz, - (byte*)protocolLabel, (word32)strlen(protocolLabel), - (byte*)resMasterLabel, (word32)strlen(resMasterLabel), + (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel), + (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel), tv->hashFinished2, hashAlgSz, tv->hashAlg); if (ret != 0) break; @@ -22348,6 +22989,9 @@ WOLFSSL_TEST_SUBROUTINE int tls13_kdf_test(void) #endif /* WOLFSSL_TLS13 */ +static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point -- + * see print_fiducials() below. + */ #if defined(HAVE_ECC) && defined(HAVE_X963_KDF) @@ -22455,38 +23099,38 @@ WOLFSSL_TEST_SUBROUTINE int x963kdf_test(void) ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0, kek, sizeof(verify)); if (ret != 0) - return -9800; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(verify, kek, sizeof(verify)) != 0) - return -9801; + return WC_TEST_RET_ENC_NC; #endif #ifndef NO_SHA256 ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0, kek, sizeof(verify2)); if (ret != 0) - return -9802; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0) - return -9803; + return WC_TEST_RET_ENC_NC; #endif #ifdef WOLFSSL_SHA512 ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0, kek, sizeof(verify3)); if (ret != 0) - return -9804; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0) - return -9805; + return WC_TEST_RET_ENC_NC; ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4, sizeof(info4), kek, sizeof(verify4)); if (ret != 0) - return -9806; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0) - return -9807; + return WC_TEST_RET_ENC_NC; #endif return 0; @@ -22494,6 +23138,161 @@ WOLFSSL_TEST_SUBROUTINE int x963kdf_test(void) #endif /* HAVE_X963_KDF */ +#if defined(HAVE_HPKE) && (defined(HAVE_ECC) || defined(HAVE_CURVE25519)) && \ + defined(HAVE_AESGCM) + +static int hpke_test_single(Hpke* hpke) +{ + int ret = 0; + int rngRet = 0; + WC_RNG rng[1]; + const char* start_text = "this is a test"; + const char* info_text = "info"; + const char* aad_text = "aad"; + byte ciphertext[MAX_HPKE_LABEL_SZ]; + byte plaintext[MAX_HPKE_LABEL_SZ]; + void* receiverKey = NULL; + void* ephemeralKey = NULL; +#ifdef WOLFSSL_SMALL_STACK + uint8_t *pubKey = NULL; /* public key */ + word16 pubKeySz = (word16)HPKE_Npk_MAX; +#else + uint8_t pubKey[HPKE_Npk_MAX]; /* public key */ + word16 pubKeySz = (word16)sizeof(pubKey); +#endif + + rngRet = ret = wc_InitRng(rng); + + if (ret != 0) + return ret; + +#ifdef WOLFSSL_SMALL_STACK + if (ret == 0) { + pubKey = (uint8_t *)XMALLOC(pubKeySz, HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER); + if (pubKey == NULL) + ret = MEMORY_E; + } +#endif + + /* generate the keys */ + if (ret == 0) + ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng); + + if (ret == 0) + ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng); + + /* seal */ + if (ret == 0) { + ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey, + (byte*)info_text, (word32)XSTRLEN(info_text), + (byte*)aad_text, (word32)XSTRLEN(aad_text), + (byte*)start_text, (word32)XSTRLEN(start_text), + ciphertext); + } + + /* export ephemeral key */ + if (ret == 0) + ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz); + + /* open with exported ephemeral key */ + if (ret == 0) { + ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz, + (byte*)info_text, (word32)XSTRLEN(info_text), + (byte*)aad_text, (word32)XSTRLEN(aad_text), + ciphertext, (word32)XSTRLEN(start_text), + plaintext); + } + + if (ret == 0) + ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text)); + + if (ephemeralKey != NULL) + wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap); + + if (receiverKey != NULL) + wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap); + +#ifdef WOLFSSL_SMALL_STACK + if (pubKey != NULL) + XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); +#endif + + if (rngRet == 0) + wc_FreeRng(rng); + + return ret; +} + +WOLFSSL_TEST_SUBROUTINE int hpke_test(void) +{ + int ret = 0; + Hpke hpke[1]; + +#if defined(HAVE_ECC) + #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) + /* p256 */ + ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256, + HPKE_AES_128_GCM, NULL); + + if (ret != 0) + return ret; + + ret = hpke_test_single(hpke); + + if (ret != 0) + return ret; + #endif + + #if defined(WOLFSSL_SHA384) && \ + (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) + /* p384 */ + ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384, + HPKE_AES_128_GCM, NULL); + + if (ret != 0) + return ret; + + ret = hpke_test_single(hpke); + + if (ret != 0) + return ret; + #endif + + #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \ + (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) + /* p521 */ + ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512, + HPKE_AES_128_GCM, NULL); + + if (ret != 0) + return ret; + + ret = hpke_test_single(hpke); + + if (ret != 0) + return ret; + #endif +#endif + +#if defined(HAVE_CURVE25519) + /* test with curve25519 and aes256 */ + ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256, + HPKE_AES_256_GCM, NULL); + + if (ret != 0) + return ret; + + ret = hpke_test_single(hpke); + + if (ret != 0) + return ret; +#endif + + return ret; +/* x448 and chacha20 are unimplemented */ +} +#endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */ #ifdef HAVE_ECC @@ -22606,7 +23405,7 @@ static int ecc_test_vector_item(const eccVector* vector) if (ret != 0) goto done; if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) { - ret = -9810; + ret = WC_TEST_RET_ENC_NC; goto done; } @@ -22615,11 +23414,12 @@ static int ecc_test_vector_item(const eccVector* vector) goto done; if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 || sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) { - ret = -9811; + ret = WC_TEST_RET_ENC_NC; goto done; } #endif +#ifdef HAVE_ECC_VERIFY do { #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); @@ -22633,7 +23433,8 @@ static int ecc_test_vector_item(const eccVector* vector) TEST_SLEEP(); if (verify != 1) - ret = -9812; + ret = WC_TEST_RET_ENC_NC; +#endif done: @@ -22978,11 +23779,11 @@ static int ecc_test_deterministic_k(WC_RNG* rng) TEST_SLEEP(); if (sigSz != sizeof(expSig)) { - ret = -9830; + ret = WC_TEST_RET_ENC_NC; goto done; } if (XMEMCMP(sig, expSig, sigSz) != 0) { - ret = -9831; + ret = WC_TEST_RET_ENC_NC; goto done; } @@ -23100,7 +23901,7 @@ static int ecc384_test_deterministic_k(WC_RNG* rng) mp_read_radix(expR, expRstr, MP_RADIX_HEX); mp_read_radix(expS, expSstr, MP_RADIX_HEX); if (mp_cmp(r, expR) != MP_EQ) { - ret = -1; + ret = WC_TEST_RET_ENC_NC; } done: @@ -23219,7 +24020,7 @@ static int ecc521_test_deterministic_k(WC_RNG* rng) mp_read_radix(expR, expRstr, MP_RADIX_HEX); mp_read_radix(expS, expSstr, MP_RADIX_HEX); if (mp_cmp(r, expR) != MP_EQ) { - ret = -1; + ret = WC_TEST_RET_ENC_NC; } done: @@ -23292,7 +24093,10 @@ static int ecc_test_sign_vectors(WC_RNG* rng) if (ret != 0) { goto done; } +#if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \ + && (HAVE_FIPS_VERSION > 2))) wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN); +#endif ret = wc_ecc_sign_set_k(k, sizeof(k), key); if (ret != 0) { @@ -23313,11 +24117,11 @@ static int ecc_test_sign_vectors(WC_RNG* rng) TEST_SLEEP(); if (sigSz != sizeof(expSig)) { - ret = -9830; + ret = WC_TEST_RET_ENC_NC; goto done; } if (XMEMCMP(sig, expSig, sigSz) != 0) { - ret = -9831; + ret = WC_TEST_RET_ENC_NC; goto done; } @@ -23345,7 +24149,7 @@ done: } #endif -#ifdef HAVE_ECC_CDH +#if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE) static int ecc_test_cdh_vectors(WC_RNG* rng) { int ret; @@ -23424,7 +24228,7 @@ static int ecc_test_cdh_vectors(WC_RNG* rng) /* compare results */ if (x != z || XMEMCMP(sharedA, sharedB, x)) { - ERROR_OUT(-9840, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } done: @@ -23445,7 +24249,7 @@ done: return ret; } -#endif /* HAVE_ECC_CDH */ +#endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */ #endif /* HAVE_ECC_VECTOR_TEST */ #ifdef HAVE_ECC_KEY_IMPORT @@ -23502,73 +24306,71 @@ static int ecc_test_make_pub(WC_RNG* rng) { XFILE file = XFOPEN(eccKeyDerFile, "rb"); if (!file) { - ERROR_OUT(-9850, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file); XFCLOSE(file); + if (tmpSz == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #endif /* USE_CERT_BUFFERS_256 */ /* import private only then test with */ ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL); if (ret == 0) { - ERROR_OUT(-9851, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key); if (ret == 0) { - ERROR_OUT(-9852, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } x = 0; ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz); - if (ret != 0) { - ERROR_OUT(-9853, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_ECC_KEY_EXPORT x = ECC_BUFSIZE; ret = wc_ecc_export_private_only(key, exportBuf, &x); - if (ret != 0) { - ERROR_OUT(-9854, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); /* make private only key */ wc_ecc_free(key); wc_ecc_init_ex(key, HEAP_HINT, devId); ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key); - if (ret != 0) { - ERROR_OUT(-9855, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); x = ECC_BUFSIZE; ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0); if (ret == 0) { - ERROR_OUT(-9856, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif /* HAVE_ECC_KEY_EXPORT */ ret = wc_ecc_make_pub(NULL, NULL); if (ret == 0) { - ERROR_OUT(-9857, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } TEST_SLEEP(); #ifndef WOLFSSL_NO_MALLOC pubPoint = wc_ecc_new_point_h(HEAP_HINT); if (pubPoint == NULL) { - ERROR_OUT(-9858, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #if !defined(WOLFSSL_CRYPTOCELL) ret = wc_ecc_make_pub(key, pubPoint); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-9859, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif TEST_SLEEP(); @@ -23577,7 +24379,7 @@ static int ecc_test_make_pub(WC_RNG* rng) x = ECC_BUFSIZE; ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0); if (ret == 0) { - ERROR_OUT(-9860, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif /* HAVE_ECC_KEY_EXPORT */ #endif /* !WOLFSSL_NO_MALLOC */ @@ -23586,11 +24388,10 @@ static int ecc_test_make_pub(WC_RNG* rng) /* create a new key since above test for loading key is not supported */ #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \ defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \ - defined(WOLFSSL_SECO_CAAM) + defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM) ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key); - if (ret != 0) { - ERROR_OUT(-9861, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \ @@ -23607,9 +24408,8 @@ static int ecc_test_make_pub(WC_RNG* rng) &tmpSz, rng, key); } } while (ret == WC_PENDING_E); - if (ret != 0) { - ERROR_OUT(-9862, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); #ifdef HAVE_ECC_VERIFY @@ -23624,21 +24424,19 @@ static int ecc_test_make_pub(WC_RNG* rng) (word32)XSTRLEN((const char*)msg), &verify, key); } } while (ret == WC_PENDING_E); - if (ret != 0) { - ERROR_OUT(-9863, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (verify != 1) { - ERROR_OUT(-9864, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } TEST_SLEEP(); #ifdef HAVE_ECC_KEY_EXPORT /* exporting the public part should now work */ x = ECC_BUFSIZE; ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0); - if (ret != 0) { - ERROR_OUT(-9865, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif /* HAVE_ECC_KEY_EXPORT */ #endif /* HAVE_ECC_VERIFY */ @@ -23648,24 +24446,22 @@ static int ecc_test_make_pub(WC_RNG* rng) /* now test private only key with creating a shared secret */ x = ECC_BUFSIZE; ret = wc_ecc_export_private_only(key, exportBuf, &x); - if (ret != 0) { - ERROR_OUT(-9866, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050) /* make private only key */ wc_ecc_free(key); wc_ecc_init_ex(key, HEAP_HINT, devId); ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key); - if (ret != 0) { - ERROR_OUT(-9867, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); /* check that public export fails with private only key */ x = ECC_BUFSIZE; ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0); if (ret == 0) { - ERROR_OUT(-9868, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif /* WOLFSSL_QNX_CAAM */ @@ -23679,9 +24475,8 @@ static int ecc_test_make_pub(WC_RNG* rng) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-9869, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \ @@ -23702,9 +24497,8 @@ static int ecc_test_make_pub(WC_RNG* rng) } } while (ret == WC_PENDING_E); wc_ecc_free(pub); - if (ret != 0) { - ERROR_OUT(-9870, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */ #endif /* WOLF_CRYPTO_CB_ONLY_ECC */ @@ -23861,7 +24655,7 @@ static int ecc_test_key_gen(WC_RNG* rng, int keySize) } ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile, - ECC_PRIVATEKEY_TYPE, -8347); + ECC_PRIVATEKEY_TYPE); if (ret != 0) { goto done; } @@ -23872,7 +24666,7 @@ static int ecc_test_key_gen(WC_RNG* rng, int keySize) ERROR_OUT(derSz, done); } if (derSz == 0) { - ERROR_OUT(-9890, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #ifdef HAVE_COMP_KEY @@ -23882,11 +24676,11 @@ static int ecc_test_key_gen(WC_RNG* rng, int keySize) ERROR_OUT(derSz, done); } if (derSz == 0) { - ERROR_OUT(-9890, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif - ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0, -8348); + ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0); if (ret != 0) { goto done; } @@ -23900,10 +24694,10 @@ static int ecc_test_key_gen(WC_RNG* rng, int keySize) } if (derSz == 0) { - ERROR_OUT(-9891, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } - ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0, -8349); + ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0); if (ret != 0) { goto done; } @@ -23929,20 +24723,17 @@ done: static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, int curve_id, const ecc_set_type* dp) { -#if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \ +#if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \ !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT); WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT); + word32 y; #endif #ifdef HAVE_ECC_KEY_EXPORT #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32) WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT); #endif word32 x = 0; -#if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \ - !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) - word32 y; -#endif #if defined(HAVE_ECC_SIGN) && !defined(WOLFSSL_KCAPI_ECC) WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT); WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT); @@ -23969,17 +24760,17 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \ !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) if (sharedA == NULL || sharedB == NULL) - ERROR_OUT(-9900, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #endif #ifdef HAVE_ECC_KEY_EXPORT if (exportBuf == NULL) - ERROR_OUT(-9901, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #endif #if defined(HAVE_ECC_SIGN) && !defined(WOLFSSL_KCAPI_ECC) if (sig == NULL || digest == NULL) - ERROR_OUT(-9902, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #endif #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */ @@ -23991,7 +24782,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, if ((userA == NULL) || (userB == NULL) || (pubKey == NULL)) - ERROR_OUT(-9903, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif XMEMSET(userA, 0, sizeof *userA); @@ -24000,22 +24791,22 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_init_ex(userA, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-9904, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_init_ex(userB, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-9905, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-9906, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef WOLFSSL_CUSTOM_CURVES if (dp != NULL) { ret = wc_ecc_set_custom_curve(userA, dp); if (ret != 0) - ERROR_OUT(-9907, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_set_custom_curve(userB, dp); if (ret != 0) - ERROR_OUT(-9908, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif @@ -24033,18 +24824,18 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, if (ret == ECC_CURVE_OID_E) goto done; /* catch case, where curve is not supported */ if (ret != 0) - ERROR_OUT(-9910, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); if (wc_ecc_get_curve_idx(curve_id) != -1) { curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id); if (curveSize != userA->dp->size) - ERROR_OUT(-9911, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } ret = wc_ecc_check_key(userA); if (ret != 0) - ERROR_OUT(-9912, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); /* ATECC508/608 configuration may not support more than one ECDH key */ @@ -24055,7 +24846,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0) - ERROR_OUT(-9914, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); /* only perform the below tests if the key size matches */ @@ -24068,10 +24859,10 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, !defined(HAVE_SELFTEST) ret = wc_ecc_set_rng(userA, rng); if (ret != 0) - ERROR_OUT(-9915, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_set_rng(userB, rng); if (ret != 0) - ERROR_OUT(-9916, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif x = ECC_SHARED_SIZE; @@ -24082,9 +24873,8 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, if (ret == 0) ret = wc_ecc_shared_secret(userA, userB, sharedA, &x); } while (ret == WC_PENDING_E); - if (ret != 0) { - ERROR_OUT(-9917, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); y = ECC_SHARED_SIZE; @@ -24096,15 +24886,14 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_shared_secret(userB, userA, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9918, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (y != x) - ERROR_OUT(-9919, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); if (XMEMCMP(sharedA, sharedB, x)) - ERROR_OUT(-9920, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); -#endif /* HAVE_ECC_DHE */ #ifdef HAVE_ECC_CDH /* add cofactor flag */ @@ -24120,7 +24909,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_shared_secret(userA, userB, sharedA, &x); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9921, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); y = ECC_SHARED_SIZE; @@ -24132,38 +24921,39 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_shared_secret(userB, userA, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9922, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (y != x) - ERROR_OUT(-9923, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); if (XMEMCMP(sharedA, sharedB, x)) - ERROR_OUT(-9924, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); /* remove cofactor flag */ wc_ecc_set_flags(userA, 0); wc_ecc_set_flags(userB, 0); #endif /* HAVE_ECC_CDH */ +#endif /* HAVE_ECC_DHE */ #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */ #ifdef HAVE_ECC_KEY_EXPORT x = ECC_KEY_EXPORT_BUF_SIZE; ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0); if (ret != 0) - ERROR_OUT(-9925, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_ECC_KEY_IMPORT #ifdef WOLFSSL_CUSTOM_CURVES if (dp != NULL) { ret = wc_ecc_set_custom_curve(pubKey, dp); if (ret != 0) - ERROR_OUT(-9926, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id); if (ret != 0) - ERROR_OUT(-9927, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) #ifdef HAVE_ECC_DHE @@ -24176,10 +24966,10 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9928, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (XMEMCMP(sharedA, sharedB, y)) - ERROR_OUT(-9929, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); #endif /* HAVE_ECC_DHE */ @@ -24188,22 +24978,22 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, x = ECC_KEY_EXPORT_BUF_SIZE; ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1); if (ret != 0) - ERROR_OUT(-9930, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); wc_ecc_free(pubKey); ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-9931, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef WOLFSSL_CUSTOM_CURVES if (dp != NULL) { ret = wc_ecc_set_custom_curve(pubKey, dp); if (ret != 0) - ERROR_OUT(-9932, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id); if (ret != 0) - ERROR_OUT(-9933, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_ECC_DHE y = ECC_SHARED_SIZE; @@ -24215,10 +25005,10 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9934, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (XMEMCMP(sharedA, sharedB, y)) - ERROR_OUT(-9935, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); #endif /* HAVE_ECC_DHE */ #endif /* HAVE_COMP_KEY */ @@ -24253,7 +25043,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, userA); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9936, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); #ifdef HAVE_ECC_VERIFY @@ -24268,9 +25058,9 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, &verify, userA); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9937, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (verify != 1) - ERROR_OUT(-9938, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); } #endif /* HAVE_ECC_VERIFY */ @@ -24290,7 +25080,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9939, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); TEST_SLEEP(); #ifdef HAVE_ECC_VERIFY @@ -24304,9 +25094,9 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA); } while (ret == WC_PENDING_E); if (ret != 0) - ERROR_OUT(-9940, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (verify != 1) - ERROR_OUT(-9941, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); } #endif /* HAVE_ECC_VERIFY */ @@ -24320,7 +25110,7 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, x = ECC_KEY_EXPORT_BUF_SIZE; ret = wc_ecc_export_private_only(userA, exportBuf, &x); if (ret != 0) - ERROR_OUT(-9942, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #elif defined(HAVE_ECC_KEY_EXPORT) (void)exportBuf; #endif /* HAVE_ECC_KEY_EXPORT */ @@ -24480,25 +25270,25 @@ static int ecc_point_test(void) outLen = sizeof(out); point = wc_ecc_new_point(); if (point == NULL) - return -10000; + return WC_TEST_RET_ENC_ERRNO; point2 = wc_ecc_new_point(); if (point2 == NULL) { wc_ecc_del_point(point); - return -10001; + return WC_TEST_RET_ENC_NC; } #ifdef HAVE_COMP_KEY point3 = wc_ecc_new_point(); if (point3 == NULL) { wc_ecc_del_point(point2); wc_ecc_del_point(point); - return -10002; + return WC_TEST_RET_ENC_NC; } point4 = wc_ecc_new_point(); if (point4 == NULL) { wc_ecc_del_point(point3); wc_ecc_del_point(point2); wc_ecc_del_point(point); - return -10003; + return WC_TEST_RET_ENC_NC; } #endif @@ -24506,117 +25296,117 @@ static int ecc_point_test(void) wc_ecc_del_point(NULL); ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point); if (ret != ECC_BAD_ARG_E) { - ret = -10004; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point); if (ret != ECC_BAD_ARG_E) { - ret = -10005; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL); if (ret != ECC_BAD_ARG_E) { - ret = -10006; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_export_point_der(-1, point, out, &outLen); if (ret != ECC_BAD_ARG_E) { - ret = -10007; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen); if (ret != ECC_BAD_ARG_E) { - ret = -10008; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen); if (ret != LENGTH_ONLY_E || outLen != sizeof(out)) { - ret = -10009; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_export_point_der(curve_idx, point, out, NULL); if (ret != ECC_BAD_ARG_E) { - ret = -10010; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } outLen = 0; ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen); if (ret != BUFFER_E) { - ret = -10011; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_copy_point(NULL, NULL); if (ret != ECC_BAD_ARG_E) { - ret = -10012; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_copy_point(NULL, point2); if (ret != ECC_BAD_ARG_E) { - ret = -10013; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_copy_point(point, NULL); if (ret != ECC_BAD_ARG_E) { - ret = -10014; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(NULL, NULL); if (ret != BAD_FUNC_ARG) { - ret = -10015; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(NULL, point2); if (ret != BAD_FUNC_ARG) { - ret = -10016; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(point, NULL); if (ret != BAD_FUNC_ARG) { - ret = -10017; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } /* Use API. */ ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point); if (ret != 0) { - ret = -10018; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } outLen = sizeof(out); ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen); if (ret != 0) { - ret = -10019; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } if (outLen != sizeof(der)) { - ret = -10020; + ret = WC_TEST_RET_ENC_NC; goto done; } if (XMEMCMP(out, der, outLen) != 0) { - ret = -10021; + ret = WC_TEST_RET_ENC_NC; goto done; } ret = wc_ecc_copy_point(point2, point); if (ret != MP_OKAY) { - ret = -10022; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(point2, point); if (ret != MP_EQ) { - ret = -10023; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2); if (ret != 0) { - ret = -10024; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(point2, point); if (ret != MP_GT) { - ret = -10025; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24624,37 +25414,37 @@ static int ecc_point_test(void) (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3); if (ret != 0) { - ret = -10026; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0); if (ret != 0) { - ret = -10027; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(point3, point4); if (ret != MP_EQ) { - ret = -10028; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3); if (ret != 0) { - ret = -10029; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0); if (ret != 0) { - ret = -10030; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_cmp_point(point3, point4); if (ret != MP_EQ) { - ret = -10031; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif @@ -24691,32 +25481,32 @@ static int ecc_sig_test(WC_RNG* rng, ecc_key* key) ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key)); if (ret != size) - return -10040; + return WC_TEST_RET_ENC_NC; sigSz = (word32)ret; ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in, inLen, out, &sigSz, key, sizeof(*key), rng); if (ret != 0) - return -10041; + return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in, inLen, out, sigSz, key, sizeof(*key)); if (ret != 0) - return -10042; + return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); sigSz = (word32)sizeof(out); ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng); if (ret != 0) - return -10043; + return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key)); if (ret != 0) - return -10044; + return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); return 0; @@ -24748,7 +25538,7 @@ static int ecc_exp_imp_test(ecc_key* key) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (keyImp == NULL) - ERROR_OUT(-10050, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #endif wc_ecc_init_ex(keyImp, HEAP_HINT, devId); @@ -24756,19 +25546,19 @@ static int ecc_exp_imp_test(ecc_key* key) privLen = sizeof(priv); ret = wc_ecc_export_private_only(key, priv, &privLen); if (ret != 0) { - ret = -10051; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } pubLen = sizeof(pub); ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen); if (ret != 0) { - ret = -10052; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp); if (ret != 0) { - ret = -10053; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24777,7 +25567,7 @@ static int ecc_exp_imp_test(ecc_key* key) ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1); if (ret != 0) { - ret = -10054; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24786,7 +25576,7 @@ static int ecc_exp_imp_test(ecc_key* key) curve_id = wc_ecc_get_curve_id(key->idx); if (curve_id < 0) { - ret = -10055; + ret = WC_TEST_RET_ENC_EC(curve_id); goto done; } @@ -24794,7 +25584,7 @@ static int ecc_exp_imp_test(ecc_key* key) ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp, curve_id); if (ret != 0) { - ret = -10056; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24805,7 +25595,7 @@ static int ecc_exp_imp_test(ecc_key* key) pubLenX = pubLenY = 32; ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY); if (ret != 0) { - ret = -10057; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24813,7 +25603,7 @@ static int ecc_exp_imp_test(ecc_key* key) /* test import of public */ ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1); if (ret != 0) { - ret = -10058; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif @@ -24826,7 +25616,7 @@ static int ecc_exp_imp_test(ecc_key* key) ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY, priv, &privLen); if (ret != 0) { - ret = -10059; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24834,7 +25624,7 @@ static int ecc_exp_imp_test(ecc_key* key) /* test import of private and public */ ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1); if (ret != 0) { - ret = -10060; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif @@ -24895,7 +25685,7 @@ static int ecc_mulmod_test(ecc_key* key1) ret = wc_ecc_mulmod(&key1->k, &key2->pubkey, &key3->pubkey, &key2->k, &key3->k, 1); if (ret != 0) { - ret = -10070; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -24930,23 +25720,23 @@ static int ecc_ssh_test(ecc_key* key, WC_RNG* rng) /* Parameter Validation testing. */ ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen); if (ret != BAD_FUNC_ARG) - return -10080; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen); if (ret != BAD_FUNC_ARG) - return -10081; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen); if (ret != BAD_FUNC_ARG) - return -10082; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL); if (ret != BAD_FUNC_ARG) - return -10083; + return WC_TEST_RET_ENC_EC(ret); #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \ (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \ !defined(HAVE_SELFTEST) ret = wc_ecc_set_rng(key, rng); if (ret != 0) - return -10084; + return WC_TEST_RET_ENC_EC(ret); #else (void)rng; #endif @@ -24961,7 +25751,7 @@ static int ecc_ssh_test(ecc_key* key, WC_RNG* rng) ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen); } while (ret == WC_PENDING_E); if (ret != 0) - return -10085; + return WC_TEST_RET_ENC_EC(ret); TEST_SLEEP(); return 0; @@ -24991,12 +25781,12 @@ static int ecc_def_curve_test(WC_RNG *rng) /* Use API */ ret = wc_ecc_set_flags(NULL, 0); if (ret != BAD_FUNC_ARG) { - ret = -10090; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_set_flags(key, 0); if (ret != 0) { - ret = -10091; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #ifndef WOLF_CRYPTO_CB_ONLY_ECC @@ -25040,10 +25830,12 @@ static int ecc_def_curve_test(WC_RNG *rng) byte der[128]; word32 derSz; if (!file) { - ERROR_OUT(-10093, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } derSz = (word32)XFREAD(der, 1, sizeof(der), file); XFCLOSE(file); + if (derSz == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz); } #endif @@ -25139,22 +25931,22 @@ static int ecc_decode_test(void) inSz = sizeof(good); ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz); if (ret != BAD_FUNC_ARG) { - ret = -10100; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_EccPublicKeyDecode(good, NULL, key, inSz); if (ret != BAD_FUNC_ARG) { - ret = -10101; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz); if (ret != BAD_FUNC_ARG) { - ret = -10102; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0); if (ret != BAD_FUNC_ARG) { - ret = -10103; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -25163,14 +25955,14 @@ static int ecc_decode_test(void) inSz = sizeof(good) - inOutIdx; ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz); if (ret != ASN_PARSE_E) { - ret = -10104; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inOutIdx = 4; inSz = sizeof(good) - inOutIdx; ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz); if (ret != ASN_PARSE_E) { - ret = -10105; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } /* Bad data. */ @@ -25178,56 +25970,56 @@ static int ecc_decode_test(void) inOutIdx = 0; ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz); if (ret != ASN_OBJECT_ID_E && ret != ASN_PARSE_E) { - ret = -10106; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badOneObjId); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz); if (ret != ASN_OBJECT_ID_E && ret != ASN_PARSE_E) { - ret = -10107; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badObjId1Len); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz); if (ret != ASN_PARSE_E) { - ret = -10108; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badObj2d1Len); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz); if (ret != ASN_PARSE_E) { - ret = -10109; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNotBitStr); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz); if (ret != ASN_BITSTR_E && ret != ASN_PARSE_E) { - ret = -10110; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badBitStrLen); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz); if (ret != ASN_PARSE_E) { - ret = -10111; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badNoBitStrZero); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz); if (ret != ASN_EXPECT_0_E && ret != ASN_PARSE_E) { - ret = -10112; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } inSz = sizeof(badPoint); inOutIdx = 0; ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz); if (ret != ASN_ECC_KEY_E && ret != ASN_PARSE_E) { - ret = -10113; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -25235,7 +26027,7 @@ static int ecc_decode_test(void) inOutIdx = 0; ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz); if (ret != 0) { - ret = -10114; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -25369,7 +26161,7 @@ static int ecc_test_custom_curves(WC_RNG* rng) ret = wc_ecc_init_ex(key, HEAP_HINT, devId); if (ret != 0) { - ret = -10120; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } @@ -25377,7 +26169,7 @@ static int ecc_test_custom_curves(WC_RNG* rng) ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key, sizeof(eccKeyExplicitCurve)); if (ret != 0) - ret = -10121; + ret = WC_TEST_RET_ENC_EC(ret); done: @@ -25396,7 +26188,7 @@ static int ecc_test_custom_curves(WC_RNG* rng) } #endif /* WOLFSSL_CUSTOM_CURVES */ -#ifdef WOLFSSL_CERT_GEN +#if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) /* Make Cert / Sign example for ECC cert and ECC CA */ static int ecc_test_cert_gen(WC_RNG* rng) @@ -25444,7 +26236,7 @@ static int ecc_test_cert_gen(WC_RNG* rng) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { - ERROR_OUT(-10130, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); } #endif @@ -25457,11 +26249,13 @@ static int ecc_test_cert_gen(WC_RNG* rng) #else file = XFOPEN(eccCaKey384File, "rb"); if (!file) { - ERROR_OUT(-10131, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); } bytes = XFREAD(der, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); (void)eccCaKeyFile; #endif /* USE_CERT_BUFFERS_256 */ #else @@ -25471,10 +26265,12 @@ static int ecc_test_cert_gen(WC_RNG* rng) #else file = XFOPEN(eccCaKeyFile, "rb"); if (!file) { - ERROR_OUT(-10132, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); } bytes = XFREAD(der, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); #ifdef ENABLE_ECC384_CERT_GEN_TEST (void)eccCaKey384File; #endif @@ -25483,33 +26279,29 @@ static int ecc_test_cert_gen(WC_RNG* rng) /* Get CA Key */ ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-10133, exit); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes); - if (ret != 0) { - ERROR_OUT(-10134, exit); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* Make a public key */ ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-10135, exit); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-10136, exit); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); TEST_SLEEP(); /* Setup Certificate */ - if (wc_InitCert_ex(myCert, HEAP_HINT, devId)) { - ERROR_OUT(-10137, exit); - } + ret = wc_InitCert_ex(myCert, HEAP_HINT, devId); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); #ifndef NO_SHA256 myCert->sigType = CTC_SHA256wECDSA; @@ -25527,19 +26319,19 @@ static int ecc_test_cert_gen(WC_RNG* rng) myCert->certPoliciesNb = 2; /* add SKID from the Public Key */ - if (wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey) != 0) { - ERROR_OUT(-10138, exit); - } + ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* add AKID from the Public Key */ - if (wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey) != 0) { - ERROR_OUT(-10139, exit); - } + ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); /* add Key Usage */ - if (wc_SetKeyUsage(myCert, certKeyUsage) != 0) { - ERROR_OUT(-10140, exit); - } + ret = wc_SetKeyUsage(myCert, certKeyUsage); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); #endif /* WOLFSSL_CERT_EXT */ #ifdef ENABLE_ECC384_CERT_GEN_TEST @@ -25561,13 +26353,12 @@ static int ecc_test_cert_gen(WC_RNG* rng) #endif #endif #endif /* ENABLE_ECC384_CERT_GEN_TEST */ - if (ret < 0) { - ERROR_OUT(-10141, exit); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng); if (certSz < 0) { - ERROR_OUT(-10142, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit); } ret = 0; @@ -25580,9 +26371,8 @@ static int ecc_test_cert_gen(WC_RNG* rng) FOURK_BUF, NULL, caEccKey, rng); } } while (ret == WC_PENDING_E); - if (ret < 0) { - ERROR_OUT(-10143, exit); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); certSz = ret; TEST_SLEEP(); @@ -25591,14 +26381,14 @@ static int ecc_test_cert_gen(WC_RNG* rng) ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0); if (ret != 0) { FreeDecodedCert(decode); - ERROR_OUT(-10144, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } FreeDecodedCert(decode); #endif ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile, - CERT_TYPE, -6735); + CERT_TYPE); if (ret != 0) { goto exit; } @@ -25645,7 +26435,7 @@ static int ecc_test_allocator(WC_RNG* rng) key = wc_ecc_key_new(HEAP_HINT); if (key == NULL) { - ERROR_OUT(-10150, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); } #ifndef WC_NO_RNG @@ -25653,9 +26443,8 @@ static int ecc_test_allocator(WC_RNG* rng) #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE); #endif - if (ret != 0) { - ERROR_OUT(-10151, exit); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); #else /* use test ECC key */ ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key, @@ -25785,32 +26574,32 @@ static int crypto_ecc_verify(const byte *key, uint32_t keySz, if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 || hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2)) { - return BAD_FUNC_ARG; + return WC_TEST_RET_ENC_NC; } /* Setup the ECC key */ ret = wc_ecc_init(&ecc); if (ret < 0) { - return ret; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_ecc_set_nonblock(&ecc, &nb_ctx); if (ret != MP_OKAY) { wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } /* Setup the signature r/s variables */ ret = mp_init(&r); if (ret != MP_OKAY) { wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } ret = mp_init(&s); if (ret != MP_OKAY) { mp_clear(&r); wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } /* Import public key x/y */ @@ -25823,15 +26612,19 @@ static int crypto_ecc_verify(const byte *key, uint32_t keySz, ); /* Make sure it was a public key imported */ if (ret == 0 && ecc.type != ECC_PUBLICKEY) { - ret = ECC_BAD_ARG_E; + ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */ } /* Import signature r/s */ if (ret == 0) { ret = mp_read_unsigned_bin(&r, sig, curveSz); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } /* Verify ECC Signature */ @@ -25847,14 +26640,16 @@ static int crypto_ecc_verify(const byte *key, uint32_t keySz, /* This is where real-time work could be called */ } while (ret == FP_WOULDBLOCK); - #ifdef DEBUG_WOLFSSL + #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) printf("ECC non-block verify: %d times\n", count); #endif + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } /* check verify result */ if (ret == 0 && verify_res == 0) { - ret = SIG_VERIFY_E; + ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */; } mp_clear(&r); @@ -25880,7 +26675,7 @@ static int crypto_ecc_sign(const byte *key, uint32_t keySz, if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL || curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2)) { - return BAD_FUNC_ARG; + return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */; } /* Initialize signature result */ @@ -25889,26 +26684,26 @@ static int crypto_ecc_sign(const byte *key, uint32_t keySz, /* Setup the ECC key */ ret = wc_ecc_init(&ecc); if (ret < 0) { - return ret; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_ecc_set_nonblock(&ecc, &nb_ctx); if (ret != MP_OKAY) { wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } /* Setup the signature r/s variables */ ret = mp_init(&r); if (ret != MP_OKAY) { wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } ret = mp_init(&s); if (ret != MP_OKAY) { mp_clear(&r); wc_ecc_free(&ecc); - return ret; + return WC_TEST_RET_ENC_EC(ret); } /* Import private key "k" */ @@ -25918,6 +26713,8 @@ static int crypto_ecc_sign(const byte *key, uint32_t keySz, &ecc, curveId /* ECC Curve Id */ ); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); if (ret == 0) { do { @@ -25932,9 +26729,11 @@ static int crypto_ecc_sign(const byte *key, uint32_t keySz, /* This is where real-time work could be called */ } while (ret == FP_WOULDBLOCK); - #ifdef DEBUG_WOLFSSL + #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) printf("ECC non-block sign: %d times\n", count); #endif + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { @@ -25975,28 +26774,40 @@ static int ecc_test_nonblock_dhe(int curveId, word32 curveSz, ret = wc_ecc_init(&keyA); if (ret == 0) { ret = wc_ecc_init(&keyB); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_ecc_set_nonblock(&keyA, &nbCtxA); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_ecc_set_nonblock(&keyB, &nbCtxB); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { do { ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId); count++; } while (ret == FP_WOULDBLOCK); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } -#ifdef DEBUG_WOLFSSL +#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) fprintf(stderr, "ECC non-block key gen: %d times\n", count); #endif if (ret == 0) { ret = wc_ecc_check_key(&keyA); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz, privKey, curveId); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } count = 0; if (ret == 0) { @@ -26004,19 +26815,23 @@ static int ecc_test_nonblock_dhe(int curveId, word32 curveSz, ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA); count++; } while (ret == FP_WOULDBLOCK); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } -#ifdef DEBUG_WOLFSSL +#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK) fprintf(stderr, "ECC non-block shared secret: %d times\n", count); #endif if (ret == 0) { do { ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB); } while (ret == FP_WOULDBLOCK); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { if (secretSzA != secretSzB || XMEMCMP(secretA, secretB, secretSzA) != 0) { - ret = -1; + ret = WC_TEST_RET_ENC_NC; } } @@ -26043,7 +26858,7 @@ static int ecc_test_nonblock_ecdsa(int curveId, word32 curveSz, sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE); if (sig == NULL) { - ret = -1; + ret = WC_TEST_RET_ENC_ERRNO; } if (ret == 0) { /* Sign hash using private key */ @@ -26142,7 +26957,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void) #endif #ifndef WC_NO_RNG if (ret != 0) - return -10300; + return WC_TEST_RET_ENC_EC(ret); #else (void)ret; #endif @@ -26269,7 +27084,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void) goto done; } #endif -#ifdef HAVE_ECC_CDH +#if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE) ret = ecc_test_cdh_vectors(&rng); if (ret != 0) { printf("ecc_test_cdh_vectors failed! %d\n", ret); @@ -26287,7 +27102,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test(void) #elif defined(HAVE_ECC_KEY_IMPORT) (void)ecc_test_make_pub; /* for compiler warning */ #endif -#ifdef WOLFSSL_CERT_GEN +#if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) ret = ecc_test_cert_gen(&rng); if (ret != 0) { printf("ecc_test_cert_gen failed!: %d\n", ret); @@ -26321,6 +27136,121 @@ done: #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \ (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256)) +#if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3)) +static int ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b) +{ +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + byte* plaintext; + byte* encrypted; + byte* decrypted; +#else + byte plaintext[128]; + byte encrypted[128]; + byte decrypted[128]; +#endif + ecEncCtx* aCtx = NULL; + ecEncCtx* bCtx = NULL; + static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15}; + int ret = 0; + static const char message[] = "Hello wolfSSL!"; + word32 plaintextLen; + word32 encryptLen = 128; + word32 decryptLen = 128; + +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + plaintext = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + encrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + decrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); +#endif + + wc_ecc_free(a); + wc_ecc_free(b); + + ret = wc_ecc_init(a); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + if (ret == 0) { + ret = wc_ecc_init(b); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + + if (ret == 0) + ret = wc_ecc_make_key(rng, 32, a); + + if (ret == 0) + ret = wc_ecc_make_key(rng, 32, b); + + /* create context */ + if (ret == 0) { + aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng); + + if (aCtx == NULL) + ret = WC_TEST_RET_ENC_NC; + } + + if (ret == 0) { + bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng); + + if (bCtx == NULL) + ret = WC_TEST_RET_ENC_NC; + } + + /* set salt */ + if (ret == 0) { + ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt)); + if (ret != 0) + ret = 10472; + } + + if (ret == 0) { + ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt)); + if (ret != 0) + ret = 10473; + } + + XMEMSET(plaintext, 0, 128); + XSTRLCPY((char *)plaintext, message, sizeof plaintext); + plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) / + AES_BLOCK_SIZE) * AES_BLOCK_SIZE; + + /* encrypt */ + if (ret == 0) { + ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted, + &encryptLen, aCtx); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + + /* decrypt */ + if (ret == 0) { + ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted, + &decryptLen, bCtx); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + + /* compare */ + if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0) + ret = WC_TEST_RET_ENC_NC; + + wc_ecc_free(a); + wc_ecc_free(b); + + wc_ecc_ctx_free(aCtx); + wc_ecc_ctx_free(bCtx); + +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) + XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); +#endif + + return ret; +} +#endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ + /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in * wolfFIPS 5.3. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test(). @@ -26466,14 +27396,14 @@ static int ecc_encrypt_kat(WC_RNG *rng) userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (userB == NULL) { - ret = -10451; + ret = WC_TEST_RET_ENC_ERRNO; } #ifdef WOLFSSL_ECIES_OLD if (ret == 0) { userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (userA == NULL) { - ret = -10450; + ret = WC_TEST_RET_ENC_ERRNO; } } #endif @@ -26482,14 +27412,14 @@ static int ecc_encrypt_kat(WC_RNG *rng) if (ret == 0) { ret = wc_ecc_init_ex(userB, HEAP_HINT, devId); if (ret != 0) - ret = -10453; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { userBInit = 1; #ifdef WOLFSSL_ECIES_OLD ret = wc_ecc_init_ex(userA, HEAP_HINT, devId); if (ret != 0) - ret = -10452; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { userAInit = 1; @@ -26509,7 +27439,7 @@ static int ecc_encrypt_kat(WC_RNG *rng) userB, ECC_SECP256R1); #endif if (ret != 0) - ret = -10454; + ret = WC_TEST_RET_ENC_EC(ret); } #ifdef WOLFSSL_ECIES_OLD @@ -26517,7 +27447,7 @@ static int ecc_encrypt_kat(WC_RNG *rng) ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA, ECC_SECP256R1); if (ret != 0) - ret = -10455; + ret = WC_TEST_RET_ENC_EC(ret); } #endif @@ -26527,7 +27457,7 @@ static int ecc_encrypt_kat(WC_RNG *rng) if (ret == 0) { ret = wc_ecc_set_rng(userB, rng); if (ret != 0) { - ret = -10456; + ret = WC_TEST_RET_ENC_EC(ret); } } #else @@ -26538,11 +27468,11 @@ static int ecc_encrypt_kat(WC_RNG *rng) ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain, &plainSz, NULL); if (ret != 0) - ret = -10457; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { if (XMEMCMP(plain, msg, sizeof(msg)) != 0) { - ret = -10458; + ret = WC_TEST_RET_ENC_NC; } } @@ -26622,25 +27552,25 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, /* encrypt msg to B */ ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL); if (ret != 0) { - ret = -10405; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #ifdef WOLFSSL_ECIES_OLD tmpKey->dp = userA->dp; ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey); if (ret != 0) { - ret = -10413; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif /* decrypt msg from A */ ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL); if (ret != 0) { - ret = -10406; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } if (XMEMCMP(plain, msg, sizeof(msg)) != 0) { - ret = -10407; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } #ifndef WOLFSSL_ECIES_OLD @@ -26650,7 +27580,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, goto done; if (XMEMCMP(plain, msg, sizeof(msg)) != 0) { - ret = -10415; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } #endif @@ -26658,7 +27588,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng); srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng); if (cliCtx == NULL || srvCtx == NULL) { - ret = -10408; goto done; + ret = WC_TEST_RET_ENC_ERRNO; goto done; } ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo); @@ -26671,13 +27601,13 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, /* get salt to send to peer */ tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx); if (tmpSalt == NULL) { - ret = -10409; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ); tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx); if (tmpSalt == NULL) { - ret = -10410; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ); @@ -26712,7 +27642,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, goto done; if (XMEMCMP(plain, msg, sizeof(msg)) != 0) { - ret = -10411; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } /* msg2 (response) from B to A */ @@ -26729,7 +27659,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, tmpKey->dp = userB->dp; ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey); if (ret != 0) { - ret = -10414; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #else wc_ecc_free(tmpKey); @@ -26742,7 +27672,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, goto done; if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) { - ret = -10412; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } #if defined(HAVE_COMP_KEY) && \ @@ -26754,7 +27684,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng); srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng); if (cliCtx == NULL || srvCtx == NULL) { - ret = -10416; goto done; + ret = WC_TEST_RET_ENC_ERRNO; goto done; } ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo); @@ -26767,13 +27697,13 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, /* get salt to send to peer */ tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx); if (tmpSalt == NULL) { - ret = -10417; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ); tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx); if (tmpSalt == NULL) { - ret = -10418; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ); @@ -26809,7 +27739,7 @@ static int ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB, goto done; if (XMEMCMP(plain, msg, sizeof(msg)) != 0) { - ret = -10419; goto done; + ret = WC_TEST_RET_ENC_NC; goto done; } #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */ @@ -26856,7 +27786,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_encrypt_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -10400; + return WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, @@ -26883,7 +27813,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_encrypt_test(void) ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0){ - ret = -10401; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB); @@ -26891,7 +27821,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_encrypt_test(void) ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE); #endif if (ret != 0){ - ret = -10402; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \ @@ -26899,11 +27829,11 @@ WOLFSSL_TEST_SUBROUTINE int ecc_encrypt_test(void) !defined(HAVE_SELFTEST) ret = wc_ecc_set_rng(userA, &rng); if (ret != 0) { - ret = -10403; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } ret = wc_ecc_set_rng(userB, &rng); if (ret != 0) { - ret = -10404; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif @@ -26948,6 +27878,11 @@ WOLFSSL_TEST_SUBROUTINE int ecc_encrypt_test(void) } } #endif +#endif /* !NO_AES && WOLFSSL_AES_COUNTER */ +#if !defined(NO_AES) && defined(HAVE_AES_CBC) + if (ret == 0) { + ret = ecc_ctx_kdf_salt_test(&rng, userA, userB); + } #endif #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */ @@ -27008,20 +27943,20 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-10420, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-10421, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-10421, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); bytes = (size_t)sizeof_ecc_clikey_der_256; /* place client key into ecc_key struct cliKey */ ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey, (word32)bytes); if (ret != 0) - ERROR_OUT(-10422, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); idx = 0; bytes = (size_t)sizeof_ecc_key_der_256; @@ -27030,7 +27965,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey, (word32)bytes); if (ret != 0) - ERROR_OUT(-10423, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifndef WC_NO_RNG #ifndef HAVE_FIPS @@ -27039,19 +27974,17 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - ERROR_OUT(-10424, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \ (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \ !defined(HAVE_SELFTEST) ret = wc_ecc_set_rng(cliKey, &rng); - if (ret != 0) { - ERROR_OUT(-10425, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_ecc_set_rng(servKey, &rng); - if (ret != 0) { - ERROR_OUT(-10425, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #endif /* !WC_NO_RNG */ @@ -27063,23 +27996,21 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) x = sizeof(out); ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL); if (ret < 0) - ERROR_OUT(-10426, done); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef WOLFSSL_ECIES_OLD tmpKey->dp = cliKey->dp; ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey); if (ret != 0) { - ret = -10414; goto done; + ret = WC_TEST_RET_ENC_EC(ret); goto done; } #endif y = sizeof(plain); ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL); if (ret < 0) - ERROR_OUT(-10427, done); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (XMEMCMP(plain, in, inLen)) - ERROR_OUT(-10428, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif @@ -27092,8 +28023,8 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey); } while (ret == WC_PENDING_E); if (ret < 0) - ERROR_OUT(-10429, done); - TEST_SLEEP(); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); +TEST_SLEEP(); XMEMSET(plain, 0, sizeof(plain)); @@ -27106,10 +28037,9 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) cliKey); } while (ret == WC_PENDING_E); if (ret < 0) - ERROR_OUT(-10430, done); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); if (verify != 1) - ERROR_OUT(-10431, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); TEST_SLEEP(); #ifdef WOLFSSL_CERT_EXT @@ -27120,7 +28050,7 @@ WOLFSSL_TEST_SUBROUTINE int ecc_test_buffers(void) ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey, (word32) bytes); if (ret != 0) - ERROR_OUT(-10432, done); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif ret = 0; @@ -27284,18 +28214,18 @@ static int curve25519_overflow_test(void) for (i = 0; i < X25519_TEST_CNT; i++) { if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i], sizeof(pb[i]), &userA) != 0) { - ret = -10500 - i; break; + ret = WC_TEST_RET_ENC_I(i); break; } /* test against known test vector */ XMEMSET(shared, 0, sizeof(shared)); y = sizeof(shared); if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) { - ret = -10510 - i; break; + ret = WC_TEST_RET_ENC_I(i); break; } if (XMEMCMP(ss[i], shared, y)) { - ret = -10520 - i; break; + ret = WC_TEST_RET_ENC_I(i); break; } } @@ -27310,6 +28240,7 @@ static int curve25519_overflow_test(void) */ static int curve25519_check_public_test(void) { + int ret; /* Little-endian values that will fail */ byte fail_le[][CURVE25519_KEYSIZE] = { { @@ -27363,19 +28294,21 @@ static int curve25519_check_public_test(void) /* Parameter checks */ /* NULL pointer */ - if (wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN) != - BAD_FUNC_ARG) { - return -10600; + ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN); + if (ret != BAD_FUNC_ARG) { + return WC_TEST_RET_ENC_EC(ret); } - if (wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN) != - BAD_FUNC_ARG) { - return -10601; + ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN); + if (ret != BAD_FUNC_ARG) { + return WC_TEST_RET_ENC_EC(ret); } /* Length of 0 treated differently to other invalid lengths for TLS */ - if (wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN) != BUFFER_E) - return -10602; - if (wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN) != BUFFER_E) - return -10603; + ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN); + if (ret != BUFFER_E) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN); + if (ret != BUFFER_E) + return WC_TEST_RET_ENC_EC(ret); /* Length not CURVE25519_KEYSIZE */ for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) { @@ -27383,11 +28316,11 @@ static int curve25519_check_public_test(void) continue; if (wc_curve25519_check_public(good, i, EC25519_LITTLE_ENDIAN) != ECC_BAD_ARG_E) { - return -10604 - i; + return WC_TEST_RET_ENC_I(i); } if (wc_curve25519_check_public(good, i, EC25519_BIG_ENDIAN) != ECC_BAD_ARG_E) { - return -10614 - i; + return WC_TEST_RET_ENC_I(i); } } @@ -27395,25 +28328,27 @@ static int curve25519_check_public_test(void) for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) { if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE, EC25519_LITTLE_ENDIAN) == 0) { - return -10624 - i; + return WC_TEST_RET_ENC_I(i); } } /* Big-endian fail cases */ for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) { if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE, EC25519_BIG_ENDIAN) == 0) { - return -10634 - i; + return WC_TEST_RET_ENC_I(i); } } /* Check a valid public value works! */ - if (wc_curve25519_check_public(good, CURVE25519_KEYSIZE, - EC25519_LITTLE_ENDIAN) != 0) { - return -10644; + ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE, + EC25519_LITTLE_ENDIAN); + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); } - if (wc_curve25519_check_public(good, CURVE25519_KEYSIZE, - EC25519_BIG_ENDIAN) != 0) { - return -10645; + ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE, + EC25519_BIG_ENDIAN); + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); } return 0; @@ -27445,15 +28380,17 @@ static int curve255519_der_test(void) word32 outputSz = 128; word32 idx; - if (wc_curve25519_init_ex(&key, HEAP_HINT, devId) != 0) { - return -10723; - } + ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* Test decode / encode of Curve25519 private key only */ if (ret == 0) { idx = 0; ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key, (word32)sizeof(kCurve25519PrivDer)); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { outputSz = (word32)sizeof(output); @@ -27463,12 +28400,12 @@ static int curve255519_der_test(void) ret = 0; } else { - ret = -10724; + ret = WC_TEST_RET_ENC_EC(ret); } } if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) || XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) { - ret = -10725; + ret = WC_TEST_RET_ENC_NC; } /* Test decode / encode of Curve25519 public key only */ @@ -27476,6 +28413,8 @@ static int curve255519_der_test(void) idx = 0; ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key, (word32)sizeof(kCurve25519PubDer)); + if (ret < 0) + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { outputSz = (word32)sizeof(output); @@ -27485,12 +28424,12 @@ static int curve255519_der_test(void) ret = 0; } else { - ret = -10726; + ret = WC_TEST_RET_ENC_EC(ret); } } if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) || XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) { - ret = -10727; + ret = WC_TEST_RET_ENC_NC; } wc_curve25519_free(&key); @@ -27569,50 +28508,54 @@ WOLFSSL_TEST_SUBROUTINE int curve25519_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -10700; + return WC_TEST_RET_ENC_EC(ret); wc_curve25519_init_ex(&userA, HEAP_HINT, devId); wc_curve25519_init_ex(&userB, HEAP_HINT, devId); wc_curve25519_init_ex(&pubKey, HEAP_HINT, devId); /* make curve25519 keys */ - if (wc_curve25519_make_key(&rng, 32, &userA) != 0) - return -10701; + ret = wc_curve25519_make_key(&rng, 32, &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_curve25519_make_key(&rng, 32, &userB) != 0) - return -10702; + ret = wc_curve25519_make_key(&rng, 32, &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_CURVE25519_SHARED_SECRET /* find shared secret key */ x = sizeof(sharedA); if ((ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x)) != 0) { printf("wc_curve25519_shared_secret 1 %d\n", ret); - return -10703; + return WC_TEST_RET_ENC_EC(ret); } y = sizeof(sharedB); if ((ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y)) != 0) { printf("wc_curve25519_shared_secret 2 %d\n", ret); - return -10704; + return WC_TEST_RET_ENC_EC(ret); } /* compare shared secret keys to test they are the same */ if (y != x) - return -10705; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(sharedA, sharedB, x)) - return -10706; + return WC_TEST_RET_ENC_NC; #endif #ifdef HAVE_CURVE25519_KEY_EXPORT /* export a public key and import it for another user */ x = sizeof(exportBuf); - if (wc_curve25519_export_public(&userA, exportBuf, &x) != 0) - return -10707; + ret = wc_curve25519_export_public(&userA, exportBuf, &x); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_CURVE25519_KEY_IMPORT - if (wc_curve25519_import_public(exportBuf, x, &pubKey) != 0) - return -10708; + ret = wc_curve25519_import_public(exportBuf, x, &pubKey); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #endif #endif @@ -27621,64 +28564,73 @@ WOLFSSL_TEST_SUBROUTINE int curve25519_test(void) /* test shared key after importing a public key */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0) - return -10709; + if (wc_curve25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0) { + return WC_TEST_RET_ENC_NC; + } if (XMEMCMP(sharedA, sharedB, y)) - return -10710; + return WC_TEST_RET_ENC_NC; /* import RFC test vectors and compare shared key */ - if (wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA) - != 0) - return -10711; + ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), + &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB) - != 0) - return -10712; + ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), + &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* test against known test vector */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve25519_shared_secret(&userA, &userB, sharedB, &y) != 0) - return -10713; + ret = wc_curve25519_shared_secret(&userA, &userB, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss, sharedB, y)) - return -10714; + return WC_TEST_RET_ENC_NC; /* test swapping roles of keys and generating same shared key */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve25519_shared_secret(&userB, &userA, sharedB, &y) != 0) - return -10715; + ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss, sharedB, y)) - return -10716; + return WC_TEST_RET_ENC_NC; /* test with 1 generated key and 1 from known test vector */ - if (wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA) - != 0) - return -10717; + ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), + &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); wc_curve25519_free(&userB); wc_curve25519_init_ex(&userB, HEAP_HINT, devId); - if (wc_curve25519_make_key(&rng, 32, &userB) != 0) - return -10718; + ret = wc_curve25519_make_key(&rng, 32, &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); x = sizeof(sharedA); - if (wc_curve25519_shared_secret(&userA, &userB, sharedA, &x) != 0) - return -10719; + ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); y = sizeof(sharedB); - if (wc_curve25519_shared_secret(&userB, &userA, sharedB, &y) != 0) - return -10720; + ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* compare shared secret keys to test they are the same */ if (y != x) - return -10721; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(sharedA, sharedB, x)) - return -10722; + return WC_TEST_RET_ENC_NC; ret = curve25519_overflow_test(); if (ret != 0) @@ -27726,7 +28678,7 @@ static int ed25519_test_cert(void) tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { - ERROR_OUT(-10730, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #ifdef USE_CERT_BUFFERS_256 @@ -27735,21 +28687,22 @@ static int ed25519_test_cert(void) #elif !defined(NO_FILESYSTEM) file = XFOPEN(caEd25519Cert, "rb"); if (file == NULL) { - ERROR_OUT(-10731, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #else /* No certificate to use. */ - ERROR_OUT(-10732, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif InitDecodedCert(&cert[0], tmp, (word32)bytes, 0); caCert = &cert[0]; ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-10733, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef USE_CERT_BUFFERS_256 XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert); @@ -27757,40 +28710,39 @@ static int ed25519_test_cert(void) #elif !defined(NO_FILESYSTEM) file = XFOPEN(serverEd25519Cert, "rb"); if (file == NULL) { - ERROR_OUT(-10734, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #else /* No certificate to use. */ - ERROR_OUT(-10735, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif InitDecodedCert(&cert[1], tmp, (word32)bytes, 0); serverCert = &cert[1]; ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-10736, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_ED25519_VERIFY ret = wc_ed25519_init(&key); - if (ret < 0) { - ERROR_OUT(-10737, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); pubKey = &key; ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize, pubKey); - if (ret < 0) { - ERROR_OUT(-10738, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); - if (wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength, + ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength, serverCert->source + serverCert->certBegin, serverCert->sigIndex - serverCert->certBegin, - &verify, pubKey) < 0 || verify != 1) { - ERROR_OUT(-10739, done); - } + &verify, pubKey); + if (ret < 0 || verify != 1) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif /* HAVE_ED25519_VERIFY */ done: @@ -27825,7 +28777,7 @@ static int ed25519_test_make_cert(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -10750; + return WC_TEST_RET_ENC_EC(ret); wc_ed25519_init(&key); privKey = &key; @@ -27838,40 +28790,34 @@ static int ed25519_test_make_cert(void) cert.isCA = 0; #ifdef WOLFSSL_CERT_EXT ret = wc_SetKeyUsage(&cert, certKeyUsage); - if (ret < 0) { - ERROR_OUT(-10751, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey); - if (ret < 0) { - ERROR_OUT(-10752, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey); - if (ret < 0) { - ERROR_OUT(-10753, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { - ERROR_OUT(-10754, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } cert.sigType = CTC_ED25519; ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng); - if (ret < 0) { - ERROR_OUT(-10755, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng); - if (ret < 0) { - ERROR_OUT(-10756, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); InitDecodedCert(&decode, tmp, ret, HEAP_HINT); ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0); FreeDecodedCert(&decode); - if (ret != 0) { - ERROR_OUT(-10757, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); done: if (tmp != NULL) @@ -27952,7 +28898,7 @@ static int ed25519ctx_test(void) ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key, contextCtx, sizeof(contextCtx)); if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0) - ret = -10801; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ @@ -27960,7 +28906,7 @@ static int ed25519ctx_test(void) ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key, contextCtx, sizeof(contextCtx)); if (ret == 0 && verify != 1) - ret = -10802; + ret = WC_TEST_RET_ENC_NC; #endif if (ret == 0) @@ -27968,7 +28914,7 @@ static int ed25519ctx_test(void) NULL, 0); if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0) - ret = -10803; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ @@ -27976,7 +28922,7 @@ static int ed25519ctx_test(void) ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key, NULL, 0); if (ret == 0 && verify != 1) - ret = -10804; + ret = WC_TEST_RET_ENC_NC; #endif wc_ed25519_free(&key); @@ -28055,7 +29001,7 @@ static int ed25519ph_test(void) ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId); if (ret != 0) - return -10900; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh, sizeof(pKeyPh), &key); @@ -28064,7 +29010,7 @@ static int ed25519ph_test(void) NULL, 0); if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0) - ret = -10901; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ @@ -28072,7 +29018,7 @@ static int ed25519ph_test(void) ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, NULL, 0); if (ret == 0 && verify != 1) - ret = -10902; + ret = WC_TEST_RET_ENC_NC; #endif if (ret == 0) @@ -28080,7 +29026,7 @@ static int ed25519ph_test(void) contextPh2, sizeof(contextPh2)); if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0) - ret = -10903; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ @@ -28088,7 +29034,7 @@ static int ed25519ph_test(void) ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, contextPh2, sizeof(contextPh2)); if (ret == 0 && verify != 1) - ret = -10904; + ret = WC_TEST_RET_ENC_NC; #endif if (ret == 0) @@ -28096,28 +29042,28 @@ static int ed25519ph_test(void) NULL, 0); if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0) - ret = -10905; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) if (ret == 0) ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, &key, NULL, 0); if (ret == 0 && verify != 1) - ret = -10906; + ret = WC_TEST_RET_ENC_NC; #endif if (ret == 0) ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, contextPh2, sizeof(contextPh2)); if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0) - ret = -10907; + ret = WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) if (ret == 0) ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, &key, contextPh2, sizeof(contextPh2)); if (ret == 0 && verify != 1) - ret = -10908; + ret = WC_TEST_RET_ENC_NC; #endif wc_ed25519_free(&key); @@ -28539,7 +29485,7 @@ WOLFSSL_TEST_SUBROUTINE int ed25519_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -11000; + return WC_TEST_RET_ENC_EC(ret); wc_ed25519_init_ex(&key, HEAP_HINT, devId); wc_ed25519_init_ex(&key2, HEAP_HINT, devId); @@ -28561,70 +29507,70 @@ WOLFSSL_TEST_SUBROUTINE int ed25519_test(void) if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i], pKeySz[i], &key) != 0) - return -11001 - i; + return WC_TEST_RET_ENC_I(i); if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key) != 0) - return -11011 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(out, sigs[i], 64)) - return -11021 - i; + return WC_TEST_RET_ENC_I(i); #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, &key) != 0 || verify != 1) - return -11031 - i; + return WC_TEST_RET_ENC_I(i); #ifdef WOLFSSL_ED25519_STREAMING_VERIFY /* test verify on good msg using streaming interface directly */ if (wc_ed25519_verify_msg_init(out, outlen, &key, (byte)Ed25519, NULL, 0) != 0) - return -11211 - i; + return WC_TEST_RET_ENC_I(i); for (j = 0; j < msgSz[i]; j += i) { if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), &key) != 0) - return -11221 - i; + return WC_TEST_RET_ENC_I(i); } if (wc_ed25519_verify_msg_final(out, outlen, &verify, &key) != 0 || verify != 1) - return -11231 - i; + return WC_TEST_RET_ENC_I(i); #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */ /* test verify on bad msg */ out[outlen-1] = out[outlen-1] + 1; if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, &key) == 0 || verify == 1) - return -11041 - i; + return WC_TEST_RET_ENC_I(i); #endif /* HAVE_ED25519_VERIFY */ /* test api for import/exporting keys */ exportPSz = sizeof(exportPKey); exportSSz = sizeof(exportSKey); if (wc_ed25519_export_public(&key, exportPKey, &exportPSz) != 0) - return -11051 - i; + return WC_TEST_RET_ENC_I(i); if (wc_ed25519_import_public_ex(exportPKey, exportPSz, &key2, 1) != 0) - return -11061 - i; + return WC_TEST_RET_ENC_I(i); if (wc_ed25519_export_private_only(&key, exportSKey, &exportSSz) != 0) - return -11071 - i; + return WC_TEST_RET_ENC_I(i); if (wc_ed25519_import_private_key(exportSKey, exportSSz, exportPKey, exportPSz, &key2) != 0) - return -11081 - i; + return WC_TEST_RET_ENC_I(i); /* clear "out" buffer and test sign with imported keys */ outlen = sizeof(out); XMEMSET(out, 0, sizeof(out)); if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key2) != 0) - return -11091 - i; + return WC_TEST_RET_ENC_I(i); #if defined(HAVE_ED25519_VERIFY) if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, &key2) != 0 || verify != 1) - return -11101 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(out, sigs[i], 64)) - return -11111 - i; + return WC_TEST_RET_ENC_I(i); #endif /* HAVE_ED25519_VERIFY */ } @@ -28639,57 +29585,62 @@ WOLFSSL_TEST_SUBROUTINE int ed25519_test(void) #ifndef NO_ASN /* Try ASN.1 encoded private-only key and public key. */ idx = 0; - if (wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, &key3, - sizeof(privateEd25519)) != 0) - return -11121; + ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, &key3, + sizeof(privateEd25519)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); idx = 0; if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, &key3, sizeof(badPrivateEd25519)) == 0) - return -11122; - - if (wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3) - != BAD_FUNC_ARG) - return -11131; + return WC_TEST_RET_ENC_NC; + ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); /* try with a buffer size that is too large */ idx = 0; if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, &key3, sizeof(badPublicEd25519)) == 0) - return -11140; + return WC_TEST_RET_ENC_NC; idx = 0; - if (wc_Ed25519PublicKeyDecode(publicEd25519, &idx, &key3, - sizeof(publicEd25519)) != 0) - return -11141; + ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, &key3, + sizeof(publicEd25519)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3) != 0) - return -11151; + ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigs[0], 64)) - return -11161; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED25519_VERIFY) /* test verify on good msg */ - if (wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, &key3) - != 0 || verify != 1) - return -11171; + ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, &key3); + if (ret != 0 || verify != 1) + return WC_TEST_RET_ENC_EC(ret); + #endif /* HAVE_ED25519_VERIFY */ wc_ed25519_free(&key3); wc_ed25519_init(&key3); idx = 0; - if (wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, &key3, - sizeof(privPubEd25519)) != 0) - return -11181; + ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, &key3, + sizeof(privPubEd25519)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3) != 0) - return -11191; + ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigs[0], 64)) - return -11201; + return WC_TEST_RET_ENC_NC; wc_ed25519_free(&key3); #endif /* NO_ASN */ @@ -28784,21 +29735,23 @@ static int curve448_check_public_test(void) 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 }; int i; + int ret; /* Parameter checks */ /* NULL pointer */ - if (wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN) != - BAD_FUNC_ARG) { - return -11300; - } - if (wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN) != BAD_FUNC_ARG) { - return -11301; - } + ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); /* Length of 0 treated differently to other invalid lengths for TLS */ - if (wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN) != BUFFER_E) - return -11302; - if (wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN) != BUFFER_E) - return -11303; + ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN); + if (ret != BUFFER_E) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN); + if (ret != BUFFER_E) + return WC_TEST_RET_ENC_EC(ret); /* Length not CURVE448_KEY_SIZE */ for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) { @@ -28806,11 +29759,11 @@ static int curve448_check_public_test(void) continue; if (wc_curve448_check_public(good, i, EC448_LITTLE_ENDIAN) != ECC_BAD_ARG_E) { - return -11304 - i; + return WC_TEST_RET_ENC_I(i); } if (wc_curve448_check_public(good, i, EC448_BIG_ENDIAN) != ECC_BAD_ARG_E) { - return -11314 - i; + return WC_TEST_RET_ENC_I(i); } } @@ -28818,26 +29771,25 @@ static int curve448_check_public_test(void) for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) { if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE, EC448_LITTLE_ENDIAN) == 0) { - return -11324 - i; + return WC_TEST_RET_ENC_I(i); } } /* Big-endian fail cases */ for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) { if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE, EC448_BIG_ENDIAN) == 0) { - return -11334 - i; + return WC_TEST_RET_ENC_I(i); } } /* Check a valid public value works! */ - if (wc_curve448_check_public(good, CURVE448_KEY_SIZE, - EC448_LITTLE_ENDIAN) != 0) { - return -11344; - } - if (wc_curve448_check_public(good, CURVE448_KEY_SIZE, - EC448_BIG_ENDIAN) != 0) { - return -11345; - } + ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, + EC448_LITTLE_ENDIAN); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -28929,46 +29881,52 @@ WOLFSSL_TEST_SUBROUTINE int curve448_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -11400; + return WC_TEST_RET_ENC_EC(ret); wc_curve448_init(&userA); wc_curve448_init(&userB); wc_curve448_init(&pubKey); /* make curve448 keys */ - if (wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA) != 0) - return -11401; + ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB) != 0) - return -11402; + ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_CURVE448_SHARED_SECRET /* find shared secret key */ x = sizeof(sharedA); - if (wc_curve448_shared_secret(&userA, &userB, sharedA, &x) != 0) - return -11403; + ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); y = sizeof(sharedB); - if (wc_curve448_shared_secret(&userB, &userA, sharedB, &y) != 0) - return -11404; + ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* compare shared secret keys to test they are the same */ if (y != x) - return -11405; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(sharedA, sharedB, x)) - return -11406; + return WC_TEST_RET_ENC_NC; #endif #ifdef HAVE_CURVE448_KEY_EXPORT /* export a public key and import it for another user */ x = sizeof(exportBuf); - if (wc_curve448_export_public(&userA, exportBuf, &x) != 0) - return -11407; + ret = wc_curve448_export_public(&userA, exportBuf, &x); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #ifdef HAVE_CURVE448_KEY_IMPORT - if (wc_curve448_import_public(exportBuf, x, &pubKey) != 0) - return -11408; + ret = wc_curve448_import_public(exportBuf, x, &pubKey); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #endif #endif @@ -28977,61 +29935,67 @@ WOLFSSL_TEST_SUBROUTINE int curve448_test(void) /* test shared key after importing a public key */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y) != 0) - return -11409; + ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(sharedA, sharedB, y)) - return -11410; + return WC_TEST_RET_ENC_NC; /* import RFC test vectors and compare shared key */ - if (wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA) - != 0) - return -11411; + ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB) - != 0) - return -11412; + ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* test against known test vector */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve448_shared_secret(&userA, &userB, sharedB, &y) != 0) - return -11413; + ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss, sharedB, y)) - return -11414; + return WC_TEST_RET_ENC_NC; /* test swapping roles of keys and generating same shared key */ XMEMSET(sharedB, 0, sizeof(sharedB)); y = sizeof(sharedB); - if (wc_curve448_shared_secret(&userB, &userA, sharedB, &y) != 0) - return -11415; + ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss, sharedB, y)) - return -11416; + return WC_TEST_RET_ENC_NC; /* test with 1 generated key and 1 from known test vector */ - if (wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA) - != 0) - return -11417; + ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_curve448_make_key(&rng, 56, &userB) != 0) - return -11418; + ret = wc_curve448_make_key(&rng, 56, &userB); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); x = sizeof(sharedA); - if (wc_curve448_shared_secret(&userA, &userB, sharedA, &x) != 0) - return -11419; + ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); y = sizeof(sharedB); - if (wc_curve448_shared_secret(&userB, &userA, sharedB, &y) != 0) - return -11420; + ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); /* compare shared secret keys to test they are the same */ if (y != x) - return -11421; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(sharedA, sharedB, x)) - return -11422; + return WC_TEST_RET_ENC_NC; ret = curve448_check_public_test(); if (ret != 0) @@ -29068,7 +30032,7 @@ static int ed448_test_cert(void) tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { - ERROR_OUT(-11430, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } #ifdef USE_CERT_BUFFERS_256 @@ -29077,21 +30041,22 @@ static int ed448_test_cert(void) #elif !defined(NO_FILESYSTEM) file = XFOPEN(caEd448Cert, "rb"); if (file == NULL) { - ERROR_OUT(-11431, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #else /* No certificate to use. */ - ERROR_OUT(-11432, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif InitDecodedCert(&cert[0], tmp, (word32)bytes, 0); caCert = &cert[0]; ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-11433, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef USE_CERT_BUFFERS_256 XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert); @@ -29099,38 +30064,38 @@ static int ed448_test_cert(void) #elif !defined(NO_FILESYSTEM) file = XFOPEN(serverEd448Cert, "rb"); if (file == NULL) { - ERROR_OUT(-11434, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); #else /* No certificate to use. */ - ERROR_OUT(-11435, done); + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif InitDecodedCert(&cert[1], tmp, (word32)bytes, 0); serverCert = &cert[1]; ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL); - if (ret != 0) { - ERROR_OUT(-11436, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef HAVE_ED448_VERIFY ret = wc_ed448_init(&key); - if (ret < 0) { - ERROR_OUT(-11437, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); pubKey = &key; ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey); - if (ret < 0) { - ERROR_OUT(-11438, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); - if (wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength, + ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength, serverCert->source + serverCert->certBegin, serverCert->sigIndex - serverCert->certBegin, - &verify, pubKey, NULL, 0) < 0 || verify != 1) { - ERROR_OUT(-11439, done); + &verify, pubKey, NULL, 0); + if (ret < 0 || verify != 1) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); } #endif /* HAVE_ED448_VERIFY */ @@ -29166,7 +30131,7 @@ static int ed448_test_make_cert(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -11450; + return WC_TEST_RET_ENC_EC(ret); wc_ed448_init(&key); privKey = &key; @@ -29179,40 +30144,34 @@ static int ed448_test_make_cert(void) cert.isCA = 0; #ifdef WOLFSSL_CERT_EXT ret = wc_SetKeyUsage(&cert, certKeyUsage); - if (ret < 0) { - ERROR_OUT(-11451, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey); - if (ret < 0) { - ERROR_OUT(-11452, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey); - if (ret < 0) { - ERROR_OUT(-11453, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { - ERROR_OUT(-11454, done); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); } cert.sigType = CTC_ED448; ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng); - if (ret < 0) { - ERROR_OUT(-11455, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng); - if (ret < 0) { - ERROR_OUT(-11456, done); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); InitDecodedCert(&decode, tmp, ret, HEAP_HINT); ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0); FreeDecodedCert(&decode); - if (ret != 0) { - ERROR_OUT(-11457, done); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); done: if (tmp != NULL) @@ -29227,6 +30186,7 @@ done: defined(HAVE_ED448_KEY_IMPORT) static int ed448_ctx_test(void) { + int ret; byte out[ED448_SIG_SIZE]; word32 outlen; #ifdef HAVE_ED448_VERIFY @@ -29285,25 +30245,29 @@ static int ed448_ctx_test(void) outlen = sizeof(out); XMEMSET(out, 0, sizeof(out)); - if (wc_ed448_init_ex(&key, HEAP_HINT, devId) != 0) - return -11500; + ret = wc_ed448_init_ex(&key, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx, - sizeof(pKeyCtx), &key) != 0) - return -11501; + ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx, + sizeof(pKeyCtx), &key); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key, - contextCtx, sizeof(contextCtx)) != 0) - return -11502; + ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key, + contextCtx, sizeof(contextCtx)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigCtx, sizeof(sigCtx))) - return -11503; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED448_VERIFY) /* test verify on good msg */ - if (wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key, - contextCtx, sizeof(contextCtx)) != 0 || verify != 1) - return -11504; + ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key, + contextCtx, sizeof(contextCtx)); + if (ret != 0 || verify != 1) + return WC_TEST_RET_ENC_EC(ret); #endif wc_ed448_free(&key); @@ -29313,6 +30277,7 @@ static int ed448_ctx_test(void) static int ed448ph_test(void) { + int ret; byte out[ED448_SIG_SIZE]; word32 outlen; #ifdef HAVE_ED448_VERIFY @@ -29401,75 +30366,78 @@ static int ed448ph_test(void) outlen = sizeof(out); XMEMSET(out, 0, sizeof(out)); - if (wc_ed448_init_ex(&key, HEAP_HINT, devId) != 0) - return -11600; + ret = wc_ed448_init_ex(&key, HEAP_HINT, devId); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh, - sizeof(pKeyPh), &key) != 0) { - return -11601; - } + ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh, + sizeof(pKeyPh), &key); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL, - 0) != 0) { - return -11602; - } + ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL, + 0); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigPh1, sizeof(sigPh1))) - return -11603; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED448_VERIFY) /* test verify on good msg */ - if (wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, - NULL, 0) != 0 || verify != 1) { - return -11604; + ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, + NULL, 0); + if (ret != 0 || verify != 1) { + return WC_TEST_RET_ENC_EC(ret); } #endif - if (wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, - contextPh2, sizeof(contextPh2)) != 0) { - return -11605; - } + ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, + contextPh2, sizeof(contextPh2)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigPh2, sizeof(sigPh2))) - return -11606; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED448_VERIFY) /* test verify on good msg */ - if (wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, - contextPh2, sizeof(contextPh2)) != 0 || - verify != 1) { - return -11607; + ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key, + contextPh2, sizeof(contextPh2)); + if (ret != 0 || verify != 1) { + return WC_TEST_RET_ENC_EC(ret); } #endif - if (wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL, - 0) != 0) { - return -11608; - } + ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL, + 0); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigPh1, sizeof(sigPh1))) - return -11609; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED448_VERIFY) - if (wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, - &key, NULL, 0) != 0 || verify != 1) { - return -11610; + ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, + &key, NULL, 0); + if (ret != 0 || verify != 1) { + return WC_TEST_RET_ENC_EC(ret); } #endif - if (wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, - contextPh2, sizeof(contextPh2)) != 0) { - return -11611; - } + ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, + contextPh2, sizeof(contextPh2)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(out, sigPh2, sizeof(sigPh2))) - return -11612; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ED448_VERIFY) - if (wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, - &key, contextPh2, sizeof(contextPh2)) != 0 || - verify != 1) { - return -11613; + ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify, + &key, contextPh2, sizeof(contextPh2)); + if (ret != 0 || verify != 1) { + return WC_TEST_RET_ENC_EC(ret); } #endif @@ -29981,21 +30949,26 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) #endif if (ret != 0) { XMEMSET(&rng, 0, sizeof(rng)); - ERROR_OUT(-11700, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - if (wc_ed448_init(key) < 0) - ERROR_OUT(-11903, out); - if (wc_ed448_init(key2) < 0) - ERROR_OUT(-11904, out); + ret = wc_ed448_init(key); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_ed448_init(key2); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN) - if (wc_ed448_init(key3) < 0) - ERROR_OUT(-11905, out); + ret = wc_ed448_init(key3); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif - if (wc_ed448_make_key(&rng, ED448_KEY_SIZE, key) < 0) - ERROR_OUT(-11906, out); - if (wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2) < 0) - ERROR_OUT(-11907, out); + ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* helper functions for signature and key size */ keySz = wc_ed448_size(key); @@ -30009,40 +30982,40 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i], pKeySz[i], key) != 0) - ERROR_OUT(-11701 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL, 0) != 0) - ERROR_OUT(-11711 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); if (XMEMCMP(out, sigs[i], 114)) - ERROR_OUT(-11721 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #if defined(HAVE_ED448_VERIFY) /* test verify on good msg */ if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key, NULL, 0) != 0 || verify != 1) - ERROR_OUT(-11731 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #ifdef WOLFSSL_ED448_STREAMING_VERIFY /* test verify on good msg using streaming interface directly */ if (wc_ed448_verify_msg_init(out, outlen, key, (byte)Ed448, NULL, 0) != 0) - ERROR_OUT(-11911 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); for (j = 0; j < msgSz[i]; j += i) { if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0) - ERROR_OUT(-11921 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); } if (wc_ed448_verify_msg_final(out, outlen, &verify, key) != 0 || verify != 1) - ERROR_OUT(-11931 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #endif /* WOLFSSL_ED448_STREAMING_VERIFY */ /* test verify on bad msg */ out[outlen-2] = out[outlen-2] + 1; if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key, NULL, 0) == 0 || verify == 1) - ERROR_OUT(-11741 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #endif /* HAVE_ED448_VERIFY */ /* test api for import/exporting keys */ @@ -30055,29 +31028,29 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if ((exportPKey == NULL) || (exportSKey == NULL)) - ERROR_OUT(-11902, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = 0; do { if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) { - ret = -11751 - i; + ret = WC_TEST_RET_ENC_I(i); break; } if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) { - ret = -11761 - i; + ret = WC_TEST_RET_ENC_I(i); break; } if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) { - ret = -11771 - i; + ret = WC_TEST_RET_ENC_I(i); break; } if (wc_ed448_import_private_key(exportSKey, exportSSz, exportPKey, exportPSz, key2) != 0) { - ret = -11781 - i; + ret = WC_TEST_RET_ENC_I(i); break; } @@ -30086,7 +31059,7 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) XMEMSET(out, 0, sizeof(out)); if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL, 0) != 0) { - ret = -11791 - i; + ret = WC_TEST_RET_ENC_I(i); break; } } while(0); @@ -30101,10 +31074,10 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) #if defined(HAVE_ED448_VERIFY) if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2, NULL, 0) != 0 || verify != 1) - ERROR_OUT(-11801 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); if (XMEMCMP(out, sigs[i], SIGSZ)) - ERROR_OUT(-11811 - i, out); + ERROR_OUT(WC_TEST_RET_ENC_I(i), out); #endif /* HAVE_ED448_VERIFY */ } @@ -30119,46 +31092,52 @@ WOLFSSL_TEST_SUBROUTINE int ed448_test(void) #ifndef NO_ASN /* Try ASN.1 encoded private-only key and public key. */ idx = 0; - if (wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3, - sizeof(privateEd448)) != 0) - ERROR_OUT(-11821, out); + ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3, + sizeof(privateEd448)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0) - != BAD_FUNC_ARG) - ERROR_OUT(-11831, out); + ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0); + if (ret != BAD_FUNC_ARG) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); idx = 0; - if (wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, - sizeof(publicEd448)) != 0) - ERROR_OUT(-11841, out); + ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0) != 0) - ERROR_OUT(-11851, out); + ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(out, sigs[0], SIGSZ)) - ERROR_OUT(-11861, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #if defined(HAVE_ED448_VERIFY) /* test verify on good msg */ - if (wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3, - NULL, 0) != 0 || verify != 1) - ERROR_OUT(-11871, out); + ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3, + NULL, 0); + if (ret != 0 || verify != 1) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif /* HAVE_ED448_VERIFY */ wc_ed448_free(key3); - if (wc_ed448_init(key3) < 0) - ERROR_OUT(-11908, out); + ret = wc_ed448_init(key3); + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); idx = 0; - if (wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3, - sizeof(privPubEd448)) != 0) - ERROR_OUT(-11881, out); + ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3, + sizeof(privPubEd448)); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); - if (wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0) != 0) - ERROR_OUT(-11891, out); + ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(out, sigs[0], SIGSZ)) - ERROR_OUT(-11901, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); #endif /* NO_ASN */ #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */ @@ -30658,44 +31637,44 @@ static int kyber512_kat(void) ret = wc_KyberKey_Init(KYBER512, &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_MakeKeyWithRandom(&key, kyber512_rand, sizeof(kyber512_rand)); if (ret != 0) - return -20102; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePublicKey(&key, pub, sizeof(pub)); if (ret != 0) - return -20103; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePrivateKey(&key, priv, sizeof(priv)); if (ret != 0) - return -20104; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0) - return -20105; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0) - return -20106; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_EncapsulateWithRandom(&key, ct, ss, kyber512enc_rand, sizeof(kyber512enc_rand)); if (ret != 0) - return -20107; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0) - return -20108; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0) - return -20109; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_Decapsulate(&key, ss_dec, ct, sizeof(kyber512_ct)); if (ret != 0) - return -20110; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0) - return -20111; + return WC_TEST_RET_ENC_NC; wc_KyberKey_Free(&key); @@ -31329,44 +32308,44 @@ static int kyber768_kat(void) ret = wc_KyberKey_Init(KYBER768, &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20201; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_MakeKeyWithRandom(&key, kyber768_rand, sizeof(kyber768_rand)); if (ret != 0) - return -20202; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePublicKey(&key, pub, sizeof(pub)); if (ret != 0) - return -20203; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePrivateKey(&key, priv, sizeof(priv)); if (ret != 0) - return -20204; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0) - return -20205; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0) - return -20206; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_EncapsulateWithRandom(&key, ct, ss, kyber768enc_rand, sizeof(kyber768enc_rand)); if (ret != 0) - return -20207; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0) - return -20208; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0) - return -20209; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_Decapsulate(&key, ss_dec, ct, sizeof(kyber768_ct)); if (ret != 0) - return -20210; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0) - return -20211; + return WC_TEST_RET_ENC_NC; wc_KyberKey_Free(&key); @@ -32203,44 +33182,44 @@ static int kyber1024_kat(void) ret = wc_KyberKey_Init(KYBER1024, &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20301; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_MakeKeyWithRandom(&key, kyber1024_rand, sizeof(kyber1024_rand)); if (ret != 0) - return -20302; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePublicKey(&key, pub, sizeof(pub)); if (ret != 0) - return -20303; + return WC_TEST_RET_ENC_EC(ret); ret = wc_KyberKey_EncodePrivateKey(&key, priv, sizeof(priv)); if (ret != 0) - return -20304; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0) - return -20305; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0) - return -20306; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_EncapsulateWithRandom(&key, ct, ss, kyber1024enc_rand, sizeof(kyber1024enc_rand)); if (ret != 0) - return -20307; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0) - return -20308; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0) - return -20309; + return WC_TEST_RET_ENC_NC; ret = wc_KyberKey_Decapsulate(&key, ss_dec, ct, sizeof(kyber1024_ct)); if (ret != 0) - return -20310; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0) - return -20311; + return WC_TEST_RET_ENC_NC; wc_KyberKey_Free(&key); @@ -32283,65 +33262,65 @@ WOLFSSL_TEST_SUBROUTINE int kyber_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - return -20000; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) { ret = wc_KyberKey_Init(testData[i][0], &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20001 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_MakeKey(&key, &rng); if (ret != 0) - return -20002 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_EncodePublicKey(&key, pub, testData[i][2]); if (ret != 0) - return -20003 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_EncodePrivateKey(&key, priv, testData[i][1]); if (ret != 0) - return -20004 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_Init(testData[i][0], &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20005 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_DecodePublicKey(&key, pub, testData[i][2]); if (ret != 0) - return -20006 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_Encapsulate(&key, ct, ss, &rng); if (ret != 0) - return -20007 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_EncodePublicKey(&key, pub2, testData[i][2]); if (ret != 0) - return -20008 - i * 20; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(pub, pub2, testData[i][2]) != 0) - return -20009 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_Init(testData[i][0], &key, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -20010 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_DecodePrivateKey(&key, priv, testData[i][1]); if (ret != 0) - return -20011 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_Decapsulate(&key, ss_dec, ct, testData[i][3]); if (ret != 0) - return -20012 - i * 20; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(ss, ss_dec, sizeof(ss)) != 0) - return -20013 - i * 20; + return WC_TEST_RET_ENC_I(i); ret = wc_KyberKey_EncodePrivateKey(&key, priv2, testData[i][1]); if (ret != 0) - return -20014 - i * 20; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(priv, priv2, testData[i][2]) != 0) - return -20015 - i * 20; + return WC_TEST_RET_ENC_I(i); wc_KyberKey_Free(&key); } @@ -32370,6 +33349,10 @@ WOLFSSL_TEST_SUBROUTINE int kyber_test(void) } #endif /* WOLFSSL_HAVE_KYBER */ +static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point -- + * see print_fiducials() below. + */ + #ifdef WOLFCRYPT_HAVE_ECCSI static int eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk, ecc_point* pvt) @@ -32386,403 +33369,403 @@ static int eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk, ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10023; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10024; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10025; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10026; + return WC_TEST_RET_ENC_EC(ret); wc_FreeEccsiKey(NULL); /* Create a valid key. */ ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID); if (ret != 0) - return -10027; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiKey(NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10028; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiKey(key, NULL); if (ret != BAD_FUNC_ARG) - return -10029; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiKey(NULL, rng); if (ret != BAD_FUNC_ARG) - return -10030; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10031; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL); if (ret != BAD_FUNC_ARG) - return -10032; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt); if (ret != BAD_FUNC_ARG) - return -10033; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10034; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10035; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10036; + return WC_TEST_RET_ENC_EC(ret); /* No key set */ ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt); if (ret != BAD_STATE_E) - return -10037; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10038; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt, NULL); if (ret != BAD_FUNC_ARG) - return -10039; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL, &valid); if (ret != BAD_FUNC_ARG) - return -10040; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt, &valid); if (ret != BAD_FUNC_ARG) - return -10041; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt, &valid); if (ret != BAD_FUNC_ARG) - return -10042; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt, &valid); if (ret != BAD_FUNC_ARG) - return -10043; + return WC_TEST_RET_ENC_EC(ret); /* No key set */ ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt, &valid); if (ret != BAD_STATE_E) - return -10044; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10045; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(key, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10046; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(NULL, pvt, NULL); if (ret != BAD_FUNC_ARG) - return -10047; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(NULL, NULL, &valid); if (ret != BAD_FUNC_ARG) - return -10048; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(key, pvt, NULL); if (ret != BAD_FUNC_ARG) - return -10049; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(key, NULL, &valid); if (ret != BAD_FUNC_ARG) - return -10050; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPvt(NULL, pvt, &valid); if (ret != BAD_FUNC_ARG) - return -10051; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10052; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL); if (ret != BAD_FUNC_ARG) - return -10053; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10054; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz); if (ret != BAD_FUNC_ARG) - return -10055; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz); if (ret != BAD_FUNC_ARG) - return -10056; + return WC_TEST_RET_ENC_EC(ret); /* No key created so no curve information. */ ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10057; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10058; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiSsk(key, ssk, data, NULL); if (ret != BAD_FUNC_ARG) - return -10059; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiSsk(key, NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10060; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz); if (ret != BAD_FUNC_ARG) - return -10061; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10058; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10059; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10060; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10061; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10062; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL); if (ret != BAD_FUNC_ARG) - return -10063; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt); if (ret != BAD_FUNC_ARG) - return -10064; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10065; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10066; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10067; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiSsk(key, data, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10068; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk); if (ret != BAD_FUNC_ARG) - return -10069; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk); if (ret != BAD_FUNC_ARG) - return -10070; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10067; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvt(key, data, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10068; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt); if (ret != BAD_FUNC_ARG) - return -10069; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt); if (ret != BAD_FUNC_ARG) - return -10070; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10067; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10068; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt); if (ret != BAD_FUNC_ARG) - return -10069; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt); if (ret != BAD_FUNC_ARG) - return -10070; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiKey(NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10071; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiKey(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10072; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiKey(NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10073; + return WC_TEST_RET_ENC_EC(ret); /* No key to export */ ret = wc_ExportEccsiKey(key, NULL, &sz); if (ret != BAD_STATE_E) - return -10074; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiKey(NULL, NULL, 0); if (ret != BAD_FUNC_ARG) - return -10075; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiKey(key, NULL, 0); if (ret != BAD_FUNC_ARG) - return -10076; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiKey(NULL, data, 0); if (ret != BAD_FUNC_ARG) - return -10077; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPrivateKey(NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10071; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPrivateKey(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10072; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPrivateKey(NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10073; + return WC_TEST_RET_ENC_EC(ret); /* No key to export */ ret = wc_ExportEccsiPrivateKey(key, NULL, &sz); if (ret != BAD_STATE_E) - return -10074; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0); if (ret != BAD_FUNC_ARG) - return -10075; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPrivateKey(key, NULL, 0); if (ret != BAD_FUNC_ARG) - return -10076; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPrivateKey(NULL, data, 0); if (ret != BAD_FUNC_ARG) - return -10077; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10078; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPublicKey(key, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10079; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10080; + return WC_TEST_RET_ENC_EC(ret); /* No key to export */ ret = wc_ExportEccsiPublicKey(key, data, &sz, 1); if (ret != BAD_STATE_E) - return -10081; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1); if (ret != BAD_FUNC_ARG) - return -10082; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1); if (ret != BAD_FUNC_ARG) - return -10083; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1); if (ret != BAD_FUNC_ARG) - return -10084; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10085; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL); if (ret != BAD_FUNC_ARG) - return -10086; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz); if (ret != BAD_FUNC_ARG) - return -10087; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz); if (ret != BAD_FUNC_ARG) - return -10088; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash, &hashSz); if (ret != BAD_FUNC_ARG) - return -10089; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz); if (ret != BAD_STATE_E) - return -10091; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiHash(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiHash(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiHash(NULL, hash, 1); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(key, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(NULL, ssk, NULL); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(NULL, NULL, pvt); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(key, ssk, NULL); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(key, NULL, pvt); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(NULL, ssk, pvt); if (ret != BAD_FUNC_ARG) - return -10090; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL); if (ret != BAD_FUNC_ARG) - return -10092; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL); if (ret != BAD_FUNC_ARG) - return -10093; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig, &sigSz); if (ret != BAD_FUNC_ARG) - return -10096; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig, &sigSz); if (ret != BAD_FUNC_ARG) - return -10098; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig, &sigSz); if (ret != BAD_FUNC_ARG) - return -10099; + return WC_TEST_RET_ENC_EC(ret); /* Key not set. */ ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL, &sigSz); if (ret != BAD_STATE_E) - return -10100; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, &valid); if (ret != BAD_FUNC_ARG) - return -10101; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL); if (ret != BAD_FUNC_ARG) - return -10102; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, &valid); if (ret != BAD_FUNC_ARG) - return -10103; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, &valid); if (ret != BAD_FUNC_ARG) - return -10104; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0, &valid); if (ret != BAD_FUNC_ARG) - return -10106; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, &valid); if (ret != BAD_STATE_E) - return -10106; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(key, ssk, pvt); if (ret != 0) - return -10107; + return WC_TEST_RET_ENC_EC(ret); /* Identity hash not set. */ ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL, &sigSz); if (ret != BAD_STATE_E) - return -10108; + return WC_TEST_RET_ENC_EC(ret); wc_FreeEccsiKey(key); @@ -32844,31 +33827,31 @@ static int eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt) ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0); if (ret != 0) - return -10108; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt); if (ret != 0) - return -10109; + return WC_TEST_RET_ENC_EC(ret); ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash, &hashSz); if (ret != 0) - return -10112; + return WC_TEST_RET_ENC_EC(ret); if (hashSz != sizeof(expHash)) - return -10113; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(hash, expHash, hashSz) != 0) - return -10114; + return WC_TEST_RET_ENC_NC; ret = wc_SetEccsiHash(key, hash, hashSz); if (ret != 0) - return -10112; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10115; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10116; + return WC_TEST_RET_ENC_NC; return 0; } @@ -32882,79 +33865,84 @@ static int eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt) mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (decSsk == NULL) - return -10173; + return WC_TEST_RET_ENC_ERRNO; #else mp_int decSsk[1]; #endif ret = mp_init(decSsk); if (ret != 0) - ERROR_OUT(-10117, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); decPvt = wc_ecc_new_point(); if (decPvt == NULL) - ERROR_OUT(-10118, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz); if (ret != LENGTH_ONLY_E) - ERROR_OUT(-10119, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32 * 3) - ERROR_OUT(-10120, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz); if (ret != 0) - ERROR_OUT(-10121, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32* 3) - ERROR_OUT(-10122, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt); if (ret != 0) - ERROR_OUT(-10123, out); - if (mp_cmp(ssk, decSsk) != MP_EQ) - ERROR_OUT(-10124, out); - if (wc_ecc_cmp_point(pvt, decPvt) != MP_EQ) - ERROR_OUT(-10125, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = mp_cmp(ssk, decSsk); + if (ret != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + ret = wc_ecc_cmp_point(pvt, decPvt); + if (ret != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz); if (ret != LENGTH_ONLY_E) - ERROR_OUT(-10119, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32) - ERROR_OUT(-10120, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz); if (ret != 0) - ERROR_OUT(-10121, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32) - ERROR_OUT(-10122, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk); if (ret != 0) - ERROR_OUT(-10123, out); - if (mp_cmp(ssk, decSsk) != MP_EQ) - ERROR_OUT(-10124, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = mp_cmp(ssk, decSsk); + if (ret != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1); if (ret != LENGTH_ONLY_E) - ERROR_OUT(-10126, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32 * 2) - ERROR_OUT(-10127, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1); if (ret != 0) - ERROR_OUT(-10128, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32 * 2) - ERROR_OUT(-10129, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt); if (ret != 0) - ERROR_OUT(-10130, out); - if (wc_ecc_cmp_point(pvt, decPvt) != MP_EQ) - ERROR_OUT(-10131, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_ecc_cmp_point(pvt, decPvt); + if (ret != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); sz = sizeof(data); ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0); if (ret != 0) - ERROR_OUT(-10128, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (sz != 32 * 2 + 1) - ERROR_OUT(-10129, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt); if (ret != 0) - ERROR_OUT(-10130, out); - if (wc_ecc_cmp_point(pvt, decPvt) != MP_EQ) - ERROR_OUT(-10131, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_ecc_cmp_point(pvt, decPvt); + if (ret != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_NC, out); wc_ecc_del_point(decPvt); @@ -32977,51 +33965,51 @@ static int eccsi_imp_exp_key_test(EccsiKey* priv) ret = wc_ExportEccsiKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10132; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 3) - return -10133; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiKey(priv, data, &sz); if (ret != 0) - return -10134; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiKey(priv, data, sz); if (ret != 0) - return -10135; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10132; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 3) - return -10143; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiKey(priv, out, &sz); if (ret != 0) - return -10144; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 3) - return -10145; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(data, out, sz) != 0) - return -10146; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10156; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32) - return -10157; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiPrivateKey(priv, data, &sz); if (ret != 0) - return -10158; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPrivateKey(priv, data, sz); if (ret != 0) - return -10159; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10152; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32) - return -10163; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiPrivateKey(priv, out, &sz); if (ret != 0) - return -10164; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32) - return -10165; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(data, out, sz) != 0) - return -10166; + return WC_TEST_RET_ENC_NC; return 0; } @@ -33035,39 +34023,39 @@ static int eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2) ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1); if (ret != LENGTH_ONLY_E) - return -10136; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 2) - return -10137; + return WC_TEST_RET_ENC_NC; ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1); if (ret != 0) - return -10138; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportEccsiPublicKey(key2, data, sz, 1); if (ret != 0) - return -10139; + return WC_TEST_RET_ENC_EC(ret); sz = sizeof(pubData); ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1); if (ret != 0) - return -10140; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 2) - return -10141; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(data, pubData, sz) != 0) - return -10142; + return WC_TEST_RET_ENC_NC; sz = sizeof(pubData); ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0); if (ret != 0) - return -10140; + return WC_TEST_RET_ENC_EC(ret); if (sz != 32 * 2 + 1) - return -10141; + return WC_TEST_RET_ENC_NC; if (pubData[0] != 0x04) - return -10140; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(pubData + 1, data, sz - 1) != 0) - return -10142; + return WC_TEST_RET_ENC_NC; ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0); if (ret != 0) - return -10139; + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -33083,7 +34071,7 @@ static int eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng, ret = wc_MakeEccsiKey(priv, rng); if (ret != 0) - return -10143; + return WC_TEST_RET_ENC_EC(ret); ret = eccsi_imp_exp_key_test(priv); if (ret < 0) @@ -33095,14 +34083,14 @@ static int eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng, ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt); if (ret != 0) - return -10144; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt, &valid); if (ret != 0) - return -10145; + return WC_TEST_RET_ENC_EC(ret); if (!valid) - return -10146; + return WC_TEST_RET_ENC_NC; ret = eccsi_enc_dec_pair_test(priv, ssk, pvt); if (ret != 0) @@ -33127,101 +34115,107 @@ static int eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng, byte msg[] = { 0x00 }; word32 msgSz = sizeof(msg); +#ifdef WOLFSSL_SHA384 + ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv, + &hashSz); + if (ret != BAD_FUNC_ARG) + return WC_TEST_RET_ENC_EC(ret); +#endif ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv, &hashSz); if (ret != 0) - return -10147; + return WC_TEST_RET_ENC_EC(ret); if (hashSz != 32) - return -10148; + return WC_TEST_RET_ENC_NC; ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub, &hashSz); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); if (hashSz != 32) - return -10150; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(hashPriv, hashPub, hashSz) != 0) - return -10151; + return WC_TEST_RET_ENC_NC; ret = wc_SetEccsiHash(priv, hashPriv, hashSz); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiPair(priv, ssk, pvt); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL, &sigSz); if (ret != LENGTH_ONLY_E) - return -10152; + return WC_TEST_RET_ENC_EC(ret); if (sigSz != 129) - return -10153; + return WC_TEST_RET_ENC_NC; ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig, &sigSz); if (ret != 0) - return -10154; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetEccsiHash(pub, hashPub, hashSz); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10155; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10156; + return WC_TEST_RET_ENC_NC; /* Check that changing HS results in verification failure. */ hashPub[0] ^= 0x80; ret = wc_SetEccsiHash(pub, hashPub, hashSz); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10157; + return WC_TEST_RET_ENC_EC(ret); if (verified) - return -10158; + return WC_TEST_RET_ENC_NC; hashPub[0] ^= 0x80; ret = wc_SetEccsiHash(pub, hashPub, hashSz); if (ret != 0) - return -10149; + return WC_TEST_RET_ENC_EC(ret); /* Check that changing msg results in verification failure. */ msg[0] ^= 0x80; ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10159; + return WC_TEST_RET_ENC_EC(ret); if (verified) - return -10160; + return WC_TEST_RET_ENC_NC; msg[0] ^= 0x80; /* Check that changing signature results in verification failure. */ sig[0] ^= 0x80; ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10161; + return WC_TEST_RET_ENC_EC(ret); if (verified) - return -10162; + return WC_TEST_RET_ENC_NC; sig[0] ^= 0x80; /* Check that key state hasn't been invalidated. */ ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10163; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10164; + return WC_TEST_RET_ENC_NC; /* Check that verifying with the private key works. */ ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10165; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10166; + return WC_TEST_RET_ENC_NC; /* Check that the KPAK is converted from montgomery form. */ ret = eccsi_imp_exp_key_test(priv); @@ -33232,25 +34226,25 @@ static int eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng, ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10167; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10168; + return WC_TEST_RET_ENC_NC; /* Check that the KPAK is converted from montgomery form. */ ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt, &valid); if (ret != 0) - return -10169; + return WC_TEST_RET_ENC_EC(ret); if (!valid) - return -10170; + return WC_TEST_RET_ENC_NC; /* Check that KPAK can converted to Montgomery form again. */ ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz, &verified); if (ret != 0) - return -10171; + return WC_TEST_RET_ENC_EC(ret); if (!verified) - return -10172; + return WC_TEST_RET_ENC_NC; /* Check that the KPAK is converted from montgomery form. */ ret = eccsi_imp_exp_pubkey_test(priv, pub); @@ -33273,7 +34267,7 @@ int eccsi_test(void) priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL) - ret = -10205; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(priv, 0, sizeof(*priv)); @@ -33281,7 +34275,7 @@ int eccsi_test(void) pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (pub == NULL) - ret = -10206; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(pub, 0, sizeof(*pub)); } @@ -33290,7 +34284,7 @@ int eccsi_test(void) ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ssk == NULL) - ret = -10207; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(ssk, 0, sizeof(*ssk)); } @@ -33302,7 +34296,7 @@ int eccsi_test(void) ret = wc_InitRng(&rng); #endif if (ret != 0) - ret = -10200; + ret = WC_TEST_RET_ENC_EC(ret); else rng_inited = 1; } @@ -33310,13 +34304,13 @@ int eccsi_test(void) if (ret == 0) { pvt = wc_ecc_new_point(); if (pvt == NULL) - ret = -10201; + ret = WC_TEST_RET_ENC_NC; } if (ret == 0) { ret = mp_init(ssk); if (ret != 0) - ret = -10202; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { @@ -33326,13 +34320,13 @@ int eccsi_test(void) if (ret == 0) { ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID); if (ret != 0) - ret = -10203; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID); if (ret != 0) - ret = -10204; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { @@ -33384,10 +34378,10 @@ static int sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk) ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10205; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID); if (ret != BAD_FUNC_ARG) - return -10206; + return WC_TEST_RET_ENC_EC(ret); wc_FreeSakkeKey(NULL); @@ -33396,409 +34390,409 @@ static int sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk) ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID); if (ret != 0) - return -10207; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeKey(NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10208; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeKey(key, NULL); if (ret != BAD_FUNC_ARG) - return -10209; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeKey(NULL, rng); if (ret != BAD_FUNC_ARG) - return -10210; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePublicKey(NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10211; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePublicKey(key, NULL); if (ret != BAD_FUNC_ARG) - return -10212; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePublicKey(NULL, rsk); if (ret != BAD_FUNC_ARG) - return -10213; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL); if (ret != BAD_FUNC_ARG) - return -10214; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeRsk(key, id, 1, NULL); if (ret != BAD_FUNC_ARG) - return -10215; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeRsk(key, NULL, 1, rsk); if (ret != BAD_FUNC_ARG) - return -10216; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeRsk(NULL, id, 1, rsk); if (ret != BAD_FUNC_ARG) - return -10217; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10218; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL); if (ret != BAD_FUNC_ARG) - return -10219; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid); if (ret != BAD_FUNC_ARG) - return -10220; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkeKey(NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10221; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkeKey(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10222; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkeKey(NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10223; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeKey(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10224; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeKey(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10225; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeKey(NULL, data, 1); if (ret != BAD_FUNC_ARG) - return -10226; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10227; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePrivateKey(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10228; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePrivateKey(NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10229; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePrivateKey(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10230; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePrivateKey(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10231; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePrivateKey(NULL, data, 1); if (ret != BAD_FUNC_ARG) - return -10232; + return WC_TEST_RET_ENC_EC(ret); sz = sizeof(data); ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10233; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10234; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10235; + return WC_TEST_RET_ENC_EC(ret); ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10236; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL); if (ret != BAD_FUNC_ARG) - return -10237; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeSakkeRsk(key, data, sz, NULL); if (ret != BAD_FUNC_ARG) - return -10238; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk); if (ret != BAD_FUNC_ARG) - return -10239; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk); if (ret != BAD_FUNC_ARG) - return -10240; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeRsk(NULL, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10237; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeRsk(key, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10237; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeRsk(NULL, data, sz); if (ret != BAD_FUNC_ARG) - return -10237; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkeRsk(key, data, 1); if (ret != BUFFER_E) - return -10237; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10241; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10242; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL); if (ret != BAD_FUNC_ARG) - return -10243; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len); if (ret != BAD_FUNC_ARG) - return -10244; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL); if (ret != BAD_FUNC_ARG) - return -10245; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(key, NULL, data, &len); if (ret != BAD_FUNC_ARG) - return -10246; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len); if (ret != BAD_FUNC_ARG) - return -10247; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len); if (ret != LENGTH_ONLY_E) - return -10248; + return WC_TEST_RET_ENC_EC(ret); len--; ret = wc_GenerateSakkeRskTable(key, rsk, data, &len); if (ret != BUFFER_E) - return -10249; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10250; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePublicKey(key, data, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10251; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1); if (ret != BAD_FUNC_ARG) - return -10252; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1); if (ret != BAD_FUNC_ARG) - return -10253; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePublicKey(key, NULL, sz, 1); if (ret != BAD_FUNC_ARG) - return -10254; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ImportSakkePublicKey(NULL, data, sz, 1); if (ret != BAD_FUNC_ARG) - return -10255; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkeAuthSize(NULL, NULL); if (ret != BAD_FUNC_ARG) - return -10256; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkeAuthSize(key, NULL); if (ret != BAD_FUNC_ARG) - return -10257; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkeAuthSize(NULL, &authSz); if (ret != BAD_FUNC_ARG) - return -10258; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1); if (ret != BAD_FUNC_ARG) - return -10259; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1); if (ret != BAD_FUNC_ARG) - return -10260; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(NULL, id, 1); if (ret != BAD_FUNC_ARG) - return -10261; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10262; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1); if (ret != BAD_FUNC_ARG) - return -10263; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10264; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePointI(NULL, id, 1); if (ret != BAD_FUNC_ARG) - return -10265; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkePointITable(NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10266; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkePointITable(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10267; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkePointITable(NULL, data, &len); if (ret != BAD_FUNC_ARG) - return -10268; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkePointITable(key, NULL, &len); if (ret != LENGTH_ONLY_E) - return -10269; + return WC_TEST_RET_ENC_EC(ret); len--; ret = wc_GenerateSakkePointITable(key, data, &len); if (ret != BUFFER_E) - return -10270; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointITable(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10271; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointITable(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10272; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointITable(NULL, data, 1); if (ret != BAD_FUNC_ARG) - return -10273; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointITable(key, data, 1); if (ret != BUFFER_E) - return -10274; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ClearSakkePointITable(NULL); if (ret != BAD_FUNC_ARG) - return -10275; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkePointI(NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10276; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkePointI(key, data, NULL); if (ret != BAD_FUNC_ARG) - return -10277; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GetSakkePointI(NULL, data, &sz); if (ret != BAD_FUNC_ARG) - return -10278; + return WC_TEST_RET_ENC_EC(ret); sz = 1; ret = wc_GetSakkePointI(key, data, &sz); if (ret != BUFFER_E) - return -10279; + return WC_TEST_RET_ENC_EC(ret); sz = 256; ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10280; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10281; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10282; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz); if (ret != BAD_FUNC_ARG) - return -10283; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(key, id, 1, NULL, sz); if (ret != BAD_FUNC_ARG) - return -10284; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(key, NULL, 1, data, sz); if (ret != BAD_FUNC_ARG) - return -10285; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(NULL, id, 1, data, sz); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz); if (ret != BUFFER_E) - return -10287; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkePointI(key, id, 1, data, sz - 1); if (ret != BUFFER_E) - return -10288; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(NULL, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(key, NULL, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(NULL, id, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ssvSz = sizeof(ssv); ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, NULL); if (ret != BAD_FUNC_ARG) - return -10289; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, NULL); if (ret != BAD_FUNC_ARG) - return -10290; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, NULL); if (ret != BAD_FUNC_ARG) - return -10291; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, &authSz); if (ret != BAD_FUNC_ARG) - return -10292; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, NULL); if (ret != BAD_FUNC_ARG) - return -10293; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, &authSz); if (ret != BAD_FUNC_ARG) - return -10294; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret != BAD_FUNC_ARG) - return -10295; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret != BAD_STATE_E) - return -10295; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL); if (ret != BAD_FUNC_ARG) - return -10296; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeSSV(key, rng, data, NULL); if (ret != BAD_FUNC_ARG) - return -10297; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz); if (ret != BAD_FUNC_ARG) - return -10298; + return WC_TEST_RET_ENC_EC(ret); ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz); if (ret != BAD_FUNC_ARG) - return -10299; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeRsk(NULL, NULL, data, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeRsk(key, NULL, data, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeRsk(NULL, rsk, data, 1); if (ret != BAD_FUNC_ARG) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ssvSz = sizeof(ssv); authSz = sizeof(auth); ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != BAD_FUNC_ARG) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != BAD_STATE_E) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(key, id, 1); if (ret != 0) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != BAD_STATE_E) - return -10300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(key, id, 0); if (ret != 0) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeRsk(key, rsk, data, 1); if (ret != 0) - return -10286; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != BAD_STATE_E) - return -10300; + return WC_TEST_RET_ENC_EC(ret); wc_FreeSakkeKey(key); @@ -33937,77 +34931,77 @@ static int sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk) ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0); if (ret != 0) - return -10315; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk); if (ret != 0) - return -10316; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid); if (ret != 0) - return -10317; + return WC_TEST_RET_ENC_EC(ret); if (valid != 1) - return -10318; + return WC_TEST_RET_ENC_NC; ret = wc_SetSakkeRsk(key, rsk, NULL, 0); if (ret != 0) - return -10319; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(key, id, sizeof(id)); if (ret != 0) - return -10319; + return WC_TEST_RET_ENC_EC(ret); XMEMCPY(tmpSsv, encSsv, sizeof(encSsv)); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv), auth, sizeof(auth)); if (ret != 0) - return -10322; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0) - return -10320; + return WC_TEST_RET_ENC_NC; ret = wc_MakeSakkePointI(key, id, sizeof(id)); if (ret != 0) - return -10321; + return WC_TEST_RET_ENC_EC(ret); iTableLen = 0; ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen); if (ret != LENGTH_ONLY_E) - return -10322; + return WC_TEST_RET_ENC_EC(ret); if (iTableLen != 0) { iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (iTable == NULL) - return -10323; + return WC_TEST_RET_ENC_ERRNO; ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen); if (ret != 0) - return -10324; + return WC_TEST_RET_ENC_EC(ret); } len = 0; ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len); if (ret != LENGTH_ONLY_E) - return -10325; + return WC_TEST_RET_ENC_EC(ret); if (len > 0) { table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (table == NULL) - return -10326; + return WC_TEST_RET_ENC_ERRNO; ret = wc_GenerateSakkeRskTable(key, rsk, table, &len); if (ret != 0) - return -10327; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_SetSakkeRsk(key, rsk, table, len); if (ret != 0) - return -10319; + return WC_TEST_RET_ENC_EC(ret); XMEMCPY(tmpSsv, encSsv, sizeof(encSsv)); ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv), auth, sizeof(auth)); if (ret != 0) - return -10328; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0) - return -10329; + return WC_TEST_RET_ENC_NC; /* Don't reference table that is about to be freed. */ ret = wc_ClearSakkePointITable(key); if (ret != 0) - return -10330; + return WC_TEST_RET_ENC_EC(ret); /* Dispose of tables */ if (iTable != NULL) XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -34019,22 +35013,22 @@ static int sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk) */ ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1); if (ret != 0) - return -10331; + return WC_TEST_RET_ENC_EC(ret); if (sz != sizeof(pubData)) - return -10332; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0) - return -10333; + return WC_TEST_RET_ENC_NC; sz = sizeof(pubData) + 1; ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0); if (ret != 0) - return -10334; + return WC_TEST_RET_ENC_EC(ret); if (sz != sizeof(pubData) + 1) - return -10335; + return WC_TEST_RET_ENC_NC; if (pubKey[0] != 0x04) - return -10336; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0) - return -10337; + return WC_TEST_RET_ENC_NC; return 0; } @@ -34132,23 +35126,23 @@ static int sakke_kat_encapsulate_test(SakkeKey* key) ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0); if (ret != 0) - return -10334; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(key, id, idSz); if (ret != 0) - return -10335; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret != 0) - return -10336; + return WC_TEST_RET_ENC_EC(ret); if (authSz != 257) - return -10337; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(ssv, encSsv, ssvSz) != 0) - return -10338; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(auth, expAuth, authSz) != 0) - return -10339; + return WC_TEST_RET_ENC_NC; return 0; } @@ -34168,131 +35162,131 @@ static int sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key, ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID); if (ret != 0) - return -10339; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeKey(priv, rng); if (ret != 0) - return -10340; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkeKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10341; + return WC_TEST_RET_ENC_EC(ret); if (sz != 384) - return -10342; + return WC_TEST_RET_ENC_NC; sz--; ret = wc_ExportSakkeKey(priv, data, &sz); if (ret == 0) - return -10343; + return WC_TEST_RET_ENC_NC; sz++; ret = wc_ExportSakkeKey(priv, data, &sz); if (ret != 0) - return -10344; + return WC_TEST_RET_ENC_EC(ret); if (sz != 384) - return -10345; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkeKey(key, data, sz - 1); if (ret == 0) - return -10346; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkeKey(key, data, sz); if (ret != 0) - return -10347; + return WC_TEST_RET_ENC_EC(ret); wc_FreeSakkeKey(key); ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID); if (ret != 0) - return -10348; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePrivateKey(priv, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10349; + return WC_TEST_RET_ENC_EC(ret); if (sz != 128) - return -10350; + return WC_TEST_RET_ENC_NC; sz--; ret = wc_ExportSakkePrivateKey(priv, data, &sz); if (ret == 0) - return -10351; + return WC_TEST_RET_ENC_NC; sz++; ret = wc_ExportSakkePrivateKey(priv, data, &sz); if (ret != 0) - return -10352; + return WC_TEST_RET_ENC_EC(ret); if (sz != 128) - return -10353; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkePrivateKey(key, data, sz - 1); if (ret == 0) - return -10354; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkePrivateKey(key, data, sz); if (ret != 0) - return -10355; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkePublicKey(key, pubKey); if (ret != 0) - return -10356; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1); if (ret != LENGTH_ONLY_E) - return -10357; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10358; + return WC_TEST_RET_ENC_NC; sz--; ret = wc_ExportSakkePublicKey(priv, data, &sz, 1); if (ret == 0) - return -10359; + return WC_TEST_RET_ENC_NC; sz++; ret = wc_ExportSakkePublicKey(priv, data, &sz, 1); if (ret != 0) - return -10360; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10361; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1); if (ret == 0) - return -10362; + return WC_TEST_RET_ENC_NC; ret = wc_ImportSakkePublicKey(pub, data, sz, 1); if (ret != 0) - return -10363; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1); if (ret != 0) - return -10364; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10365; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(data, pubData, sz) != 0) - return -10366; + return WC_TEST_RET_ENC_NC; ret = wc_MakeSakkeRsk(priv, id, idSz, rsk); if (ret != 0) - return -10367; + return WC_TEST_RET_ENC_EC(ret); ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid); if (ret != 0) - return -10368; + return WC_TEST_RET_ENC_EC(ret); if (valid != 1) - return -10369; + return WC_TEST_RET_ENC_NC; ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid); if (ret != 0) - return -10370; + return WC_TEST_RET_ENC_EC(ret); if (valid != 1) - return -10371; + return WC_TEST_RET_ENC_NC; sz = sizeof(data); ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1); if (ret != 0) - return -10372; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10373; + return WC_TEST_RET_ENC_NC; ret = wc_DecodeSakkeRsk(priv, data, sz, rsk); if (ret != 0) - return -10374; + return WC_TEST_RET_ENC_EC(ret); sz = sizeof(pubData); ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0); if (ret != 0) - return -10375; + return WC_TEST_RET_ENC_EC(ret); if (sz != sizeof(pubData)) - return -10376; + return WC_TEST_RET_ENC_NC; ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk); if (ret != 0) - return -10377; + return WC_TEST_RET_ENC_EC(ret); wc_FreeSakkeKey(key); @@ -34315,103 +35309,103 @@ static int sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng, ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz); if (ret != LENGTH_ONLY_E) - return -10375; + return WC_TEST_RET_ENC_EC(ret); if (ssvSz != 16) - return -10376; + return WC_TEST_RET_ENC_NC; ssvSz += 128; ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz); if (ret == 0) - return -10377; + return WC_TEST_RET_ENC_NC; ssvSz -= 128; ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz); if (ret != 0) - return -10378; + return WC_TEST_RET_ENC_EC(ret); if (ssvSz != 16) - return -10379; + return WC_TEST_RET_ENC_NC; ret = wc_GetSakkeAuthSize(pub, &authSz); if (ret != 0) - return -10380; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(pub, id, idSz); if (ret != 0) - return -10380; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL, &authSz); if (ret != LENGTH_ONLY_E) - return -10381; + return WC_TEST_RET_ENC_EC(ret); if (authSz != 257) - return -10382; + return WC_TEST_RET_ENC_NC; authSz--; ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret == 0) - return -10383; + return WC_TEST_RET_ENC_NC; authSz++; ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret != 0) - return -10384; + return WC_TEST_RET_ENC_EC(ret); if (authSz != 257) - return -10385; + return WC_TEST_RET_ENC_NC; ret = wc_GetSakkePointI(pub, NULL, &sz); if (ret != LENGTH_ONLY_E) - return -10386; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10387; + return WC_TEST_RET_ENC_NC; ret = wc_GetSakkePointI(pub, pointI, &sz); if (ret != 0) - return -10388; + return WC_TEST_RET_ENC_EC(ret); if (sz != 256) - return -10389; + return WC_TEST_RET_ENC_NC; /* Bogus identity - make it check and regenerate I. */ ret = wc_MakeSakkePointI(pub, ssv, ssvSz); if (ret != 0) - return -10391; + return WC_TEST_RET_ENC_EC(ret); ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, &authSz); if (ret != 0) - return -10392; + return WC_TEST_RET_ENC_EC(ret); if (authSz != 257) - return -10393; + return WC_TEST_RET_ENC_NC; ret = wc_SetSakkeRsk(priv, rsk, NULL, 0); if (ret != 0) - return -10392; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SetSakkeIdentity(priv, id, idSz); if (ret != 0) - return -10392; + return WC_TEST_RET_ENC_EC(ret); authSz--; ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret == 0) - return -10394; + return WC_TEST_RET_ENC_NC; authSz++; ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != 0) - return -10395; + return WC_TEST_RET_ENC_EC(ret); ssv[0] ^= 0x80; ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != SAKKE_VERIFY_FAIL_E) - return -10396; + return WC_TEST_RET_ENC_EC(ret); ssv[0] ^= 0x80; /* Bogus identity - make it check and regenerate I. */ ret = wc_MakeSakkePointI(pub, ssv, idSz); if (ret != 0) - return -10397; + return WC_TEST_RET_ENC_EC(ret); ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth, authSz); if (ret != 0) - return -10398; + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -34428,7 +35422,7 @@ int sakke_test(void) priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (priv == NULL) - ret = -10404; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(priv, 0, sizeof(*priv)); @@ -34436,7 +35430,7 @@ int sakke_test(void) pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (pub == NULL) - ret = -10405; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(pub, 0, sizeof(*pub)); } @@ -34445,7 +35439,7 @@ int sakke_test(void) key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (key == NULL) - ret = -10406; + ret = WC_TEST_RET_ENC_NC; else XMEMSET(key, 0, sizeof(*key)); } @@ -34459,25 +35453,25 @@ int sakke_test(void) if (ret == 0) rng_inited = 1; else - ret = -10400; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { rsk = wc_ecc_new_point(); if (rsk == NULL) - ret = -10401; + ret = WC_TEST_RET_ENC_NC; } if (ret == 0) { ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID); if (ret != 0) - ret = -10402; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID); if (ret != 0) - ret = -10403; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret == 0) { @@ -34691,7 +35685,7 @@ WOLFSSL_TEST_SUBROUTINE int cmac_test(void) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL) - ERROR_OUT(-12009, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif for (i = 0, tc = testCases; @@ -34703,40 +35697,47 @@ WOLFSSL_TEST_SUBROUTINE int cmac_test(void) #if !defined(HAVE_FIPS) || \ defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3) - if (wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId) != 0) + ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId); #else - if (wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL) != 0) + ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL); #endif + if (ret != 0) { - ERROR_OUT(-12000, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } if (tc->partial) { - if (wc_CmacUpdate(cmac, tc->m, - tc->mSz/2 - tc->partial) != 0) - ERROR_OUT(-12001, out); - if (wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial, - tc->mSz/2 + tc->partial) != 0) - ERROR_OUT(-12002, out); + ret = wc_CmacUpdate(cmac, tc->m, + tc->mSz/2 - tc->partial); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial, + tc->mSz/2 + tc->partial); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } else { - if (wc_CmacUpdate(cmac, tc->m, tc->mSz) != 0) - ERROR_OUT(-12003, out); + ret = wc_CmacUpdate(cmac, tc->m, tc->mSz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } - if (wc_CmacFinal(cmac, tag, &tagSz) != 0) - ERROR_OUT(-12004, out); + ret = wc_CmacFinal(cmac, tag, &tagSz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-12005, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); XMEMSET(tag, 0, sizeof(tag)); tagSz = sizeof(tag); - if (wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz, - tc->k, tc->kSz) != 0) - ERROR_OUT(-12006, out); + ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz, + tc->k, tc->kSz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0) - ERROR_OUT(-12007, out); - if (wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz, - tc->k, tc->kSz) != 0) - ERROR_OUT(-12008, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); + ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz, + tc->k, tc->kSz); + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = 0; @@ -34977,96 +35978,122 @@ WOLFSSL_TEST_SUBROUTINE int siphash_test(void) int i; #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4 unsigned char res[SIPHASH_MAC_SIZE_16]; + unsigned char tmp[SIPHASH_MAC_SIZE_8]; SipHash siphash; for (i = 0; i < 64; i++) { ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8); if (ret != 0) - return -12100 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHashUpdate(&siphash, siphash_msg, i); if (ret != 0) - return -12200 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8); if (ret != 0) - return -12300 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0) - return -12400 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHash(siphash_key, siphash_msg, i, res, SIPHASH_MAC_SIZE_8); if (ret != 0) - return -12500 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0) - return -12600 - i; + return WC_TEST_RET_ENC_I(i); } for (i = 0; i < 64; i++) { ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16); if (ret != 0) - return -12700 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHashUpdate(&siphash, siphash_msg, i); if (ret != 0) - return -12800 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16); if (ret != 0) - return -12900 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0) - return -13000 - i; + return WC_TEST_RET_ENC_I(i); ret = wc_SipHash(siphash_key, siphash_msg, i, res, SIPHASH_MAC_SIZE_16); if (ret != 0) - return -13100 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0) - return -13200 - i; + return WC_TEST_RET_ENC_I(i); } #endif /* Testing bad parameters. */ ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13300; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13301; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13302; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSipHash(&siphash, siphash_key, 7); if (ret != BAD_FUNC_ARG) - return -13303; + return WC_TEST_RET_ENC_EC(ret); ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8); if (ret != 0) - return -13304; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashUpdate(NULL, NULL, 0); if (ret != BAD_FUNC_ARG) - return -13305; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashUpdate(&siphash, NULL, 1); if (ret != BAD_FUNC_ARG) - return -13306; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13307; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13308; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8); if (ret != BAD_FUNC_ARG) - return -13309; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16); if (ret != BAD_FUNC_ARG) - return -13310; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16); if (ret != BAD_FUNC_ARG) - return -13311; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16); if (ret != BAD_FUNC_ARG) - return -13312; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16); if (ret != BAD_FUNC_ARG) - return -13313; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHash(siphash_key, NULL, 0, res, 15); if (ret != BAD_FUNC_ARG) - return -13314; + return WC_TEST_RET_ENC_EC(ret); ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16); if (ret != BAD_FUNC_ARG) - return -13315; + return WC_TEST_RET_ENC_EC(ret); + + /* Test cache with multiple non blocksize bytes */ + ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SipHashUpdate(&siphash, siphash_msg, 5); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SipHashUpdate(&siphash, siphash_msg, 9); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0) + return WC_TEST_RET_ENC_NC; return 0; } @@ -35316,7 +36343,7 @@ WOLFSSL_TEST_SUBROUTINE int compress_test(void) c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (c == NULL || d == NULL) { - ERROR_OUT(-12100, exit); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit); } /* follow calloc and initialize to 0 */ @@ -35324,17 +36351,17 @@ WOLFSSL_TEST_SUBROUTINE int compress_test(void) XMEMSET(d, 0, dSz); if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) { - ERROR_OUT(-12101, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } cSz = (word32)ret; if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) { - ERROR_OUT(-12102, exit); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); } dSz = (word32)ret; if (XMEMCMP(d, sample_text, dSz) != 0) { - ERROR_OUT(-12103, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* GZIP tests */ @@ -35343,31 +36370,28 @@ WOLFSSL_TEST_SUBROUTINE int compress_test(void) XMEMSET(d, 0, dSz); ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP); - if (ret < 0) { - ERROR_OUT(-12104, exit); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); cSz = (word32)ret; ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP); - if (ret < 0) { - ERROR_OUT(-12105, exit); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); if (XMEMCMP(d, sample_text, dSz) != 0) { - ERROR_OUT(-12106, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } /* Try with gzip generated output */ XMEMSET(d, 0, dSz); ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz), LIBZ_WINBITS_GZIP); - if (ret < 0) { - ERROR_OUT(-12107, exit); - } + if (ret < 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit); dSz = (word32)ret; if (XMEMCMP(d, sample_text, dSz) != 0) { - ERROR_OUT(-12108, exit); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit); } ret = 0; /* success */ @@ -35453,7 +36477,7 @@ static int pkcs7_load_certs_keys( #ifdef USE_CERT_BUFFERS_1024 if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024) - return -12110; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaClientCertBuf, client_cert_der_1024, sizeof_client_cert_der_1024); @@ -35461,7 +36485,7 @@ static int pkcs7_load_certs_keys( if (rsaServerCertBuf != NULL) { if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024) - return -12111; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaServerCertBuf, server_cert_der_1024, sizeof_server_cert_der_1024); @@ -35470,14 +36494,14 @@ static int pkcs7_load_certs_keys( if (rsaCaCertBuf != NULL) { if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024) - return -12112; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024); *rsaCaCertBufSz = sizeof_ca_cert_der_1024; } #elif defined(USE_CERT_BUFFERS_2048) if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048) - return -12113; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaClientCertBuf, client_cert_der_2048, sizeof_client_cert_der_2048); @@ -35485,7 +36509,7 @@ static int pkcs7_load_certs_keys( if (rsaServerCertBuf != NULL) { if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048) - return -12114; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaServerCertBuf, server_cert_der_2048, sizeof_server_cert_der_2048); @@ -35494,7 +36518,7 @@ static int pkcs7_load_certs_keys( if (rsaCaCertBuf != NULL) { if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048) - return -12115; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048); *rsaCaCertBufSz = sizeof_ca_cert_der_2048; @@ -35502,36 +36526,42 @@ static int pkcs7_load_certs_keys( #else certFile = XFOPEN(clientCert, "rb"); if (!certFile) - return -12116; + return WC_TEST_RET_ENC_ERRNO; *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1, *rsaClientCertBufSz, certFile); XFCLOSE(certFile); + if (*rsaClientCertBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; if (rsaServerCertBuf != NULL) { certFile = XFOPEN(rsaServerCertDerFile, "rb"); if (!certFile) - return -12117; + return WC_TEST_RET_ENC_ERRNO; *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1, *rsaServerCertBufSz, certFile); XFCLOSE(certFile); + if (*rsaServerCertBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; } if (rsaCaCertBuf != NULL) { certFile = XFOPEN(rsaCaCertDerFile, "rb"); if (!certFile) - return -12118; + return WC_TEST_RET_ENC_ERRNO; *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz, certFile); XFCLOSE(certFile); + if (*rsaCaCertBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; } #endif #ifdef USE_CERT_BUFFERS_1024 if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024) - return -12119; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024, sizeof_client_key_der_1024); @@ -35539,7 +36569,7 @@ static int pkcs7_load_certs_keys( if (rsaServerPrivKeyBuf != NULL) { if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024) - return -12120; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024, sizeof_server_key_der_1024); @@ -35548,14 +36578,14 @@ static int pkcs7_load_certs_keys( if (rsaCaPrivKeyBuf != NULL) { if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024) - return -12121; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024); *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024; } #elif defined(USE_CERT_BUFFERS_2048) if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048) - return -12122; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048, sizeof_client_key_der_2048); @@ -35563,7 +36593,7 @@ static int pkcs7_load_certs_keys( if (rsaServerPrivKeyBuf != NULL) { if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048) - return -12123; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048, sizeof_server_key_der_2048); @@ -35572,7 +36602,7 @@ static int pkcs7_load_certs_keys( if (rsaCaPrivKeyBuf != NULL) { if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048) - return -12124; + return WC_TEST_RET_ENC_NC; XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048); *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048; @@ -35580,30 +36610,36 @@ static int pkcs7_load_certs_keys( #else keyFile = XFOPEN(clientKey, "rb"); if (!keyFile) - return -12125; + return WC_TEST_RET_ENC_ERRNO; *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1, *rsaClientPrivKeyBufSz, keyFile); XFCLOSE(keyFile); + if (*rsaClientPrivKeyBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; if (rsaServerPrivKeyBuf != NULL) { keyFile = XFOPEN(rsaServerKeyDerFile, "rb"); if (!keyFile) - return -12126; + return WC_TEST_RET_ENC_ERRNO; *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1, *rsaServerPrivKeyBufSz, keyFile); XFCLOSE(keyFile); + if (*rsaServerPrivKeyBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; } if (rsaCaPrivKeyBuf != NULL) { keyFile = XFOPEN(rsaCaKeyFile, "rb"); if (!keyFile) - return -12127; + return WC_TEST_RET_ENC_ERRNO; *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1, *rsaCaPrivKeyBufSz, keyFile); XFCLOSE(keyFile); + if (*rsaCaPrivKeyBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; } #endif /* USE_CERT_BUFFERS */ @@ -35614,34 +36650,38 @@ static int pkcs7_load_certs_keys( #ifdef USE_CERT_BUFFERS_256 if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256) - return -12128; + return WC_TEST_RET_ENC_NC; XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256); *eccClientCertBufSz = sizeof_cliecc_cert_der_256; #else certFile = XFOPEN(eccClientCert, "rb"); if (!certFile) - return -12129; + return WC_TEST_RET_ENC_ERRNO; *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1, *eccClientCertBufSz, certFile); XFCLOSE(certFile); + if (*eccClientCertBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; #endif /* USE_CERT_BUFFERS_256 */ #ifdef USE_CERT_BUFFERS_256 if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256) - return -12130; + return WC_TEST_RET_ENC_NC; XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256); *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256; #else keyFile = XFOPEN(eccClientKey, "rb"); if (!keyFile) - return -12131; + return WC_TEST_RET_ENC_ERRNO; *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1, *eccClientPrivKeyBufSz, keyFile); XFCLOSE(keyFile); + if (*eccClientPrivKeyBufSz == 0) + return WC_TEST_RET_ENC_ERRNO; #endif /* USE_CERT_BUFFERS_256 */ #endif /* HAVE_ECC */ @@ -35736,7 +36776,7 @@ static int myOriEncryptCb(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType, /* make sure buffers are large enough */ if ((*oriValueSz < (2 + cekSz)) || (*oriTypeSz < sizeof(oriType))) - return -12140; + return WC_TEST_RET_ENC_NC; /* our simple encryption algorithm will be take the bitwise complement */ oriValue[0] = 0x04; /*ASN OCTET STRING */ @@ -35771,14 +36811,14 @@ static int myOriDecryptCb(PKCS7* pkcs7, byte* oriType, word32 oriTypeSz, /* make sure oriType matches what we expect */ if (oriTypeSz != sizeof(asnDataOid)) - return -12150; + return WC_TEST_RET_ENC_NC; if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0) - return -12151; + return WC_TEST_RET_ENC_NC; /* make sure decrypted buffer is large enough */ if (*decryptedKeySz < oriValueSz) - return -12152; + return WC_TEST_RET_ENC_NC; /* decrypt encrypted CEK using simple bitwise complement, only for example */ @@ -35834,12 +36874,12 @@ static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz, /* test user context passed in */ if (usrCtx == NULL || *(int*)usrCtx != 1) { - return -12160; + return WC_TEST_RET_ENC_NC; } #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) - return -12164; + return WC_TEST_RET_ENC_ERRNO; #endif /* if needing to find keyIdSz can call with NULL */ @@ -35848,23 +36888,23 @@ static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz, if (ret != LENGTH_ONLY_E) { printf("Unexpected error %d when getting keyIdSz\n", ret); printf("Possibly no KEY ID attribute set\n"); - ERROR_OUT(-12161, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } else { XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw)); ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw, &keyIdSz); if (ret < 0) { - goto out; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } if (keyIdSz < 3) { printf("keyIdSz is smaller than expected\n"); - ERROR_OUT(-12162, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } if (keyIdSz > 2 + sizeof(int)) { printf("example case was only expecting a keyId of int size\n"); - ERROR_OUT(-12163, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } /* keyIdRaw[0] OCTET TAG */ @@ -35995,10 +37035,10 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #define MAX_TESTVECTORS_LEN 13 #define ADD_PKCS7ENVELOPEDVECTOR(...) { \ pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \ - if (testSz == MAX_TESTVECTORS_LEN) { \ - ret = -12534; \ - goto out; \ - } \ + if (testSz == MAX_TESTVECTORS_LEN) { \ + ret = WC_TEST_RET_ENC_NC; \ + goto out; \ + } \ XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\ } @@ -36011,7 +37051,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (testVectors == NULL) { - ret = -12534; + ret = WC_TEST_RET_ENC_ERRNO; goto out; } @@ -36144,7 +37184,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if ((! enveloped) || (! decoded)) { - ERROR_OUT(-12170, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef ECC_TIMING_RESISTANT @@ -36153,9 +37193,8 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #else ret = wc_InitRng(&rng); #endif - if (ret != 0) { - ERROR_OUT(-12171, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #endif for (i = 0; i < testSz; i++) { @@ -36167,16 +37206,15 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #endif ); if (pkcs7 == NULL) { - ERROR_OUT(-12172, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } if (testVectors[i].secretKey != NULL) { /* KEKRI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12173, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36194,7 +37232,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12174, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set key, for decryption */ @@ -36203,7 +37241,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12175, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else if (testVectors[i].password != NULL) { @@ -36211,9 +37249,8 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, /* PWRI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12176, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36231,7 +37268,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12177, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set password, for decryption */ @@ -36240,7 +37277,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12178, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } #endif /* ! NO_PWDBASED && ! NO_SHA */ @@ -36248,9 +37285,8 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, /* ORI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12179, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36262,7 +37298,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12180, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set decrypt callback for decryption */ @@ -36270,22 +37306,21 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12181, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else { /* KTRI or KARI recipient types */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12182, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert, (word32)testVectors[i].certSz); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12183, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } pkcs7->keyWrapOID = testVectors[i].keyWrapOID; @@ -36305,7 +37340,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12184, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else if (testVectors[i].ktriOptions & CMS_ISSUER_AND_SERIAL_NUMBER) { @@ -36314,7 +37349,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, CMS_ISSUER_AND_SERIAL_NUMBER); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12185, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } } @@ -36327,7 +37362,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, PKCS7_BUF_SIZE); if (envelopedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12186, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out); } /* decode envelopedData */ @@ -36337,13 +37372,13 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (pkcs7->contentOID != testVectors[i].contentOID || decodedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12187, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0){ wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12188, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifndef NO_PKCS7_STREAM @@ -36354,14 +37389,14 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, decoded, PKCS7_BUF_SIZE); if (decodedSz <= 0 && decodedSz != WC_PKCS7_WANT_READ_E) { printf("unexpected error %d\n", decodedSz); - ERROR_OUT(-12189, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0) { printf("stream read compare failed\n"); wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12190, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } } #endif @@ -36370,14 +37405,14 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12191, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File); XFCLOSE(pkcs7File); if (ret != envelopedSz) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12192, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } else { /* reset ret to 0 for success */ ret = 0; @@ -36431,12 +37466,12 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7enveloped_test(void) /* read client RSA cert and key in DER format */ rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (rsaCert == NULL) - return -12200; + return WC_TEST_RET_ENC_ERRNO; rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (rsaPrivKey == NULL) { XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -12201; + return WC_TEST_RET_ENC_NC; } rsaCertSz = FOURK_BUF; @@ -36451,7 +37486,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7enveloped_test(void) XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif - return -12202; + return WC_TEST_RET_ENC_NC; } eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -36461,7 +37496,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7enveloped_test(void) XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -12203; + return WC_TEST_RET_ENC_NC; } eccCertSz = FOURK_BUF; @@ -36481,7 +37516,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7enveloped_test(void) XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif - return -12204; + return WC_TEST_RET_ENC_EC(ret); } ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz, @@ -36629,13 +37664,14 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #endif #define MAX_TESTVECTORS_LEN 20 - #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \ - pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \ - if (testSz == MAX_TESTVECTORS_LEN) { \ - ret = -12534; \ - goto out; \ - } \ - XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\ + #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \ + pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \ + if (testSz == MAX_TESTVECTORS_LEN) { \ + ret = WC_TEST_RET_ENC_NC; \ + goto out; \ + } \ + XMEMCPY(&testVectors[testSz++], &_this_vector, \ + sizeof _this_vector); \ } pkcs7AuthEnvelopedVector *testVectors = NULL; @@ -36645,7 +37681,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (testVectors == NULL) { - ret = -12534; + ret = WC_TEST_RET_ENC_ERRNO; goto out; } @@ -36824,7 +37860,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if ((! enveloped) || (! decoded)) { - ERROR_OUT(-12210, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } /* generate senderNonce */ @@ -36834,9 +37870,8 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #else ret = wc_InitRng(&rng); #endif - if (ret != 0) { - ERROR_OUT(-12211, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); senderNonce[0] = 0x04; senderNonce[1] = PKCS7_NONCE_SZ; @@ -36844,7 +37879,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ); if (ret != 0) { wc_FreeRng(&rng); - ERROR_OUT(-12212, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } @@ -36857,16 +37892,15 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #endif ); if (pkcs7 == NULL) { - ERROR_OUT(-12213, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } if (testVectors[i].secretKey != NULL) { /* KEKRI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12214, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36888,7 +37922,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12215, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set key, for decryption */ @@ -36897,7 +37931,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12216, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else if (testVectors[i].password != NULL) { @@ -36905,9 +37939,8 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, /* PWRI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12217, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36929,7 +37962,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12218, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set password, for decryption */ @@ -36938,7 +37971,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12219, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } #endif /* ! NO_PWDBASED && ! NO_SHA */ @@ -36946,9 +37979,8 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, /* ORI recipient type */ ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId); - if (ret != 0) { - ERROR_OUT(-12220, out); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); pkcs7->content = (byte*)testVectors[i].content; pkcs7->contentSz = testVectors[i].contentSz; @@ -36964,7 +37996,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12221, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set decrypt callback for decryption */ @@ -36972,7 +38004,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, if (ret < 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12222, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else { @@ -36982,7 +38014,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, (word32)testVectors[i].certSz); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12223, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } pkcs7->keyWrapOID = testVectors[i].keyWrapOID; @@ -37006,7 +38038,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12224, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } else if (testVectors[i].ktriOptions & CMS_ISSUER_AND_SERIAL_NUMBER) { @@ -37015,7 +38047,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, CMS_ISSUER_AND_SERIAL_NUMBER); if (ret != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12225, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } } @@ -37029,7 +38061,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, PKCS7_BUF_SIZE); if (envelopedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12226, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out); } #ifndef NO_PKCS7_STREAM { /* test reading byte by byte */ @@ -37039,14 +38071,14 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, enveloped + z, 1, decoded, PKCS7_BUF_SIZE); if (decodedSz <= 0 && decodedSz != WC_PKCS7_WANT_READ_E) { printf("unexpected error %d\n", decodedSz); - ERROR_OUT(-12227, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0) { printf("stream read compare failed\n"); wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12228, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } } #endif @@ -37056,13 +38088,13 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, PKCS7_BUF_SIZE); if (decodedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12229, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0){ wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12230, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef PKCS7_OUTPUT_TEST_BUNDLES @@ -37070,14 +38102,14 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12231, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File); XFCLOSE(pkcs7File); if (ret != envelopedSz) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12232, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } else { /* reset ret to 0 for success */ ret = 0; @@ -37134,12 +38166,12 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7authenveloped_test(void) /* read client RSA cert and key in DER format */ rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (rsaCert == NULL) - return -12300; + return WC_TEST_RET_ENC_ERRNO; rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (rsaPrivKey == NULL) { XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -12301; + return WC_TEST_RET_ENC_NC; } rsaCertSz = FOURK_BUF; @@ -37154,7 +38186,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7authenveloped_test(void) XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif - return -12302; + return WC_TEST_RET_ENC_NC; } eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -37164,7 +38196,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7authenveloped_test(void) XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - return -12303; + return WC_TEST_RET_ENC_NC; } eccCertSz = FOURK_BUF; @@ -37184,7 +38216,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7authenveloped_test(void) XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #endif - return -12304; + return WC_TEST_RET_ENC_EC(ret); } ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz, @@ -37230,15 +38262,15 @@ static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId, /* test case sanity checks */ if (keyIdSz != 1) { - return -12310; + return WC_TEST_RET_ENC_NC; } if (keyId[0] != 0x00) { - return -12311; + return WC_TEST_RET_ENC_NC; } if (type != (int)PKCS7_KEKRI) { - return -12312; + return WC_TEST_RET_ENC_NC; } switch (keyWrapAlgo) { @@ -37327,7 +38359,7 @@ static int envelopedData_encrypt(byte* in, word32 inSz, byte* out, pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID); if (pkcs7 == NULL) - return -12330; + return WC_TEST_RET_ENC_ERRNO; pkcs7->content = in; pkcs7->contentSz = inSz; @@ -37343,7 +38375,7 @@ static int envelopedData_encrypt(byte* in, word32 inSz, byte* out, if (ret < 0) { printf("wc_PKCS7_AddRecipient_KEKRI() failed, ret = %d\n", ret); wc_PKCS7_Free(pkcs7); - return -12331; + return WC_TEST_RET_ENC_EC(ret); } /* encode envelopedData, returns size */ @@ -37351,7 +38383,7 @@ static int envelopedData_encrypt(byte* in, word32 inSz, byte* out, if (ret <= 0) { printf("wc_PKCS7_EncodeEnvelopedData() failed, ret = %d\n", ret); wc_PKCS7_Free(pkcs7); - return -12332; + return WC_TEST_RET_ENC_EC(ret); } @@ -37413,19 +38445,19 @@ static int generateBundle(byte* out, word32 *outSz, const byte* encryptKey, /* init PKCS7 */ pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID); if (pkcs7 == NULL) - return -12340; + return WC_TEST_RET_ENC_ERRNO; ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz); if (ret != 0) { printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret); wc_PKCS7_Free(pkcs7); - return -12341; + return WC_TEST_RET_ENC_EC(ret); } ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID); if (ret != 0) { wc_PKCS7_Free(pkcs7); - return -12342; + return WC_TEST_RET_ENC_EC(ret); } /* encode Signed Encrypted FirmwarePkgData */ @@ -37445,7 +38477,7 @@ static int generateBundle(byte* out, word32 *outSz, const byte* encryptKey, printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, " "ret = %d\n", ret); wc_PKCS7_Free(pkcs7); - return -12343; + return WC_TEST_RET_ENC_EC(ret); } else { *outSz = ret; @@ -37474,6 +38506,19 @@ static int verifyBundle(byte* derBuf, word32 derSz, int keyHint) int decodedSz = FOURK_BUF/2; WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = { +#ifdef NO_SHA +#ifdef USE_CERT_BUFFERS_1024 + 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9, + 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2, + 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06, + 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9 +#else + 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36, + 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e, + 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4, + 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71 +#endif +#else /* !NO_SHA */ #ifdef USE_CERT_BUFFERS_1024 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34, 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75, @@ -37483,6 +38528,7 @@ static int verifyBundle(byte* derBuf, word32 derSz, int keyHint) 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7, 0x85, 0x65, 0xC0 #endif +#endif /* !NO_SHA */ }; decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -37577,45 +38623,43 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7callback_test(byte* cert, word32 certSz, byte* byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (! derBuf) - ERROR_OUT(-12360, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* Doing default generation and verify */ derSz = FOURK_BUF; ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert, certSz, key, keySz); if (ret <= 0) { - ERROR_OUT(-12361, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } ret = verifyBundle(derBuf, derSz, 0); - if (ret != 0) { - ERROR_OUT(-12362, out); - } + if (ret != 0) + ERROR_OUT(ret, out); /* test choosing other key with keyID */ derSz = FOURK_BUF; ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1, cert, certSz, key, keySz); if (ret <= 0) { - ERROR_OUT(-12363, out); + ERROR_OUT(ret, out); } ret = verifyBundle(derBuf, derSz, 1); - if (ret != 0) { - ERROR_OUT(-12364, out); - } + if (ret != 0) + ERROR_OUT(ret, out); /* test fail case with wrong keyID */ derSz = FOURK_BUF; ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1, cert, certSz, key, keySz); if (ret <= 0) { - ERROR_OUT(-12365, out); + ERROR_OUT(ret, out); } ret = verifyBundle(derBuf, derSz, 1); if (ret == 0) { - ERROR_OUT(-12366, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } ret = 0; @@ -37785,7 +38829,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) for (i = 0; i < testSz; i++) { pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) { - ERROR_OUT(-12400, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } pkcs7->content = (byte*)testVectors[i].content; @@ -37802,7 +38846,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) PKCS7_BUF_SIZE); if (encryptedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12401, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out); } /* decode encryptedData */ @@ -37814,14 +38858,14 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) decoded, PKCS7_BUF_SIZE); if (decodedSz <= 0 && decodedSz != WC_PKCS7_WANT_READ_E) { printf("unexpected error %d\n", decodedSz); - ERROR_OUT(-12402, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0) { printf("stream read failed\n"); wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12403, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } } #endif @@ -37829,13 +38873,13 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) decoded, PKCS7_BUF_SIZE); if (decodedSz <= 0){ wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12404, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } /* test decode result */ if (XMEMCMP(decoded, data, sizeof(data)) != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12405, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } /* verify decoded unprotected attributes */ @@ -37853,14 +38897,14 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid, decodedAttrib->oidSz) != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12406, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } /* verify value */ if (XMEMCMP(decodedAttrib->value, expectedAttrib->value, decodedAttrib->valueSz) != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12407, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } decodedAttrib = decodedAttrib->next; @@ -37873,14 +38917,17 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7encrypted_test(void) pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12408, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File); - XFCLOSE(pkcs7File); - if (ret > 0) + if (ret < 0) + ret = WC_TEST_RET_ENC_ERRNO; + else ret = 0; + + XFCLOSE(pkcs7File); #endif wc_PKCS7_Free(pkcs7); @@ -37952,7 +38999,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7compressed_test(void) for (i = 0; i < testSz; i++) { pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) { - ERROR_OUT(-12500, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } pkcs7->content = (byte*)testVectors[i].content; @@ -37964,7 +39011,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7compressed_test(void) PKCS7_BUF_SIZE); if (compressedSz <= 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12501, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out); } /* decode compressedData */ @@ -37973,19 +39020,19 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7compressed_test(void) PKCS7_BUF_SIZE); if (decodedSz <= 0){ wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12502, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out); } /* test decode result */ if (XMEMCMP(decoded, testVectors[i].content, testVectors[i].contentSz) != 0) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12503, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } /* make sure content type is the same */ if (testVectors[i].contentOID != pkcs7->contentOID) { - ERROR_OUT(-12504, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef PKCS7_OUTPUT_TEST_BUNDLES @@ -37993,14 +39040,17 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7compressed_test(void) pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); - ERROR_OUT(-12505, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File); - XFCLOSE(pkcs7File); - if (ret > 0) + if (ret < 0) + ret = WC_TEST_RET_ENC_ERRNO; + else ret = 0; + + XFCLOSE(pkcs7File); #endif wc_PKCS7_Free(pkcs7); @@ -38109,13 +39159,14 @@ static int pkcs7signed_run_vectors( 0x01, 0x09, 0x10, 0x01, 0x10 }; #define MAX_TESTVECTORS_LEN 20 - #define ADD_PKCS7SIGNEDVECTOR(...) { \ - pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \ - if (testSz == MAX_TESTVECTORS_LEN) { \ - ret = -12534; \ - goto out; \ - } \ - XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\ + #define ADD_PKCS7SIGNEDVECTOR(...) { \ + pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \ + if (testSz == MAX_TESTVECTORS_LEN) { \ + ret = WC_TEST_RET_ENC_NC; \ + goto out; \ + } \ + XMEMCPY(&testVectors[testSz++], &_this_vector, \ + sizeof _this_vector); \ } pkcs7SignedVector *testVectors = NULL; @@ -38125,7 +39176,7 @@ static int pkcs7signed_run_vectors( testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (testVectors == NULL) { - ret = -12567; + ret = WC_TEST_RET_ENC_ERRNO; goto out; } @@ -38316,41 +39367,40 @@ static int pkcs7signed_run_vectors( outSz = FOURK_BUF; out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (out == NULL) - ERROR_OUT(-12510, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); XMEMSET(out, 0, outSz); ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16); if (ret < 0) - ERROR_OUT(-12511, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifndef HAVE_FIPS ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); #else ret = wc_InitRng(&rng); #endif if (ret != 0) - ERROR_OUT(-12512, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); for (i = 0; i < testSz; i++) { if (pkcs7) wc_PKCS7_Free(pkcs7); pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) - ERROR_OUT(-12513, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert, (word32)testVectors[i].certSz); if (ret != 0) - ERROR_OUT(-12514, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* load CA certificate, if present */ if (testVectors[i].caCert != NULL) { ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert, (word32)testVectors[i].caCertSz); if (ret != 0) - ERROR_OUT(-12515, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } pkcs7->rng = &rng; @@ -38370,7 +39420,7 @@ static int pkcs7signed_run_vectors( ret = wc_PKCS7_SetContentType(pkcs7, testVectors[i].contentType, testVectors[i].contentTypeSz); if (ret != 0) - ERROR_OUT(-12516, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set SignerIdentifier to use SubjectKeyIdentifier if desired, @@ -38378,7 +39428,7 @@ static int pkcs7signed_run_vectors( if (testVectors[i].sidType == CMS_SKID) { ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID); if (ret != 0) - ERROR_OUT(-12517, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* generate senderNonce */ @@ -38388,7 +39438,7 @@ static int pkcs7signed_run_vectors( ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ); if (ret != 0) - ERROR_OUT(-12518, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* generate transactionID (used with SCEP) */ @@ -38408,14 +39458,14 @@ static int pkcs7signed_run_vectors( #ifndef NO_SHA ret = wc_InitSha_ex(&sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-12519, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz); wc_ShaFinal(&sha, digest); wc_ShaFree(&sha); #else ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId); if (ret != 0) - ERROR_OUT(-12520, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz); wc_Sha256Final(&sha, digest); wc_Sha256Free(&sha); @@ -38434,30 +39484,30 @@ static int pkcs7signed_run_vectors( if (testVectors[i].detachedSignature == 1) { ret = wc_PKCS7_SetDetached(pkcs7, 1); if (ret != 0) - ERROR_OUT(-12521, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz); if (encodedSz < 0) - ERROR_OUT(-12522, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out); #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* write PKCS#7 to output file for more testing */ file = XFOPEN(testVectors[i].outFileName, "wb"); if (!file) { - ERROR_OUT(-12523, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } ret = (int)XFWRITE(out, 1, encodedSz, file); XFCLOSE(file); if (ret != (int)encodedSz) - ERROR_OUT(-12524, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif /* PKCS7_OUTPUT_TEST_BUNDLES */ wc_PKCS7_Free(pkcs7); pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) - ERROR_OUT(-12525, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); wc_PKCS7_InitWithCert(pkcs7, NULL, 0); if (testVectors[i].detachedSignature == 1) { @@ -38468,20 +39518,19 @@ static int pkcs7signed_run_vectors( ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz); if (ret < 0) - ERROR_OUT(-12526, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* verify contentType extracted successfully for custom content types */ if (testVectors[i].contentTypeSz > 0) { if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) { - ERROR_OUT(-12527, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType, pkcs7->contentTypeSz) != 0) { - ERROR_OUT(-12528, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } } if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0) - ERROR_OUT(-12529, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); { /* check getting signed attributes */ @@ -38494,27 +39543,37 @@ static int pkcs7signed_run_vectors( int oidSz = (int)sizeof(transIdOid) - 2; int bufSz = 0; - if (testVectors[i].signedAttribs != NULL && - wc_PKCS7_GetAttributeValue(pkcs7, oidPt, oidSz, - NULL, (word32*)&bufSz) != LENGTH_ONLY_E) - ERROR_OUT(-12530, out); + if (testVectors[i].signedAttribs != NULL) { + ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, oidSz, + NULL, (word32*)&bufSz); + if (ret != LENGTH_ONLY_E) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + ret = 0; + } if (bufSz > (int)sizeof(buf)) - ERROR_OUT(-12531, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, oidSz, buf, (word32*)&bufSz); if ((testVectors[i].signedAttribs != NULL && bufSz < 0) || (testVectors[i].signedAttribs == NULL && bufSz > 0)) - ERROR_OUT(-12532, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef PKCS7_OUTPUT_TEST_BUNDLES file = XFOPEN("./pkcs7cert.der", "wb"); if (!file) - ERROR_OUT(-12533, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file); + + if (ret < 0) + ret = WC_TEST_RET_ENC_ERRNO; + else + ret = 0; + XFCLOSE(file); + #endif /* PKCS7_OUTPUT_TEST_BUNDLES */ } @@ -38605,13 +39664,14 @@ static int pkcs7signed_run_SingleShotVectors( }; #define MAX_TESTVECTORS_LEN 19 - #define ADD_PKCS7SIGNEDVECTOR(...) { \ - pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \ - if (testSz == MAX_TESTVECTORS_LEN) { \ - ret = -12568; \ - goto out; \ - } \ - XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\ + #define ADD_PKCS7SIGNEDVECTOR(...) { \ + pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \ + if (testSz == MAX_TESTVECTORS_LEN) { \ + ret = WC_TEST_RET_ENC_NC; \ + goto out; \ + } \ + XMEMCPY(&testVectors[testSz++], &_this_vector, \ + sizeof _this_vector); \ } pkcs7SignedVector *testVectors = NULL; @@ -38621,7 +39681,7 @@ static int pkcs7signed_run_SingleShotVectors( testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (testVectors == NULL) { - ret = -12567; + ret = WC_TEST_RET_ENC_ERRNO; goto out; } @@ -38822,41 +39882,40 @@ static int pkcs7signed_run_SingleShotVectors( outSz = FOURK_BUF; out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (out == NULL) - ERROR_OUT(-12540, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); XMEMSET(out, 0, outSz); ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16); if (ret < 0) - ERROR_OUT(-12541, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifndef HAVE_FIPS ret = wc_InitRng_ex(&rng, HEAP_HINT, devId); #else ret = wc_InitRng(&rng); #endif if (ret != 0) - ERROR_OUT(-12542, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); for (i = 0; i < testSz; i++) { if (pkcs7) wc_PKCS7_Free(pkcs7); pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) - ERROR_OUT(-12543, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert, (word32)testVectors[i].certSz); if (ret != 0) - ERROR_OUT(-12544, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* load CA certificate, if present */ if (testVectors[i].caCert != NULL) { ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert, (word32)testVectors[i].caCertSz); if (ret != 0) - ERROR_OUT(-12545, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } /* set SignerIdentifier to use SubjectKeyIdentifier if desired, @@ -38864,7 +39923,7 @@ static int pkcs7signed_run_SingleShotVectors( if (testVectors[i].sidType == CMS_SKID) { ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID); if (ret != 0) - ERROR_OUT(-12546, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } if (testVectors[i].encCompFlag == 0) { @@ -38878,7 +39937,7 @@ static int pkcs7signed_run_SingleShotVectors( testVectors[i].signedAttribsSz, out, outSz); if (encodedSz < 0) - ERROR_OUT(-12547, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out); #ifndef NO_PKCS7_ENCRYPTED_DATA @@ -38896,7 +39955,7 @@ static int pkcs7signed_run_SingleShotVectors( testVectors[i].signedAttribsSz, out, outSz); if (encodedSz <= 0) - ERROR_OUT(-12548, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out); #endif #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) @@ -38911,7 +39970,7 @@ static int pkcs7signed_run_SingleShotVectors( testVectors[i].signedAttribsSz, out, outSz); if (encodedSz <= 0) - ERROR_OUT(-12549, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out); #ifndef NO_PKCS7_ENCRYPTED_DATA } else if (testVectors[i].encCompFlag == 3) { @@ -38928,38 +39987,38 @@ static int pkcs7signed_run_SingleShotVectors( testVectors[i].signedAttribsSz, out, outSz); if (encodedSz <= 0) - ERROR_OUT(-12550, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out); #endif /* NO_PKCS7_ENCRYPTED_DATA */ #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */ } else { /* unsupported SignedData single-shot combination */ - ERROR_OUT(-12551, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* write PKCS#7 to output file for more testing */ file = XFOPEN(testVectors[i].outFileName, "wb"); if (!file) - ERROR_OUT(-12552, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); ret = (int)XFWRITE(out, 1, encodedSz, file); XFCLOSE(file); file = NULL; if (ret != (int)encodedSz) - ERROR_OUT(-12553, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); #endif /* PKCS7_OUTPUT_TEST_BUNDLES */ wc_PKCS7_Free(pkcs7); pkcs7 = wc_PKCS7_New(HEAP_HINT, devId); if (pkcs7 == NULL) - ERROR_OUT(-12554, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); wc_PKCS7_InitWithCert(pkcs7, NULL, 0); ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz); if (ret < 0) - ERROR_OUT(-12555, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); #ifndef NO_PKCS7_STREAM { word32 z; @@ -38967,21 +40026,21 @@ static int pkcs7signed_run_SingleShotVectors( ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1); if (ret < 0 && ret != WC_PKCS7_WANT_READ_E) { printf("unexpected error %d\n", ret); - ERROR_OUT(-12556, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); } } } #endif if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0) - ERROR_OUT(-12557, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); if (testVectors[i].encCompFlag == 0) { /* verify decoded content matches expected */ if ((pkcs7->contentSz != testVectors[i].contentSz) || XMEMCMP(pkcs7->content, testVectors[i].content, pkcs7->contentSz)) { - ERROR_OUT(-12558, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } } @@ -38995,12 +40054,11 @@ static int pkcs7signed_run_SingleShotVectors( ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content, pkcs7->contentSz, out, outSz); if (ret < 0) - ERROR_OUT(-12559, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* compare decrypted to expected */ if (((word32)ret != testVectors[i].contentSz) || XMEMCMP(out, testVectors[i].content, ret)) - ERROR_OUT(-12560, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) @@ -39010,12 +40068,11 @@ static int pkcs7signed_run_SingleShotVectors( ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content, pkcs7->contentSz, out, outSz); if (ret < 0) - ERROR_OUT(-12561, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* compare decompressed to expected */ if (((word32)ret != testVectors[i].contentSz) || XMEMCMP(out, testVectors[i].content, ret)) - ERROR_OUT(-12562, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #ifndef NO_PKCS7_ENCRYPTED_DATA else if (testVectors[i].encCompFlag == 3) { @@ -39024,7 +40081,7 @@ static int pkcs7signed_run_SingleShotVectors( encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (encryptedTmp == NULL) - ERROR_OUT(-12563, out); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); XMEMSET(encryptedTmp, 0, encryptedTmpSz); @@ -39037,18 +40094,17 @@ static int pkcs7signed_run_SingleShotVectors( encryptedTmpSz); if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA) - ERROR_OUT(-12564, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* decompress inner compressedData */ ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp, encryptedTmpSz, out, outSz); if (ret < 0) - ERROR_OUT(-12565, out); - + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* compare decompressed to expected */ if (((word32)ret != testVectors[i].contentSz) || XMEMCMP(out, testVectors[i].content, ret)) - ERROR_OUT(-12566, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); } #endif /* NO_PKCS7_ENCRYPTED_DATA */ #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */ @@ -39122,12 +40178,12 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (rsaClientCertBuf == NULL) - ret = -12600; + ret = WC_TEST_RET_ENC_NC; rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && rsaClientPrivKeyBuf == NULL) { - ret = -12601; + ret = WC_TEST_RET_ENC_ERRNO; } rsaClientCertBufSz = FOURK_BUF; @@ -39137,12 +40193,12 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && rsaServerCertBuf == NULL) - ret = -12602; + ret = WC_TEST_RET_ENC_NC; rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && rsaServerPrivKeyBuf == NULL) { - ret = -12603; + ret = WC_TEST_RET_ENC_ERRNO; } rsaServerCertBufSz = FOURK_BUF; @@ -39152,12 +40208,12 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && rsaCaCertBuf == NULL) - ret = -12604; + ret = WC_TEST_RET_ENC_NC; rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && rsaCaPrivKeyBuf == NULL) { - ret = -12605; + ret = WC_TEST_RET_ENC_ERRNO; } rsaCaCertBufSz = FOURK_BUF; @@ -39169,13 +40225,13 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && eccClientCertBuf == NULL) { - ret = -12606; + ret = WC_TEST_RET_ENC_ERRNO; } eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (ret == 0 && eccClientPrivKeyBuf == NULL) { - ret = -12607; + ret = WC_TEST_RET_ENC_ERRNO; } eccClientCertBufSz = FOURK_BUF; @@ -39192,7 +40248,7 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) eccClientCertBuf, &eccClientCertBufSz, eccClientPrivKeyBuf, &eccClientPrivKeyBufSz); if (ret < 0) { - ret = -12608; + ret = WC_TEST_RET_ENC_EC(ret); } if (ret >= 0) @@ -39237,8 +40293,8 @@ WOLFSSL_TEST_SUBROUTINE int pkcs7signed_test(void) #endif /* HAVE_PKCS7 */ -#ifdef HAVE_VALGRIND -/* Need a static build to have access to symbols. */ +#if defined(WOLFSSL_PUBLIC_MP) && \ + (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) /* Maximum number of bytes in a number to test. */ #define MP_MAX_TEST_BYTE_LEN 32 @@ -39268,57 +40324,76 @@ static int mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng) int i, j; mp_digit rem; mp_digit rem2; + int ret; #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) for (i = 0; i < 10; i++) { for (j = 1; j < 10; j++) { - if (randNum(a, j, rng, NULL) != 0) - return -12620; - if (mp_div_3(a, r, &rem) != 0) - return -12621; - if (mp_mul_d(r, 3, r) != 0) - return -12622; - if (mp_add_d(r, rem, r) != 0) - return -12623; - if (mp_cmp(r, a) != MP_EQ) - return -12624; + ret = randNum(a, j, rng, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_3(a, r, &rem); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_mul_d(r, 3, r); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_add_d(r, rem, r); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, a); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } - if (mp_div_3(a, r, &rem) != 0) - return -12625; - if (mp_div_3(a, a, NULL) != 0) - return -12626; - if (mp_cmp(r, a) != MP_EQ) - return -12627; + ret = mp_div_3(a, r, &rem); + if (ret != 0) + return WC_TEST_RET_ENC_NC; + ret = mp_div_3(a, a, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_NC; + ret = mp_cmp(r, a); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; #endif #if defined(WOLFSSL_SP_MATH_ALL) - if (mp_div_d(a, 10, r, &rem) != 0) - return -12628; - if (mp_div_d(a, 10, a, NULL) != 0) - return -12629; - if (mp_cmp(r, a) != MP_EQ) - return -12630; + ret = mp_div_d(a, 10, r, &rem); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_d(a, 10, a, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, a); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; - if (mp_div_d(a, 12, r, &rem) != 0) - return -12631; - if (mp_div_d(a, 12, a, NULL) != 0) - return -12632; - if (mp_cmp(r, a) != MP_EQ) - return -12633; + ret = mp_div_d(a, 12, r, &rem); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_d(a, 12, a, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, a); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; - if (mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem) != 0) - return -12634; - if (mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2) != 0) - return -12635; - if (mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL) != 0) - return -12636; - if (mp_cmp(r, a) != MP_EQ) - return -12637; + ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, a); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; if (rem != rem2) - return -12638; + return WC_TEST_RET_ENC_NC; #endif (void)a; @@ -39328,6 +40403,7 @@ static int mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng) (void)j; (void)rem; (void)rem2; + (void)ret; return 0; } @@ -39351,54 +40427,64 @@ static int mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng) for (i = 0; i < 10; i++) { for (j = 2; j < 12; j++) { - if (randNum(a, j, rng, NULL) != 0) - return -12640; - if (mp_radix_size(a, MP_RADIX_DEC, &size) != MP_OKAY) - return -12641; - if (mp_toradix(a, str, MP_RADIX_DEC) != MP_OKAY) - return -12660; + ret = randNum(a, j, rng, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_radix_size(a, MP_RADIX_DEC, &size); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_toradix(a, str, MP_RADIX_DEC); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if ((int)XSTRLEN(str) != size - 1) - return -12642; - if (mp_read_radix(r, str, MP_RADIX_DEC) != MP_OKAY) - return -12661; - if (mp_cmp(a, r) != MP_EQ) - return -12643; + return WC_TEST_RET_ENC_NC; + ret = mp_read_radix(r, str, MP_RADIX_DEC); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(a, r); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } - if (mp_read_radix(r, badStr1, MP_RADIX_DEC) != MP_VAL) - return -12644; - if (mp_read_radix(r, badStr2, MP_RADIX_DEC) != MP_VAL) - return -12645; - if (mp_read_radix(r, badStr3, MP_RADIX_DEC) != MP_VAL) - return -12646; + ret = mp_read_radix(r, badStr1, MP_RADIX_DEC); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_read_radix(r, badStr2, MP_RADIX_DEC); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_read_radix(r, badStr3, MP_RADIX_DEC); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); - if (mp_read_radix(r, zeros, MP_RADIX_DEC) != MP_OKAY) - return -12647; + ret = mp_read_radix(r, zeros, MP_RADIX_DEC); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -12648; + return WC_TEST_RET_ENC_NC; mp_set(r, 1); - if (mp_read_radix(r, empty, MP_RADIX_DEC) != MP_OKAY) - return -12649; + ret = mp_read_radix(r, empty, MP_RADIX_DEC); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -12650; + return WC_TEST_RET_ENC_NC; mp_zero(a); ret = mp_radix_size(a, MP_RADIX_DEC, &size); if (ret != 0) - return -12651; + return WC_TEST_RET_ENC_EC(ret); if (size != 2) - return -12652; + return WC_TEST_RET_ENC_NC; ret = mp_toradix(a, str, MP_RADIX_DEC); if (ret != 0) - return -12653; + return WC_TEST_RET_ENC_EC(ret); if ((int)XSTRLEN(str) != size - 1) - return -12654; + return WC_TEST_RET_ENC_NC; ret = mp_read_radix(r, str, MP_RADIX_DEC); if (ret != 0) - return -12655; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -12656; + return WC_TEST_RET_ENC_NC; return 0; } @@ -39421,66 +40507,72 @@ static int mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng) for (i = 0; i < 10; i++) { for (j = 2; j < 12; j++) { - if (randNum(a, j, rng, NULL) != 0) - return -12660; + ret = randNum(a, j, rng, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); mp_radix_size(a, MP_RADIX_HEX, &size); mp_toradix(a, str, MP_RADIX_HEX); if ((int)XSTRLEN(str) != size - 1) - return -12661; + return WC_TEST_RET_ENC_NC; mp_read_radix(r, str, MP_RADIX_HEX); - if (mp_cmp(a, r) != MP_EQ) - return -12662; + ret = mp_cmp(a, r); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } - if (mp_read_radix(r, badStr1, MP_RADIX_HEX) != MP_VAL) - return -12663; - if (mp_read_radix(r, badStr2, MP_RADIX_HEX) != MP_VAL) - return -12664; + ret = mp_read_radix(r, badStr1, MP_RADIX_HEX); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_read_radix(r, badStr2, MP_RADIX_HEX); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); mp_set(r, 1); - if (mp_read_radix(r, empty, MP_RADIX_HEX) != MP_OKAY) - return -12665; + ret = mp_read_radix(r, empty, MP_RADIX_HEX); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -12666; + return WC_TEST_RET_ENC_NC; #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH) /* Fixed MP data size - string can be too long. */ longStr[0] = '8'; XMEMSET(longStr+1, '0', sizeof(longStr) - 2); longStr[sizeof(longStr)-1] = '\0'; - if (mp_read_radix(r, longStr, MP_RADIX_HEX) != MP_VAL) - return -12667; + ret = mp_read_radix(r, longStr, MP_RADIX_HEX); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); #endif mp_zero(a); ret = mp_radix_size(a, MP_RADIX_HEX, &size); if (ret != 0) - return -12668; + return WC_TEST_RET_ENC_EC(ret); #ifndef WC_DISABLE_RADIX_ZERO_PAD if (size != 3) #else if (size != 2) #endif - return -12669; + return WC_TEST_RET_ENC_NC; ret = mp_toradix(a, str, MP_RADIX_HEX); if (ret != 0) - return -12670; + return WC_TEST_RET_ENC_EC(ret); if ((int)XSTRLEN(str) != size - 1) - return -12671; + return WC_TEST_RET_ENC_NC; ret = mp_read_radix(r, str, MP_RADIX_HEX); if (ret != 0) - return -12672; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -12673; + return WC_TEST_RET_ENC_NC; #ifdef WOLFSSL_SP_MATH ret = mp_toradix(a, str, 8); if (ret != MP_VAL) - return -12674; + return WC_TEST_RET_ENC_EC(ret); ret = mp_radix_size(a, 8, &size); if (ret != MP_VAL) - return -12675; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -39490,28 +40582,34 @@ static int mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng) static int mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng) { int i; + int ret; - if (randNum(a, 4, rng, NULL) != 0) - return -12680; + ret = randNum(a, 4, rng, NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < 4; i++) { mp_copy(r1, a); - if (mp_lshd(r1, i) != MP_OKAY) - return -12681; + ret = mp_lshd(r1, i); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); #ifndef WOLFSSL_SP_MATH mp_rshd(r1, i); #else mp_rshb(r1, i * SP_WORD_SIZE); #endif - if (mp_cmp(a, r1) != MP_EQ) - return -12682; + ret = mp_cmp(a, r1); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } #ifndef WOLFSSL_SP_MATH for (i = 0; i < DIGIT_BIT+1; i++) { - if (mp_mul_2d(a, i, r1) != MP_OKAY) - return -12683; + ret = mp_mul_2d(a, i, r1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); mp_rshb(r1, i); - if (mp_cmp(a, r1) != MP_EQ) - return -12684; + ret = mp_cmp(a, r1); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } #endif @@ -39521,33 +40619,39 @@ static int mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng) static int mp_test_add_sub_d(mp_int* a, mp_int* r1) { int i, j; + int ret; for (i = 0; i <= DIGIT_BIT * 2; i++) { mp_zero(a); mp_set_bit(a, i); - if (a->used != (i + DIGIT_BIT) / DIGIT_BIT) - return -12690; + if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT) + return WC_TEST_RET_ENC_NC; for (j = 0; j < i && j < DIGIT_BIT; j++) { mp_zero(r1); mp_set_bit(r1, i); - if (mp_sub_d(r1, (mp_digit)1 << j, r1) != MP_OKAY) - return -12691; - if (mp_add_d(r1, (mp_digit)1 << j, r1) != MP_OKAY) - return -12692; - if (mp_cmp(a, r1) != MP_EQ) - return -12693; + ret = mp_sub_d(r1, (mp_digit)1 << j, r1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_add_d(r1, (mp_digit)1 << j, r1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(a, r1); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } mp_zero(r1); - if (mp_add_d(r1, 1, r1) != MP_OKAY) - return -12694; + ret = mp_add_d(r1, 1, r1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if (r1->used != 1) - return -12695; - if (mp_sub_d(r1, 1, r1) != MP_OKAY) - return -12696; + return WC_TEST_RET_ENC_NC; + ret = mp_sub_d(r1, 1, r1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); if (r1->used != 0) - return -12697; + return WC_TEST_RET_ENC_NC; return 0; } @@ -39567,28 +40671,33 @@ static int mp_test_read_to_bin(mp_int* a) p = in + sizeof(in) - i; ret = mp_read_unsigned_bin(a, p, i); if (ret != 0) - return -12710; + return WC_TEST_RET_ENC_EC(ret); for (j = i; j < (int)sizeof(out); j++) { XMEMSET(out, 0xff, sizeof(out)); ret = mp_to_unsigned_bin_len(a, out, j); if (ret != 0) - return -12711; + return WC_TEST_RET_ENC_EC(ret); for (k = 0; k < j - i; k++) { if (out[k] != 0) - return -12712; + return WC_TEST_RET_ENC_NC; } for (; k < j; k++) { if (out[k] != p[k - (j - i)]) - return -12713; + return WC_TEST_RET_ENC_NC; } } } + /* Length too small. */ + ret = mp_to_unsigned_bin_len(a, out, 1); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_read_unsigned_bin(a, NULL, 0); if (ret != 0) - return -12714; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(a)) - return -12715; + return WC_TEST_RET_ENC_NC; return 0; } @@ -39617,16 +40726,16 @@ static int mp_test_set_int(mp_int* a) ret = mp_set_int(a, n); if (ret != 0) - return -12720; + return WC_TEST_RET_ENC_EC(ret); ret = mp_unsigned_bin_size(a); if (ret != sizeof(exp)) - return -12721; + return WC_TEST_RET_ENC_NC; ret = mp_to_unsigned_bin(a, out); if (ret != 0) - return -12722; + return WC_TEST_RET_ENC_EC(ret); if (XMEMCMP(exp, out, sizeof(exp)) != 0) - return -12723; + return WC_TEST_RET_ENC_NC; return 0; } @@ -39664,12 +40773,12 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) ret = mp_init(NULL); if (ret != MP_VAL) - return -12730; + return WC_TEST_RET_ENC_EC(ret); #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC)) ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL); if (ret != MP_OKAY) - return -12731; + return WC_TEST_RET_ENC_EC(ret); #endif mp_free(NULL); @@ -39677,11 +40786,11 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC) ret = mp_grow(NULL, 1); if (ret != MP_VAL) - return -12732; + return WC_TEST_RET_ENC_EC(ret); #ifdef WOLFSSL_SP_MATH ret = mp_grow(a, SP_INT_DIGITS + 1); if (ret != MP_MEM) - return -12733; + return WC_TEST_RET_ENC_EC(ret); #endif #endif @@ -39689,49 +40798,49 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) ret = mp_abs(NULL, NULL); if (ret != MP_VAL) - return -12734; + return WC_TEST_RET_ENC_EC(ret); ret = mp_abs(a, NULL); if (ret != MP_VAL) - return -12735; + return WC_TEST_RET_ENC_EC(ret); ret = mp_abs(NULL, b); if (ret != MP_VAL) - return -12736; + return WC_TEST_RET_ENC_EC(ret); ret = mp_unsigned_bin_size(NULL); if (ret != 0) - return -12737; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer)); if (ret != MP_VAL) - return -12738; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer)); if (ret != MP_VAL) - return -12739; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer)); if (ret != MP_VAL) - return -12740; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1); if (ret != MP_VAL) - return -12741; + return WC_TEST_RET_ENC_EC(ret); #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL) ret = mp_read_radix(NULL, NULL, 16); if (ret != MP_VAL) - return -12742; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_radix(a, NULL, 16); if (ret != MP_VAL) - return -12743; + return WC_TEST_RET_ENC_EC(ret); ret = mp_read_radix(NULL, hexStr, 16); if (ret != MP_VAL) - return -12744; + return WC_TEST_RET_ENC_EC(ret); #ifndef WOLFSSL_SP_INT_NEGATIVE ret = mp_read_radix(a, negStr, 16); if (ret != MP_VAL) - return -12745; + return WC_TEST_RET_ENC_EC(ret); #ifdef WOLFSSL_SP_MATH_ALL ret = mp_read_radix(a, negStr, 10); if (ret != MP_VAL) - return -12746; + return WC_TEST_RET_ENC_EC(ret); #endif /* WOLFSSL_SP_MATH_ALL */ #endif /* WOLFSSL_SP_INT_NEGATIVE */ #endif @@ -39739,111 +40848,111 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) /* Radix 10 only supported with ALL. */ ret = mp_read_radix(a, decStr, 10); if (ret != MP_VAL) - return -12747; + return WC_TEST_RET_ENC_EC(ret); #endif /* Radix 8 not supported SP_INT. */ ret = mp_read_radix(a, "0123", 8); if (ret != MP_VAL) - return -12748; + return WC_TEST_RET_ENC_EC(ret); ret = mp_count_bits(NULL); if (ret != 0) - return -12749; + return WC_TEST_RET_ENC_EC(ret); ret = mp_is_bit_set(NULL, 0); if (ret != 0) - return -12750; + return WC_TEST_RET_ENC_EC(ret); ret = mp_leading_bit(NULL); if (ret != 0) - return -12751; + return WC_TEST_RET_ENC_EC(ret); mp_zero(a); ret = mp_leading_bit(a); if (ret != 0) - return -12752; + return WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \ !defined(NO_RSA) ret = mp_set_bit(NULL, 1); if (ret != MP_VAL) - return -12753; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \ !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_to_unsigned_bin(NULL, NULL); if (ret != MP_VAL) - return -12754; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin(a, NULL); if (ret != MP_VAL) - return -12755; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin(NULL, buffer); if (ret != MP_VAL) - return -12756; + return WC_TEST_RET_ENC_EC(ret); #endif ret = mp_to_unsigned_bin_len(NULL, NULL, 1); if (ret != MP_VAL) - return -12757; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin_len(a, NULL, 1); if (ret != MP_VAL) - return -12758; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin_len(NULL, buffer, 1); if (ret != MP_VAL) - return -12759; + return WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \ !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL); if (ret != MP_VAL) - return -12760; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin_at_pos(0, a, NULL); if (ret != MP_VAL) - return -12761; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer); if (ret != MP_VAL) - return -12762; + return WC_TEST_RET_ENC_EC(ret); ret = mp_to_unsigned_bin_at_pos(0, a, buffer); if (ret != MP_OKAY) - return -12763; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC)) ret = mp_copy(NULL, NULL); if (ret != MP_VAL) - return -12764; + return WC_TEST_RET_ENC_EC(ret); ret = mp_copy(a, NULL); if (ret != MP_VAL) - return -12765; + return WC_TEST_RET_ENC_EC(ret); ret = mp_copy(NULL, b); if (ret != MP_VAL) - return -12766; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) ret = sp_2expt(NULL, 1); if (ret != MP_VAL) - return -12767; + return WC_TEST_RET_ENC_EC(ret); #endif ret = mp_set(NULL, 0); if (ret != MP_VAL) - return -12768; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp_d(NULL, 0); if (ret != MP_LT) - return -12769; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp(NULL, NULL); if (ret != MP_EQ) - return -12770; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(a, NULL); if (ret != MP_GT) - return -12771; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(NULL, b); if (ret != MP_LT) - return -12772; + return WC_TEST_RET_ENC_NC; #ifdef WOLFSSL_SP_MATH_ALL mp_rshd(NULL, 1); @@ -39855,609 +40964,609 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_lshd(NULL, 0); if (ret != MP_VAL) - return -12773; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lshd(a, SP_INT_DIGITS + 1); if (ret != MP_VAL) - return -12774; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) ret = mp_div(NULL, NULL, a, b); if (ret != MP_VAL) - return -12775; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(a, NULL, a, b); if (ret != MP_VAL) - return -12776; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(NULL, b, a, b); if (ret != MP_VAL) - return -12777; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(a, b, NULL, NULL); if (ret != MP_VAL) - return -12778; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \ (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) ret = mp_mod(NULL, NULL, NULL); if (ret != MP_VAL) - return -12779; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(a, NULL, NULL); if (ret != MP_VAL) - return -12780; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(NULL, b, NULL); if (ret != MP_VAL) - return -12781; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(NULL, NULL, r); if (ret != MP_VAL) - return -12782; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(a, b, NULL); if (ret != MP_VAL) - return -12783; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(a, NULL, r); if (ret != MP_VAL) - return -12784; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(NULL, b, r); if (ret != MP_VAL) - return -12785; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL) ret = mp_set_int(NULL, 0); if (ret != MP_VAL) - return -12786; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \ (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA) ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL); if (ret != MP_VAL) - return 9950; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL); if (ret != MP_VAL) - return 9951; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL); if (ret != MP_VAL) - return 9952; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL); if (ret != MP_VAL) - return 9953; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a); if (ret != MP_VAL) - return 9954; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, a, 1, a, NULL); if (ret != MP_VAL) - return 9955; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, a, 1, NULL, a); if (ret != MP_VAL) - return 9956; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, NULL, 1, a, a); if (ret != MP_VAL) - return 9957; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, a, 1, a, a); if (ret != MP_VAL) - return 9958; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return 9960; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, NULL, NULL, NULL); if (ret != MP_VAL) - return 9961; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, a, NULL, NULL); if (ret != MP_VAL) - return 9962; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, a, NULL); if (ret != MP_VAL) - return 9963; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, NULL, a); if (ret != MP_VAL) - return 9964; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, a, a, NULL); if (ret != MP_VAL) - return 9965; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, a, NULL, a); if (ret != MP_VAL) - return 9966; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, NULL, a, a); if (ret != MP_VAL) - return 9967; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, a, a, a); if (ret != MP_VAL) - return 9968; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \ !defined(WC_NO_RNG) ret = mp_rand_prime(NULL, 32, NULL, NULL); if (ret != MP_VAL) - return -12787; + return WC_TEST_RET_ENC_EC(ret); ret = mp_rand_prime(a, 32, NULL, NULL); if (ret != MP_VAL) - return -12788; + return WC_TEST_RET_ENC_EC(ret); ret = mp_rand_prime(NULL, 32, rng, NULL); if (ret != MP_VAL) - return -12789; + return WC_TEST_RET_ENC_EC(ret); ret = mp_rand_prime(a, 0, rng, NULL); if (ret != MP_VAL) - return -9969; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_mul(NULL, NULL, NULL); if (ret != MP_VAL) - return -12790; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, NULL, NULL); if (ret != MP_VAL) - return -12791; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(NULL, b, NULL); if (ret != MP_VAL) - return -12792; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(NULL, NULL, r); if (ret != MP_VAL) - return -12793; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, b, NULL); if (ret != MP_VAL) - return -12794; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, NULL, r); if (ret != MP_VAL) - return -12795; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(NULL, b, r); if (ret != MP_VAL) - return -12796; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) ret = mp_sqr(NULL, NULL); if (ret != MP_VAL) - return -12797; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqr(a, NULL); if (ret != MP_VAL) - return -12798; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqr(NULL, r); if (ret != MP_VAL) - return -12799; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_sqrmod(NULL, NULL, NULL); if (ret != MP_VAL) - return -12800; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(a, NULL, NULL); if (ret != MP_VAL) - return -12801; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(NULL, a, NULL); if (ret != MP_VAL) - return -12802; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(NULL, NULL, a); if (ret != MP_VAL) - return -12803; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(a, b, NULL); if (ret != MP_VAL) - return -12804; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(a, NULL, b); if (ret != MP_VAL) - return -12805; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqrmod(NULL, a, b); if (ret != MP_VAL) - return -12806; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return -12807; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(a, NULL, NULL, NULL); if (ret != MP_VAL) - return -12808; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(NULL, a, NULL, NULL); if (ret != MP_VAL) - return -12809; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(NULL, NULL, a, NULL); if (ret != MP_VAL) - return -12810; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(NULL, NULL, NULL, a); if (ret != MP_VAL) - return -12811; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(a, b, b, NULL); if (ret != MP_VAL) - return -12812; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(a, b, NULL, a); if (ret != MP_VAL) - return -12813; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(a, NULL, b, a); if (ret != MP_VAL) - return -12814; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(NULL, b, b, a); if (ret != MP_VAL) - return -12815; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \ !defined(NO_RSA) || !defined(NO_DSA) ret = mp_add_d(NULL, 1, NULL); if (ret != MP_VAL) - return -12816; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add_d(a, 1, NULL); if (ret != MP_VAL) - return -12817; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add_d(NULL, 1, b); if (ret != MP_VAL) - return -12818; + return WC_TEST_RET_ENC_EC(ret); #endif #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA) ret = mp_sub_d(NULL, 1, NULL); if (ret != MP_VAL) - return -12819; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub_d(a, 1, NULL); if (ret != MP_VAL) - return -12820; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub_d(NULL, 1, b); if (ret != MP_VAL) - return -12821; + return WC_TEST_RET_ENC_EC(ret); #endif #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) ret = mp_div_d(NULL, 0, NULL, NULL); if (ret != MP_VAL) - return -12822; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_d(a, 0, NULL, NULL); if (ret != MP_VAL) - return -12823; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_d(NULL, 1, NULL, NULL); if (ret != MP_VAL) - return -12824; + return WC_TEST_RET_ENC_EC(ret); #endif #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \ (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN)) ret = mp_mod_d(NULL, 0, NULL); if (ret != MP_VAL) - return -12825; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_d(a, 0, NULL); if (ret != MP_VAL) - return -12826; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_d(NULL, 0, &rd); if (ret != MP_VAL) - return -12827; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) ret = mp_gcd(NULL, NULL, NULL); if (ret != MP_VAL) - return -12828; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(a, NULL, NULL); if (ret != MP_VAL) - return -12829; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(NULL, a, NULL); if (ret != MP_VAL) - return -12830; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(NULL, NULL, a); if (ret != MP_VAL) - return -12831; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(a, b, NULL); if (ret != MP_VAL) - return -12832; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(a, NULL, b); if (ret != MP_VAL) - return -12833; + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(NULL, a, b); if (ret != MP_VAL) - return -12834; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC) ret = mp_div_2_mod_ct(NULL, NULL, NULL); if (ret != MP_VAL) - return -12835; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(a, NULL, NULL); if (ret != MP_VAL) - return -12836; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(NULL, b, NULL); if (ret != MP_VAL) - return -12837; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(NULL, NULL, a); if (ret != MP_VAL) - return -12838; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(a, b, NULL); if (ret != MP_VAL) - return -12839; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(a, b, NULL); if (ret != MP_VAL) - return -12840; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2_mod_ct(NULL, b, a); if (ret != MP_VAL) - return -12841; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2(NULL, NULL); if (ret != MP_VAL) - return -12842; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2(a, NULL); if (ret != MP_VAL) - return -12843; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div_2(NULL, a); if (ret != MP_VAL) - return -12844; + return WC_TEST_RET_ENC_EC(ret); #endif #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA) ret = mp_invmod(NULL, NULL, NULL); if (ret != MP_VAL) - return -12845; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(a, NULL, NULL); if (ret != MP_VAL) - return -12846; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(NULL, b, NULL); if (ret != MP_VAL) - return -12847; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(NULL, NULL, a); if (ret != MP_VAL) - return -12848; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(a, b, NULL); if (ret != MP_VAL) - return -12849; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(a, NULL, a); if (ret != MP_VAL) - return -12850; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(NULL, b, a); if (ret != MP_VAL) - return -12851; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC) ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1); if (ret != MP_VAL) - return -12852; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(a, NULL, NULL, 1); if (ret != MP_VAL) - return -12853; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(NULL, b, NULL, 1); if (ret != MP_VAL) - return -12854; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(NULL, NULL, a, 1); if (ret != MP_VAL) - return -12855; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(a, b, NULL, 1); if (ret != MP_VAL) - return -12856; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(a, NULL, a, 1); if (ret != MP_VAL) - return -12857; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod_mont_ct(NULL, b, a, 1); if (ret != MP_VAL) - return -12858; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING) ret = mp_lcm(NULL, NULL, NULL); if (ret != MP_VAL) - return -12859; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(a, NULL, NULL); if (ret != MP_VAL) - return -12860; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(NULL, b, NULL); if (ret != MP_VAL) - return -12861; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(NULL, NULL, a); if (ret != MP_VAL) - return -12862; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(a, b, NULL); if (ret != MP_VAL) - return -12863; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(a, NULL, a); if (ret != MP_VAL) - return -12864; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(NULL, b, a); if (ret != MP_VAL) - return -12865; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL); if (ret != MP_VAL) - return -12866; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL); if (ret != MP_VAL) - return -12867; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL); if (ret != MP_VAL) - return -12868; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL); if (ret != MP_VAL) - return -12869; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a); if (ret != MP_VAL) - return -12870; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, b, 1, b, NULL); if (ret != MP_VAL) - return -12871; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, b, 1, NULL, a); if (ret != MP_VAL) - return -12872; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(a, NULL, 1, b, a); if (ret != MP_VAL) - return -12873; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_ex(NULL, b, 1, b, a); if (ret != MP_VAL) - return -12874; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return -12875; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(a, NULL, NULL, NULL); if (ret != MP_VAL) - return -12876; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(NULL, b, NULL, NULL); if (ret != MP_VAL) - return -12877; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(NULL, NULL, b, NULL); if (ret != MP_VAL) - return -12878; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(NULL, NULL, NULL, a); if (ret != MP_VAL) - return -12879; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(a, b, b, NULL); if (ret != MP_VAL) - return -12880; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(a, b, NULL, a); if (ret != MP_VAL) - return -12881; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(a, NULL, b, a); if (ret != MP_VAL) - return -12882; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod(NULL, b, b, a); if (ret != MP_VAL) - return -12883; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return -12884; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, NULL, NULL, NULL); if (ret != MP_VAL) - return -12885; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, b, NULL, NULL); if (ret != MP_VAL) - return -12886; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, b, NULL); if (ret != MP_VAL) - return -12887; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, NULL, NULL, a); if (ret != MP_VAL) - return -12888; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, b, b, NULL); if (ret != MP_VAL) - return -12889; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, b, NULL, a); if (ret != MP_VAL) - return -12890; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(a, NULL, b, a); if (ret != MP_VAL) - return -12891; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(NULL, b, b, a); if (ret != MP_VAL) - return -12892; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY) ret = mp_cnt_lsb(NULL); if (ret != 0) - return -12893; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) ret = mp_prime_is_prime(NULL, 1, NULL); if (ret != MP_VAL) - return -12894; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(a, 1, NULL); if (ret != MP_VAL) - return -12895; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(NULL, 1, &result); if (ret != MP_VAL) - return -12896; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(a, 0, &result); if (ret != MP_VAL) - return -12897; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(a, 1024, &result); if (ret != MP_VAL) - return -12898; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL); if (ret != MP_VAL) - return -12899; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(a, 1, NULL, NULL); if (ret != MP_VAL) - return -12900; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL); if (ret != MP_VAL) - return -12901; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng); if (ret != MP_VAL) - return -12902; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(a, 1, &result, NULL); if (ret != MP_VAL) - return -12903; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(a, 1, NULL, rng); if (ret != MP_VAL) - return -12904; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime_ex(NULL, 1, &result, rng); if (ret != MP_VAL) - return -12905; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA) ret = mp_exch(NULL, NULL); if (ret != MP_VAL) - return -12906; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exch(a, NULL); if (ret != MP_VAL) - return -12907; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exch(NULL, b); if (ret != MP_VAL) - return -12908; + return WC_TEST_RET_ENC_EC(ret); #endif #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \ defined(WOLFSSL_SP_MATH_ALL) ret = mp_mul_d(NULL, 1, NULL); if (ret != MP_VAL) - return -12909; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_d(a, 1, NULL); if (ret != MP_VAL) - return -12910; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_d(NULL, 1, b); if (ret != MP_VAL) - return -12911; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_RSA_VERIFY_ONLY) ret = mp_add(NULL, NULL, NULL); if (ret != MP_VAL) - return -12912; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(a, NULL, NULL); if (ret != MP_VAL) - return -12913; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(NULL, b, NULL); if (ret != MP_VAL) - return -12914; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(NULL, NULL, r); if (ret != MP_VAL) - return -12915; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(a, b, NULL); if (ret != MP_VAL) - return -12916; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(a, NULL, r); if (ret != MP_VAL) - return -12917; + return WC_TEST_RET_ENC_EC(ret); ret = mp_add(NULL, b, r); if (ret != MP_VAL) - return -12918; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \ (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) ret = mp_sub(NULL, NULL, NULL); if (ret != MP_VAL) - return -12919; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(a, NULL, NULL); if (ret != MP_VAL) - return -12920; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(NULL, b, NULL); if (ret != MP_VAL) - return -12921; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(NULL, NULL, r); if (ret != MP_VAL) - return -12922; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(a, b, NULL); if (ret != MP_VAL) - return -12923; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(a, NULL, r); if (ret != MP_VAL) - return -12924; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub(NULL, b, r); if (ret != MP_VAL) - return -12925; + return WC_TEST_RET_ENC_EC(ret); #endif @@ -40465,182 +41574,182 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) defined(WOLFSSL_CUSTOM_CURVES)) ret = mp_addmod(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return -12926; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(a, NULL, NULL, NULL); if (ret != MP_VAL) - return -12927; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(NULL, b, NULL, NULL); if (ret != MP_VAL) - return -12928; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(NULL, NULL, b, NULL); if (ret != MP_VAL) - return -12929; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(NULL, NULL, NULL, a); if (ret != MP_VAL) - return -12930; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(a, b, b, NULL); if (ret != MP_VAL) - return -12931; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(a, b, NULL, a); if (ret != MP_VAL) - return -12932; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(a, NULL, b, a); if (ret != MP_VAL) - return -12933; + return WC_TEST_RET_ENC_EC(ret); ret = mp_addmod(NULL, b, b, a); if (ret != MP_VAL) - return -12934; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SP_MATH_ALL ret = mp_submod(NULL, NULL, NULL, NULL); if (ret != MP_VAL) - return -12935; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(a, NULL, NULL, NULL); if (ret != MP_VAL) - return -12936; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(NULL, b, NULL, NULL); if (ret != MP_VAL) - return -12937; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(NULL, NULL, b, NULL); if (ret != MP_VAL) - return -12938; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(NULL, NULL, NULL, a); if (ret != MP_VAL) - return -12939; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(a, b, b, NULL); if (ret != MP_VAL) - return -12940; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(a, b, NULL, a); if (ret != MP_VAL) - return -12941; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(a, NULL, b, a); if (ret != MP_VAL) - return -12942; + return WC_TEST_RET_ENC_EC(ret); ret = mp_submod(NULL, b, b, a); if (ret != MP_VAL) - return -12943; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SP_MATH_ALL ret = mp_div_2d(NULL, 1, a, b); if (ret != MP_VAL) - return -12944; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_2d(NULL, 1, NULL); if (ret != MP_VAL) - return -12945; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_2d(a, 1, NULL); if (ret != MP_VAL) - return -12946; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_2d(NULL, 1, b); if (ret != MP_VAL) - return -12947; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_2d(NULL, 1, NULL); if (ret != MP_VAL) - return -12948; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_2d(a, 1, NULL); if (ret != MP_VAL) - return -12949; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_2d(NULL, 1, b); if (ret != MP_VAL) - return -12950; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) ret = mp_montgomery_reduce(NULL, NULL, 1); if (ret != MP_VAL) - return -12951; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_reduce(a, NULL, 1); if (ret != MP_VAL) - return -12952; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_reduce(NULL, b, 1); if (ret != MP_VAL) - return -12953; + return WC_TEST_RET_ENC_EC(ret); mp_zero(b); ret = mp_montgomery_reduce(a, b, 1); if (ret != MP_VAL) - return -12954; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SP_MATH_ALL ret = mp_montgomery_setup(NULL, NULL); if (ret != MP_VAL) - return -12955; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_setup(a, NULL); if (ret != MP_VAL) - return -12956; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_setup(NULL, &rho); if (ret != MP_VAL) - return -12957; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_calc_normalization(NULL, NULL); if (ret != MP_VAL) - return -12958; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_calc_normalization(a, NULL); if (ret != MP_VAL) - return -12959; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_calc_normalization(NULL, b); if (ret != MP_VAL) - return -12960; + return WC_TEST_RET_ENC_EC(ret); #endif ret = mp_unsigned_bin_size(NULL); if (ret != 0) - return -12961; + return WC_TEST_RET_ENC_EC(ret); #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL) ret = mp_tohex(NULL, NULL); if (ret != MP_VAL) - return -12962; + return WC_TEST_RET_ENC_EC(ret); ret = mp_tohex(a, NULL); if (ret != MP_VAL) - return -12963; + return WC_TEST_RET_ENC_EC(ret); ret = mp_tohex(NULL, hexStr); if (ret != MP_VAL) - return -12964; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY) ret = mp_todecimal(NULL, NULL); if (ret != MP_VAL) - return -12965; + return WC_TEST_RET_ENC_EC(ret); ret = mp_todecimal(a, NULL); if (ret != MP_VAL) - return -12966; + return WC_TEST_RET_ENC_EC(ret); ret = mp_todecimal(NULL, decStr); if (ret != MP_VAL) - return -12967; + return WC_TEST_RET_ENC_EC(ret); #endif #ifdef WOLFSSL_SP_MATH_ALL ret = mp_toradix(NULL, NULL, MP_RADIX_HEX); if (ret != MP_VAL) - return -12968; + return WC_TEST_RET_ENC_EC(ret); ret = mp_toradix(a, NULL, MP_RADIX_HEX); if (ret != MP_VAL) - return -12969; + return WC_TEST_RET_ENC_EC(ret); ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX); if (ret != MP_VAL) - return -12970; + return WC_TEST_RET_ENC_EC(ret); ret = mp_toradix(a, hexStr, 3); if (ret != MP_VAL) - return -12971; + return WC_TEST_RET_ENC_EC(ret); ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL); if (ret != MP_VAL) - return -12972; + return WC_TEST_RET_ENC_EC(ret); ret = mp_radix_size(a, MP_RADIX_HEX, NULL); if (ret != MP_VAL) - return -12973; + return WC_TEST_RET_ENC_EC(ret); ret = mp_radix_size(NULL, MP_RADIX_HEX, &size); if (ret != MP_VAL) - return -12974; + return WC_TEST_RET_ENC_EC(ret); ret = mp_radix_size(a, 3, &size); if (ret != MP_VAL) - return -12975; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -40651,50 +41760,52 @@ static int mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng) static int mp_test_set_is_bit(mp_int* a) { int i, j; + int ret; mp_zero(a); for (i = 0; i <= DIGIT_BIT * 2; i++) { if (mp_is_bit_set(a, i)) - return -12980; + return WC_TEST_RET_ENC_NC; for (j = 0; j < i; j++) { if (!mp_is_bit_set(a, j)) - return -12981; + return WC_TEST_RET_ENC_NC; } if (mp_set_bit(a, i) != 0) - return -12982; + return WC_TEST_RET_ENC_NC; if (!mp_is_bit_set(a, i)) - return -12983; + return WC_TEST_RET_ENC_NC; } mp_zero(a); for (i = 0; i <= DIGIT_BIT * 2; i++) { if (mp_is_bit_set(a, i)) - return -12984; + return WC_TEST_RET_ENC_NC; } for (i = 0; i <= DIGIT_BIT * 2; i++) { mp_zero(a); if (mp_set_bit(a, i) != 0) - return -12985; + return WC_TEST_RET_ENC_NC; for (j = 0; j < i; j++) { if (mp_is_bit_set(a, j)) - return -12986; + return WC_TEST_RET_ENC_NC; } if (!mp_is_bit_set(a, i)) - return -12987; + return WC_TEST_RET_ENC_NC; } #ifdef WOLFSSL_KEY_GEN for (i = 0; i < DIGIT_BIT * 2; i++) { mp_set(a, 1); - if (mp_2expt(a, i) != 0) - return -12988; + ret = mp_2expt(a, i); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); for (j = 0; j < i; j++) { if (mp_is_bit_set(a, j)) - return -12989; + return WC_TEST_RET_ENC_NC; } if (!mp_is_bit_set(a, i)) - return -12990; + return WC_TEST_RET_ENC_NC; } #endif @@ -40703,16 +41814,17 @@ static int mp_test_set_is_bit(mp_int* a) for (j = 1; j <= 3; j++) { i = SP_INT_MAX_BITS - j; if (mp_is_bit_set(a, i)) - return -12991; + return WC_TEST_RET_ENC_NC; if (mp_set_bit(a, i) != 0) - return -12992; + return WC_TEST_RET_ENC_NC; if (!mp_is_bit_set(a, i)) - return -12993; + return WC_TEST_RET_ENC_NC; #ifdef WOLFSSL_KEY_GEN - if (mp_2expt(a, i) != 0) - return -12994; + ret = mp_2expt(a, i); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (!mp_is_bit_set(a, i)) - return -12995; + return WC_TEST_RET_ENC_NC; #endif } @@ -40720,16 +41832,19 @@ static int mp_test_set_is_bit(mp_int* a) for (j = 0; j <= 3; j++) { i = SP_INT_MAX_BITS + j; if (mp_is_bit_set(a, i)) - return -12996; + return WC_TEST_RET_ENC_NC; if (mp_set_bit(a, i) != MP_VAL) - return -12997; + return WC_TEST_RET_ENC_NC; #ifdef WOLFSSL_KEY_GEN - if (mp_2expt(a, i) != MP_VAL) - return -12998; + ret = mp_2expt(a, i); + if (ret != MP_VAL) + return WC_TEST_RET_ENC_EC(ret); #endif } #endif + (void)ret; + return 0; } #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */ @@ -40743,44 +41858,44 @@ static int mp_test_cmp(mp_int* a, mp_int* b) ret = mp_cmp_d(a, 0); if (ret != MP_EQ) - return -13000; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp_d(a, 1); if (ret != MP_LT) - return -13001; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp(a, b); if (ret != MP_EQ) - return -13002; + return WC_TEST_RET_ENC_NC; mp_set(a, 1); ret = mp_cmp_d(a, 0); if (ret != MP_GT) - return -13003; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp_d(a, 1); if (ret != MP_EQ) - return -13004; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp_d(a, 2); if (ret != MP_LT) - return -13005; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp(a, b); if (ret != MP_GT) - return -13006; + return WC_TEST_RET_ENC_NC; mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX); ret = mp_cmp_d(b, -1); if (ret != MP_GT) - return -13007; + return WC_TEST_RET_ENC_EC(ret); ret = mp_cmp(a, b); if (ret != MP_LT) - return -13008; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(b, a); if (ret != MP_GT) - return -13009; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(b, b); if (ret != MP_EQ) - return -13010; + return WC_TEST_RET_ENC_NC; #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \ defined(WOLFSSL_SP_INT_NEGATIVE) @@ -40788,23 +41903,23 @@ static int mp_test_cmp(mp_int* a, mp_int* b) mp_read_radix(a, "1", MP_RADIX_HEX); ret = mp_cmp(a, b); if (ret != MP_LT) - return -13011; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(b, a); if (ret != MP_GT) - return -13012; + return WC_TEST_RET_ENC_NC; mp_read_radix(b, "-2", MP_RADIX_HEX); ret = mp_cmp(a, b); if (ret != MP_GT) - return -13013; + return WC_TEST_RET_ENC_NC; ret = mp_cmp(b, a); if (ret != MP_LT) - return -13014; + return WC_TEST_RET_ENC_NC; mp_read_radix(a, "-2", MP_RADIX_HEX); ret = mp_cmp(a, b); if (ret != MP_EQ) - return -13015; + return WC_TEST_RET_ENC_NC; #endif return 0; @@ -40821,15 +41936,16 @@ static int mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng) for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) { ret = randNum(a, j, rng, NULL); if (ret != MP_OKAY) - return -13020; + return WC_TEST_RET_ENC_EC(ret); mp_copy(a, b); for (k = 0; k <= DIGIT_BIT * 2; k++) { ret = mp_mul_2d(a, k, a); if (ret != MP_OKAY) - return -13021; + return WC_TEST_RET_ENC_EC(ret); mp_rshb(a, k); - if (mp_cmp(a, b) != MP_EQ) - return -13022; + ret = mp_cmp(a, b); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } } @@ -40839,19 +41955,20 @@ static int mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng) for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) { ret = randNum(a, j, rng, NULL); if (ret != MP_OKAY) - return -13023; + return WC_TEST_RET_ENC_EC(ret); mp_copy(a, b); for (k = 0; k < 10; k++) { ret = mp_lshd(a, k); if (ret != MP_OKAY) - return -13024; + return WC_TEST_RET_ENC_EC(ret); #ifndef WOLFSSL_SP_MATH mp_rshd(a, k); #else mp_rshb(a, k * SP_WORD_SIZE); #endif - if (mp_cmp(a, b) != MP_EQ) - return -13025; + ret = mp_cmp(a, b); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } } @@ -40860,17 +41977,17 @@ static int mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng) mp_zero(a); mp_rshd(a, 1); if (!mp_iszero(a)) - return -13026; + return WC_TEST_RET_ENC_NC; mp_set(a, 1); mp_rshd(a, 1); if (!mp_iszero(a)) - return -13027; + return WC_TEST_RET_ENC_NC; mp_set(a, 1); mp_rshd(a, 2); if (!mp_iszero(a)) - return -13028; + return WC_TEST_RET_ENC_NC; #endif return 0; @@ -40891,83 +42008,83 @@ static int mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem, ret = mp_div(a, d, r, rem); if (ret != MP_VAL) - return -13030; + return WC_TEST_RET_ENC_EC(ret); mp_set(d, 1); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13031; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13032; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(rem)) - return -13033; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13034; + return WC_TEST_RET_ENC_EC(ret); if (!mp_isone(r)) - return -13035; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(rem)) - return -13036; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < 100; i++) { for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) { ret = randNum(d, j, rng, NULL); if (ret != MP_OKAY) - return -13037; + return WC_TEST_RET_ENC_EC(ret); for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) { ret = randNum(a, k, rng, NULL); if (ret != MP_OKAY) - return -13038; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(a, d, NULL, rem); if (ret != MP_OKAY) - return -13039; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(a, d, r, NULL); if (ret != MP_OKAY) - return -13040; + return WC_TEST_RET_ENC_EC(ret); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13041; + return WC_TEST_RET_ENC_EC(ret); mp_mul(r, d, r); mp_add(r, rem, r); if (mp_cmp(r, a) != MP_EQ) - return -13042; + return WC_TEST_RET_ENC_NC; } } } ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL); if (ret != MP_OKAY) - return -13043; + return WC_TEST_RET_ENC_EC(ret); mp_add(d, d, a); mp_set(rem, 1); mp_div(a, d, NULL, rem); if (ret != MP_OKAY) - return -13044; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(rem)) - return -13045; + return WC_TEST_RET_ENC_EC(ret); mp_set(r, 1); mp_div(a, d, r, NULL); if (ret != MP_OKAY) - return -13046; + return WC_TEST_RET_ENC_EC(ret); if (mp_cmp_d(r, 2) != MP_EQ) - return -13047; + return WC_TEST_RET_ENC_EC(ret); mp_set(r, 1); mp_set(rem, 1); mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13048; + return WC_TEST_RET_ENC_EC(ret); if (mp_cmp_d(r, 2) != MP_EQ) - return -13049; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(rem)) - return -13050; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 0xfe); mp_lshd(a, 3); @@ -40976,11 +42093,11 @@ static int mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem, mp_lshd(d, 2); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13051; + return WC_TEST_RET_ENC_EC(ret); mp_mul(r, d, d); mp_add(rem, d, d); if (mp_cmp(a, d) != MP_EQ) - return -13052; + return WC_TEST_RET_ENC_NC; /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in * a digit. So mp_div must detect and handle. @@ -40993,7 +42110,7 @@ static int mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem, mp_add_d(d, 1, d); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13053; + return WC_TEST_RET_ENC_EC(ret); /* Make sure [d | d] / d is handled. */ mp_zero(a); @@ -41003,15 +42120,15 @@ static int mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem, mp_set_bit(d, DIGIT_BIT - 1); ret = mp_div(a, d, r, rem); if (ret != MP_OKAY) - return -13054; + return WC_TEST_RET_ENC_EC(ret); mp_zero(a); mp_set_bit(a, DIGIT_BIT); mp_set_bit(a, 0); mp_zero(d); if (mp_cmp(r, a) != MP_EQ) - return -13055; + return WC_TEST_RET_ENC_NC; if (mp_cmp(rem, d) != MP_EQ) - return -13056; + return WC_TEST_RET_ENC_NC; return 0; } @@ -41027,96 +42144,96 @@ static int mp_test_prime(mp_int* a, WC_RNG* rng) ret = mp_rand_prime(a, 1, rng, NULL); #if defined(WOLFSSL_SP_MATH_ALL) if (ret != 0) - return -13060; + return WC_TEST_RET_ENC_EC(ret); #else if (ret != MP_VAL) - return -13060; + return WC_TEST_RET_ENC_NC; #endif #ifndef WOLFSSL_SP_MATH ret = mp_rand_prime(a, -5, rng, NULL); if (ret != 0 || (a->dp[0] & 3) != 3) - return -13061; + return WC_TEST_RET_ENC_NC; #endif ret = mp_prime_is_prime(a, 1, &res); if (ret != MP_OKAY) - return -13062; + return WC_TEST_RET_ENC_EC(ret); #ifndef WOLFSSL_SP_MATH if (res != MP_YES) - return -13063; + return WC_TEST_RET_ENC_EC(res); #else if (res != MP_NO) - return -13063; + return WC_TEST_RET_ENC_EC(res); #endif ret = mp_prime_is_prime(a, 0, &res); if (ret != MP_VAL) - return -13064; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(a, -1, &res); if (ret != MP_VAL) - return -13065; + return WC_TEST_RET_ENC_EC(ret); ret = mp_prime_is_prime(a, 257, &res); if (ret != MP_VAL) - return -13066; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); ret = mp_prime_is_prime(a, 1, &res); if (ret != MP_OKAY) - return -13067; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13068; + return WC_TEST_RET_ENC_EC(res); ret = mp_prime_is_prime_ex(a, 1, &res, rng); if (ret != MP_OKAY) - return -13069; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13070; + return WC_TEST_RET_ENC_EC(res); mp_set(a, 2); ret = mp_prime_is_prime(a, 1, &res); if (ret != MP_OKAY) - return -13071; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_YES) - return -13072; + return WC_TEST_RET_ENC_EC(res); ret = mp_prime_is_prime_ex(a, 1, &res, rng); if (ret != MP_OKAY) - return -13073; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_YES) - return -13074; + return WC_TEST_RET_ENC_EC(res); mp_set(a, 0xfb); ret = mp_prime_is_prime(a, 1, &res); if (ret != MP_OKAY) - return -13075; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_YES) - return -13076; + return WC_TEST_RET_ENC_EC(res); ret = mp_prime_is_prime_ex(a, 1, &res, rng); if (ret != MP_OKAY) - return -13077; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_YES) - return -13078; + return WC_TEST_RET_ENC_EC(res); mp_set(a, 0x6); ret = mp_prime_is_prime(a, 1, &res); if (ret != MP_OKAY) - return -13079; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13080; + return WC_TEST_RET_ENC_EC(res); ret = mp_prime_is_prime_ex(a, 1, &res, rng); if (ret != MP_OKAY) - return -13081; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13082; + return WC_TEST_RET_ENC_EC(res); mp_set_int(a, 0x655 * 0x65b); ret = mp_prime_is_prime(a, 10, &res); if (ret != MP_OKAY) - return -13083; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13084; + return WC_TEST_RET_ENC_EC(res); ret = mp_prime_is_prime_ex(a, 10, &res, rng); if (ret != MP_OKAY) - return -13085; + return WC_TEST_RET_ENC_EC(ret); if (res != MP_NO) - return -13086; + return WC_TEST_RET_ENC_EC(res); return 0; } @@ -41139,61 +42256,69 @@ static int mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp, mp_set(b, 1); ret = mp_lcm(a, a, r); if (ret != MP_VAL) - return -13090; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(a, b, r); if (ret != MP_VAL) - return -13091; + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(b, a, r); if (ret != MP_VAL) - return -13092; + return WC_TEST_RET_ENC_EC(ret); for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) { mp_set(a, kat[i][0]); mp_set(b, kat[i][1]); ret = mp_lcm(a, b, r); if (ret != MP_OKAY) - return -13093; + return WC_TEST_RET_ENC_EC(ret); mp_set(exp, kat[i][2]); - if (mp_cmp(r, exp) != MP_EQ) - return -13094; + ret = mp_cmp(r, exp); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } (void)rng; #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \ !defined(WC_NO_RNG) - if (mp_rand_prime(a, 20, rng, NULL) != MP_OKAY) - return -13095; - if (mp_rand_prime(b, 20, rng, NULL) != MP_OKAY) - return -13096; - if (mp_mul(a, b, exp) != MP_OKAY) - return -13097; + ret = mp_rand_prime(a, 20, rng, NULL); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_rand_prime(b, 20, rng, NULL); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_mul(a, b, exp); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); ret = mp_lcm(a, b, r); if (ret != MP_OKAY) - return -13098; - if (mp_cmp(r, exp) != MP_EQ) - return -13099; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, exp); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; ret = mp_lcm(b, a, r); if (ret != MP_OKAY) - return -13100; - if (mp_cmp(r, exp) != MP_EQ) - return -13101; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, exp); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; #endif mp_set(a, 11); mp_zero(b); ret = mp_gcd(a, b, r); if (ret != MP_OKAY) - return -13102; - if (mp_cmp_d(r, 11) != MP_EQ) - return -13103; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_d(r, 11); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(b, a, r); if (ret != MP_OKAY) - return -13104; - if (mp_cmp_d(r, 11) != MP_EQ) - return -13105; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_d(r, 11); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_EC(ret); ret = mp_gcd(b, b, r); if (ret != MP_VAL) - return -13106; + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -41210,46 +42335,48 @@ static int mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng) mp_set(a, 10); ret = mp_mod_2d(a, 0, r); if (ret != MP_OKAY) - return -13110; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13111; + return WC_TEST_RET_ENC_NC; ret = mp_mod_2d(a, 1, r); if (ret != MP_OKAY) - return -13112; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13113; + return WC_TEST_RET_ENC_NC; ret = mp_mod_2d(a, 2, r); if (ret != MP_OKAY) - return -13114; - if (mp_cmp_d(r, 2)) - return -13115; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_d(r, 2); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); for (i = 2; i < 20; i++) { ret = randNum(a, i, rng, NULL); if (ret != 0) - return -13116; + return WC_TEST_RET_ENC_EC(ret); for (j = 1; j <= mp_count_bits(a); j++) { /* Get top part */ ret = mp_div_2d(a, j, t, NULL); if (ret != 0) - return -13117; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_2d(t, j, t); if (ret != 0) - return -13118; + return WC_TEST_RET_ENC_EC(ret); /* Get bottom part */ ret = mp_mod_2d(a, j, r); if (ret != 0) - return -13119; + return WC_TEST_RET_ENC_EC(ret); /* Reassemble */ ret = mp_add(t, r, r); if (ret != 0) - return -13120; - if (mp_cmp(a, r) != MP_EQ) - return -13121; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(a, r); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } @@ -41258,21 +42385,22 @@ static int mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng) for (j = 0; j < 20; j++) { ret = randNum(a, 2, rng, NULL); if (ret != 0) - return -13122; + return WC_TEST_RET_ENC_EC(ret); a->sign = MP_NEG; for (i = 1; i < DIGIT_BIT * 3 + 1; i++) { ret = mp_mod_2d(a, i, r); if (ret != 0) - return -13124; + return WC_TEST_RET_ENC_EC(ret); mp_zero(t); ret = mp_set_bit(t, i); if (ret != 0) - return -13125; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(a, t, t); if (ret != 0) - return -13126; - if (mp_cmp(r, t) != MP_EQ) - return -13127; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp(r, t); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } } #endif @@ -41281,29 +42409,52 @@ static int mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng) } #endif -#if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \ - (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN)) -static int mp_test_mod_d(mp_int* a) +#if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \ + (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) +static int mp_test_mod_d(mp_int* a, WC_RNG* rng) { int ret; mp_digit r; +#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH) + mp_digit rem; + int i; +#endif - if (mp_set(a, 1) != MP_OKAY) - return -13130; + (void)rng; + + ret = mp_set(a, 1); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_d(a, 0, &r); if (ret != MP_VAL) - return -13131; + return WC_TEST_RET_ENC_EC(ret); mp_zero(a); ret = mp_mod_d(a, 1, &r); if (ret != MP_OKAY) - return -13132; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_d(a, 3, &r); if (ret != MP_OKAY) - return -13133; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod_d(a, 5, &r); if (ret != MP_OKAY) - return -13134; + return WC_TEST_RET_ENC_EC(ret); + +#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH) + for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) { + ret = randNum(a, i, rng, NULL); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_mod_d(a, 3, &r); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + ret = mp_div_d(a, 3, a, &rem); + if (ret != MP_OKAY) + return WC_TEST_RET_ENC_EC(ret); + if (r != rem) + return WC_TEST_RET_ENC_NC; + } +#endif return 0; } @@ -41318,76 +42469,77 @@ static int mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2, for (i = 1; i < 16; i++) { ret = randNum(a, i, rng, NULL); if (ret != 0) - return -13140; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, a, r1); if (ret != 0) - return -13141; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqr(a, r2); if (ret != 0) - return -13142; + return WC_TEST_RET_ENC_EC(ret); - if (mp_cmp(r1, r2) != MP_EQ) - return -13143; + ret = mp_cmp(r1, r2); + if (ret != MP_EQ) + return WC_TEST_RET_ENC_NC; } ret = mp_set(b, 0); if (ret != MP_OKAY) - return -13144; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, b, r1); if (ret != MP_OKAY) - return -13145; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r1)) - return -13146; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sqr(b, r1); if (ret != MP_OKAY) - return -13147; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r1)) - return -13148; + return WC_TEST_RET_ENC_NC; #ifdef WOLFSSL_SP_MATH_ALL ret = mp_set(a, 1); if (ret != MP_OKAY) - return -13149; + return WC_TEST_RET_ENC_EC(ret); i = (SP_INT_DIGITS / 2) + 1; ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a); if (ret != MP_OKAY) - return -13150; + return WC_TEST_RET_ENC_EC(ret); ret = mp_set(b, 1); if (ret != MP_OKAY) - return -13151; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b); if (ret != MP_OKAY) - return -13152; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, b, r1); if (ret != MP_OKAY) - return -13153; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mul(a, a, r1); if (ret == MP_OKAY) - return -13154; + return WC_TEST_RET_ENC_NC; ret = mp_sqr(a, r1); if (ret == MP_OKAY) - return -13155; + return WC_TEST_RET_ENC_NC; ret = mp_sqr(b, r1); if (ret != MP_OKAY) - return -13156; + return WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ (defined(HAVE_ECC) && defined(FP_ECC)) ret = mp_mulmod(a, b, b, r1); if (ret != MP_OKAY) - return -13157; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mulmod(a, a, b, r1); if (ret == MP_OKAY) - return -13158; + return WC_TEST_RET_ENC_NC; #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC)) ret = mp_sqrmod(a, b, r1); if (ret == MP_OKAY) - return -13159; + return WC_TEST_RET_ENC_NC; ret = mp_sqrmod(b, a, r1); if (ret != MP_OKAY) - return -13160; + return WC_TEST_RET_ENC_EC(ret); #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */ #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */ #endif /* WOLFSSL_SP_MATH_ALL */ @@ -41405,46 +42557,47 @@ static int mp_test_invmod(mp_int* a, mp_int* m, mp_int* r) mp_set(m, 1); ret = mp_invmod(a, m, r); if (ret != MP_VAL) - return -13170; + return WC_TEST_RET_ENC_EC(ret); ret = mp_invmod(m, a, r); if (ret != MP_VAL) - return -13171; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 2); mp_set(m, 4); ret = mp_invmod(a, m, r); if (ret != MP_VAL) - return -13172; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 3); mp_set(m, 6); ret = mp_invmod(a, m, r); if (ret != MP_VAL) - return -13181; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 5*9); mp_set(m, 6*9); ret = mp_invmod(a, m, r); if (ret != MP_VAL) - return -13182; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); mp_set(m, 4); ret = mp_invmod(a, m, r); if (ret != MP_OKAY) - return -13173; + return WC_TEST_RET_ENC_EC(ret); if (!mp_isone(r)) - return -13174; + return WC_TEST_RET_ENC_NC; mp_set(a, 3); mp_set(m, 4); ret = mp_invmod(a, m, r); if (ret != MP_OKAY) - return -13175; - if (mp_cmp_d(r, 3)) - return -13176; + return WC_TEST_RET_ENC_EC(ret); + ret = mp_cmp_d(r, 3); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 3); mp_set(m, 5); ret = mp_invmod(a, m, r); if (ret != MP_OKAY) - return -13177; + return WC_TEST_RET_ENC_EC(ret); #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) /* Maximum 'a' */ @@ -41456,20 +42609,20 @@ static int mp_test_invmod(mp_int* a, mp_int* m, mp_int* r) mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE); ret = mp_invmod(a, m, r); if (ret != MP_VAL) - return -13178; + return WC_TEST_RET_ENC_EC(ret); /* Maximum modulus - even. */ mp_set(m, 0); mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1); ret = mp_invmod(a, m, r); if (ret != MP_OKAY) - return -13179; + return WC_TEST_RET_ENC_EC(ret); #endif #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE) mp_read_radix(a, "-3", 16); ret = mp_invmod(a, m, r); if (ret != MP_OKAY) - return -13180; + return WC_TEST_RET_ENC_EC(ret); #endif #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC) @@ -41477,28 +42630,28 @@ static int mp_test_invmod(mp_int* a, mp_int* m, mp_int* r) mp_set(m, 3); ret = mp_invmod_mont_ct(a, m, r, 1); if (ret != MP_VAL) - return -13190; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); mp_set(m, 0); ret = mp_invmod_mont_ct(a, m, r, 1); if (ret != MP_VAL) - return -13191; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); mp_set(m, 1); ret = mp_invmod_mont_ct(a, m, r, 1); if (ret != MP_VAL) - return -13192; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); mp_set(m, 2); ret = mp_invmod_mont_ct(a, m, r, 1); if (ret != MP_VAL) - return -13193; + return WC_TEST_RET_ENC_EC(ret); mp_set(a, 1); mp_set(m, 3); ret = mp_invmod_mont_ct(a, m, r, 1); if (ret != MP_OKAY) - return -13194; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -41516,10 +42669,10 @@ static int mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r) mp_set(m, 0x0); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_VAL) - return -13190; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_VAL) - return -13191; + return WC_TEST_RET_ENC_EC(ret); mp_set(b, 0x2); @@ -41527,66 +42680,66 @@ static int mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r) mp_set(m, 0x1); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13192; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13193; + return WC_TEST_RET_ENC_NC; ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13194; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13195; + return WC_TEST_RET_ENC_NC; mp_set(b, 0x2); mp_set(e, 0x0); mp_set(m, 0x7); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13196; + return WC_TEST_RET_ENC_EC(ret); if (!mp_isone(r)) - return -13197; + return WC_TEST_RET_ENC_NC; ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13198; + return WC_TEST_RET_ENC_EC(ret); if (!mp_isone(r)) - return -13199; + return WC_TEST_RET_ENC_NC; mp_set(b, 0x0); mp_set(e, 0x3); mp_set(m, 0x7); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13200; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13201; + return WC_TEST_RET_ENC_NC; ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13202; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13203; + return WC_TEST_RET_ENC_NC; mp_set(b, 0x10); mp_set(e, 0x3); mp_set(m, 0x7); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13204; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13205; + return WC_TEST_RET_ENC_EC(ret); mp_set(b, 0x7); mp_set(e, 0x3); mp_set(m, 0x7); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13206; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13207; + return WC_TEST_RET_ENC_NC; ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13208; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13209; + return WC_TEST_RET_ENC_NC; #ifndef WOLFSSL_SP_MATH mp_set(b, 0x01); @@ -41596,14 +42749,14 @@ static int mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r) mp_copy(b, m); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13210; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13211; + return WC_TEST_RET_ENC_NC; ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13212; + return WC_TEST_RET_ENC_EC(ret); if (!mp_iszero(r)) - return -13213; + return WC_TEST_RET_ENC_NC; #endif mp_set(b, 0x2); @@ -41611,10 +42764,10 @@ static int mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r) mp_set(m, 0x7); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_OKAY) - return -13214; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_OKAY) - return -13215; + return WC_TEST_RET_ENC_EC(ret); #ifdef WOLFSSL_SP_MATH_ALL mp_set(b, 0x2); @@ -41624,10 +42777,10 @@ static int mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r) mp_add_d(m, 0x01, m); ret = mp_exptmod_ex(b, e, 1, m, r); if (ret != MP_VAL) - return -13216; + return WC_TEST_RET_ENC_EC(ret); ret = mp_exptmod_nct(b, e, m, r); if (ret != MP_VAL) - return -13217; + return WC_TEST_RET_ENC_EC(ret); #endif return 0; @@ -41671,50 +42824,50 @@ static int mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng) mp_zero(m); ret = mp_set_bit(m, exp[i]); if (ret != MP_OKAY) - return -13220; + return WC_TEST_RET_ENC_EC(ret); ret = mp_sub_d(m, sub[i], m); if (ret != MP_OKAY) - return -13221; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_setup(m, &mp); if (ret != MP_OKAY) - return -13222; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_calc_normalization(n, m); if (ret != MP_OKAY) - return -13223; + return WC_TEST_RET_ENC_EC(ret); for (j = 0; j < 10; j++) { ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL); if (ret != 0) - return -13224; + return WC_TEST_RET_ENC_EC(ret); ret = mp_mod(a, m, a); if (ret != 0) - return -13225; + return WC_TEST_RET_ENC_EC(ret); /* r = a * a */ ret = mp_sqrmod(a, m, r); if (ret != MP_OKAY) - return -13226; + return WC_TEST_RET_ENC_EC(ret); /* Convert to Montgomery form = a*n */ ret = mp_mulmod(a, n, m, a); if (ret != MP_OKAY) - return -13227; + return WC_TEST_RET_ENC_EC(ret); /* a*a mod m == ((a*n) * (a*n)) / n / n */ ret = mp_sqr(a, a); if (ret != MP_OKAY) - return -13228; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_reduce(a, m, mp); if (ret != MP_OKAY) - return -13229; + return WC_TEST_RET_ENC_EC(ret); ret = mp_montgomery_reduce(a, m, mp); if (ret != MP_OKAY) - return -13230; + return WC_TEST_RET_ENC_EC(ret); if (mp_cmp(a, r) != MP_EQ) - return -13231; + return WC_TEST_RET_ENC_NC; } } @@ -41736,11 +42889,11 @@ static int mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng) ret = mp_montgomery_reduce(a, m, mp); if (ret != MP_OKAY) - return -13240; + return WC_TEST_RET_ENC_EC(ret); /* Result is m or 0 if reduced to range of modulus. */ if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES) - return -13241; + return WC_TEST_RET_ENC_NC; } return 0; @@ -41750,26 +42903,48 @@ static int mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng) WOLFSSL_TEST_SUBROUTINE int mp_test(void) { WC_RNG rng; + int rng_inited = 0; int ret; #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) int i, j; #ifndef WOLFSSL_SP_MATH int k; #endif - mp_digit d; + mp_digit d = 0; +#endif +#ifdef WOLFSSL_SMALL_STACK + mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER), + *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER), + *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER), + *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER), + *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER); + if ((a == NULL) || + (b == NULL) || + (r1 == NULL) || + (r2 == NULL) || + (p == NULL)) + { + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done); + } +#else + mp_int a[1], b[1], r1[1], r2[1], p[1]; #endif - mp_int a, b, r1, r2, p; - ret = mp_init_multi(&a, &b, &r1, &r2, NULL, NULL); + ret = mp_init_multi(a, b, r1, r2, NULL, NULL); if (ret != 0) - return -13300; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifdef WOLFSSL_SP_MATH_ALL - mp_init_copy(&p, &a); + mp_init_copy(p, a); #else - ret = mp_init(&p); + ret = mp_init(p); if (ret != 0) - return -13301; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #endif #ifndef HAVE_FIPS @@ -41779,252 +42954,279 @@ WOLFSSL_TEST_SUBROUTINE int mp_test(void) #endif if (ret != 0) goto done; + rng_inited = 1; #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) - mp_set_int(&a, 0); - if (a.used != 0 || a.dp[0] != 0) - return -13302; + mp_set_int(a, 0); + if (a->used != 0 || a->dp[0] != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) { for (i = 0; i < 4 * j; i++) { /* New values to use. */ - ret = randNum(&p, j, &rng, NULL); + ret = randNum(p, j, &rng, NULL); if (ret != 0) - return -13303; - ret = randNum(&a, j, &rng, NULL); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = randNum(a, j, &rng, NULL); if (ret != 0) - return -13304; - ret = randNum(&b, j, &rng, NULL); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = randNum(b, j, &rng, NULL); if (ret != 0) - return -13305; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d)); if (ret != 0) - return -13306; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); d &= MP_MASK; #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \ (defined(ECC_SHAMIR) || defined(FP_ECC))) /* Ensure sqrmod produce same result as mulmod. */ - ret = mp_sqrmod(&a, &p, &r1); + ret = mp_sqrmod(a, p, r1); if (ret != 0) - return -13307; - ret = mp_mulmod(&a, &a, &p, &r2); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = mp_mulmod(a, a, p, r2); if (ret != 0) - return -13308; - if (mp_cmp(&r1, &r2) != 0) - return -13309; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (mp_cmp(r1, r2) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \ !defined(WOLFSSL_SP_INT_NEGATIVE)) - ret = mp_addmod(&a, &b, &p, &r1); + ret = mp_addmod(a, b, p, r1); if (ret != 0) - return -13310; - ret = mp_submod(&r1, &b, &p, &r2); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = mp_submod(r1, b, p, r2); if (ret != 0) - return -13311; - ret = mp_mod(&a, &p, &r1); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = mp_mod(a, p, r1); if (ret != 0) - return -13312; - if (mp_cmp(&r1, &r2) != MP_EQ) - return -13313; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (mp_cmp(r1, r2) != MP_EQ) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #else /* Ensure add with mod produce same result as sub with mod. */ - ret = mp_addmod(&a, &b, &p, &r1); + ret = mp_addmod(a, b, p, r1); if (ret != 0) - return -13314; - b.sign ^= 1; - ret = mp_submod(&a, &b, &p, &r2); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + b->sign ^= 1; + ret = mp_submod(a, b, p, r2); if (ret != 0) - return -13315; - if (mp_cmp(&r1, &r2) != 0) - return -13316; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (mp_cmp(r1, r2) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif #endif /* Ensure add digit produce same result as sub digit. */ - ret = mp_add_d(&a, d, &r1); + ret = mp_add_d(a, d, r1); if (ret != 0) - return -13317; - ret = mp_sub_d(&r1, d, &r2); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + ret = mp_sub_d(r1, d, r2); if (ret != 0) - return -13318; - if (mp_cmp(&a, &r2) != 0) - return -13319; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (mp_cmp(a, r2) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); /* Invert - if p is even it will use the slow impl. * - if p and a are even it will fail. */ - ret = mp_invmod(&a, &p, &r1); + ret = mp_invmod(a, p, r1); if (ret != 0 && ret != MP_VAL) - return -13320; - ret = 0; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); #ifndef WOLFSSL_SP_MATH /* Shift up and down number all bits in a digit. */ for (k = 0; k < DIGIT_BIT; k++) { - mp_mul_2d(&a, k, &r1); - mp_div_2d(&r1, k, &r2, &p); - if (mp_cmp(&a, &r2) != 0) - return -13321; - if (!mp_iszero(&p)) - return -13322; - mp_rshb(&r1, k); - if (mp_cmp(&a, &r1) != 0) - return -13323; + mp_mul_2d(a, k, r1); + mp_div_2d(r1, k, r2, p); + if (mp_cmp(a, r2) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); + if (!mp_iszero(p)) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); + mp_rshb(r1, k); + if (mp_cmp(a, r1) != 0) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif } } /* Test adding and subtracting zero from zero. */ - mp_zero(&a); - ret = mp_add_d(&a, 0, &r1); + mp_zero(a); + ret = mp_add_d(a, 0, r1); if (ret != 0) - return -13329; - if (!mp_iszero(&r1)) { - return -13330; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (!mp_iszero(r1)) { + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } - ret = mp_sub_d(&a, 0, &r2); + ret = mp_sub_d(a, 0, r2); if (ret != 0) - return -13331; - if (!mp_iszero(&r2)) { - return -13332; + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done); + if (!mp_iszero(r2)) { + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #if DIGIT_BIT >= 32 /* Check that setting a 32-bit digit works. */ d &= 0xffffffffU; - mp_set_int(&a, d); - if (a.used != 1 || a.dp[0] != d) - return -13324; + mp_set_int(a, d); + if (a->used != 1 || a->dp[0] != d) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); #endif /* Check setting a bit and testing a bit works. */ for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) { - mp_zero(&a); - mp_set_bit(&a, i); - if (!mp_is_bit_set(&a, i)) - return -13325; + mp_zero(a); + mp_set_bit(a, i); + if (!mp_is_bit_set(a, i)) + ERROR_OUT(WC_TEST_RET_ENC_NC, done); } #endif #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY) - mp_zero(&a); - i = mp_cnt_lsb(&a); + mp_zero(a); + i = mp_cnt_lsb(a); if (i != 0) - return -13326; - mp_set(&a, 1); - i = mp_cnt_lsb(&a); + ERROR_OUT(WC_TEST_RET_ENC_I(i), done); + mp_set(a, 1); + i = mp_cnt_lsb(a); if (i != 0) - return -13327; + ERROR_OUT(WC_TEST_RET_ENC_I(i), done); - mp_set(&a, 32); - i = mp_cnt_lsb(&a); + mp_set(a, 32); + i = mp_cnt_lsb(a); if (i != 5) - return -13328; + ERROR_OUT(WC_TEST_RET_ENC_I(i), done); - mp_zero(&a); - mp_set_bit(&a, 129); - i = mp_cnt_lsb(&a); + mp_zero(a); + mp_set_bit(a, 129); + i = mp_cnt_lsb(a); if (i != 129) - return -13328; + ERROR_OUT(WC_TEST_RET_ENC_I(i), done); #endif #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - if ((ret = mp_test_param(&a, &b, &r1, &rng)) != 0) - return ret; + if ((ret = mp_test_param(a, b, r1, &rng)) != 0) + goto done; #endif #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH) - if ((ret = mp_test_div_3(&a, &r1, &rng)) != 0) - return ret; + if ((ret = mp_test_div_3(a, r1, &rng)) != 0) + goto done; #endif #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \ !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \ (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \ (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY))) - if ((ret = mp_test_radix_10(&a, &r1, &rng)) != 0) - return ret; + if ((ret = mp_test_radix_10(a, r1, &rng)) != 0) + goto done; #endif #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \ defined(HAVE_ECC)) - if ((ret = mp_test_radix_16(&a, &r1, &rng)) != 0) - return ret; + if ((ret = mp_test_radix_16(a, r1, &rng)) != 0) + goto done; #endif - if ((ret = mp_test_shift(&a, &r1, &rng)) != 0) - return ret; - if ((ret = mp_test_add_sub_d(&a, &r1)) != 0) - return ret; - if ((ret = mp_test_read_to_bin(&a)) != 0) - return ret; + if ((ret = mp_test_shift(a, r1, &rng)) != 0) + goto done; + if ((ret = mp_test_add_sub_d(a, r1)) != 0) + goto done; + if ((ret = mp_test_read_to_bin(a)) != 0) + goto done; #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - if ((ret = mp_test_set_int(&a)) != 0) - return ret; + if ((ret = mp_test_set_int(a)) != 0) + goto done; #endif - if ((ret = mp_test_cmp(&a, &r1)) != 0) - return ret; + if ((ret = mp_test_cmp(a, r1)) != 0) + goto done; #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY) - if ((ret = mp_test_shbd(&a, &b, &rng)) != 0) - return ret; + if ((ret = mp_test_shbd(a, b, &rng)) != 0) + goto done; #endif #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - if ((ret = mp_test_set_is_bit(&a)) != 0) - return ret; + if ((ret = mp_test_set_is_bit(a)) != 0) + goto done; #endif #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) - if ((ret = mp_test_div(&a, &b, &r1, &r2, &rng)) != 0) - return ret; + if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0) + goto done; #endif #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \ !defined(WC_NO_RNG) - if ((ret = mp_test_prime(&a, &rng)) != 0) - return ret; + if ((ret = mp_test_prime(a, &rng)) != 0) + goto done; #endif #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING) - if ((ret = mp_test_lcm_gcd(&a, &b, &r1, &r2, &rng)) != 0) - return ret; + if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0) + goto done; #endif #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \ defined(WOLFSSL_SP_MATH_ALL) - if ((ret = mp_test_mod_2d(&a, &r1, &p, &rng)) != 0) - return ret; + if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0) + goto done; #endif -#if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \ - (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN)) - if ((ret = mp_test_mod_d(&a)) != 0) - return ret; +#if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \ + (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) + if ((ret = mp_test_mod_d(a, &rng)) != 0) + goto done; #endif - if ((ret = mp_test_mul_sqr(&a, &b, &r1, &r2, &rng)) != 0) - return ret; + if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0) + goto done; #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \ defined(OPENSSL_EXTRA) - if ((ret = mp_test_invmod(&a, &b, &r1)) != 0) - return ret; + if ((ret = mp_test_invmod(a, b, r1)) != 0) + goto done; #endif #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \ (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA) - if ((ret = mp_test_exptmod(&a, &b, &r1, &r2)) != 0) - return ret; + if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0) + goto done; #endif #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \ defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) - if ((ret = mp_test_mont(&a, &b, &r1, &r2, &rng)) != 0) - return ret; + if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0) + goto done; #endif done: - mp_clear(&p); - mp_clear(&r2); - mp_clear(&r1); - mp_clear(&b); - mp_clear(&a); - wc_FreeRng(&rng); + +#ifdef WOLFSSL_SMALL_STACK + if (p) { + mp_clear(p); + XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } + if (r2) { + mp_clear(r2); + XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } + if (r1) { + mp_clear(r1); + XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } + if (b) { + mp_clear(b); + XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } + if (a) { + mp_clear(a); + XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + } +#else + mp_clear(p); + mp_clear(r2); + mp_clear(r1); + mp_clear(b); + mp_clear(a); +#endif + + if (rng_inited) + wc_FreeRng(&rng); return ret; } -#endif + +#endif /* WOLFSSL_PUBLIC_MP && (WOLFSSL_SP_MATH_ALL || USE_FAST_MATH) */ #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN) @@ -42098,14 +43300,28 @@ static int GenerateNextP(mp_int* p1, mp_int* p2, int k) #endif ret = mp_init(ki); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + if (ret == 0) { ret = mp_set(ki, k); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + if (ret == 0) { ret = mp_sub_d(p1, 1, p2); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + if (ret == 0) { ret = mp_mul(p2, ki, p2); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + if (ret == 0) { ret = mp_add_d(p2, 1, p2); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } mp_clear(ki); #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) @@ -42137,20 +43353,33 @@ static int GenerateP(mp_int* p1, mp_int* p2, mp_int* p3, ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL); if (ret != 0) { - ret = MP_MEM; + ret = WC_TEST_RET_ENC_EC(ret); goto out; } for (i = 0; ret == 0 && i < ecPairsSz; i++) { ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, ecPairs[i].coeffSz); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } /* p1 = 2^exp */ - if (ret == 0) - ret = mp_2expt(y, ecPairs[i].exp); + ret = mp_2expt(y, ecPairs[i].exp); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } /* p1 = p1 * m */ - if (ret == 0) - ret = mp_mul(x, y, x); + ret = mp_mul(x, y, x); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } /* p1 += */ - if (ret == 0) - ret = mp_add(p1, x, p1); + ret = mp_add(p1, x, p1); + if (ret != 0) { + ret = WC_TEST_RET_ENC_EC(ret); + break; + } mp_zero(x); mp_zero(y); } @@ -42204,75 +43433,86 @@ WOLFSSL_TEST_SUBROUTINE int prime_test(void) #endif ret = wc_InitRng(&rng); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + if (ret == 0) { ret = mp_init_multi(n, p1, p2, p3, NULL, NULL); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } if (ret == 0) ret = GenerateP(p1, p2, p3, ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA); - if (ret == 0) + if (ret == 0) { ret = mp_mul(p1, p2, n); - if (ret == 0) + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } + if (ret == 0) { ret = mp_mul(n, p3, n); + if (ret != 0) + ret = WC_TEST_RET_ENC_EC(ret); + } if (ret != 0) - ERROR_OUT(-13400, out); + ERROR_OUT(ret, out); /* Check the old prime test using the number that false positives. * This test result should indicate as not prime. */ ret = mp_prime_is_prime(n, 40, &isPrime); if (ret != 0) - ERROR_OUT(-13401, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (isPrime) - ERROR_OUT(-13402, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* This test result should fail. It should indicate the value as prime. */ ret = mp_prime_is_prime(n, 8, &isPrime); if (ret != 0) - ERROR_OUT(-13403, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (!isPrime) - ERROR_OUT(-13404, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* This test result should indicate the value as not prime. */ ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng); if (ret != 0) - ERROR_OUT(-13405, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (isPrime) - ERROR_OUT(-13406, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime)); if (ret != 0) - ERROR_OUT(-13407, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* This test result should indicate the value as prime. */ ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng); if (ret != 0) - ERROR_OUT(-13408, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (!isPrime) - ERROR_OUT(-13409, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); /* This test result should indicate the value as prime. */ isPrime = -1; ret = mp_prime_is_prime(n, 8, &isPrime); if (ret != 0) - ERROR_OUT(-13410, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (!isPrime) - ERROR_OUT(-13411, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne)); if (ret != 0) - ERROR_OUT(-13412, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); /* This test result should indicate the value as not prime. */ ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng); if (ret != 0) - ERROR_OUT(-13413, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (isPrime) - ERROR_OUT(-13414, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = mp_prime_is_prime(n, 8, &isPrime); if (ret != 0) - ERROR_OUT(-13415, out); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); if (isPrime) - ERROR_OUT(-13416, out); + ERROR_OUT(WC_TEST_RET_ENC_NC, out); ret = 0; @@ -42372,57 +43612,57 @@ WOLFSSL_TEST_SUBROUTINE int berder_test(void) for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) { ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len); if (ret != LENGTH_ONLY_E) - return -13500 - i; + return WC_TEST_RET_ENC_I(i); if (len != testData[i].outSz) - return -13510 - i; + return WC_TEST_RET_ENC_I(i); len = testData[i].outSz; ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len); if (ret != 0) - return -13520 - i; + return WC_TEST_RET_ENC_I(i); if (XMEMCMP(out, testData[i].out, len) != 0) - return -13530 - i; + return WC_TEST_RET_ENC_I(i); for (l = 1; l < testData[i].inSz; l++) { ret = wc_BerToDer(testData[i].in, l, NULL, &len); if (ret != ASN_PARSE_E) - return -13540; + return WC_TEST_RET_ENC_EC(ret); len = testData[i].outSz; ret = wc_BerToDer(testData[i].in, l, out, &len); if (ret != ASN_PARSE_E) - return -13541; + return WC_TEST_RET_ENC_EC(ret); } for (l = 0; l < testData[i].outSz-1; l++) { ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l); if (ret != BUFFER_E) - return -13542; + return WC_TEST_RET_ENC_EC(ret); } } ret = wc_BerToDer(NULL, 4, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -13543; + return WC_TEST_RET_ENC_EC(ret); ret = wc_BerToDer(out, 4, NULL, NULL); if (ret != BAD_FUNC_ARG) - return -13544; + return WC_TEST_RET_ENC_EC(ret); ret = wc_BerToDer(NULL, 4, NULL, &len); if (ret != BAD_FUNC_ARG) - return -13545; + return WC_TEST_RET_ENC_EC(ret); ret = wc_BerToDer(NULL, 4, out, NULL); if (ret != BAD_FUNC_ARG) - return -13546; + return WC_TEST_RET_ENC_EC(ret); ret = wc_BerToDer(out, 4, out, NULL); if (ret != BAD_FUNC_ARG) - return -13547; + return WC_TEST_RET_ENC_EC(ret); ret = wc_BerToDer(NULL, 4, out, &len); if (ret != BAD_FUNC_ARG) - return -13548; + return WC_TEST_RET_ENC_EC(ret); for (l = 1; l < sizeof(good4_out); l++) { len = l; ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len); if (ret != BUFFER_E) - return -13549; + return WC_TEST_RET_ENC_EC(ret); } return 0; @@ -42441,6 +43681,7 @@ static void my_Logging_cb(const int logLevel, const char *const logMessage) WOLFSSL_TEST_SUBROUTINE int logging_test(void) { + int ret; #ifdef DEBUG_WOLFSSL const char* msg = "Testing, testing. 1, 2, 3, 4 ..."; byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; @@ -42450,11 +43691,13 @@ WOLFSSL_TEST_SUBROUTINE int logging_test(void) for (i = 0; i < (int)sizeof(b); i++) b[i] = i; - if (wolfSSL_Debugging_ON() != 0) - return -13600; + ret = wolfSSL_Debugging_ON(); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); - if (wolfSSL_SetLoggingCb(my_Logging_cb) != 0) - return -13601; + ret = wolfSSL_SetLoggingCb(my_Logging_cb); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); WOLFSSL_MSG(msg); WOLFSSL_BUFFER(a, sizeof(a)); @@ -42479,7 +43722,7 @@ WOLFSSL_TEST_SUBROUTINE int logging_test(void) /* check the logs were disabled */ if (i != log_cnt) - return -13602; + return WC_TEST_RET_ENC_NC; /* restore callback and leave logging enabled */ wolfSSL_SetLoggingCb(NULL); @@ -42490,20 +43733,26 @@ WOLFSSL_TEST_SUBROUTINE int logging_test(void) (void)b; #else - if (wolfSSL_Debugging_ON() != NOT_COMPILED_IN) - return -13603; + ret = wolfSSL_Debugging_ON(); + if (ret != NOT_COMPILED_IN) + return WC_TEST_RET_ENC_EC(ret); wolfSSL_Debugging_OFF(); - if (wolfSSL_SetLoggingCb(NULL) != NOT_COMPILED_IN) - return -13604; + ret = wolfSSL_SetLoggingCb(NULL); + if (ret != NOT_COMPILED_IN) + return WC_TEST_RET_ENC_EC(ret); #endif /* DEBUG_WOLFSSL */ return 0; } - +#if defined(__INCLUDE_NUTTX_CONFIG_H) +WOLFSSL_TEST_SUBROUTINE int wolfcrypt_mutex_test(void) +#else WOLFSSL_TEST_SUBROUTINE int mutex_test(void) +#endif { #ifdef WOLFSSL_PTHREADS wolfSSL_Mutex m; + int ret; #endif #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX) #ifndef WOLFSSL_STATIC_MEMORY @@ -42512,41 +43761,49 @@ WOLFSSL_TEST_SUBROUTINE int mutex_test(void) wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex), HEAP_HINT, DYNAMIC_TYPE_MUTEX); if (mm != NULL) { - if (wc_InitMutex(mm) != 0) { + ret = wc_InitMutex(mm); + if (ret != 0) { WOLFSSL_MSG("Init Mutex failed"); XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX); - mm = NULL; + return WC_TEST_RET_ENC_EC(ret); } } #endif if (mm == NULL) - return -13700; + return WC_TEST_RET_ENC_ERRNO; wc_FreeMutex(mm); XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX); #endif /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */ #ifdef WOLFSSL_PTHREADS - if (wc_InitMutex(&m) != 0) - return -13701; - if (wc_LockMutex(&m) != 0) - return -13702; + ret = wc_InitMutex(&m); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_LockMutex(&m); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS) /* trying to free a locked mutex is not portable behavior with pthread */ /* Attempting to destroy a locked mutex results in undefined behavior */ - if (wc_FreeMutex(&m) != BAD_MUTEX_E) - return -13703; + ret = wc_FreeMutex(&m); + if (ret != BAD_MUTEX_E) + return WC_TEST_RET_ENC_EC(ret); #endif - if (wc_UnLockMutex(&m) != 0) - return -13704; - if (wc_FreeMutex(&m) != 0) - return -13705; + ret = wc_UnLockMutex(&m); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_FreeMutex(&m); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS) /* Trying to use a pthread after free'ing is not portable behavior */ - if (wc_LockMutex(&m) != BAD_MUTEX_E) - return -13706; - if (wc_UnLockMutex(&m) != BAD_MUTEX_E) - return -13707; + ret = wc_LockMutex(&m); + if (ret != BAD_MUTEX_E) + return WC_TEST_RET_ENC_EC(ret); + ret = wc_UnLockMutex(&m); + if (ret != BAD_MUTEX_E) + return WC_TEST_RET_ENC_EC(ret); #endif #endif @@ -42631,8 +43888,9 @@ WOLFSSL_TEST_SUBROUTINE int memcb_test(void) wolfSSL_Realloc_cb rc; /* Save existing memory callbacks */ - if (wolfSSL_GetAllocators(&mc, &fc, &rc) != 0) - return -13800; + ret = wolfSSL_GetAllocators(&mc, &fc, &rc); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \ !defined(WOLFSSL_STATIC_MEMORY) @@ -42640,16 +43898,17 @@ WOLFSSL_TEST_SUBROUTINE int memcb_test(void) /* test realloc */ b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (b == NULL) { - ERROR_OUT(-13801, exit_memcb); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb); } XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); b = NULL; /* Use API. */ - if (wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb, + ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb, (wolfSSL_Free_cb)my_Free_cb, - (wolfSSL_Realloc_cb)my_Realloc_cb) != 0) { - ERROR_OUT(-13802, exit_memcb); + (wolfSSL_Realloc_cb)my_Realloc_cb); + if (ret != 0) { + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb); } b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -42666,7 +43925,7 @@ WOLFSSL_TEST_SUBROUTINE int memcb_test(void) #else if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0) #endif - ret = -13803; + ret = WC_TEST_RET_ENC_NC; #endif /* !WOLFSSL_NO_MALLOC */ #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \ @@ -42687,7 +43946,7 @@ exit_memcb: #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */ -#ifdef WOLFSSL_IMX6_CAAM_BLOB +#if defined(WOLFSSL_CAAM_BLOB) WOLFSSL_TEST_SUBROUTINE int blob_test(void) { int ret = 0; @@ -42718,46 +43977,41 @@ WOLFSSL_TEST_SUBROUTINE int blob_test(void) XMEMSET(out, 0, sizeof(out)); outSz = sizeof(blob); ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz); - if (ret != 0) { - ERROR_OUT(-13900, exit_blob); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob); blob[outSz - 2] += 1; ret = wc_caamOpenBlob(blob, outSz, out, &outSz); if (ret == 0) { /* should fail with altered blob */ - ERROR_OUT(-13901, exit_blob); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob); } XMEMSET(blob, 0, sizeof(blob)); outSz = sizeof(blob); ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz); - if (ret != 0) { - ERROR_OUT(-13902, exit_blob); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob); ret = wc_caamOpenBlob(blob, outSz, out, &outSz); - if (ret != 0) { - ERROR_OUT(-13903, exit_blob); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob); if (XMEMCMP(out, iv, sizeof(iv))) { - ERROR_OUT(-13904, exit_blob); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob); } XMEMSET(blob, 0, sizeof(blob)); outSz = sizeof(blob); ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz); - if (ret != 0) { - ERROR_OUT(-13905, exit_blob); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob); ret = wc_caamOpenBlob(blob, outSz, out, &outSz); - if (ret != 0) { - ERROR_OUT(-13906, exit_blob); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob); if (XMEMCMP(out, text, sizeof(text))) { - ERROR_OUT(-13907, exit_blob); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob); } exit_blob: @@ -42778,7 +44032,7 @@ typedef struct { * When CB_ONLY_RSA is enabled, software imple. is not available. * * ctx callback ctx - * returen 0 on success, otherwise return -8000 - -8007 + * returen 0 on success, otherwise return negative */ static int rsa_onlycb_test(myCryptoDevCtx *ctx) { @@ -42834,7 +44088,7 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) - ERROR_OUT(-8000, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb); #endif #ifdef USE_CERT_BUFFERS_1024 @@ -42848,12 +44102,15 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) #elif !defined(NO_FILESYSTEM) file = XFOPEN(clientKey, "rb"); if (!file) { + ret = WC_TEST_RET_ENC_ERRNO; err_sys("can't open ./certs/client-key.der, " - "Please run from wolfSSL home dir", -40); - ERROR_OUT(-8001, exit_onlycb); + "Please run from wolfSSL home dir", ret); + ERROR_OUT(ret, exit_onlycb); } bytes = XFREAD(tmp, 1, FOURK_BUF, file); XFCLOSE(file); + if (bytes == 0) + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb); #endif #ifdef WOLFSSL_KEY_GEN @@ -42864,9 +44121,8 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) */ ctx->exampleVar = 99; ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng); - if (ret != 0) { - ERROR_OUT(-8002, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); /* wc_MakeRsaKey() -> rsa cb -> * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID) * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure) @@ -42874,19 +44130,17 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) ctx->exampleVar = 1; ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng); if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8003, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else /* reset return code */ ret = 0; #endif ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8004, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes); - if (ret != 0) { - ERROR_OUT(-8005, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); sigSz = (word32)wc_RsaEncryptSize(key); @@ -42899,9 +44153,8 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) ctx->exampleVar = 99; ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, sizeof(*key), NULL); - if (ret != 0) { - ERROR_OUT(-8006, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } if (ret == 0) { /* wc_SignatureGenerate() -> rsa cb -> @@ -42913,7 +44166,7 @@ static int rsa_onlycb_test(myCryptoDevCtx *ctx) ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in, inLen, out, &sigSz, key, sizeof(*key), NULL); if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8007, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else /* reset return code */ ret = 0; @@ -42941,7 +44194,7 @@ exit_onlycb: * When CB_ONLY_ECC is enabled, software imple. is not available. * * ctx callback ctx - * returen 0 on success, otherwise return -8008 - -8018 + * returen 0 on success, otherwise return negative */ static int ecc_onlycb_test(myCryptoDevCtx *ctx) { @@ -43020,24 +44273,22 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (key == NULL || pub == NULL) { - ERROR_OUT(-8008, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb); } #endif ret = wc_ecc_init_ex(key, HEAP_HINT, devId); - if (ret != 0) { - ERROR_OUT(-8009, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */ ctx->exampleVar = 99; ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key); - if (ret != 0) { - ERROR_OUT(-8010, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key); if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8011, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else /* reset return code */ ret = 0; @@ -43048,23 +44299,21 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx, key, sizeof_ecc_key_der_256); } - if (ret != 0) { - ERROR_OUT(-8012, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); /* wc_CryptoCb_EccSign cb test, no actual testing */ ctx->exampleVar = 99; if (ret == 0) { ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key); } - if (ret != 0) { - ERROR_OUT(-8013, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; if (ret == 0) { ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key); } if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8014, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else ret = 0; @@ -43074,16 +44323,15 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) if (ret == 0) { ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key); } - if (ret != 0) { - ERROR_OUT(-8015, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; if (ret == 0) { ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key); } if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8016, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else ret = 0; @@ -43097,15 +44345,14 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) if (ret == 0) { ret = wc_ecc_shared_secret(key, pub, out, &outLen); } - if (ret != 0) { - ERROR_OUT(-8017, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; if (ret == 0) { ret = wc_ecc_shared_secret(key, pub, out, &outLen); } if (ret != NO_VALID_DEVID) { - ERROR_OUT(-8018, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else ret = 0; @@ -43118,7 +44365,7 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) privKey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp, sizeof_ecc_clikey_der_256); if (privKey == NULL) { - ERROR_OUT(-8019, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } pkey = (ecc_key*)privKey->ecc->internal; pkey->devId = devId; @@ -43126,7 +44373,7 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) p = ecc_clikeypub_der_256; pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256); if (pubKey == NULL) { - ERROR_OUT(-8020, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } pkey = (ecc_key*)pubKey->ecc->internal; pkey->devId = devId; @@ -43136,18 +44383,18 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) ret = EVP_DigestSignInit(&mdCtx, NULL, EVP_sha256(), NULL, privKey); if (ret != WOLFSSL_SUCCESS) { - ERROR_OUT(-8021, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } ret = EVP_DigestSignUpdate(&mdCtx, testData, (unsigned int)XSTRLEN(testData)); if (ret != WOLFSSL_SUCCESS) { - ERROR_OUT(-8022, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz); if (ret != WOLFSSL_SUCCESS) { - ERROR_OUT(-8023, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } ctx->exampleVar = 99; @@ -43155,23 +44402,21 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) /* just called crypt callback as dummy * EVP_DigestSignFinal returns 0 internally. */ - if (ret != 0) { - ERROR_OUT(-8024, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz); /* just called crypt callback as dummy * EVP_DigestSignFinal returns 0 internally. */ - if (ret != 0) { - ERROR_OUT(-8025, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); /* restore checkSz for verify */ checkSz = 71; ret = EVP_MD_CTX_cleanup(&mdCtx); if (ret != SSL_SUCCESS) { - ERROR_OUT(-8026, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } /* verify */ @@ -43182,34 +44427,33 @@ static int ecc_onlycb_test(myCryptoDevCtx *ctx) ret = EVP_DigestVerifyInit(&mdCtx, NULL, EVP_sha256(), NULL, pubKey); } if (ret != WOLFSSL_SUCCESS) { - ERROR_OUT(-8027, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } if (ret == WOLFSSL_SUCCESS) { ret = EVP_DigestVerifyUpdate(&mdCtx, testData, (unsigned int)XSTRLEN(testData)); } if (ret != WOLFSSL_SUCCESS) { - ERROR_OUT(-8028, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } ctx->exampleVar = 99; ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz); /* just called crypt callback as dummy * EVP_DigestSignFinal returns 0 internally. */ - if (ret != 0) { - ERROR_OUT(-8029, exit_onlycb); - } + if (ret != 0) + ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); ctx->exampleVar = 1; ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz); /* just called crypt callback as dummy * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID. */ if (ret != -1) { - ERROR_OUT(-8030, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } ret = EVP_MD_CTX_cleanup(&mdCtx); if (ret != SSL_SUCCESS) { - ERROR_OUT(-8031, exit_onlycb); + ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb); } else ret = 0; #endif @@ -44004,50 +45248,50 @@ WOLFSSL_TEST_SUBROUTINE int certpiv_test(void) /* Test with Identiv 0x0A, 0x0B and 0x0C markers */ ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv)); if (ret != 0) { - return -14000; + return WC_TEST_RET_ENC_EC(ret); } if (!piv.isIdentiv) { - return -14001; + return WC_TEST_RET_ENC_NC; } if ((piv.cert == NULL) || (piv.certSz != 2)) { - return -14002; + return WC_TEST_RET_ENC_NC; } if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) { - return -14003; + return WC_TEST_RET_ENC_NC; } if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) { - return -14004; + return WC_TEST_RET_ENC_NC; } if (!piv.isX509) { - return -14005; + return WC_TEST_RET_ENC_NC; } if ((piv.nonce == NULL) || (piv.nonceSz != 1)) { - return -14006; + return WC_TEST_RET_ENC_NC; } if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) { - return -14007; + return WC_TEST_RET_ENC_NC; } XMEMSET(&piv, 0, sizeof(piv)); /* Test with NIST PIV format */ ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert)); if (ret != 0) { - return -14010; + return WC_TEST_RET_ENC_EC(ret); } if (piv.isIdentiv) { - return -14011; + return WC_TEST_RET_ENC_NC; } if ((piv.cert == NULL) || (piv.certSz != 2)) { - return -14012; + return WC_TEST_RET_ENC_NC; } if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) { - return -14013; + return WC_TEST_RET_ENC_NC; } if ((piv.compression != 0)) { - return -14014; + return WC_TEST_RET_ENC_NC; } if (!piv.isX509) { - return -14015; + return WC_TEST_RET_ENC_NC; } return ret; @@ -44067,18 +45311,22 @@ static time_t time_cb(time_t* t) WOLFSSL_TEST_SUBROUTINE int time_test(void) { time_t t; + int ret; - if (wc_SetTimeCb(time_cb) != 0) - return -15000; + ret = wc_SetTimeCb(time_cb); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); t = wc_Time(NULL); if (t != 99) - return -15001; - if (wc_GetTime(&t, sizeof(time_t)) != 0) - return -15002; + return WC_TEST_RET_ENC_NC; + ret = wc_GetTime(&t, sizeof(time_t)); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); if (t != 99) - return -15003; - if (wc_SetTimeCb(NULL) != 0) - return -15004; + return WC_TEST_RET_ENC_NC; + ret = wc_SetTimeCb(NULL); + if (ret != 0) + return WC_TEST_RET_ENC_EC(ret); return 0; } @@ -44186,39 +45434,39 @@ WOLFSSL_TEST_SUBROUTINE int aes_siv_test(void) byte computedCiphertext[82]; byte computedPlaintext[82]; byte siv[AES_BLOCK_SIZE]; - int rc = 0; + int ret = 0; for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) { - rc = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz, + ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz, testVectors[i].assoc, testVectors[i].assocSz, testVectors[i].nonce, testVectors[i].nonceSz, testVectors[i].plaintext, testVectors[i].plaintextSz, siv, computedCiphertext); - if (rc != 0) { - return -16000; + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); } - rc = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE); - if (rc != 0) { - return -16001; + ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE); + if (ret != 0) { + return WC_TEST_RET_ENC_NC; } - rc = XMEMCMP(computedCiphertext, testVectors[i].ciphertext, + ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext, testVectors[i].ciphertextSz); - if (rc != 0) { - return -16002; + if (ret != 0) { + return WC_TEST_RET_ENC_NC; } - rc = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz, + ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz, testVectors[i].assoc, testVectors[i].assocSz, testVectors[i].nonce, testVectors[i].nonceSz, computedCiphertext, testVectors[i].plaintextSz, siv, computedPlaintext); - if (rc != 0) { - return -16003; + if (ret != 0) { + return WC_TEST_RET_ENC_EC(ret); } - rc = XMEMCMP(computedPlaintext, testVectors[i].plaintext, + ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext, testVectors[i].plaintextSz); - if (rc != 0) { - return -16004; + if (ret != 0) { + return WC_TEST_RET_ENC_NC; } } @@ -44228,8 +45476,18 @@ WOLFSSL_TEST_SUBROUTINE int aes_siv_test(void) #undef ERROR_OUT +static const int fiducial4 = WC_TEST_RET_LN; + +/* print the fiducial line numbers assigned above, allowing confirmation of + * source code version match when in doubt. + */ +static void print_fiducials(void) { + printf(" [fiducial line numbers: %d %d %d %d]\n", + fiducial1, fiducial2, fiducial3, fiducial4); +} + #else #ifndef NO_MAIN_DRIVER - int main() { return 0; } + int main(void) { return 0; } #endif #endif /* NO_CRYPT_TEST */ diff --git a/recipes-examples/wolfcrypt/wolfcrypttest/test.h b/recipes-examples/wolfcrypt/wolfcrypttest/test.h index c5f92bc..d49f5f0 100644 --- a/recipes-examples/wolfcrypt/wolfcrypttest/test.h +++ b/recipes-examples/wolfcrypt/wolfcrypttest/test.h @@ -1,6 +1,6 @@ /* wolfcrypt/test/test.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2023 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -42,10 +42,54 @@ int wolfcrypt_test_main(int argc, char** argv); int wolf_test_task(void); #endif +#ifndef WC_TEST_RET_HAVE_CUSTOM_MACROS + +#define WC_TEST_RET_TAG_NC 0 +#define WC_TEST_RET_TAG_EC 1 +#define WC_TEST_RET_TAG_ERRNO 2 +#define WC_TEST_RET_TAG_I 3 + +#define WC_TEST_RET_ENC(line, i, tag) \ + (-((line) + ((int)((unsigned)(i) & 0x7ff) * 100000) + ((tag) << 29))) + +#ifndef WC_TEST_RET_LN +#define WC_TEST_RET_LN __LINE__ +#endif + +/* encode no code */ +#define WC_TEST_RET_ENC_NC WC_TEST_RET_ENC(WC_TEST_RET_LN, 0, WC_TEST_RET_TAG_NC) + +/* encode positive integer */ +#define WC_TEST_RET_ENC_I(i) WC_TEST_RET_ENC(WC_TEST_RET_LN, i, WC_TEST_RET_TAG_I) + +/* encode error code (negative integer) */ +#define WC_TEST_RET_ENC_EC(ec) WC_TEST_RET_ENC(WC_TEST_RET_LN, -(ec), WC_TEST_RET_TAG_EC) + +/* encode system/libc error code */ +#if defined(HAVE_ERRNO_H) && !defined(NO_FILESYSTEM) && \ + !defined(NO_STDIO_FILESYSTEM) && !defined(WOLFSSL_USER_IO) +#include +#define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC(WC_TEST_RET_LN, errno, WC_TEST_RET_TAG_ERRNO) +#else +#define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC_NC +#endif + +#define WC_TEST_RET_DEC_TAG(x) ((-(x)) >> 29) + +/* decode line number */ +#define WC_TEST_RET_DEC_LN(x) (((-(x)) & ~(3 << 29)) % 100000) + +/* decode integer or errno */ +#define WC_TEST_RET_DEC_I(x) (((-(x)) & ~(3 << 29)) / 100000) + +/* decode error code */ +#define WC_TEST_RET_DEC_EC(x) (-WC_TEST_RET_DEC_I(x)) + +#endif /* !WC_TEST_RET_HAVE_CUSTOM_MACROS */ + #ifdef __cplusplus } /* extern "C" */ #endif #endif /* WOLFCRYPT_TEST_H */ - diff --git a/recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb b/recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb index 755d139..0ca222f 100644 --- a/recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb +++ b/recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb @@ -8,7 +8,7 @@ SECTION = "x11/applications" FILESEXTRAPATHS_prepend := "${THISDIR}:" LICENSE = "GPLv2" -LIC_FILES_CHKSUM = "file://test.c;beginline=1;endline=20;md5=bd722cec0f7e815c9c724017872b3b73" +LIC_FILES_CHKSUM = "file://test.c;beginline=1;endline=20;md5=61d63fb8b820bae4d85beb53e7acf340" DEPENDS += "wolfssl" diff --git a/recipes-wolfssl/wolfmqtt/files/0001-fix-have-wolfssl-m4-rule.patch b/recipes-wolfssl/wolfmqtt/files/0001-fix-have-wolfssl-m4-rule.patch deleted file mode 100644 index 32f0e59..0000000 --- a/recipes-wolfssl/wolfmqtt/files/0001-fix-have-wolfssl-m4-rule.patch +++ /dev/null @@ -1,13 +0,0 @@ -Index: wolfmqtt-1.1.0/m4/have_wolfssl.m4 -=================================================================== ---- wolfmqtt-1.1.0.orig/m4/have_wolfssl.m4 -+++ wolfmqtt-1.1.0/m4/have_wolfssl.m4 -@@ -7,7 +7,7 @@ - AC_DEFUN([_TAO_SEARCH_LIBWOLFSSL],[ - AC_REQUIRE([AC_LIB_PREFIX]) - -- LDFLAGS="$LDFLAGS -L/usr/local/lib" -+ LDFLAGS="$LDFLAGS" - LIBS="$LIBS -lwolfssl" - - AC_LIB_HAVE_LINKFLAGS(wolfssl,, diff --git a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.14.1.bb b/recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb similarity index 89% rename from recipes-wolfssl/wolfmqtt/wolfmqtt_1.14.1.bb rename to recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb index d7b657f..15f24ae 100644 --- a/recipes-wolfssl/wolfmqtt/wolfmqtt_1.14.1.bb +++ b/recipes-wolfssl/wolfmqtt/wolfmqtt_1.15.1.bb @@ -12,13 +12,13 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=2c1c00f9d3ed9e24fa69b932b7e7aff2" DEPENDS += "wolfssl" -SRC_URI = "git://github.com/wolfssl/wolfMQTT.git;protocol=https;tag=v${PV} \ - file://0001-fix-have-wolfssl-m4-rule.patch" +SRC_URI = "git://github.com/wolfssl/wolfMQTT.git;protocol=https;tag=v${PV}" S = "${WORKDIR}/git" inherit autotools pkgconfig +EXTRA_OECONF = "--with-libwolfssl-prefix=${COMPONENTS_DIR}/${PACKAGE_ARCH}/wolfssl/usr" do_configure_prepend() { (cd ${S}; ./autogen.sh; cd -) } diff --git a/recipes-wolfssl/wolfssh/wolfssh_1.4.11.bb b/recipes-wolfssl/wolfssh/wolfssh_1.4.12.bb similarity index 100% rename from recipes-wolfssl/wolfssh/wolfssh_1.4.11.bb rename to recipes-wolfssl/wolfssh/wolfssh_1.4.12.bb diff --git a/recipes-wolfssl/wolfssl/files/6247.patch b/recipes-wolfssl/wolfssl/files/6247.patch new file mode 100644 index 0000000..a217f23 --- /dev/null +++ b/recipes-wolfssl/wolfssl/files/6247.patch @@ -0,0 +1,38 @@ +From e1730c760c79b7d5ebc7613555ab8e221e7ac521 Mon Sep 17 00:00:00 2001 +From: JacobBarthelmeh +Date: Wed, 29 Mar 2023 14:11:56 -0700 +Subject: [PATCH] check if colrm is available for options.h creation + +--- + configure.ac | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 38afb1f1a0a..81f75b970f0 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -8641,8 +8641,23 @@ echo "extern \"C\" {" >> $OPTION_FILE + echo "#endif" >> $OPTION_FILE + echo "" >> $OPTION_FILE + ++# check for supported command to trim option with ++which colrm &> /dev/null ++RESULT=$? ++if test "$RESULT" = "0"; then ++ TRIM="colrm 3" ++else ++ which cut &> /dev/null ++ RESULT=$? ++ if test "$RESULT" = "0"; then ++ TRIM="cut -c1-2" ++ else ++ AC_MSG_ERROR([Could not find colrm or cut to make options file]) ++ fi ++fi ++ + for option in $CPPFLAGS $AM_CPPFLAGS $CFLAGS $AM_CFLAGS; do +- opt_type=$(echo $option | colrm 3) ++ opt_type=$(echo $option | $TRIM ) + case "$opt_type" in + -D) + RHS_only=$(echo $option | sed 's/^-D//') diff --git a/recipes-wolfssl/wolfssl/wolfssl_5.5.4.bb b/recipes-wolfssl/wolfssl/wolfssl_5.6.0.bb similarity index 96% rename from recipes-wolfssl/wolfssl/wolfssl_5.5.4.bb rename to recipes-wolfssl/wolfssl/wolfssl_5.6.0.bb index 58fc9e7..58f2dc9 100644 --- a/recipes-wolfssl/wolfssl/wolfssl_5.5.4.bb +++ b/recipes-wolfssl/wolfssl/wolfssl_5.6.0.bb @@ -15,6 +15,7 @@ PROVIDES += "wolfssl" RPROVIDES_${PN} = "wolfssl" SRC_URI = "git://github.com/wolfssl/wolfssl.git;nobranch=1;protocol=https;tag=v${PV}-stable;" +SRC_URI += "file://6247.patch" S = "${WORKDIR}/git" diff --git a/recipes-wolfssl/wolftpm/wolftpm_2.6.0.bb b/recipes-wolfssl/wolftpm/wolftpm_2.7.0.bb similarity index 100% rename from recipes-wolfssl/wolftpm/wolftpm_2.6.0.bb rename to recipes-wolfssl/wolftpm/wolftpm_2.7.0.bb