From c01cd808da3a41ce7f60e88241c10f224f304cf2 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 10 Jan 2020 09:42:25 -0800 Subject: [PATCH] changes for build with s7g2 add project info add project info adjust wolfssl library template change TRNG collection fix include.am fix argument for TRNG rename example templates comment out DEBUG_WOLFSSL change include.am update license --- IDE/Renesas/e2studio/DK-S7G2/README.md | 27 ++ .../DK-S7G2/benchmark-template/.cproject | 400 ++++++++++++++++++ .../DK-S7G2/benchmark-template/.project | 34 ++ .../benchmark-template/src/app_entry.c | 298 +++++++++++++ .../DK-S7G2/example_server-template/.cproject | 391 +++++++++++++++++ .../DK-S7G2/example_server-template/.project | 27 ++ .../example_server-template/src/app_entry.c | 181 ++++++++ IDE/Renesas/e2studio/DK-S7G2/include.am | 22 + IDE/Renesas/e2studio/DK-S7G2/user_settings.h | 64 +++ .../DK-S7G2/wolfcrypttest-template/.cproject | 392 +++++++++++++++++ .../DK-S7G2/wolfcrypttest-template/.project | 34 ++ .../wolfcrypttest-template/src/app_entry.c | 76 ++++ .../DK-S7G2/wolfssl-template-project/.project | 49 +++ .../configuration.xml | 352 +++++++++++++++ IDE/include.am | 1 + wolfcrypt/benchmark/benchmark.c | 26 ++ wolfcrypt/src/random.c | 49 ++- wolfcrypt/src/wc_port.c | 15 +- wolfssl/wolfio.h | 13 + 19 files changed, 2448 insertions(+), 3 deletions(-) create mode 100644 IDE/Renesas/e2studio/DK-S7G2/README.md create mode 100644 IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.cproject create mode 100644 IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.project create mode 100644 IDE/Renesas/e2studio/DK-S7G2/benchmark-template/src/app_entry.c create mode 100644 IDE/Renesas/e2studio/DK-S7G2/example_server-template/.cproject create mode 100644 IDE/Renesas/e2studio/DK-S7G2/example_server-template/.project create mode 100644 IDE/Renesas/e2studio/DK-S7G2/example_server-template/src/app_entry.c create mode 100644 IDE/Renesas/e2studio/DK-S7G2/include.am create mode 100644 IDE/Renesas/e2studio/DK-S7G2/user_settings.h create mode 100644 IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.cproject create mode 100644 IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.project create mode 100644 IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/src/app_entry.c create mode 100644 IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/.project create mode 100644 IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/configuration.xml diff --git a/IDE/Renesas/e2studio/DK-S7G2/README.md b/IDE/Renesas/e2studio/DK-S7G2/README.md new file mode 100644 index 000000000..4c999418e --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/README.md @@ -0,0 +1,27 @@ + +## Building wolfSSL For DK-S7G2 + +- First physically toggle the ENET1 and JTAG switch to on with the DK-S7G2 board. +- Open e2studio and set the workspace to be wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/ +- Create a Synergy library project named wolfssl "File->New->Synergy C/C++ Project", "Renesas Synergy C Library Project" then "Next", set wolfssl as the "Project Name" then "Next", set Board to "S7G2 DK" then "Next", finally select the BSP radius and click "Finish" +- Copy configuration.xml and .project from wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/ into the wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl directory +- (optional but necessary for production) Add TRNG support by clicking on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > TRNG Driver on r_sce_trng". Then uncomment WOLFSSL_SCE define in wolfssl project src/user_settings.h +- Generate the changes by clicking on "Generate Project Content" +- Exclude src/wolfcrypt/port and all src/wolfcrypt/*.S and src/wolfcrypt/*.asm files from the build +- Exclude src/wolfcrypt/evp.c, src/wolfcrypt/misc.c and src/wolfssl/bio.c +- Set the Preprocessor define in wolfssl proejct to have WOLFSSL_USER_SETTINGS. Right click on wolfssl project "Properties -> C/C++ Build -> GNU ARM Cross C Compiler -> Preprocessor" add WOLFSSL_USER_SETTINGS under "Defined symbols" +- Set include to wolfssl directory. Right click on project "Properties -> C/C++Build -> GNU ARM Cross Compiler -> Includes". Add "${ProjDirPath}/../../../../.." and "${ProjDirPath}/../" +- Build wolfssl by right clicking on wolfssl project and selecting "Build Project" + +## Example Projects and Building + +- Create a new Synergy project "Renesas Synergy C Project Using Synergy Library" +- Set it to use the wolfssl library +- Copy in the .cproject, .project and source file from the template desired i.e. wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/ +- Right click on the created project and select "Build Project" + +The example_server loops looking to accept connections and closes immediatly after a successful connection was made. + +The benchmark example tries to do a TCP connection to SERVER_IP on port 11112 and a TLS connection to SERVER_IP on port 11111 then does wolfCrypt benchmark collection. + +The wolfcryptest runs through all of the unit tests from wolfcrypt/test/test.c \ No newline at end of file diff --git a/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.cproject b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.cproject new file mode 100644 index 000000000..09d87045d --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.cproject @@ -0,0 +1,400 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.project b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.project new file mode 100644 index 000000000..1b60e8e4f --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.project @@ -0,0 +1,34 @@ + + + benchmark + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.renesas.cdt.synergy.contentgen.synergyExecutableNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + src/benchmark + 2 + PARENT-5-PROJECT_LOC/wolfcrypt/benchmark + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/src/app_entry.c b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/src/app_entry.c new file mode 100644 index 000000000..1bcbc55ee --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/benchmark-template/src/app_entry.c @@ -0,0 +1,298 @@ +/* app_entry.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#include "app.h" +#include "stdio.h" +extern void initialise_monitor_handles(void); + +#include + +#ifndef WOLFCRYPT_ONLY + +#include + +#define USE_CERT_BUFFERS_2048 +#define USE_CERT_BUFFERS_256 +#include + +#include "nx_api.h" +#define CONNECTION_TIMES 100 +#define SERVER_IP IP_ADDRESS(10,22,73,128) +#define TLS_PORT 11111 +#define TCP_PORT 11112 + +static double miliseconds = 0; +void timer_callback(timer_callback_args_t * args) +{ + miliseconds++; + (void)args; +} + +/* version is the type of TLS version to use. For example TLS1.2 = version 2 + * and TLS1.3 = version 3 + * + * suites is a null terminated string containing the cipher suites to us, or + * can be NULL for default*/ +static void benchmark_TLS(int version, char* suites, int group) +{ + UINT TEST_PORT = TLS_PORT; + ULONG TEST_IP = SERVER_IP; + int i; + NX_TCP_SOCKET sockfd; + int ret; + int groups[1]; + double start; + WOLFSSL_METHOD* method = NULL; + + WOLFSSL_CTX* ctx; + WOLFSSL* ssl; + + switch (version) { + case 2: method = wolfTLSv1_2_client_method(); break; +#ifdef WOLFSSL_TLS13 + case 3: method = wolfTLSv1_3_client_method(); break; +#endif + default: + printf("Unknown TLS version (Check if wolfSSL was built with it supported)\n"); + return; + } + + ctx = wolfSSL_CTX_new(method); + if (ctx == NULL) { + printf("unable to create ctx\n"); + return; + } + +#ifndef NO_RSA + /* add default RSA CA */ + ret = wolfSSL_CTX_load_verify_buffer(ctx, ca_cert_der_2048, + sizeof_ca_cert_der_2048, SSL_FILETYPE_ASN1); + if (ret != WOLFSSL_SUCCESS) { + printf("error %d loading CA\n", ret); + return; + } +#endif + +#ifdef HAVE_ECC + /* add default ECDSA CA */ + ret = wolfSSL_CTX_load_verify_buffer(ctx, ca_ecc_cert_der_256, + sizeof_ca_ecc_cert_der_256, SSL_FILETYPE_ASN1); + if (ret != WOLFSSL_SUCCESS) { + printf("error %d loading CA\n", ret); + return; + } + +#endif + + if (suites != NULL) { + ret = wolfSSL_CTX_set_cipher_list(ctx, suites); + if (ret != WOLFSSL_SUCCESS) { + printf("error %d setting cipher suites %s\n", ret, suites); + return; + } + } + +#ifdef WOLFSSL_TLS13 + if (version == 3) { + groups[0] = group; + ret = wolfSSL_CTX_set_groups(ctx, groups, 1); + if (ret != WOLFSSL_SUCCESS) { + printf("error setting group\n"); + return; + } + } +#endif + + printf("Trying to connect to 0x%lX on port %d\n", TEST_IP, TEST_PORT); + + miliseconds = 0; + g_timer0.p_api->open(g_timer0.p_ctrl, g_timer0.p_cfg); + g_timer0.p_api->start(g_timer0.p_ctrl); + + start = (double)tx_time_get(); // TX_TIMER_TICKS_PER_SECOND = 100 + ret = (int)nx_tcp_socket_create(&g_ip0, &sockfd, "TLS_CLIENT", NX_IP_NORMAL, + NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 1500, NX_NULL, NX_NULL); + if (ret != NX_SUCCESS) { + printf("failed to create socket err = 0x%X\n", ret); + return; + } + for (i = 0; i < CONNECTION_TIMES; i++) { + + ret = (int)nx_tcp_client_socket_bind(&sockfd, NX_ANY_PORT, NX_WAIT_FOREVER); + if (ret != NX_SUCCESS) { + printf("failed to bind socket\n"); + return; + } + + ret = (int)nx_tcp_client_socket_connect(&sockfd, TEST_IP, TEST_PORT, NX_WAIT_FOREVER); + if (ret != NX_SUCCESS) { + printf("failed to connect with error 0x%X\n", ret); + return; + } + + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + printf("Error creating ssl\n"); + return; + } + +#ifdef WOLFSSL_TLS13 + if (version == 3) { + ret = wolfSSL_UseKeyShare(ssl, group); + if (ret != WOLFSSL_SUCCESS) { + printf("Error %d with set key share\n", ret); + return; + } + } +#endif + + wolfSSL_SetIO_NetX(ssl, &sockfd, NX_WAIT_FOREVER); + + ret = wolfSSL_connect(ssl); + if (ret != WOLFSSL_SUCCESS) { + printf("Error %d with wolfssl connect\n", ret); + return; + } + wolfSSL_free(ssl); + + nx_tcp_socket_disconnect(&sockfd, NX_WAIT_FOREVER); + + ret = nx_tcp_client_socket_unbind(&sockfd); + if (ret != NX_SUCCESS) { + printf("failed to unbind with error 0x%X\n", ret); + return; + } + + } + nx_tcp_socket_delete(&sockfd); + + g_timer0.p_api->stop(g_timer0.p_ctrl); + start = (double)tx_time_get() - start; + g_timer0.p_api->close(g_timer0.p_ctrl); + + printf("%d TLS connections took %f seconds and %f tx_time ticks\n", + CONNECTION_TIMES, (miliseconds / 10), start); + wolfSSL_CTX_free(ctx); +} + + +static void benchmark_TCP() +{ + UINT TEST_PORT = TCP_PORT; + ULONG TEST_IP = SERVER_IP; + int i; + NX_TCP_SOCKET sockfd; + int ret; + double start; + + + { + NX_PACKET* response; + printf("Pinging server to see if up .. "); + fflush(stdout); + ret = (int)nx_icmp_ping(&g_ip0, TEST_IP, "Hello", strlen("Hello"), &response, 2000); + if (ret != NX_SUCCESS) { + printf("Unable to ping server, error = 0x%X\n", ret); + return; + } + printf("got response from server\n"); + nx_packet_release(response); + } + + printf("Benchmarking client TCP connection\n"); + printf("Trying to connect to 0x%lX on port %d\n", TEST_IP, TEST_PORT); + start = (double)tx_time_get() / TX_TIMER_TICKS_PER_SECOND; + ret = (int)nx_tcp_socket_create(&g_ip0, &sockfd, "TCP_CLIENT", NX_IP_NORMAL, + NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 256, NX_NULL, NX_NULL); + if (ret != NX_SUCCESS) { + printf("failed to create socket err = 0x%X\n", ret); + return; + } + + for (i = 0; i < CONNECTION_TIMES; i++) { + ret = (int)nx_tcp_client_socket_bind(&sockfd, NX_ANY_PORT, NX_WAIT_FOREVER); + if (ret != NX_SUCCESS) { + printf("failed to bind socket\n"); + return; + } + + ret = (int)nx_tcp_client_socket_connect(&sockfd, TEST_IP, TEST_PORT, NX_WAIT_FOREVER); + if (ret != NX_SUCCESS) { + printf("failed to connect with error 0x%X\n", ret); + return; + } + + nx_tcp_socket_disconnect(&sockfd, NX_WAIT_FOREVER); + + ret = (int)nx_tcp_client_socket_unbind(&sockfd); + if (ret != NX_SUCCESS) { + printf("failed to unbind with error 0x%X\n", ret); + return; + } + } + nx_tcp_socket_delete(&sockfd); + + start = ((double)tx_time_get() / TX_TIMER_TICKS_PER_SECOND) - start; + printf("%d TCP connections took %f seconds\n", CONNECTION_TIMES, start); +} +#endif /* WOLFCRYPT_ONLY */ + +/* Benchmark entry function */ +void app_entry(void) +{ + initialise_monitor_handles(); + +#ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); +#endif + + wolfSSL_Init(); + +#ifndef WOLFCRYPT_ONLY + benchmark_TCP(); + + printf("\nBenchmarking client TLSv1.2 connection using ECDHE-RSA-AES128-GCM-SHA256\n"); + benchmark_TLS(2, "ECDHE-RSA-AES128-GCM-SHA256", 0); + #ifdef WOLFSSL_TLS13 + #ifdef HAVE_CURVE25519 + printf("\nBenchmarking client TLSv1.3 WOLFSSL_ECC_X25519 connection using TLS13_AES128_GCM_SHA256\n"); + benchmark_TLS(3, "TLS13-AES128-GCM-SHA256", (int)WOLFSSL_ECC_X25519); + #endif + #ifdef HAVE_ECC + printf("\nBenchmarking client TLSv1.3 WOLFSSL_ECC_SECP256R1 connection using TLS13_AES128_GCM_SHA256\n"); + benchmark_TLS(3, "TLS13-AES128-GCM-SHA256", (int)WOLFSSL_ECC_SECP256R1); + #endif + printf("\nBenchmarking client TLSv1.3 WOLFSSL_FFDHE_2048 connection using TLS13_AES128_GCM_SHA256\n"); + benchmark_TLS(3, "TLS13-AES128-GCM-SHA256", (int)WOLFSSL_FFDHE_2048); + #endif +#endif + +#if 1 + /* run wolfcrypt benchmarks */ + benchmark_test(NULL); +#endif + + wolfSSL_Cleanup(); + while (1) + { + tx_thread_sleep (100); + } +} diff --git a/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.cproject b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.cproject new file mode 100644 index 000000000..3b026ad59 --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.cproject @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.project b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.project new file mode 100644 index 000000000..aaff6e3d7 --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/.project @@ -0,0 +1,27 @@ + + + example_server + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.renesas.cdt.synergy.contentgen.synergyExecutableNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/example_server-template/src/app_entry.c b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/src/app_entry.c new file mode 100644 index 000000000..92a32d8d7 --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/example_server-template/src/app_entry.c @@ -0,0 +1,181 @@ +/* app_entry.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + + +#include "app.h" +#include "nx_api.h" +#include "stdio.h" +extern void initialise_monitor_handles(void); + +#include +#define USE_CERT_BUFFERS_2048 +#define USE_CERT_BUFFERS_256 +#include +#define TLS_PORT 11111 + +static void server() +{ + UINT TEST_PORT = TLS_PORT; + NX_TCP_SOCKET sockfd; + int ret; + unsigned char* cert; + int certSz; + + unsigned char* key; + int keySz; + + WOLFSSL_CTX* ctx; + WOLFSSL* ssl; + + ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()); + if (ctx == NULL) { + printf("Unable to create ctx\n"); + return; + } + +#ifndef NO_RSA + cert = server_cert_der_2048; + certSz = sizeof_server_cert_der_2048; + key = server_key_der_2048; + keySz = sizeof_server_key_der_2048; +#endif + +#if 0 + /* Use ECDSA */ + cert = serv_ecc_der_256; + certSz = sizeof_serv_ecc_der_256; + key = ecc_key_der_256; + keySz = sizeof_ecc_key_der_256; +#endif + + ret = wolfSSL_CTX_use_certificate_buffer(ctx, cert, + certSz, SSL_FILETYPE_ASN1); + if (ret != WOLFSSL_SUCCESS) { + printf("Unable to load certificate ret = %d\n", ret); + wolfSSL_CTX_free(ctx); + return; + } + + ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, key, + keySz, SSL_FILETYPE_ASN1); + if (ret != WOLFSSL_SUCCESS) { + printf("Unable to load key ret = %d\n", ret); + wolfSSL_CTX_free(ctx); + return; + } + +#ifdef WOLFSSL_TLS13 + { + int groups[3]; + int idx = 0; + + #ifdef HAVE_CURVE25519 + groups[idx++] = WOLFSSL_ECC_X25519; + #endif + #ifdef HAVE_ECC + groups[idx++] = WOLFSSL_ECC_SECP256R1; + #endif + groups[idx++] = WOLFSSL_FFDHE_2048; + + ret = wolfSSL_CTX_set_groups(ctx, groups, idx); + if (ret != WOLFSSL_SUCCESS) { + printf("Unable to set groups\n"); + } + } +#endif + printf("Waiting for connections on port %d\n", TEST_PORT); + + ret = (int)nx_tcp_socket_create(&g_ip0, &sockfd, "TLS_SERVER", NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 1500, NX_NULL, NX_NULL); + if (ret != NX_SUCCESS) { + printf("failed to create socket err = 0x%X\n", ret); + } + + ret = (int)nx_tcp_server_socket_listen(&g_ip0, TEST_PORT, &sockfd, + NX_MAX_LISTEN_REQUESTS, NULL); + if (ret != NX_SUCCESS) { + printf("failed to listen\n"); + } + + while (1) { + ret = (int)nx_tcp_server_socket_accept(&sockfd, NX_WAIT_FOREVER); + if (ret != NX_SUCCESS) { + printf("failed to accept with error 0x%X\n", ret); + break; + } + + ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + printf("Error creating ssl\n"); + break; + } + + wolfSSL_SetIO_NetX(ssl, &sockfd, NX_WAIT_FOREVER); + + ret = wolfSSL_accept(ssl); + if (ret != WOLFSSL_SUCCESS) { + printf("Error %d with wolfssl accept\n", wolfSSL_get_error(ssl, ret)); + wolfSSL_free(ssl); + break; + } + wolfSSL_free(ssl); + + nx_tcp_socket_disconnect(&sockfd, NX_WAIT_FOREVER); + + ret = (int)nx_tcp_server_socket_unaccept(&sockfd); + if (ret != NX_SUCCESS) { + printf("failed to unaccept with error 0x%X\n", ret); + break; + } + + ret = (int)nx_tcp_server_socket_relisten(&g_ip0, TEST_PORT, &sockfd); + if (ret != NX_SUCCESS && ret != NX_CONNECTION_PENDING) { + printf("failed to relisten 0x%X\n", ret); + break; + } + } + ret = (int)nx_tcp_server_socket_unlisten(&g_ip0, TEST_PORT); + if (ret != NX_SUCCESS) { + printf("failed to unlisten\n"); + return; + } + + nx_tcp_socket_delete(&sockfd); + + wolfSSL_CTX_free(ctx); +} + +/* app entry function */ +void app_entry(void) +{ + initialise_monitor_handles(); + wolfSSL_Init(); + +#ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); +#endif + server(); + wolfSSL_Cleanup(); + printf("Server closed down\n"); + while (1) + { + tx_thread_sleep (1); + } +} diff --git a/IDE/Renesas/e2studio/DK-S7G2/include.am b/IDE/Renesas/e2studio/DK-S7G2/include.am new file mode 100644 index 000000000..739be2cab --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/include.am @@ -0,0 +1,22 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/README.md +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/user_settings.h + +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/.project +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/configuration.xml + +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.cproject +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.project +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/src/app_entry.c + +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/example_server-template/.cproject +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/example_server-template/.project +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/example_server-template/src/app_entry.c + +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.cproject +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/benchmark-template/.project +EXTRA_DIST+= IDE/Renesas/e2studio/DK-S7G2/benchmark-template/src/app_entry.c + diff --git a/IDE/Renesas/e2studio/DK-S7G2/user_settings.h b/IDE/Renesas/e2studio/DK-S7G2/user_settings.h new file mode 100644 index 000000000..ad58cd67f --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/user_settings.h @@ -0,0 +1,64 @@ + +#ifndef USER_SETTINGS_H +#define USER_SETTINGS_H + +//#define DEBUG_WOLFSSL + +#define NO_MAIN_DRIVER +#define USE_CERT_BUFFERS_2048 +#define USE_CERT_BUFFERS_256 + +/* print out cycles per byte with benchmark when component r_wdt WDT is enabled */ +#define SYNERGY_CYCLE_COUNT +#define BENCH_EMBEDDED + +/* Use TRNG */ +//#define WOLFSSL_SCE +#ifndef WOLFSSL_SCE + /* use unsafe test seed if TRNG not used (not for production) */ + #define WOLFSSL_GENSEED_FORTEST +#endif + +#define HAVE_ECC +#define ALT_ECC_SIZE + +#define HAVE_CHACHA +#define HAVE_POLY1305 +#define HAVE_ONE_TIME_AUTH +#define HAVE_AESGCM + +#define USE_FAST_MATH + +#define TFM_TIMING_RESISTANT +#define WC_RSA_BLINDING +#define ECC_TIMING_RESISTANT + +#define NO_WOLFSSL_DIR + +#define HAVE_NETX +#define THREADX +#define THREADX_NO_DC_PRINTF +#define NO_WRITEV +#define SIZEOF_LONG 4 +#define SIZEOF_LONG_LONG 8 + +#if 1 + /* Optimizations */ + #define WOLFSSL_HAVE_SP_RSA + #define WOLFSSL_HAVE_SP_ECC + #define WOLFSSL_SP_ARM_CORTEX_M_ASM +#endif + +/* TLS 1.3 */ +#define WOLFSSL_TLS13 +#define HAVE_TLS_EXTENSIONS +#define HAVE_SUPPORTED_CURVES +#define HAVE_FFDHE_2048 +#define HAVE_HKDF +#define WC_RSA_PSS + +#define HAVE_CURVE25519 +#define HAVE_ED25519 +#define WOLFSSL_SHA512 + +#endif diff --git a/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.cproject b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.cproject new file mode 100644 index 000000000..67ebabc0d --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.cproject @@ -0,0 +1,392 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.project b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.project new file mode 100644 index 000000000..24fa740ee --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/.project @@ -0,0 +1,34 @@ + + + wolfcrypttest + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.renesas.cdt.synergy.contentgen.synergyExecutableNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + src/test + 2 + PARENT-5-PROJECT_LOC/wolfcrypt/test + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/src/app_entry.c b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/src/app_entry.c new file mode 100644 index 000000000..c9eee735e --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/src/app_entry.c @@ -0,0 +1,76 @@ +/* app_entry.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + + +#include +#include "stdio.h" +extern void initialise_monitor_handles(void); + +#include +#include +#include "wolfcrypt/test/test.h" + +typedef struct func_args { + int argc; + char** argv; + int return_code; +} func_args; + +void app_entry(void) +{ + func_args args; + + args.argc = 0; + args.argv = NULL; + args.return_code = 0; + + initialise_monitor_handles(); + wolfCrypt_Init(); + +#if 1 + /* sanity check on RNG */ + printf("Doing quick sanity check on RNG\n"); + { + int i; + for (i = 0; i < 10; i++) { + int j, ret; + WC_RNG rng; + unsigned char buffer[20] = {0}; + + wc_InitRng(&rng); + ret = wc_RNG_GenerateBlock(&rng, buffer, 20); + if (ret != 0) { + printf("Error generating random block\n"); + } + for (j = 0; j < 20; j++) { + printf("%02X", buffer[j]); + } + printf("\n"); + wc_FreeRng(&rng); + } + } + printf("\n"); +#endif + + wolfcrypt_test(&args); + wolfCrypt_Cleanup(); + printf("done with wolfcrypt test, ret = %d\n", args.return_code); +} diff --git a/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/.project b/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/.project new file mode 100644 index 000000000..11745f883 --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/.project @@ -0,0 +1,49 @@ + + + wolfssl + + + + + + com.renesas.cdt.synergy.contentgen.synergyBuilder + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + com.renesas.cdt.synergy.contentgen.synergyNature + + + + src/user_settings.h + 1 + PARENT-1-PROJECT_LOC/user_settings.h + + + src/wolfcrypt + 2 + PARENT-5-PROJECT_LOC/wolfcrypt/src + + + src/wolfssl + 2 + PARENT-5-PROJECT_LOC/src + + + diff --git a/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/configuration.xml b/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/configuration.xml new file mode 100644 index 000000000..6622d9f67 --- /dev/null +++ b/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/configuration.xml @@ -0,0 +1,352 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SSP Common Code + Renesas.Synergy.1.7.0.pack + + + Clock Generation Circuit: Provides=[CGC] + Renesas.Synergy.1.7.0.pack + + + Event Link Controller: Provides=[ELC] + Renesas.Synergy.1.7.0.pack + + + Factory MCU Information Module: Provides=[FMI] + Renesas.Synergy.1.7.0.pack + + + I/O Port: Provides=[IO Port] + Renesas.Synergy.1.7.0.pack + + + Board support package for R7FS7G27H2A01CBD + Renesas.Synergy_mcu_s7g2.1.7.0.pack + + + Board support package for S7G2 + Renesas.Synergy_mcu_s7g2.1.7.0.pack + + + Board support package for S7G2 + Renesas.Synergy_mcu_s7g2.1.7.0.pack + + + S7G2_DK Board Support Files + Renesas.Synergy_board_s7g2_dk.1.7.0.pack + + + Real Time Clock: Provides=[RTC] + Renesas.Synergy.1.7.0.pack + + + General Purpose Timer: Provides=[Timer ,GPT] + Renesas.Synergy.1.7.0.pack + + + Watchdog Timer: Provides=[WDT] + Renesas.Synergy.1.7.0.pack + + + Express Logic NetX: Provides=[NetX] , Requires=[ThreadX ,NetX Driver] + Renesas.Synergy.1.7.0.pack + + + Express Logic NetX Synergy Port: Provides=[NetX Driver] , Requires=[NetX] + Renesas.Synergy.1.7.0.pack + + + Express Logic ThreadX: Provides=[ThreadX] + Renesas.Synergy.1.7.0.pack + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IDE/include.am b/IDE/include.am index 2ea00f2de..fe260fb6a 100644 --- a/IDE/include.am +++ b/IDE/include.am @@ -21,6 +21,7 @@ include IDE/ECLIPSE/DEOS/include.am include IDE/ECLIPSE/MICRIUM/include.am include IDE/ECLIPSE/SIFIVE/include.am include IDE/mynewt/include.am +include IDE/Renesas/e2studio/DK-S7G2/include.am include IDE/Renesas/cs+/Projects/include.am include IDE/Renesas/e2studio/Projects/include.am include IDE/WICED-STUDIO/include.am diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 7a905e59c..d48395296 100755 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -618,6 +618,24 @@ static const char* bench_desc_words[][9] = { XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.2f,\n", \ (float)total_cycles / (count*s)) +#elif defined(SYNERGY_CYCLE_COUNT) + #include "hal_data.h" + static THREAD_LS_T word64 begin_cycles; + static THREAD_LS_T word64 total_cycles; + + #define INIT_CYCLE_COUNTER + #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0; + #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles; + + /* s == size in bytes that 1 count represents, normally BENCH_SIZE */ + #define SHOW_INTEL_CYCLES(b, n, s) \ + XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), " %s = %6.2f\n", \ + bench_result_words1[lng_index][2], \ + (float)total_cycles / (count*s)) + #define SHOW_INTEL_CYCLES_CSV(b, n, s) \ + XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), "%.2f,\n", \ + (float)total_cycles / (count*s)) + #else #define INIT_CYCLE_COUNTER #define BEGIN_INTEL_CYCLES @@ -5694,6 +5712,14 @@ exit_ed_verify: return (double) ticks/TICKS_PER_SECOND; } + +#elif defined(THREADX) + #include "tx_api.h" + double current_time(int reset) + { + (void)reset; + return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND; + } #else #include diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index a9dcac362..50cfab564 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -155,6 +155,7 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b) #elif defined(WOLFSSL_PB) #elif defined(WOLFSSL_ZEPHYR) #elif defined(WOLFSSL_TELIT_M2MB) +#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG) #else /* include headers that may be needed to get good seed */ #include @@ -2312,8 +2313,52 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) } return ret; } - - + +#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG) + #include "hal_data.h" + + int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) + { + uint32_t ret; + uint32_t blocks; + word32 len = sz; + + ret = g_sce_trng.p_api->open(g_sce_trng.p_ctrl, g_sce_trng.p_cfg); + if (ret != SSP_SUCCESS) { + /* error opening TRNG driver */ + return -1; + } + + blocks = sz / sizeof(uint32_t); + if (blocks > 0) { + ret = g_sce_trng.p_api->read(g_sce_trng.p_ctrl, (uint32_t*)output, + blocks); + if (ret != SSP_SUCCESS) { + return -1; + } + } + + len = len - (blocks * sizeof(uint32_t)); + if (len > 0) { + uint32_t tmp; + + if (len > sizeof(uint32_t)) { + return -1; + } + ret = g_sce_trng.p_api->read(g_sce_trng.p_ctrl, (uint32_t*)tmp, 1); + if (ret != SSP_SUCCESS) { + return -1; + } + XMEMCPY(output + (blocks * sizeof(uint32_t)), (byte*)&tmp, len); + } + + ret = g_sce_trng.p_api->close(g_sce_trng.p_ctrl); + if (ret != SSP_SUCCESS) { + /* error opening TRNG driver */ + return -1; + } + return 0; + } #elif defined(CUSTOM_RAND_GENERATE_BLOCK) /* #define CUSTOM_RAND_GENERATE_BLOCK myRngFunc * extern int myRngFunc(byte* output, word32 sz); diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index a23d4449b..2265416c8 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -82,6 +82,10 @@ #include #endif +#ifdef WOLFSSL_SCE + #include "hal_data.h" +#endif + #if defined(WOLFSSL_DSP) && !defined(WOLFSSL_DSP_BUILD) #include "rpcmem.h" #endif @@ -224,6 +228,13 @@ int wolfCrypt_Init(void) #endif #endif +#ifdef WOLFSSL_SCE + if ((ret = g_sce.p_api->open(g_sce.p_ctrl, g_sce.p_cfg)) != SSP_SUCCESS) { + WOLFSSL_MSG("Error opening SCE\n"); + return -1; /* FATAL_ERROR */ + } +#endif + #if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \ defined(WOLFSSL_IMX6_CAAM_BLOB) if ((ret = wc_caamInit()) != 0) { @@ -276,7 +287,9 @@ int wolfCrypt_Cleanup(void) #ifdef WOLFSSL_ASYNC_CRYPT wolfAsync_HardwareStop(); #endif - + #ifdef WOLFSSL_SCE + g_sce.p_api->close(g_sce.p_ctrl); + #endif #if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \ defined(WOLFSSL_IMX6_CAAM_BLOB) wc_caamFree(); diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 9ea0a0322..d0d17a093 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -82,6 +82,8 @@ #include "FreeRTOS_Sockets.h" #elif defined(WOLFSSL_IAR_ARM) /* nothing */ + #elif defined(HAVE_NETX_BSD) + #include "nx_bsd.h" #elif defined(WOLFSSL_VXWORKS) #include #include @@ -120,6 +122,9 @@ #include #elif defined(WOLFSSL_ZEPHYR) #include + #elif defined(HAVE_NETX) + #include "nx_api.h" + #include "errno.h" #elif !defined(WOLFSSL_NO_SOCK) #include #include @@ -233,6 +238,14 @@ #define SOCKET_EPIPE EPIPE #define SOCKET_ECONNREFUSED SOCKET_ERROR #define SOCKET_ECONNABORTED SOCKET_ERROR +#elif defined(HAVE_NETX) + #define SOCKET_EWOULDBLOCK NX_NOT_CONNECTED + #define SOCKET_EAGAIN NX_NOT_CONNECTED + #define SOCKET_ECONNRESET NX_NOT_CONNECTED + #define SOCKET_EINTR NX_NOT_CONNECTED + #define SOCKET_EPIPE NX_NOT_CONNECTED + #define SOCKET_ECONNREFUSED NX_NOT_CONNECTED + #define SOCKET_ECONNABORTED NX_NOT_CONNECTED #else #define SOCKET_EWOULDBLOCK EWOULDBLOCK #define SOCKET_EAGAIN EAGAIN