From 2ad6ce351b822bf9dd759c640210bbe1ddf68234 Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Sun, 18 Nov 2018 23:37:22 -0800 Subject: [PATCH] add micrium current_time and use correct serial function --- IDE/ECLIPSE/MICRIUM/client_wolfssl.c | 2 +- IDE/ECLIPSE/MICRIUM/user_settings.h | 28 ++++++++----- IDE/ECLIPSE/MICRIUM/wolfsslRunTests.c | 59 +++++++++++++++++++++++++++ wolfcrypt/benchmark/benchmark.c | 28 +++++++++---- 4 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 IDE/ECLIPSE/MICRIUM/wolfsslRunTests.c diff --git a/IDE/ECLIPSE/MICRIUM/client_wolfssl.c b/IDE/ECLIPSE/MICRIUM/client_wolfssl.c index 11197633a..f21f7365a 100644 --- a/IDE/ECLIPSE/MICRIUM/client_wolfssl.c +++ b/IDE/ECLIPSE/MICRIUM/client_wolfssl.c @@ -19,7 +19,7 @@ #define TX_MSG "GET /index.html HTTP/1.0\r\n\r\n" #define TX_MSG_SIZE sizeof(TX_MSG) -const CPU_CHAR google_certs_ca[]="\n\ +const CPU_INT08U google_certs_ca[]="\n\ ## Google Internet Authority G3 \n\ -----BEGIN CERTIFICATE-----\n\ MIIEXDCCA0SgAwIBAgINAeOpMBz8cgY4P5pTHTANBgkqhkiG9w0BAQsFADBMMSAw\n\ diff --git a/IDE/ECLIPSE/MICRIUM/user_settings.h b/IDE/ECLIPSE/MICRIUM/user_settings.h index 2704394dd..ae77b1643 100644 --- a/IDE/ECLIPSE/MICRIUM/user_settings.h +++ b/IDE/ECLIPSE/MICRIUM/user_settings.h @@ -6,19 +6,21 @@ #endif #define MICRIUM -#define WOLFSSL_MICRIUM_3_0 +/* You can select one or all of the following tests */ +#define WOLFSSL_WOLFCRYPT_TEST #define WOLFSSL_BENCHMARK_TEST -/* -#define WOLFSSL_MICRIUM_CRYPTO_TEST -#define WOLFSSL_MICRIUM_CLIENT_TEST -#define WOLFSSL_MICRIUM_SERVER_TEST -*/ +#define WOLFSSL_CLIENT_TEST +#define WOLFSSL_SERVER_TEST -/* test.h includes platform dependent header files. -When using Windows simulator, you must define USE_WINDOWS_API */ +/* adjust x to seconds since Jan 01 1970. (UTC) +https://www.unixtimestamp.com/ +*/ +#define CURRENT_UNIX_TS 1542605837 + +/* When using Windows simulator, you must define USE_WINDOWS_API for test.h to build */ #ifdef _WIN32 -define USE_WINDOWS_API +#define USE_WINDOWS_API #endif #define NO_FILESYSTEM @@ -39,11 +41,17 @@ define USE_WINDOWS_API #define NO_WRITE_TEMP_FILES /* no pow, no math.h */ -#define WOLFSSL_DH_CONST +//#define WOLFSSL_DH_CONST #define XSNPRINTF snprintf //#define NO_ASN_TIME +#define HAVE_AESGCM +#define WOLFSSL_SHA512 +#define HAVE_ECC +#define HAVE_CURVE25519 +#define CURVE25519_SMALL +#define HAVE_ED25519 #ifdef __cplusplus } /* extern "C" */ diff --git a/IDE/ECLIPSE/MICRIUM/wolfsslRunTests.c b/IDE/ECLIPSE/MICRIUM/wolfsslRunTests.c new file mode 100644 index 000000000..e6c4867e8 --- /dev/null +++ b/IDE/ECLIPSE/MICRIUM/wolfsslRunTests.c @@ -0,0 +1,59 @@ +#include /* master includes from Micrium Freescale Kinetis K70*/ + +#include + +/* +* Description : This function runs wolfssl tests. +* Caller(s) : main() in app.c +* Note(s) : none. +*/ + +int wolfsslRunTests (void) +{ + CLK_ERR err; + CLK_TS_SEC ts_unix_sec; + CPU_BOOLEAN valid; + static int initialized = 0; + + if(!initialized) { + Clk_Init(&err); + + if (err == CLK_ERR_NONE) { + APP_TRACE_INFO(("Clock module successfully initialized\n")); + } else { + APP_TRACE_INFO(("Clock module initialization failed\n")); + return -1; + } + + valid = Clk_GetTS_Unix(&ts_unix_sec); + + if (valid == DEF_OK) { + APP_TRACE_INFO(("Timestamp Unix = %u\n", ts_unix_sec)); + } else { + APP_TRACE_INFO(("Get TS Unix error\n")); + } + #if defined(CURRENT_UNIX_TS) + valid = Clk_SetTS_Unix(CURRENT_UNIX_TS); + if (valid != DEF_OK) { + APP_TRACE_INFO(("Clk_SetTS_Unix error\n")); + return -1; + } + #endif + initialized = 1; + } + + #if defined(WOLFSSL_WOLFCRYPT_TEST) + wolfcrypt_test(NULL); + #endif + #if defined(WOLFSSL_BENCHMARK_TEST) + benchmark_test(NULL); + #endif + #if defined(WOLFSSL_CLIENT_TEST) + wolfssl_client_test(); + #endif + #if defined(WOLFSSL_SERVER_TEST) + wolfssl_server_test(); + #endif + + return 0; +} diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 8e388d3fd..8704a2868 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -60,6 +60,11 @@ #undef printf #define printf PRINTF +#elif defined(MICRIUM) + #include + void BSP_Ser_Printf (CPU_CHAR* format, ...); + #undef printf + #define printf BSP_Ser_Printf #else #include #endif @@ -439,7 +444,7 @@ static const char* bench_Usage_msg1[][10] = { "- アルゴリズムのベンチマークを実施します。\n 利用可能なアルゴリズムは下記を含みます:\n", "-lng 指定された言語でベンチマーク結果を表示します。\n 0: 英語、 1: 日本語\n", " ブロックサイズをバイト単位で指定します。\n", - }, + }, }; static const char* bench_result_words1[][4] = { @@ -455,7 +460,7 @@ static const char* bench_result_words1[][4] = { static const char* bench_desc_words[][9] = { /* 0 1 2 3 4 5 6 7 8 */ {"public", "private", "key gen", "agree" , "sign", "verify", "encryption", "decryption", NULL}, /* 0 English */ - {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , NULL}, /* 1 Japanese */ + {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , NULL}, /* 1 Japanese */ }; #endif @@ -977,7 +982,7 @@ static void bench_stats_sym_finish(const char* desc, int doAsync, int count, SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), countSz); } else { XSNPRINTF(msg, sizeof(msg), "%-16s%s %5.0f %s %s %5.3f %s, %8.3f %s/s", - desc, BENCH_ASYNC_GET_NAME(doAsync), blocks, blockType, word[0], total, word[1], + desc, BENCH_ASYNC_GET_NAME(doAsync), blocks, blockType, word[0], total, word[1], persec, blockType); SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz); } @@ -1637,11 +1642,9 @@ int benchmark_test(void *args) (void)args; - printf( -"------------------------------------------------------------------------------" -"\n wolfSSL version %s\n" -"------------------------------------------------------------------------------" -"\n", LIBWOLFSSL_VERSION_STRING); + printf("------------------------------------------------------------------------------\n"); + printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING); + printf("------------------------------------------------------------------------------\n"); ret = benchmark_init(); if (ret != 0) @@ -3854,7 +3857,6 @@ static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING], const int len = (int)XSTRLEN((char*)messageStr); double start = 0.0f; const char**desc = bench_desc_words[lng_index]; - DECLARE_VAR_INIT(message, byte, len, messageStr, HEAP_HINT); DECLARE_ARRAY(enc, byte, BENCH_MAX_PENDING, rsaKeySz/8, HEAP_HINT); DECLARE_ARRAY(out, byte, BENCH_MAX_PENDING, rsaKeySz/8, HEAP_HINT); @@ -5040,6 +5042,14 @@ exit_ed_verify: #elif defined(WOLFSSL_SGX) double current_time(int reset); +#elif defined(MICRIUM) + double current_time(int reset) + { + CPU_ERR err; + + (void)reset; + return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err); + } #else #include