From 3366acc9ce6cb6d0d647af94b84226bd0cdf575b Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 7 Feb 2019 16:11:17 +1000 Subject: [PATCH] Zephyr port of crypto --- src/internal.c | 7 + wolfcrypt/benchmark/benchmark.c | 55 +++++ wolfcrypt/src/logging.c | 2 + wolfcrypt/src/memory.c | 13 ++ wolfcrypt/src/random.c | 36 ++++ wolfcrypt/src/wc_port.c | 136 +++++++++++- wolfcrypt/test/test.c | 357 ++++++++++++++++---------------- wolfssl/internal.h | 4 + wolfssl/ssl.h | 3 +- wolfssl/test.h | 63 +++++- wolfssl/wolfcrypt/settings.h | 23 ++ wolfssl/wolfcrypt/types.h | 6 +- wolfssl/wolfcrypt/wc_port.h | 54 +++++ wolfssl/wolfio.h | 5 + 14 files changed, 579 insertions(+), 185 deletions(-) diff --git a/src/internal.c b/src/internal.c index 16b35131b..63b67805b 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6436,6 +6436,13 @@ ProtocolVersion MakeDTLSv1_2(void) return now; } +#elif defined(WOLFSSL_ZEPHYR) + + word32 LowResTimer(void) + { + return k_uptime_get() / 1000; + } + #else /* Posix style time */ #ifndef USER_TIME diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index a6cb58e72..9fb97c9b2 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -69,6 +69,29 @@ void BSP_Ser_Printf (CPU_CHAR* format, ...); #undef printf #define printf BSP_Ser_Printf +#elif defined(WOLFSSL_ZEPHYR) + #include + + #define BENCH_EMBEDDED + + #define printf printfk + + static int printfk(const char *fmt, ...) + { + int ret; + char line[150]; + va_list ap; + + va_start(ap, fmt); + + ret = vsnprintf(line, sizeof(line), fmt, ap); + line[sizeof(line)-1] = '\0'; + printk("%s", line); + + va_end(ap); + + return ret; + } #else #include #endif @@ -228,6 +251,7 @@ typedef struct bench_alg { int val; } bench_alg; +#ifndef MAIN_NO_ARGS /* All recognized cipher algorithm choosing command line options. */ static const bench_alg bench_cipher_opt[] = { { "-cipher", -1 }, @@ -410,6 +434,7 @@ static const bench_alg bench_other_opt[] = { #endif { NULL, 0} }; +#endif /* MAIN_NO_ARGS */ #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */ @@ -424,7 +449,9 @@ static const bench_alg bench_other_opt[] = { #endif static int lng_index = 0; + #ifndef NO_MAIN_DRIVER +#ifndef MAIN_NO_ARGS static const char* bench_Usage_msg1[][10] = { /* 0 English */ { "-? Help, print this usage\n 0: English, 1: Japanese\n", @@ -453,6 +480,7 @@ static const char* bench_Usage_msg1[][10] = { }, #endif }; +#endif /* MAIN_NO_ARGS */ #endif static const char* bench_result_words1[][4] = { @@ -1707,6 +1735,8 @@ int benchmark_test(void *args) benchmarks_do(NULL); #endif + printf("Benchmark complete\n"); + ret = benchmark_free(); EXIT_TEST(ret); @@ -5252,6 +5282,21 @@ exit_ed_verify: (void)reset; return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err); } +#elif defined(WOLFSSL_ZEPHYR) + + #include + + double current_time(int reset) + { + (void)reset; + + #if defined(CONFIG_ARCH_POSIX) + k_cpu_idle(); + #endif + + return (double)k_uptime_get() / 1000; + } + #else #include @@ -5297,6 +5342,8 @@ void benchmark_configure(int block_size) #ifndef NO_MAIN_DRIVER +#ifndef MAIN_NO_ARGS + #ifndef WOLFSSL_BENCHMARK_ALL /* Display the algorithm string and keep to 80 characters per line. * @@ -5378,13 +5425,18 @@ static int string_matches(const char* arg, const char* str) int len = (int)XSTRLEN(str) + 1; return XSTRNCMP(arg, str, len) == 0; } +#endif /* MAIN_NO_ARGS */ + #ifdef WOLFSSL_ESPIDF int wolf_benchmark_task( ) +#elif defined(MAIN_NO_ARGS) +int main() #else int main(int argc, char** argv) #endif { int ret = 0; +#ifndef MAIN_NO_ARGS int optMatched; #ifdef WOLFSSL_ESPIDF int argc = construct_argv(); @@ -5393,7 +5445,9 @@ int main(int argc, char** argv) #ifndef WOLFSSL_BENCHMARK_ALL int i; #endif +#endif +#ifndef MAIN_NO_ARGS while (argc > 1) { if (string_matches(argv[1], "-?")) { if(--argc>1){ @@ -5499,6 +5553,7 @@ int main(int argc, char** argv) argc--; argv++; } +#endif /* MAIN_NO_ARGS */ #ifdef HAVE_STACK_SIZE ret = StackSizeCheck(NULL, benchmark_test); diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index 481313365..8f83bd5a3 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -259,6 +259,8 @@ static void wolfssl_log(const int logLevel, const char *const logMessage) LOG_DEBUG(&mynewt_log, LOG_MODULE_DEFAULT, "%s\n", logMessage); #elif defined(WOLFSSL_ESPIDF) ESP_LOGI("wolfssl", "%s", logMessage); +#elif defined(WOLFSSL_ZEPHYR) + printk("%s\n", logMessage); #else fprintf(stderr, "%s\n", logMessage); #endif diff --git a/wolfcrypt/src/memory.c b/wolfcrypt/src/memory.c index 0b4f7d96c..72c88a195 100644 --- a/wolfcrypt/src/memory.c +++ b/wolfcrypt/src/memory.c @@ -53,6 +53,19 @@ Possible memory options: * WOLFSSL_HEAP_TEST: Used for internal testing of heap hint */ +#ifdef WOLFSSL_ZEPHYR +#undef realloc +void *z_realloc(void *ptr, size_t size) +{ + if (ptr == NULL) + ptr = malloc(size); + else + ptr = realloc(ptr, size); + + return ptr; +} +#define realloc z_realloc +#endif #ifdef USE_WOLFSSL_MEMORY diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index a5fe6c838..a9477737b 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -148,6 +148,7 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b) #elif defined(MICRIUM) #elif defined(WOLFSSL_NUCLEUS) #elif defined(WOLFSSL_PB) +#elif defined(WOLFSSL_ZEPHYR) #else /* include headers that may be needed to get good seed */ #include @@ -2157,6 +2158,41 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) #define USE_TEST_GENSEED +#elif defined(WOLFSSL_ZEPHYR) + + #include + #ifndef _POSIX_C_SOURCE + #include + #else + #include + #endif + + int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) + { + int ret = 0; + struct device* dev; + + dev = device_get_binding(CONFIG_ENTROPY_NAME); + if (dev != NULL) { + if (entropy_get_entropy(dev, output, sz) != 0) + ret = READ_RAN_E; + } + else { + word32 now; + while (sz > 0) { + word32 len = sizeof(now); + if (sz < len) + len = sz; + now = k_cycle_get_32(); + XMEMCPY(output, &now, sz); + output += len; + sz -= len; + } + } + + return ret; + } + #elif defined(NO_DEV_RANDOM) #error "you need to write an os specific wc_GenerateSeed() here" diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 8ad7390f6..53c28a643 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -298,6 +298,37 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) return 0; } } while (FindNextFileA(ctx->hFind, &ctx->FindFileData)); +#elif defined(WOLFSSL_ZEPHYR) + if (fs_opendir(&ctx->dir, path) != 0) { + WOLFSSL_MSG("opendir path verify locations failed"); + return BAD_PATH_ERROR; + } + ctx->dirp = &ctx->dir; + + while ((fs_readdir(&ctx->dir, &ctx->entry)) != 0) { + dnameLen = (int)XSTRLEN(ctx->entry.name); + + if (pathLen + dnameLen + 2 >= MAX_FILENAME_SZ) { + ret = BAD_PATH_ERROR; + break; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '/'; + + /* Use dnameLen + 1 for GCC 8 warnings of truncating d_name. Because + * of earlier check it is known that dnameLen is less than + * MAX_FILENAME_SZ - (pathLen + 2) so dnameLen +1 will fit */ + XSTRNCPY(ctx->name + pathLen + 1, ctx->entry.name, dnameLen + 1); + if (fs_stat(ctx->name, &ctx->s) != 0) { + WOLFSSL_MSG("stat on name failed"); + ret = BAD_PATH_ERROR; + break; + } else if (ctx->s.type == FS_DIR_ENTRY_FILE) { + if (name) + *name = ctx->name; + return 0; + } + } #else ctx->dir = opendir(path); if (ctx->dir == NULL) { @@ -370,6 +401,31 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) return 0; } } +#elif defined(WOLFSSL_ZEPHYR) + while ((fs_readdir(&ctx->dir, &ctx->entry)) != 0) { + dnameLen = (int)XSTRLEN(ctx->entry.name); + + if (pathLen + dnameLen + 2 >= MAX_FILENAME_SZ) { + ret = BAD_PATH_ERROR; + break; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '/'; + /* Use dnameLen + 1 for GCC 8 warnings of truncating d_name. Because + * of earlier check it is known that dnameLen is less than + * MAX_FILENAME_SZ - (pathLen + 2) so that dnameLen +1 will fit */ + XSTRNCPY(ctx->name + pathLen + 1, ctx->entry.name, dnameLen + 1); + + if (fs_stat(ctx->name, &ctx->s) != 0) { + WOLFSSL_MSG("stat on name failed"); + ret = BAD_PATH_ERROR; + break; + } else if (ctx->s.type == FS_DIR_ENTRY_FILE) { + if (name) + *name = ctx->name; + return 0; + } + } #else while ((ctx->entry = readdir(ctx->dir)) != NULL) { dnameLen = (int)XSTRLEN(ctx->entry->d_name); @@ -413,6 +469,11 @@ void wc_ReadDirClose(ReadDirCtx* ctx) FindClose(ctx->hFind); ctx->hFind = INVALID_HANDLE_VALUE; } +#elif defined(WOLFSSL_ZEPHYR) + if (ctx->dirp) { + fs_closedir(ctx->dirp); + ctx->dirp = NULL; + } #else if (ctx->dir) { closedir(ctx->dir); @@ -423,6 +484,33 @@ void wc_ReadDirClose(ReadDirCtx* ctx) #endif /* !NO_FILESYSTEM && !NO_WOLFSSL_DIR */ +#if !defined(NO_FILESYSTEM) && defined(WOLFSSL_ZEPHYR) +XFILE z_fs_open(const char* filename, const char* perm) +{ + XFILE file; + + file = XMALLOC(sizeof(file), NULL, DYNAMIC_TYPE_FILE); + if (file != NULL) + fs_open(file, filename); + + return file; +} + +int z_fs_close(XFILE file) +{ + int ret; + + if (file == NULL) + return -1; + ret = (fs_close(file) == 0) ? 0 : -1; + + XFREE(file, NULL, DYNAMIC_TYPE_FILE); + + return ret; +} + +#endif /* !NO_FILESYSTEM && !NO_WOLFSSL_DIR */ + wolfSSL_Mutex* wc_InitAndAllocMutex(void) { @@ -1468,6 +1556,37 @@ int wolfSSL_CryptHwMutexUnLock(void) { return BAD_MUTEX_E; } +#elif defined(WOLFSSL_ZEPHYR) + + int wc_InitMutex(wolfSSL_Mutex* m) + { + k_mutex_init(m); + + return 0; + } + + int wc_FreeMutex(wolfSSL_Mutex* m) + { + return 0; + } + + int wc_LockMutex(wolfSSL_Mutex* m) + { + int ret = 0; + + if (k_mutex_lock(m, K_FOREVER) != 0) + ret = BAD_MUTEX_E; + + return ret; + } + + int wc_UnLockMutex(wolfSSL_Mutex* m) + { + k_mutex_unlock(m); + + return 0; + } + #else #warning No mutex handling defined @@ -1639,7 +1758,6 @@ time_t deos_time(time_t* timer) } #endif /* WOLFSSL_DEOS */ - #if defined(MICRIUM) time_t micrium_time(time_t* timer) @@ -1717,6 +1835,22 @@ time_t XTIME(time_t * timer) } #endif /* WOLFSSL_XILINX */ + +#if defined(WOLFSSL_ZEPHYR) + +time_t z_time(time_t * timer) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_REALTIME, &ts) == 0) + if (timer != NULL) + *timer = ts.tv_sec; + + return ts.tv_sec; +} + +#endif /* WOLFSSL_ZEPHYR */ + #endif /* !NO_ASN_TIME */ #ifndef WOLFSSL_LEANPSK diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 21b032f86..af06bc6dc 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -187,6 +187,10 @@ #elif defined(WOLFSSL_ESPIDF) #include #include +#elif defined(WOLFSSL_ZEPHYR) + #include + + #define printf printk #else #include #endif @@ -468,7 +472,7 @@ int wolfcrypt_test(void* args) if (wc_LoadStaticMemory(&HEAP_HINT, gTestMemory, sizeof(gTestMemory), WOLFMEM_GENERAL, 1) != 0) { printf("unable to load static memory"); - exit(EXIT_FAILURE); + return(EXIT_FAILURE); } #endif @@ -1070,6 +1074,8 @@ initDefaultName(); if (args) ((func_args*)args)->return_code = ret; + printf("Test complete\n"); + EXIT_TEST(ret); } @@ -1164,14 +1170,14 @@ static int _SaveDerAndPem(const byte* der, int derSz, { #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) int ret; - FILE* derFile; + XFILE derFile; - derFile = fopen(fileDer, "wb"); + derFile = XFOPEN(fileDer, "wb"); if (!derFile) { return errBase + 0; } - ret = (int)fwrite(der, 1, derSz, derFile); - fclose(derFile); + ret = (int)XFWRITE(der, 1, derSz, derFile); + XFCLOSE(derFile); if (ret != derSz) { return errBase + 1; } @@ -1179,7 +1185,7 @@ static int _SaveDerAndPem(const byte* der, int derSz, if (pem && filePem) { #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) - FILE* pemFile; + XFILE pemFile; #endif #ifdef WOLFSSL_DER_TO_PEM pemSz = wc_DerToPem(der, derSz, pem, pemSz, pemType); @@ -1188,12 +1194,12 @@ static int _SaveDerAndPem(const byte* der, int derSz, } #endif #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) - pemFile = fopen(filePem, "wb"); + pemFile = XFOPEN(filePem, "wb"); if (!pemFile) { return errBase + 3; } - ret = (int)fwrite(pem, 1, pemSz, pemFile); - fclose(pemFile); + ret = (int)XFWRITE(pem, 1, pemSz, pemFile); + XFCLOSE(pemFile); if (ret != pemSz) { return errBase + 4; } @@ -8830,7 +8836,7 @@ int cert_test(void) DecodedCert cert; byte* tmp; size_t bytes; - FILE *file; + XFILE file; int ret; tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); @@ -8839,15 +8845,15 @@ int cert_test(void) /* Certificate with Name Constraints extension. */ #ifdef FREESCALE_MQX - file = fopen(".\\certs\\test\\cert-ext-nc.der", "rb"); + file = XFOPEN(".\\certs\\test\\cert-ext-nc.der", "rb"); #else - file = fopen("./certs/test/cert-ext-nc.der", "rb"); + file = XFOPEN("./certs/test/cert-ext-nc.der", "rb"); #endif if (!file) { ERROR_OUT(-6601, done); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); if (ret != 0) { @@ -8857,15 +8863,15 @@ int cert_test(void) /* Certificate with Inhibit Any Policy extension. */ #ifdef FREESCALE_MQX - file = fopen(".\\certs\\test\\cert-ext-ia.der", "rb"); + file = XFOPEN(".\\certs\\test\\cert-ext-ia.der", "rb"); #else - file = fopen("./certs/test/cert-ext-ia.der", "rb"); + file = XFOPEN("./certs/test/cert-ext-ia.der", "rb"); #endif if (!file) { ERROR_OUT(-6603, done); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); InitDecodedCert(&cert, tmp, (word32)bytes, 0); ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL); if (ret != 0) { @@ -8886,7 +8892,7 @@ int certext_test(void) DecodedCert cert; byte* tmp; size_t bytes; - FILE *file; + XFILE file; int ret; /* created from rsa_test : othercert.der */ @@ -8919,14 +8925,14 @@ int certext_test(void) return -6700; /* load othercert.der (Cert signed by an authority) */ - file = fopen(otherCertDerFile, "rb"); + file = XFOPEN(otherCertDerFile, "rb"); if (!file) { XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); return -6701; } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); InitDecodedCert(&cert, tmp, (word32)bytes, 0); @@ -8966,14 +8972,14 @@ int certext_test(void) #ifdef HAVE_ECC /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */ - file = fopen(certEccDerFile, "rb"); + file = XFOPEN(certEccDerFile, "rb"); if (!file) { XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); return -6710; } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); InitDecodedCert(&cert, tmp, (word32)bytes, 0); @@ -9014,14 +9020,14 @@ int certext_test(void) #endif /* HAVE_ECC */ /* load cert.der (self signed certificate) */ - file = fopen(certDerFile, "rb"); + file = XFOPEN(certDerFile, "rb"); if (!file) { XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); return -6719; } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); InitDecodedCert(&cert, tmp, (word32)bytes, 0); @@ -10074,7 +10080,7 @@ int rsa_no_pad_test(void) word32 plainSz = RSA_TEST_BYTES; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) \ && !defined(NO_FILESYSTEM) - FILE *file; + XFILE file; #endif DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT); DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT); @@ -10108,15 +10114,15 @@ int rsa_no_pad_test(void) #elif defined(USE_CERT_BUFFERS_2048) XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); #elif !defined(NO_FILESYSTEM) - file = fopen(clientKey, "rb"); + file = XFOPEN(clientKey, "rb"); if (!file) { err_sys("can't open ./certs/client-key.der, " "Please run from wolfSSL home dir", -40); ERROR_OUT(-6901, exit_rsa_nopadding); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #else /* No key to use. */ ERROR_OUT(-6902, exit_rsa_nopadding); @@ -10276,7 +10282,7 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) size_t bytes3; word32 idx3 = 0; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) - FILE* file3; + XFILE file3; #endif #ifdef WOLFSSL_TEST_CERT DecodedCert decode; @@ -10397,12 +10403,12 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048); bytes3 = sizeof_ca_cert_der_2048; #else - file3 = fopen(rsaCaCertDerFile, "rb"); + file3 = XFOPEN(rsaCaCertDerFile, "rb"); if (!file3) { ERROR_OUT(-6930, exit_rsa); } - bytes3 = fread(tmp, 1, FOURK_BUF, file3); - fclose(file3); + bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); + XFCLOSE(file3); #endif /* USE_CERT_BUFFERS */ #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \ @@ -10440,13 +10446,13 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048); bytes3 = sizeof_ca_key_der_2048; #else - file3 = fopen(rsaCaKeyFile, "rb"); + file3 = XFOPEN(rsaCaKeyFile, "rb"); if (!file3) { ERROR_OUT(-6935, exit_rsa); } - bytes3 = fread(tmp, 1, FOURK_BUF, file3); - fclose(file3); + bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); + XFCLOSE(file3); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(&caKey, HEAP_HINT); @@ -10575,7 +10581,7 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) word32 idx3 = 0; #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \ || !defined(USE_CERT_BUFFERS_256) - FILE* file3; + XFILE file3; #endif #ifdef WOLFSSL_TEST_CERT DecodedCert decode; @@ -10607,13 +10613,13 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048); bytes3 = sizeof_ca_key_der_2048; #else - file3 = fopen(rsaCaKeyFile, "rb"); + file3 = XFOPEN(rsaCaKeyFile, "rb"); if (!file3) { ERROR_OUT(-6948, exit_rsa); } - bytes3 = fread(tmp, 1, FOURK_BUF, file3); - fclose(file3); + bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); + XFCLOSE(file3); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(&caKey, HEAP_HINT); @@ -10630,13 +10636,13 @@ static int rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp) XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256); bytes3 = sizeof_ecc_key_pub_der_256; #else - file3 = fopen(eccKeyPubFile, "rb"); + file3 = XFOPEN(eccKeyPubFile, "rb"); if (!file3) { ERROR_OUT(-6951, exit_rsa); } - bytes3 = fread(tmp, 1, FOURK_BUF, file3); - fclose(file3); + bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3); + XFCLOSE(file3); #endif ret = wc_ecc_init_ex(&caEccKeyPub, HEAP_HINT, devId); @@ -10870,7 +10876,8 @@ int rsa_test(void) const word32 plainSz = RSA_TEST_BYTES; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) \ && !defined(NO_FILESYSTEM) - FILE *file, *file2; + XFILE file; + XFILE file2; #endif #ifdef WOLFSSL_TEST_CERT DecodedCert cert; @@ -10927,15 +10934,15 @@ int rsa_test(void) #elif defined(USE_CERT_BUFFERS_2048) XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); #elif !defined(NO_FILESYSTEM) - file = fopen(clientKey, "rb"); + file = XFOPEN(clientKey, "rb"); if (!file) { err_sys("can't open ./certs/client-key.der, " "Please run from wolfSSL home dir", -40); ERROR_OUT(-7001, exit_rsa); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #else /* No key to use. */ ERROR_OUT(-7002, exit_rsa); @@ -11447,13 +11454,13 @@ int rsa_test(void) XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048); bytes = (size_t)sizeof_client_cert_der_2048; #elif !defined(NO_FILESYSTEM) - file2 = fopen(clientCert, "rb"); + file2 = XFOPEN(clientCert, "rb"); if (!file2) { ERROR_OUT(-7038, exit_rsa); } - bytes = fread(tmp, 1, FOURK_BUF, file2); - fclose(file2); + bytes = XFREAD(tmp, 1, FOURK_BUF, file2); + XFCLOSE(file2); #else /* No certificate to use. */ ERROR_OUT(-7039, exit_rsa); @@ -11486,15 +11493,15 @@ int rsa_test(void) XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048); bytes = sizeof_client_keypub_der_2048; #else - file = fopen(clientKeyPub, "rb"); + file = XFOPEN(clientKeyPub, "rb"); if (!file) { err_sys("can't open ./certs/client-keyPub.der, " "Please run from wolfSSL home dir", -40); ERROR_OUT(-7041, exit_rsa); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(&keypub, HEAP_HINT); @@ -11531,9 +11538,9 @@ int rsa_test(void) { Cert myCert; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) - FILE* caFile; + XFILE caFile; #endif - FILE* ntruPrivFile; + XFILE ntruPrivFile; int certSz; word32 idx3 = 0; #ifdef WOLFSSL_TEST_CERT @@ -11579,13 +11586,13 @@ int rsa_test(void) XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048); bytes = sizeof_ca_key_der_2048; #else - caFile = fopen(rsaCaKeyFile, "rb"); + caFile = XFOPEN(rsaCaKeyFile, "rb"); if (!caFile) { ERROR_OUT(-7048, exit_rsa); } - bytes = fread(tmp, 1, FOURK_BUF, caFile); - fclose(caFile); + bytes = XFREAD(tmp, 1, FOURK_BUF, caFile); + XFCLOSE(caFile); #endif /* USE_CERT_BUFFERS */ ret = wc_InitRsaKey(&caKey, HEAP_HINT); @@ -11692,12 +11699,12 @@ int rsa_test(void) } #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) - ntruPrivFile = fopen("./ntru-key.raw", "wb"); + ntruPrivFile = XFOPEN("./ntru-key.raw", "wb"); if (!ntruPrivFile) { ERROR_OUT(-7061, exit_rsa); } - ret = (int)fwrite(private_key, 1, private_key_len, ntruPrivFile); - fclose(ntruPrivFile); + ret = (int)XFWRITE(private_key, 1, private_key_len, ntruPrivFile); + XFCLOSE(ntruPrivFile); if (ret != private_key_len) { ERROR_OUT(-7062, exit_rsa); } @@ -12159,12 +12166,12 @@ int dh_test(void) #elif defined(NO_ASN) /* don't use file, no DER parsing */ #elif !defined(NO_FILESYSTEM) - FILE* file = fopen(dhKey, "rb"); + XFILE file = XFOPEN(dhKey, "rb"); if (!file) return -7100; - bytes = (word32) fread(tmp, 1, sizeof(tmp), file); - fclose(file); + bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), file); + XFCLOSE(file); #else /* No DH key to use. */ return -7101; @@ -12326,12 +12333,12 @@ int dsa_test(void) XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048); bytes = sizeof_dsa_key_der_2048; #else - FILE* file = fopen(dsaKey, "rb"); + XFILE file = XFOPEN(dsaKey, "rb"); if (!file) return -7200; - bytes = (word32) fread(tmp, 1, sizeof(tmp), file); - fclose(file); + bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), file); + XFCLOSE(file); #endif /* USE_CERT_BUFFERS */ ret = wc_InitSha_ex(&sha, HEAP_HINT, devId); @@ -14129,7 +14136,8 @@ int openssl_pkey0_test(void) size_t keySz; byte plain[256]; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) - FILE *keyFile, *keypubFile; + XFILE keyFile; + XFILE keypubFile; char cliKey[] = "./certs/client-key.der"; char cliKeypub[] = "./certs/client-keyPub.der"; @@ -14155,7 +14163,7 @@ int openssl_pkey0_test(void) XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048); pubBytes = sizeof_client_keypub_der_2048; #else - keyFile = fopen(cliKey, "rb"); + keyFile = XFOPEN(cliKey, "rb"); if (!keyFile) { XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); @@ -14163,9 +14171,9 @@ int openssl_pkey0_test(void) "Please run from wolfSSL home dir", ERR_BASE_PKEY-3); return ERR_BASE_PKEY-3; } - prvBytes = (int)fread(prvTmp, 1, (int)FOURK_BUFF, keyFile); - fclose(keyFile); - keypubFile = fopen(cliKeypub, "rb"); + prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile); + XFCLOSE(keyFile); + keypubFile = XFOPEN(cliKeypub, "rb"); if (!keypubFile) { XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); @@ -14173,8 +14181,8 @@ int openssl_pkey0_test(void) "Please run from wolfSSL home dir", -4); return ERR_BASE_PKEY-4; } - pubBytes = (int)fread(pubTmp, 1, (int)FOURK_BUFF, keypubFile); - fclose(keypubFile); + pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile); + XFCLOSE(keypubFile); #endif /* USE_CERT_BUFFERS */ prvRsa = wolfSSL_RSA_new(); @@ -14351,9 +14359,9 @@ int openssl_pkey1_test(void) x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048, sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1); #else - FILE* f; + XFILE f; - f = fopen(clientKey, "rb"); + f = XFOPEN(clientKey, "rb"); if (!f) { err_sys("can't open ./certs/client-key.der, " @@ -14361,8 +14369,8 @@ int openssl_pkey1_test(void) return -7700; } - cliKeySz = (long)fread(tmp, 1, FOURK_BUF, f); - fclose(f); + cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f); + XFCLOSE(f); /* using existing wolfSSL api to get public and private key */ x509 = wolfSSL_X509_load_certificate_file(clientCert, SSL_FILETYPE_ASN1); @@ -14495,7 +14503,8 @@ int openssl_evpSig_test(void) int ret, ret1, ret2; #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) - FILE *keyFile, *keypubFile; + XFILE keyFile; + XFILE keypubFile; char cliKey[] = "./certs/client-key.der"; char cliKeypub[] = "./certs/client-keyPub.der"; #endif @@ -14520,7 +14529,7 @@ int openssl_evpSig_test(void) XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048); pubBytes = sizeof_client_keypub_der_2048; #else - keyFile = fopen(cliKey, "rb"); + keyFile = XFOPEN(cliKey, "rb"); if (!keyFile) { XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); @@ -14528,9 +14537,9 @@ int openssl_evpSig_test(void) "Please run from wolfSSL home dir", -40); return ERR_BASE_EVPSIG-3; } - prvBytes = (int)fread(prvTmp, 1, (int)FOURK_BUFF, keyFile); - fclose(keyFile); - keypubFile = fopen(cliKeypub, "rb"); + prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile); + XFCLOSE(keyFile); + keypubFile = XFOPEN(cliKeypub, "rb"); if (!keypubFile) { XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER); @@ -14538,8 +14547,8 @@ int openssl_evpSig_test(void) "Please run from wolfSSL home dir", -41); return ERR_BASE_EVPSIG-4; } - pubBytes = (int)fread(pubTmp, 1, (int)FOURK_BUFF, keypubFile); - fclose(keypubFile); + pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile); + XFCLOSE(keypubFile); #endif /* USE_CERT_BUFFERS */ prvRsa = wolfSSL_RSA_new(); @@ -15467,10 +15476,10 @@ static int ecc_test_cdh_vectors(void) const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b"; /* setup private and public keys */ - ret = wc_ecc_init(&pub_key); + ret = wc_ecc_init_ex(&pub_key, HEAP_HINT, devId); if (ret != 0) return ret; - ret = wc_ecc_init(&priv_key); + ret = wc_ecc_init_ex(&priv_key, HEAP_HINT, devId); if (ret != 0) { wc_ecc_free(&pub_key); goto done; @@ -15528,10 +15537,10 @@ static int ecc_test_make_pub(WC_RNG* rng) int verify = 0; #endif #ifndef USE_CERT_BUFFERS_256 - FILE* file; + XFILE file; #endif - wc_ecc_init(&key); + wc_ecc_init_ex(&key, HEAP_HINT, devId); tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { @@ -15547,13 +15556,13 @@ static int ecc_test_make_pub(WC_RNG* rng) XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256); tmpSz = (size_t)sizeof_ecc_key_der_256; #else - file = fopen(eccKeyDerFile, "rb"); + file = XFOPEN(eccKeyDerFile, "rb"); if (!file) { ERROR_OUT(-8313, done); } - tmpSz = (word32)fread(tmp, 1, FOURK_BUF, file); - fclose(file); + tmpSz = (word32)XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #endif /* USE_CERT_BUFFERS_256 */ /* import private only then test with */ @@ -15582,7 +15591,7 @@ static int ecc_test_make_pub(WC_RNG* rng) /* make private only key */ wc_ecc_free(&key); - wc_ecc_init(&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(-8318, done); @@ -15659,7 +15668,7 @@ static int ecc_test_make_pub(WC_RNG* rng) /* make private only key */ wc_ecc_free(&key); - wc_ecc_init(&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(-8329, done); @@ -15673,7 +15682,7 @@ static int ecc_test_make_pub(WC_RNG* rng) } /* make public key for shared secret */ - wc_ecc_init(&pub); + wc_ecc_init_ex(&pub, HEAP_HINT, devId); ret = wc_ecc_make_key(rng, 32, &pub); #if defined(WOLFSSL_ASYNC_CRYPT) ret = wc_AsyncWait(ret, &pub.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN); @@ -16434,7 +16443,7 @@ static int ecc_exp_imp_test(ecc_key* key) const char d[] = "8c14b793cb19137e323a6d2e2a870bca" "2e7a493ec1153b3a95feb8a4873f8d08"; - wc_ecc_init(&keyImp); + wc_ecc_init_ex(&keyImp, HEAP_HINT, devId); privLen = sizeof(priv); ret = wc_ecc_export_private_only(key, priv, &privLen); @@ -16456,7 +16465,7 @@ static int ecc_exp_imp_test(ecc_key* key) } wc_ecc_free(&keyImp); - wc_ecc_init(&keyImp); + wc_ecc_init_ex(&keyImp, HEAP_HINT, devId); ret = wc_ecc_import_raw_ex(&keyImp, qx, qy, d, ECC_SECP256R1); if (ret != 0) { @@ -16465,7 +16474,7 @@ static int ecc_exp_imp_test(ecc_key* key) } wc_ecc_free(&keyImp); - wc_ecc_init(&keyImp); + wc_ecc_init_ex(&keyImp, HEAP_HINT, devId); curve_id = wc_ecc_get_curve_id(key->idx); if (curve_id < 0) { @@ -16482,7 +16491,7 @@ static int ecc_exp_imp_test(ecc_key* key) } wc_ecc_free(&keyImp); - wc_ecc_init(&keyImp); + wc_ecc_init_ex(&keyImp, HEAP_HINT, devId); /* test export public raw */ pubLenX = pubLenY = 32; @@ -16502,7 +16511,7 @@ static int ecc_exp_imp_test(ecc_key* key) #endif wc_ecc_free(&keyImp); - wc_ecc_init(&keyImp); + wc_ecc_init_ex(&keyImp, HEAP_HINT, devId); /* test export private and public raw */ pubLenX = pubLenY = privLen = 32; @@ -16536,8 +16545,8 @@ static int ecc_mulmod_test(ecc_key* key1) ecc_key key2; ecc_key key3; - wc_ecc_init(&key2); - wc_ecc_init(&key3); + wc_ecc_init_ex(&key2, HEAP_HINT, devId); + wc_ecc_init_ex(&key3, HEAP_HINT, devId); /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */ /* Need base point (Gx,Gy) and parameter A - load them as the public and @@ -16603,7 +16612,7 @@ static int ecc_def_curve_test(WC_RNG *rng) int ret; ecc_key key; - wc_ecc_init(&key); + wc_ecc_init_ex(&key, HEAP_HINT, devId); /* Use API */ ret = wc_ecc_set_flags(NULL, 0); @@ -16687,7 +16696,7 @@ static int ecc_decode_test(void) 0x03, 0x03, 0x00, 0x04, 0x01 }; XMEMSET(&key, 0, sizeof(key)); - wc_ecc_init(&key); + wc_ecc_init_ex(&key, HEAP_HINT, devId); inSz = sizeof(good); ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, &key, inSz); @@ -16912,7 +16921,7 @@ static int ecc_test_cert_gen(WC_RNG* rng) size_t bytes; word32 idx = 0; #ifndef USE_CERT_BUFFERS_256 - FILE* file; + XFILE file; #endif #ifdef WOLFSSL_TEST_CERT DecodedCert decode; @@ -16941,13 +16950,13 @@ static int ecc_test_cert_gen(WC_RNG* rng) XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384); bytes = sizeof_ca_ecc_key_der_384; #else - file = fopen(eccCaKey384File, "rb"); + file = XFOPEN(eccCaKey384File, "rb"); if (!file) { ERROR_OUT(-8519, exit); } - bytes = fread(der, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(der, 1, FOURK_BUF, file); + XFCLOSE(file); (void)eccCaKeyFile; #endif /* USE_CERT_BUFFERS_256 */ #else @@ -16955,12 +16964,12 @@ static int ecc_test_cert_gen(WC_RNG* rng) XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256); bytes = sizeof_ca_ecc_key_der_256; #else - file = fopen(eccCaKeyFile, "rb"); + file = XFOPEN(eccCaKeyFile, "rb"); if (!file) { ERROR_OUT(-8520, exit); } - bytes = fread(der, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(der, 1, FOURK_BUF, file); + XFCLOSE(file); #ifdef ENABLE_ECC384_CERT_GEN_TEST (void)eccCaKey384File; #endif @@ -17845,7 +17854,7 @@ static int ed25519_test_cert(void) int ret; byte* tmp; size_t bytes; - FILE* file; + XFILE file; tmp = XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { @@ -17856,12 +17865,12 @@ static int ed25519_test_cert(void) XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert); bytes = sizeof_ca_ed25519_cert; #elif !defined(NO_FILESYSTEM) - file = fopen(caEd25519Cert, "rb"); + file = XFOPEN(caEd25519Cert, "rb"); if (file == NULL) { ERROR_OUT(-8824, done); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #else /* No certificate to use. */ ERROR_OUT(-8825, done); @@ -17878,12 +17887,12 @@ static int ed25519_test_cert(void) XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert); bytes = sizeof_server_ed25519_cert; #elif !defined(NO_FILESYSTEM) - file = fopen(serverEd25519Cert, "rb"); + file = XFOPEN(serverEd25519Cert, "rb"); if (file == NULL) { ERROR_OUT(-8827, done); } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); + bytes = XFREAD(tmp, 1, FOURK_BUF, file); + XFCLOSE(file); #else /* No certificate to use. */ ERROR_OUT(-8828, done); @@ -19098,8 +19107,8 @@ static int pkcs7_load_certs_keys( byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz) { #ifndef NO_FILESYSTEM - FILE* certFile; - FILE* keyFile; + XFILE certFile; + XFILE keyFile; #endif #ifndef NO_RSA @@ -19166,32 +19175,32 @@ static int pkcs7_load_certs_keys( *rsaCaCertBufSz = sizeof_ca_cert_der_2048; } #else - certFile = fopen(clientCert, "rb"); + certFile = XFOPEN(clientCert, "rb"); if (!certFile) return -9210; - *rsaClientCertBufSz = (word32)fread(rsaClientCertBuf, 1, + *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1, *rsaClientCertBufSz, certFile); - fclose(certFile); + XFCLOSE(certFile); if (rsaServerCertBuf != NULL) { - certFile = fopen(rsaServerCertDerFile, "rb"); + certFile = XFOPEN(rsaServerCertDerFile, "rb"); if (!certFile) return -9211; - *rsaServerCertBufSz = (word32)fread(rsaServerCertBuf, 1, + *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1, *rsaServerCertBufSz, certFile); - fclose(certFile); + XFCLOSE(certFile); } if (rsaCaCertBuf != NULL) { - certFile = fopen(rsaCaCertDerFile, "rb"); + certFile = XFOPEN(rsaCaCertDerFile, "rb"); if (!certFile) return -9212; - *rsaCaCertBufSz = (word32)fread(rsaCaCertBuf, 1, *rsaCaCertBufSz, + *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz, certFile); - fclose(certFile); + XFCLOSE(certFile); } #endif @@ -19244,32 +19253,32 @@ static int pkcs7_load_certs_keys( *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048; } #else - keyFile = fopen(clientKey, "rb"); + keyFile = XFOPEN(clientKey, "rb"); if (!keyFile) return -9219; - *rsaClientPrivKeyBufSz = (word32)fread(rsaClientPrivKeyBuf, 1, + *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1, *rsaClientPrivKeyBufSz, keyFile); - fclose(keyFile); + XFCLOSE(keyFile); if (rsaServerPrivKeyBuf != NULL) { - keyFile = fopen(rsaServerKeyDerFile, "rb"); + keyFile = XFOPEN(rsaServerKeyDerFile, "rb"); if (!keyFile) return -9220; - *rsaServerPrivKeyBufSz = (word32)fread(rsaServerPrivKeyBuf, 1, + *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1, *rsaServerPrivKeyBufSz, keyFile); - fclose(keyFile); + XFCLOSE(keyFile); } if (rsaCaPrivKeyBuf != NULL) { - keyFile = fopen(rsaCaKeyFile, "rb"); + keyFile = XFOPEN(rsaCaKeyFile, "rb"); if (!keyFile) return -9221; - *rsaCaPrivKeyBufSz = (word32)fread(rsaCaPrivKeyBuf, 1, + *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1, *rsaCaPrivKeyBufSz, keyFile); - fclose(keyFile); + XFCLOSE(keyFile); } #endif /* USE_CERT_BUFFERS */ @@ -19285,13 +19294,13 @@ static int pkcs7_load_certs_keys( XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256); *eccClientCertBufSz = sizeof_cliecc_cert_der_256; #else - certFile = fopen(eccClientCert, "rb"); + certFile = XFOPEN(eccClientCert, "rb"); if (!certFile) return -9211; - *eccClientCertBufSz = (word32)fread(eccClientCertBuf, 1, + *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1, *eccClientCertBufSz, certFile); - fclose(certFile); + XFCLOSE(certFile); #endif /* USE_CERT_BUFFERS_256 */ #ifdef USE_CERT_BUFFERS_256 @@ -19301,13 +19310,13 @@ static int pkcs7_load_certs_keys( XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256); *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256; #else - keyFile = fopen(eccClientKey, "rb"); + keyFile = XFOPEN(eccClientKey, "rb"); if (!keyFile) return -9213; - *eccClientPrivKeyBufSz = (word32)fread(eccClientPrivKeyBuf, 1, + *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1, *eccClientPrivKeyBufSz, keyFile); - fclose(keyFile); + XFCLOSE(keyFile); #endif /* USE_CERT_BUFFERS_256 */ #endif /* HAVE_ECC */ @@ -19473,7 +19482,7 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, byte decoded[2048]; PKCS7* pkcs7; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* pkcs7File; + XFILE pkcs7File; #endif const byte data[] = { /* Hello World */ @@ -19827,14 +19836,14 @@ static int pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #endif #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* output pkcs7 envelopedData for external testing */ - pkcs7File = fopen(testVectors[i].outFileName, "wb"); + pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); return -9327; } - ret = (int)fwrite(enveloped, 1, envelopedSz, pkcs7File); - fclose(pkcs7File); + ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File); + XFCLOSE(pkcs7File); if (ret != envelopedSz) { wc_PKCS7_Free(pkcs7); return -9328; @@ -20015,7 +20024,7 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, WC_RNG rng; PKCS7* pkcs7; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* pkcs7File; + XFILE pkcs7File; #endif const byte data[] = { /* Hello World */ @@ -20457,14 +20466,14 @@ static int pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz, #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* output pkcs7 envelopedData for external testing */ - pkcs7File = fopen(testVectors[i].outFileName, "wb"); + pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); return -9388; } - ret = (int)fwrite(enveloped, 1, envelopedSz, pkcs7File); - fclose(pkcs7File); + ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File); + XFCLOSE(pkcs7File); if (ret != envelopedSz) { wc_PKCS7_Free(pkcs7); return -9389; @@ -20608,7 +20617,7 @@ int pkcs7encrypted_test(void) byte encrypted[2048]; byte decoded[2048]; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* pkcs7File; + XFILE pkcs7File; #endif PKCS7Attrib* expectedAttrib; @@ -20819,14 +20828,14 @@ int pkcs7encrypted_test(void) #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* output pkcs7 envelopedData for external testing */ - pkcs7File = fopen(testVectors[i].outFileName, "wb"); + pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); return -9406; } - ret = (int)fwrite(encrypted, encryptedSz, 1, pkcs7File); - fclose(pkcs7File); + ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File); + XFCLOSE(pkcs7File); if (ret > 0) ret = 0; @@ -20860,7 +20869,7 @@ int pkcs7compressed_test(void) byte compressed[2048]; byte decoded[2048]; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* pkcs7File; + XFILE pkcs7File; #endif const byte data[] = { /* Hello World */ @@ -20917,14 +20926,14 @@ int pkcs7compressed_test(void) #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* output pkcs7 compressedData for external testing */ - pkcs7File = fopen(testVectors[i].outFileName, "wb"); + pkcs7File = XFOPEN(testVectors[i].outFileName, "wb"); if (!pkcs7File) { wc_PKCS7_Free(pkcs7); return -9455; } - ret = (int)fwrite(compressed, compressedSz, 1, pkcs7File); - fclose(pkcs7File); + ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File); + XFCLOSE(pkcs7File); if (ret > 0) ret = 0; @@ -20984,7 +20993,7 @@ static int pkcs7signed_run_vectors( WC_RNG rng; PKCS7* pkcs7; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* file; + XFILE file; #endif const byte data[] = { /* Hello World */ @@ -21343,14 +21352,14 @@ static int pkcs7signed_run_vectors( #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* write PKCS#7 to output file for more testing */ - file = fopen(testVectors[i].outFileName, "wb"); + file = XFOPEN(testVectors[i].outFileName, "wb"); if (!file) { XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_PKCS7_Free(pkcs7); return -9523; } - ret = (int)fwrite(out, 1, encodedSz, file); - fclose(file); + ret = (int)XFWRITE(out, 1, encodedSz, file); + XFCLOSE(file); if (ret != (int)encodedSz) { XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_PKCS7_Free(pkcs7); @@ -21430,14 +21439,14 @@ static int pkcs7signed_run_vectors( } #ifdef PKCS7_OUTPUT_TEST_BUNDLES - file = fopen("./pkcs7cert.der", "wb"); + file = XFOPEN("./pkcs7cert.der", "wb"); if (!file) { XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_PKCS7_Free(pkcs7); return -9533; } - ret = (int)fwrite(pkcs7->singleCert, 1, pkcs7->singleCertSz, file); - fclose(file); + ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file); + XFCLOSE(file); #endif /* PKCS7_OUTPUT_TEST_BUNDLES */ wc_PKCS7_Free(pkcs7); @@ -21487,7 +21496,7 @@ static int pkcs7signed_run_SingleShotVectors( WC_RNG rng; PKCS7* pkcs7; #ifdef PKCS7_OUTPUT_TEST_BUNDLES - FILE* file; + XFILE file; #endif const byte data[] = { /* Hello World */ @@ -21834,14 +21843,14 @@ static int pkcs7signed_run_SingleShotVectors( #ifdef PKCS7_OUTPUT_TEST_BUNDLES /* write PKCS#7 to output file for more testing */ - file = fopen(testVectors[i].outFileName, "wb"); + file = XFOPEN(testVectors[i].outFileName, "wb"); if (!file) { XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_PKCS7_Free(pkcs7); return -9562; } - ret = (int)fwrite(out, 1, encodedSz, file); - fclose(file); + ret = (int)XFWRITE(out, 1, encodedSz, file); + XFCLOSE(file); if (ret != (int)encodedSz) { XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); wc_PKCS7_Free(pkcs7); diff --git a/wolfssl/internal.h b/wolfssl/internal.h index d4fbefaba..4b8906fd9 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -169,6 +169,10 @@ void mynewt_ctx_clear(void *ctx); void* mynewt_ctx_new(); #endif +#elif defined(WOLFSSL_ZEPHYR) + #ifndef SINGLE_THREADED + #include + #endif #else #ifndef SINGLE_THREADED #define WOLFSSL_PTHREADS diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 44bc2367b..d5e5f97ce 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -1707,7 +1707,8 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL*, void* key, unsigned int len, #elif !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_IAR_ARM) && \ !defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \ !defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) && \ - !defined(WOLFSSL_CHIBIOS) && !defined(WOLFSSL_CONTIKI) + !defined(WOLFSSL_CHIBIOS) && !defined(WOLFSSL_CONTIKI) && \ + !defined(WOLFSSL_ZEPHYR) #include #endif /* allow writev style writing */ diff --git a/wolfssl/test.h b/wolfssl/test.h index a9af40315..1267d6424 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -93,6 +93,30 @@ #include #include #define SOCKET_T int +#elif defined(WOLFSSL_ZEPHYR) + #include + #include + #include + #define SOCKET_T int + #define SOL_SOCKET 1 + #define SO_REUSEADDR 201 + #define WOLFSSL_USE_GETADDRINFO + + static unsigned long inet_addr(const char *cp) + { + unsigned int a[4]; unsigned long ret; + int i, j; + for (i=0, j=0; i<4; i++) { + a[i] = 0; + while (cp[j] != '.' && cp[j] != '\0') { + a[i] *= 10; + a[i] += cp[j] - '0'; + j++; + } + } + ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ; + return(ret) ; + } #else #include #include @@ -203,6 +227,10 @@ typedef void THREAD_RETURN; typedef Task_Handle THREAD_TYPE; #define WOLFSSL_THREAD + #elif defined(WOLFSSL_ZEPHYR) + typedef unsigned int THREAD_RETURN; + typedef k_tid_t THREAD_TYPE; + #define WOLFSSL_THREAD #else typedef unsigned int THREAD_RETURN; typedef intptr_t THREAD_TYPE; @@ -394,7 +422,10 @@ static const word16 wolfSSLPort = 11111; #define EXIT_FAILURE 1 #endif -#ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST +#if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR) + #ifndef EXIT_SUCCESS + #define EXIT_SUCCESS 0 + #endif #define XEXIT(rc) return rc #define XEXIT_T(rc) return (THREAD_RETURN)rc #else @@ -404,7 +435,7 @@ static const word16 wolfSSLPort = 11111; static WC_INLINE -#ifdef WOLFSSL_FORCE_MALLOC_FAIL_TEST +#if defined(WOLFSSL_FORCE_MALLOC_FAIL_TEST) || defined(WOLFSSL_ZEPHYR) THREAD_RETURN #else WC_NORETURN void @@ -751,6 +782,7 @@ static WC_INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer, #ifndef TEST_IPV6 /* peer could be in human readable form */ if ( ((size_t)peer != INADDR_ANY) && isalpha((int)peer[0])) { + #ifndef WOLFSSL_USE_GETADDRINFO #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) int err; struct hostent* entry = gethostbyname(peer, &err); @@ -767,6 +799,19 @@ static WC_INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer, entry->h_length); useLookup = 1; } + #else + struct zsock_addrinfo hints, *addrInfo; + char portStr[6]; + XSNPRINTF(portStr, sizeof(portStr), "%d", port); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = udp ? SOCK_DGRAM : SOCK_STREAM; + hints.ai_protocol = udp ? IPPROTO_UDP : IPPROTO_TCP; + if (getaddrinfo((char*)peer, portStr, &hints, &addrInfo) == 0) { + XMEMCPY(addr, addrInfo->ai_addr, sizeof(*addr)); + useLookup = 1; + } + #endif else err_sys("no entry for host"); } @@ -862,7 +907,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp) err_sys("setsockopt SO_NOSIGPIPE failed\n"); } #elif defined(WOLFSSL_MDK_ARM) || defined (WOLFSSL_TIRTOS) ||\ - defined(WOLFSSL_KEIL_TCP_NET) + defined(WOLFSSL_KEIL_TCP_NET) || defined(WOLFSSL_ZEPHYR) /* nothing to define */ #else /* no S_NOSIGPIPE */ signal(SIGPIPE, SIG_IGN); @@ -993,7 +1038,7 @@ static WC_INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr, tcp_socket(sockfd, udp, sctp); #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM)\ - && !defined(WOLFSSL_KEIL_TCP_NET) + && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR) { int res, on = 1; socklen_t len = sizeof(on); @@ -1014,7 +1059,8 @@ static WC_INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr, if (listen(*sockfd, SOCK_LISTEN_MAX_QUEUE) != 0) err_sys("tcp listen failed"); } - #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) + #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS) \ + && !defined(WOLFSSL_ZEPHYR) if (*port == 0) { socklen_t len = sizeof(addr); if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) { @@ -1062,7 +1108,7 @@ static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_MDK_ARM) \ - && !defined(WOLFSSL_KEIL_TCP_NET) + && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_ZEPHYR) { int res, on = 1; socklen_t len = sizeof(on); @@ -1186,7 +1232,8 @@ static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd) if (ret == SOCKET_ERROR) err_sys("ioctlsocket failed"); #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \ - || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) + || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \ + || defined(WOLFSSL_ZEPHYR) /* non blocking not supported, for now */ #else int flags = fcntl(*sockfd, F_GETFL, 0); @@ -1357,6 +1404,8 @@ static WC_INLINE unsigned int my_psk_server_tls13_cb(WOLFSSL* ssl, #elif defined(WOLFSSL_TIRTOS) extern double current_time(); +#elif defined(WOLFSSL_ZEPHYR) + extern double current_time(); #else #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_CHIBIOS) diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index e7fa29e85..5c46a4ec2 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -1378,6 +1378,29 @@ extern void uITRON4_free(void *p) ; #endif /*(WOLFSSL_APACHE_MYNEWT)*/ +#ifdef WOLFSSL_ZEPHYR + #include + #include + #include + #include + + #define WOLFSSL_DH_CONST + #define WOLFSSL_HAVE_MIN + #define WOLFSSL_HAVE_MAX + #define NO_WRITEV + + #define USE_FLAT_BENCHMARK_H + #define USE_FLAT_TEST_H + #define EXIT_FAILURE 1 + #define MAIN_NO_ARGS + + void *z_realloc(void *ptr, size_t size); + #define realloc z_realloc + + #define CONFIG_NET_BUF_USER_DATA_SIZE 10 + #define CONFIG_NET_SOCKETS_POSIX_NAMES +#endif + #ifdef WOLFSSL_IMX6 #ifndef SIZEOF_LONG_LONG #define SIZEOF_LONG_LONG 8 diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 59a4a4cf0..e29f8fcbd 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -175,7 +175,8 @@ #if defined(_MSC_VER) #define THREAD_LS_T __declspec(thread) /* Thread local storage only in FreeRTOS v8.2.1 and higher */ - #elif defined(FREERTOS) || defined(FREERTOS_TCP) + #elif defined(FREERTOS) || defined(FREERTOS_TCP) || \ + defined(WOLFSSL_ZEPHYR) #define THREAD_LS_T #else #define THREAD_LS_T __thread @@ -360,7 +361,8 @@ #endif #ifndef XSTRNCASECMP - #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS) + #if defined(MICROCHIP_PIC32) || defined(WOLFSSL_TIRTOS) || \ + defined(WOLFSSL_ZEPHYR) /* XC32 does not support strncasecmp, so use case sensitive one */ #define XSTRNCASECMP(s1,s2,n) strncmp((s1),(s2),(n)) #elif defined(USE_WINDOWS_API) || defined(FREERTOS_TCP_WINSIM) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index ee91b1a08..66e8a39bf 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -108,6 +108,14 @@ #include "nucleus.h" #elif defined(WOLFSSL_APACHE_MYNEWT) /* do nothing */ +#elif defined(WOLFSSL_ZEPHYR) + #ifndef SINGLE_THREADED + #include + + #define WOLFSSL_PTHREADS + #define HAVE_PTHREAD + #include + #endif #else #ifndef SINGLE_THREADED #define WOLFSSL_PTHREADS @@ -185,6 +193,8 @@ typedef RTHANDLE wolfSSL_Mutex; #elif defined(WOLFSSL_NUCLEUS_1_2) typedef NU_SEMAPHORE wolfSSL_Mutex; + #elif defined(WOLFSSL_ZEPHYR) + typedef struct k_mutex wolfSSL_Mutex; #else #error Need a mutex type in multithreaded mode #endif /* USE_WINDOWS_API */ @@ -321,6 +331,27 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #define XSEEK_END 2 #define XBADFILE NULL #define XFGETS(b,s,f) -2 /* Not ported yet */ +#elif defined(WOLFSSL_ZEPHYR) + #include + + #define XFILE struct fs_file_t* + #define STAT struct fs_dirent + + XFILE z_fs_open(const char* filename, const char* perm); + int z_fs_close(XFILE file); + + #define XFOPEN z_fs_open + #define XFCLOSE z_fs_close + #define XFSEEK fs_seek + #define XFTELL fs_tell + #define XFREWIND fs_rewind + #define XREWIND(F) fs_seek(F, 0, FS_SEEK_SET) + #define XFREAD(P,S,N,F) fs_read(F, P, S*N) + #define XFWRITE(P,S,N,F) fs_write(F, P, S*N) + #define XSEEK_END FS_SEEK_END + #define XBADFILE NULL + #define XFGETS(b,s,f) -2 /* Not ported yet */ + #elif defined(WOLFSSL_USER_FILESYSTEM) /* To be defined in user_settings.h */ #else @@ -364,6 +395,11 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #ifdef USE_WINDOWS_API WIN32_FIND_DATAA FindFileData; HANDLE hFind; + #elif defined(WOLFSSL_ZEPHYR) + struct fs_dirent entry; + struct fs_dir_t dir; + struct fs_dirent s; + struct fs_dir_t* dirp; #else struct dirent* entry; DIR* dir; @@ -486,6 +522,24 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #define WOLFSSL_GMTIME #define USE_WOLF_TM #define USE_WOLF_TIME_T + +#elif defined(WOLFSSL_ZEPHYR) + #ifndef _POSIX_C_SOURCE + #include + #else + #include + #endif + + typedef signed int time_t; + + time_t z_time(time_t *timer); + + #define XTIME(tl) z_time((tl)) + #define XGMTIME(c, t) gmtime((c)) + #define WOLFSSL_GMTIME + + #define USE_WOLF_TM + #else /* default */ /* uses complete facility */ diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index a92f27d90..4cc238478 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -116,6 +116,8 @@ #include #include #include + #elif defined(WOLFSSL_ZEPHYR) + #include #elif !defined(WOLFSSL_NO_SOCK) #include #include @@ -257,6 +259,9 @@ #elif defined(WOLFSSL_NUCLEUS_1_2) #define SEND_FUNCTION NU_Send #define RECV_FUNCTION NU_Recv +#elif defined(WOLFSSL_ZEPHYR) + #define SEND_FUNCTION zsock_send + #define RECV_FUNCTION zsock_recv #else #define SEND_FUNCTION send #define RECV_FUNCTION recv