From 5c6f6fdb7dd10f066d201507580854abb082b26f Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Mon, 19 Aug 2019 17:32:22 +0900 Subject: [PATCH] Renesas TSIP Support merged from private repo removed unneccessary #include make line as 80 characters added simple tls server Disable TLS-linked API use when being SERVER SIDE, still use certificate verify API Added utility tools, generate signature arrays etc added vars to store tsip hmac keys fix build failure when disabling dc_printf --- .gitignore | 6 + IDE/Renesas/e2studio/Projects/README_TSIP.md | 103 +++ .../e2studio/Projects/common/user_settings.h | 34 +- IDE/Renesas/e2studio/Projects/test/.cproject | 434 ++++++++++-- IDE/Renesas/e2studio/Projects/test/.project | 28 +- .../e2studio/Projects/test/src/key_data.c | 266 +++++++ .../e2studio/Projects/test/src/key_data.h | 26 + .../e2studio/Projects/test/src/test_main.c | 170 ++++- .../e2studio/Projects/test/src/wolf_client.c | 197 ++++++ .../e2studio/Projects/test/src/wolf_server.c | 195 ++++++ .../e2studio/Projects/test/src/wolfssl_demo.h | 24 + .../Projects/test/src/wolfssl_dummy.c | 41 ++ .../Projects/tools/generate_rsa_keypair.sh | 52 ++ .../e2studio/Projects/tools/genhexbuf.pl | 89 +++ .../e2studio/Projects/tools/rsa_pss_sign.sh | 34 + .../e2studio/Projects/wolfssl/.cproject | 10 +- .../e2studio/Projects/wolfssl/.project | 15 + src/internal.c | 181 +++-- src/keys.c | 13 +- src/ssl.c | 29 +- src/tls.c | 58 +- wolfcrypt/src/asn.c | 190 ++++- wolfcrypt/src/port/Renesas/renesas_tsip_aes.c | 150 ++++ wolfcrypt/src/port/Renesas/renesas_tsip_sha.c | 262 +++++++ .../src/port/Renesas/renesas_tsip_util.c | 654 ++++++++++++++++++ wolfcrypt/src/random.c | 97 ++- wolfcrypt/src/sha.c | 12 +- wolfcrypt/src/sha256.c | 17 +- wolfcrypt/src/wc_port.c | 14 +- wolfcrypt/test/test.c | 32 +- wolfssl/internal.h | 11 + wolfssl/wolfcrypt/aes.h | 9 + wolfssl/wolfcrypt/asn.h | 16 + .../port/Renesas/renesas-tsip-crypt.h | 153 ++++ wolfssl/wolfcrypt/settings.h | 15 + wolfssl/wolfcrypt/sha.h | 4 +- wolfssl/wolfcrypt/sha256.h | 3 + 37 files changed, 3454 insertions(+), 190 deletions(-) create mode 100644 IDE/Renesas/e2studio/Projects/README_TSIP.md create mode 100644 IDE/Renesas/e2studio/Projects/test/src/key_data.c create mode 100644 IDE/Renesas/e2studio/Projects/test/src/key_data.h create mode 100644 IDE/Renesas/e2studio/Projects/test/src/wolf_client.c create mode 100755 IDE/Renesas/e2studio/Projects/test/src/wolf_server.c create mode 100644 IDE/Renesas/e2studio/Projects/test/src/wolfssl_demo.h create mode 100644 IDE/Renesas/e2studio/Projects/test/src/wolfssl_dummy.c create mode 100755 IDE/Renesas/e2studio/Projects/tools/generate_rsa_keypair.sh create mode 100755 IDE/Renesas/e2studio/Projects/tools/genhexbuf.pl create mode 100755 IDE/Renesas/e2studio/Projects/tools/rsa_pss_sign.sh create mode 100644 wolfcrypt/src/port/Renesas/renesas_tsip_aes.c create mode 100644 wolfcrypt/src/port/Renesas/renesas_tsip_sha.c create mode 100644 wolfcrypt/src/port/Renesas/renesas_tsip_util.c create mode 100644 wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h diff --git a/.gitignore b/.gitignore index 7627375d2..557539c95 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,9 @@ IDE/XCODE/Index \.settings/ \.cproject \.project + +# Renesas e2studio +/IDE/Renesas/e2studio/Projects/test/src/smc_gen +/IDE/Renesas/e2studio/Projects/test/trash +/IDE/Renesas/e2studio/Projects/test/*.launch +/IDE/Renesas/e2studio/Projects/test/*.scfg diff --git a/IDE/Renesas/e2studio/Projects/README_TSIP.md b/IDE/Renesas/e2studio/Projects/README_TSIP.md new file mode 100644 index 000000000..af95604a3 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/README_TSIP.md @@ -0,0 +1,103 @@ +# TSIP FIT Module port +Support for TSIP FIT driver for symmetric AES, SHA1/SHA256 hardware accleration and TLS-linked capability including Root CA, the server certificate or intermediate certificate verification. + +## Overview +Renesas TSIP FIT module with wolfSSL by setting *WOLFSSL_RENESAS_TSIP* definition. + +Including the following examples: + +* simple tls_client/tls_server +* crypt test +* crypt benchmark + + The *user_settings.h* file enables some of the hardened settings. + +## Requirements +### 1. [Renesas TSIP FIT module](https://www.renesas.com/us/en/products/software-tools/software-os-middleware-driver/security-crypto/trusted-secure-ip-driver.html) +- [FIT module](https://www.renesas.com/us/en/products/software-tools/software-os-middleware-driver/software-package/fit.html) +Note : The included example program is tested with TSIP FIT version 1.06. + +### 2. [e2studio](https://www.renesas.com/us/en/products/software-tools/tools/ide/e2studio.html) + +### 3. Evaluation Board that suppports TSIP +Note : The included example program is tested with [GR-ROSE](http://gadget.renesas.com/en/product/rose.html), which is classified to RX65N. + +## Setup and Build wolfSSL library + 1. Uncomment out #define WOLFSSL_RENESAS_TSIP in /path/to/wolfssl/wolfssl/wolfcrypt/settings.h + Uncomment out #define WOLFSSL_RENESAS_RX65N in /path/to/wolfssl/wolfssl/wolfcrypt/settings.h + 2. Open a project file at /path/to/wolfssl/IDE/Renesas/e2studio/Projects/wolfssl/ by e2studio and build to create wolfssl library + +To disable portions of the hardware acceleration you can optionally define: + +``` +/* Disabled SHA acceleration */ +#define NO_WOLFSSL_RENESAS_TSIP_CRYPT_HASH +/* Disabled TLS-linked acceleration */ +#define NO_WOLFSSL_RENESAS_TSIP_TLS_SESSION +``` + +## Setup and Build an example program +An example program expects the following FIT modules: + +* r_bsp +* r_cmt_rx +* r_config +* r_ether_rx +* r_sys_time_rx +* r_t4_driver_rx +* r_t4_rx +* r_tsip_rx + +These needed source files can be generated by creating a dummy project including Renesas Smart Configurator as steps below: + + 1. Create a dummy project including Renesas Smart Configurator for your evaluation board type + 2. Open Smart Configurator and add FIT modules above + You would need to expand *User Statck Size* property and *Heap Size* of r_bsp. + Change IP ADDRESS and PORT NUMBER in r_t4_rx_config.h + `#define T4_CFG_FIXED_IP_ADDRESS_CH0 192,168,1,33` + `#define T4_CFG_TCP_REPID1_PORT_NUMBER 11111` + Note: It would need to modify other configuration base on evaluation board. + 3. Generate source code +Now, you can copy these FIT modules into an example project. + 4. Make "smc_gen" folder under /path/to/wolfssl/IDE/Renesas/e2studio/Projects/test/src/ + 5. Copy the FIT modules into the folder that is created at step 4. + 6. Open an example project file at /path/to/wolfssl/IDE/Renesas/e2studio/Projects/test/ by e2studio + 7. Enable a macro definition in /path/to/wolfssl/IDE/Renesas/e2studio/Projects/test/src/wolfssl_demo.h for application type + `#define CRYPT_TEST // enable crypt test` + `#define BENCHMARK // enable benchmark application` + `#define TLS_CLIENT // enable simple tls client application` + `#define TLS_SERVER // enable simple tls server application` + `#define USE_TSIP_TLS // inform user key and flash keying` + 7. Setup debug configuration based on your debug hardware + +### Create flash keyring and use it in an example program + 1. Please follow the instruction at TSIP manual, chapter 7. Key Data Operations. + 2. Copy and past s_flash[] data to s_flash[] data in example-program/key_data.c +`const uint32_t s_flash[] =` +### Create RSA key pair for signing Root CA verification and ust them in an example program + To use TSIP TLS-linked APIs, it needs RSA key pair and Root CA certificate bundle signature by RSA 2048 PSS with SHA256. + The following steps describe RSA key pair generation and signing Root CA. + + 1. Create public key and praivte key pair + e.g. + openssl genrsa 2048 > private_key.pem + openssl ras -in private_key.pem -pubout -out public_key.pem + 2. PSS signe by using created private key + e.g. + openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pass_saltlen:-1 -sign "private_key" -out "out_signed_file" "in_target_der_file" + + 3. Create encrypted RSA public key for CA verification + Extract publicExponent and privateExponet from created key pair at step 1. + To generate RSA public key for CA verification, please follow the instruction at TSIP manual, chapter 7.7. + +### Coding + +In your application you must include before any other wolfSSL headers. If building the sources directly we recommend defining `WOLFSSL_USER_SETTINGS` and adding your own `user_settings.h` file. You can find a good reference for this in `/path/to/Renesas/e2studio/Projects/common/user_settings.h`. + +## Support + For question please email [support@wolfssl.com] + +* Renesas : e2Studio v7.4.0 +* ToolChain : Renesas CCRX version 3.00.00 +* Board : [GR-ROSE](http://gadget.renesas.com/en/product/rose.html) +* wolfSSL : 4.1.0 diff --git a/IDE/Renesas/e2studio/Projects/common/user_settings.h b/IDE/Renesas/e2studio/Projects/common/user_settings.h index 43bb8b8fc..a1e14be9e 100644 --- a/IDE/Renesas/e2studio/Projects/common/user_settings.h +++ b/IDE/Renesas/e2studio/Projects/common/user_settings.h @@ -31,10 +31,11 @@ #define WOLFSSL_NO_CURRDIR #define NO_FILESYSTEM #define WOLFSSL_LOG_PRINTF - -/* #define DEBUG_WOLFSSL */ - -#define OPENSSL_EXTRA +#define WOLFSSL_HAVE_MIN +#define WOLFSSL_HAVE_MAX +#if !defined(min) + #define min(data1, data2) _builtin_min(data1, data2) +#endif #define WOLFSSL_SMALL_STACK #define WOLFSSL_DH_CONST @@ -47,15 +48,15 @@ #define USE_WOLF_TIMEVAL_T #define WOLFSSL_USER_CURRTIME /* for benchmark */ - -#define WOLFSSL_GENSEED_FORTEST /* Wardning: define your own seed gen */ - #define TFM_TIMING_RESISTANT #define ECC_TIMING_RESISTANT #define WC_RSA_BLINDING #define SINGLE_THREADED /* or define RTOS option */ -/* #define WOLFSSL_CMSIS_RTOS */ +#ifndef SINGLE_THREADED + /* expects use FRERRTOS */ + #define FREERTOS +#endif /* #define NO_DH */ #define HAVE_AESGCM @@ -66,3 +67,20 @@ #define HAVE_ED25519 /* #define NO_WOLFSSL_STUB */ +/* #define DEBUG_WOLFSSL */ +/* TSIP TLS specific definitions */ +#if !defined(WOLFSSL_RENESAS_TSIP) + #define OPENSSL_EXTRA + #define WOLFSSL_GENSEED_FORTEST /* Wardning: define your own seed gen */ +#else + #define NO_DES3 +#if defined(WOLFSSL_RENESAS_RX65N) + /* In the case of Static RSA and AES-CBC use */ + #define HAVE_AES_CBC + #define WOLFSSL_STATIC_RSA + /* for disabling TSIP CRYPT */ + /* #define NO_RENESAS_TSIP_CRYPT */ + /* for disabling TSIP TLS COMMON CRYPT */ + /* #define NO_WOLFSSL_RENESAS_TSIP_TLS_SESSION */ +#endif +#endif diff --git a/IDE/Renesas/e2studio/Projects/test/.cproject b/IDE/Renesas/e2studio/Projects/test/.cproject index bd6ffeec9..7caf5163b 100644 --- a/IDE/Renesas/e2studio/Projects/test/.cproject +++ b/IDE/Renesas/e2studio/Projects/test/.cproject @@ -1,8 +1,8 @@ - - + + @@ -14,83 +14,408 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -98,13 +423,16 @@ - + + + + diff --git a/IDE/Renesas/e2studio/Projects/test/.project b/IDE/Renesas/e2studio/Projects/test/.project index 3776d30b1..56fb1785e 100644 --- a/IDE/Renesas/e2studio/Projects/test/.project +++ b/IDE/Renesas/e2studio/Projects/test/.project @@ -17,6 +17,11 @@ + + com.renesas.cdt.managedbuild.renesas.misrachecker.builder + + + org.eclipse.cdt.core.cnature @@ -25,14 +30,29 @@ - src/test.c + src/benchmark.c 1 - PARENT-5-PROJECT_LOC/wolfcrypt/test/test.c + copy_PARENT1/wolfcrypt/benchmark/benchmark.c - src/wolfssl_dummy.c + src/benchmark.h 1 - PARENT-1-PROJECT_LOC/common/wolfssl_dummy.c + copy_PARENT1/wolfcrypt/benchmark/benchmark.h + + + src/test.c + 1 + copy_PARENT1/wolfcrypt/test/test.c + + + copy_PARENT + $%7BPARENT-3-ECLIPSE_HOME%7D/workspace/wolfssl + + + copy_PARENT1 + $%7BPARENT-1-copy_PARENT%7D/wolfssl_tsip + + diff --git a/IDE/Renesas/e2studio/Projects/test/src/key_data.c b/IDE/Renesas/e2studio/Projects/test/src/key_data.c new file mode 100644 index 000000000..9c50e4c8a --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/key_data.c @@ -0,0 +1,266 @@ + +#include "key_data.h" +#ifdef WOLFSSL_RENESAS_TSIP +const st_key_block_data_t g_key_block_data = +{ + + /* uint8_t encrypted_session_key[R_TSIP_AES_CBC_IV_BYTE_SIZE * 2]; */ + { + 0xCE, 0xE0, 0xE9, 0x86, 0x62, 0x59, 0xF9, 0x8F, 0x3C, 0xFB, 0x81, 0x39, 0xC2, 0x82, 0xC7, 0xC9, + 0xCD, 0xEA, 0x6B, 0x16, 0x66, 0x77, 0x38, 0xCA, 0xF5, 0x6E, 0x6D, 0x5B, 0xF0, 0x30, 0xA2, 0x94 + }, + /* uint8_t iv[R_TSIP_AES_CBC_IV_BYTE_SIZE]; */ + { + 0xF6, 0xA9, 0x83, 0x5A, 0xA1, 0x65, 0x1D, 0x28, 0xC8, 0x1A, 0xA6, 0x9D, 0x34, 0xB2, 0x4D, 0x92 + }, + /* uint8_t encrypted_user_rsa2048_ne_key[R_TSIP_RSA2048_NE_KEY_BYTE_SIZE + 16]; */ + { + 0xFC, 0xB4, 0x0F, 0x72, 0xFE, 0xB4, 0xB1, 0xF7, 0xDB, 0xA7, 0x49, 0x9E, 0x0F, 0xF6, 0x4B, 0xA7, + 0x08, 0x0D, 0x3A, 0xFD, 0xAB, 0x7D, 0x82, 0xD7, 0x26, 0x36, 0xFC, 0xED, 0x3E, 0x53, 0xBC, 0xA1, + 0x3D, 0x75, 0x03, 0x5B, 0x53, 0x6D, 0x63, 0xBB, 0xB0, 0x9A, 0xD7, 0xEB, 0x7C, 0x99, 0x3B, 0xE4, + 0xB7, 0xA3, 0x83, 0xE7, 0x27, 0xBE, 0x88, 0x06, 0x2B, 0x81, 0x66, 0xF8, 0x94, 0x3E, 0x86, 0x02, + 0x5F, 0x97, 0x05, 0xFD, 0x93, 0x78, 0x06, 0x3A, 0xC6, 0xD0, 0x3A, 0x82, 0x5D, 0x10, 0xC4, 0xE3, + 0x30, 0x68, 0x48, 0x25, 0x31, 0xCD, 0x50, 0xBC, 0x91, 0xAF, 0x00, 0x4B, 0xAA, 0x6E, 0x3F, 0x6E, + 0x7F, 0x6A, 0x43, 0xAB, 0xB7, 0x06, 0x8D, 0x05, 0x1D, 0x26, 0x17, 0xE9, 0xD9, 0x72, 0x35, 0xED, + 0x79, 0x13, 0xEB, 0x57, 0xED, 0x33, 0x3B, 0x9B, 0x75, 0x15, 0xAB, 0x13, 0xEE, 0xDB, 0xCC, 0x9F, + 0x78, 0xF0, 0x51, 0x67, 0x53, 0xC2, 0xC3, 0xEF, 0xB1, 0x16, 0x39, 0xCB, 0x24, 0x5D, 0x11, 0x43, + 0x3F, 0xDC, 0x90, 0xD2, 0xA9, 0x4B, 0x6C, 0x9C, 0xBC, 0x77, 0x7B, 0xA4, 0x02, 0x8A, 0xB3, 0x7A, + 0x99, 0x75, 0x76, 0x86, 0xE2, 0xEA, 0x83, 0x8D, 0x07, 0xB0, 0xF1, 0xF0, 0x6E, 0x21, 0x19, 0x2E, + 0x16, 0x6B, 0xA3, 0x81, 0xB2, 0xE6, 0x29, 0x16, 0xAA, 0xBC, 0x43, 0x73, 0x1C, 0xC4, 0xDB, 0x92, + 0x2A, 0xA9, 0x20, 0x37, 0x64, 0x4C, 0xE1, 0x95, 0x91, 0x8C, 0x1E, 0xCD, 0xA3, 0xFE, 0x8B, 0x23, + 0x89, 0x2B, 0x6D, 0xA8, 0x6D, 0xD1, 0x7C, 0x20, 0xB9, 0x32, 0xA3, 0x0C, 0x8A, 0x5E, 0xE8, 0x7B, + 0xC8, 0x32, 0xA2, 0x81, 0x30, 0x7D, 0x21, 0x56, 0x97, 0x9C, 0x0C, 0x68, 0xAD, 0xFD, 0x6D, 0xFD, + 0xE0, 0x04, 0xE5, 0xB3, 0xC7, 0xED, 0x84, 0xCB, 0xD4, 0xB0, 0x84, 0x09, 0x99, 0xC3, 0xFB, 0x8B, + 0x91, 0x55, 0x2C, 0xCB, 0x48, 0x06, 0xD1, 0x6C, 0xE0, 0x42, 0x13, 0xDF, 0x2B, 0x73, 0x25, 0xB3, + 0x15, 0xC5, 0x8A, 0xDF, 0x01, 0x2B, 0x96, 0x01, 0x95, 0x84, 0xE4, 0x8E, 0xBA, 0x32, 0xCB, 0x77 + }, +}; + +const uint32_t s_flash[] = +{ + 0xa6f0651c, 0xa17c5a15, 0xa23e1bfb, 0xc04e1bb9, + 0x5594fc81, 0x67fad158, 0xfda808ae, 0x7e01cb88, + 0xbf12d558, 0x9ec08adc, 0x21c25af2, 0x60d43062, + 0x82e6b470, 0x178879a6, 0x9ddb263f, 0xddb57b53, + 0x220ea793, 0x24de7b88, 0x9fa846e4, 0xdf9059f9, + 0x7ce55a19, 0x686689e5, 0x9aaef400, 0x88fd178a, + 0xf4e33b46, 0xc9394a88, 0x712823b9, 0xca75513f, + 0x63859e61, 0x45477873, 0x357b5776, 0x83cc1def, + 0x74cb65ab, 0xa919863c, 0x9f75e62e, 0x5fd62143, + 0xdbae440a, 0x34053525, 0x56e221e1, 0x8ffbaeb5, + 0xa75c55f0, 0x34727e44, 0x2c791463, 0x7670923f, + 0xc0287d97, 0x0a09b5c9, 0xfaecf18e, 0x09ceab85, + 0x687ad46f, 0x7e4d8adb, 0x6def5893, 0x6f236da3, + 0xab6e15e1, 0x653f41d0, 0x05652571, 0x9ec8ec15, + 0x2d4acb06, 0x7d5c2c26, 0xf49455cb, 0x9872dc50, + 0xb9fe50a2, 0x34bf45ae, 0x4cf2b6bf, 0xe1c75c7b, + 0x6e23718f, 0x227b0a55, 0x3a5e8b00, 0x83222dba, + 0x4041008f, 0x40fc8d01, 0xcd6c5c64, 0x0b8183b5, + 0x678bf9e7, 0x57844b52, 0xb4c81735, 0x559e77f3, + 0xb2b6800e, 0x715de4e2, 0x7a2720bb, 0x7b434710, + 0xee264103, 0x9db8c751, 0x78291c62, 0x77b883f4, + 0xa27d1216, 0x4e733ba6, 0x8a5f40dc, 0x32d2dd82, + 0x8a5fdc67, 0xd8fb0926, 0x9d5aec51, 0x08bfce4d, + 0x2a54839b, 0xe6601069, 0x564fbdbf, 0x9bb43dc7, + 0x9bb59d3a, 0xc3aaa60c, 0x2f2e75d7, 0x6a953972, + 0x6de4fd23, 0x546c212b, 0xe8aad33f, 0xca416c37, + 0xa74b36f9, 0x520330f0, 0x96145828, 0x09c21110, + 0x0b29365a, 0xfe9a9e60, 0x82b3a215, 0x752daa46, + 0x45bd59d6, 0x145ba47f, 0x75e40f92, 0x2f904860, + 0x609e3b0a, 0x8e6e6aa8, 0xe88ea1c3, 0x22a1db60, + 0x9947e0c7, 0x28416ca7, 0x3cb6abe6, 0x0e367da7, + 0x17b16976, 0x5323ccde, 0xc7337459, 0xf07293ad, +}; + +const unsigned char ca_cert_der[] = +{ + 0x30, 0x82, 0x04, 0xAA, 0x30, 0x82, 0x03, 0x92, 0xA0, 0x03, + 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0x86, 0xFF, 0xF5, 0x8E, + 0x10, 0xDE, 0xB8, 0xFB, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, + 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, + 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, + 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, + 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, + 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x0A, + 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74, 0x68, + 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, + 0x0A, 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, + 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, + 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, + 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, + 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, + 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, + 0x31, 0x35, 0x32, 0x33, 0x30, 0x39, 0x5A, 0x17, 0x0D, 0x32, + 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35, 0x32, 0x33, 0x30, + 0x39, 0x5A, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, + 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, + 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, + 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, + 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, + 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, + 0x6F, 0x74, 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x0B, 0x0C, 0x0A, 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, + 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, + 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, + 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, + 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, + 0x63, 0x6F, 0x6D, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, + 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, + 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xBF, 0x0C, 0xCA, 0x2D, + 0x14, 0xB2, 0x1E, 0x84, 0x42, 0x5B, 0xCD, 0x38, 0x1F, 0x4A, + 0xF2, 0x4D, 0x75, 0x10, 0xF1, 0xB6, 0x35, 0x9F, 0xDF, 0xCA, + 0x7D, 0x03, 0x98, 0xD3, 0xAC, 0xDE, 0x03, 0x66, 0xEE, 0x2A, + 0xF1, 0xD8, 0xB0, 0x7D, 0x6E, 0x07, 0x54, 0x0B, 0x10, 0x98, + 0x21, 0x4D, 0x80, 0xCB, 0x12, 0x20, 0xE7, 0xCC, 0x4F, 0xDE, + 0x45, 0x7D, 0xC9, 0x72, 0x77, 0x32, 0xEA, 0xCA, 0x90, 0xBB, + 0x69, 0x52, 0x10, 0x03, 0x2F, 0xA8, 0xF3, 0x95, 0xC5, 0xF1, + 0x8B, 0x62, 0x56, 0x1B, 0xEF, 0x67, 0x6F, 0xA4, 0x10, 0x41, + 0x95, 0xAD, 0x0A, 0x9B, 0xE3, 0xA5, 0xC0, 0xB0, 0xD2, 0x70, + 0x76, 0x50, 0x30, 0x5B, 0xA8, 0xE8, 0x08, 0x2C, 0x7C, 0xED, + 0xA7, 0xA2, 0x7A, 0x8D, 0x38, 0x29, 0x1C, 0xAC, 0xC7, 0xED, + 0xF2, 0x7C, 0x95, 0xB0, 0x95, 0x82, 0x7D, 0x49, 0x5C, 0x38, + 0xCD, 0x77, 0x25, 0xEF, 0xBD, 0x80, 0x75, 0x53, 0x94, 0x3C, + 0x3D, 0xCA, 0x63, 0x5B, 0x9F, 0x15, 0xB5, 0xD3, 0x1D, 0x13, + 0x2F, 0x19, 0xD1, 0x3C, 0xDB, 0x76, 0x3A, 0xCC, 0xB8, 0x7D, + 0xC9, 0xE5, 0xC2, 0xD7, 0xDA, 0x40, 0x6F, 0xD8, 0x21, 0xDC, + 0x73, 0x1B, 0x42, 0x2D, 0x53, 0x9C, 0xFE, 0x1A, 0xFC, 0x7D, + 0xAB, 0x7A, 0x36, 0x3F, 0x98, 0xDE, 0x84, 0x7C, 0x05, 0x67, + 0xCE, 0x6A, 0x14, 0x38, 0x87, 0xA9, 0xF1, 0x8C, 0xB5, 0x68, + 0xCB, 0x68, 0x7F, 0x71, 0x20, 0x2B, 0xF5, 0xA0, 0x63, 0xF5, + 0x56, 0x2F, 0xA3, 0x26, 0xD2, 0xB7, 0x6F, 0xB1, 0x5A, 0x17, + 0xD7, 0x38, 0x99, 0x08, 0xFE, 0x93, 0x58, 0x6F, 0xFE, 0xC3, + 0x13, 0x49, 0x08, 0x16, 0x0B, 0xA7, 0x4D, 0x67, 0x00, 0x52, + 0x31, 0x67, 0x23, 0x4E, 0x98, 0xED, 0x51, 0x45, 0x1D, 0xB9, + 0x04, 0xD9, 0x0B, 0xEC, 0xD8, 0x28, 0xB3, 0x4B, 0xBD, 0xED, + 0x36, 0x79, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x81, 0xFC, + 0x30, 0x81, 0xF9, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, + 0x04, 0x16, 0x04, 0x14, 0x27, 0x8E, 0x67, 0x11, 0x74, 0xC3, + 0x26, 0x1D, 0x3F, 0xED, 0x33, 0x63, 0xB3, 0xA4, 0xD8, 0x1D, + 0x30, 0xE5, 0xE8, 0xD5, 0x30, 0x81, 0xC9, 0x06, 0x03, 0x55, + 0x1D, 0x23, 0x04, 0x81, 0xC1, 0x30, 0x81, 0xBE, 0x80, 0x14, + 0x27, 0x8E, 0x67, 0x11, 0x74, 0xC3, 0x26, 0x1D, 0x3F, 0xED, + 0x33, 0x63, 0xB3, 0xA4, 0xD8, 0x1D, 0x30, 0xE5, 0xE8, 0xD5, + 0xA1, 0x81, 0x9A, 0xA4, 0x81, 0x97, 0x30, 0x81, 0x94, 0x31, + 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, + 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, + 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, + 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, + 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, + 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74, 0x68, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A, 0x43, 0x6F, + 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18, + 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, + 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, + 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, + 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, + 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, + 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x09, 0x00, + 0x86, 0xFF, 0xF5, 0x8E, 0x10, 0xDE, 0xB8, 0xFB, 0x30, 0x0C, + 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, + 0x01, 0xFF, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0x9E, 0x28, 0x88, 0x72, 0x00, 0xCA, 0xE6, 0xE7, + 0x97, 0xCA, 0xC1, 0xF1, 0x1F, 0x9E, 0x12, 0xB2, 0xB8, 0xC7, + 0x51, 0xEA, 0x28, 0xE1, 0x36, 0xB5, 0x2D, 0xE6, 0x2F, 0x08, + 0x23, 0xCB, 0xA9, 0x4A, 0x87, 0x25, 0xC6, 0x5D, 0x89, 0x45, + 0xEA, 0xF5, 0x00, 0x98, 0xAC, 0x76, 0xFB, 0x1B, 0xAF, 0xF0, + 0xCE, 0x64, 0x9E, 0xDA, 0x08, 0xBF, 0xB6, 0xEB, 0xB4, 0xB5, + 0x0C, 0xA0, 0xE7, 0xF6, 0x47, 0x59, 0x1C, 0x61, 0xCF, 0x2E, + 0x0E, 0x58, 0xA4, 0x82, 0xAC, 0x0F, 0x3F, 0xEC, 0xC4, 0xAE, + 0x80, 0xF7, 0xB0, 0x8A, 0x1E, 0x85, 0x41, 0xE8, 0xFF, 0xFE, + 0xFE, 0x4F, 0x1A, 0x24, 0xD5, 0x49, 0xFA, 0xFB, 0xFE, 0x5E, + 0xE5, 0xD3, 0x91, 0x0E, 0x4F, 0x4E, 0x0C, 0x21, 0x51, 0x71, + 0x83, 0x04, 0x6B, 0x62, 0x7B, 0x4F, 0x59, 0x76, 0x48, 0x81, + 0x1E, 0xB4, 0xF7, 0x04, 0x47, 0x8A, 0x91, 0x57, 0xA3, 0x11, + 0xA9, 0xF2, 0x20, 0xB4, 0x78, 0x33, 0x62, 0x3D, 0xB0, 0x5E, + 0x0D, 0xF9, 0x86, 0x38, 0x82, 0xDA, 0xA1, 0x98, 0x8D, 0x19, + 0x06, 0x87, 0x21, 0x39, 0xB7, 0x02, 0xF7, 0xDA, 0x7D, 0x58, + 0xBA, 0x52, 0x15, 0xD8, 0x3B, 0xC9, 0x7B, 0x58, 0x34, 0xA0, + 0xC7, 0xE2, 0x7C, 0xA9, 0x83, 0x13, 0xE1, 0xB6, 0xEC, 0x01, + 0xBF, 0x52, 0x33, 0x0B, 0xC4, 0xFE, 0x43, 0xD3, 0xC6, 0xA4, + 0x8E, 0x2F, 0x87, 0x7F, 0x7A, 0x44, 0xEA, 0xCA, 0x53, 0x6C, + 0x85, 0xED, 0x65, 0x76, 0x73, 0x31, 0x03, 0x4E, 0xEA, 0xBD, + 0x35, 0x54, 0x13, 0xF3, 0x64, 0x87, 0x6B, 0xDF, 0x34, 0xDD, + 0x34, 0xA1, 0x88, 0x3B, 0xDB, 0x4D, 0xAF, 0x1B, 0x64, 0x90, + 0x92, 0x71, 0x30, 0x8E, 0xC8, 0xCC, 0xE5, 0x60, 0x24, 0xAF, + 0x31, 0x16, 0x39, 0x33, 0x91, 0x50, 0xF9, 0xAB, 0x68, 0x42, + 0x74, 0x7A, 0x35, 0xD9, 0xDD, 0xC8, 0xC4, 0x52 +}; +const int sizeof_ca_cert_der = sizeof(ca_cert_der); + +/* ./ca-cert.der.sign, */ +const unsigned char ca_cert_sig[] = +{ + 0x86, 0xD6, 0xC5, 0xB0, 0xE1, 0x37, 0x4C, 0x21, 0xF7, 0x8D, + 0x7C, 0x36, 0x80, 0xDB, 0x51, 0x58, 0x9D, 0x32, 0x5A, 0x1C, + 0xF3, 0xAC, 0x24, 0x17, 0xD4, 0x61, 0x9F, 0x09, 0x73, 0xA0, + 0x1E, 0x30, 0xE7, 0x6F, 0x00, 0xF8, 0xDB, 0xAA, 0x34, 0x4E, + 0x96, 0xA3, 0x3D, 0xBC, 0xE8, 0xFF, 0xBE, 0x4E, 0x62, 0x70, + 0x7B, 0xC7, 0x65, 0x2E, 0x9D, 0x1C, 0xE1, 0x5A, 0x7C, 0x2B, + 0xCD, 0x57, 0xEA, 0xF4, 0x16, 0xBC, 0x47, 0x26, 0xF5, 0x41, + 0x1F, 0x4E, 0xFD, 0xA5, 0x65, 0xAE, 0x31, 0xEB, 0xDF, 0x10, + 0xAF, 0xCB, 0xCB, 0x27, 0x84, 0xB6, 0x59, 0x3C, 0x6B, 0x9B, + 0x68, 0xAF, 0xEF, 0x35, 0xAF, 0x59, 0x9B, 0x07, 0x69, 0x75, + 0x1A, 0x99, 0x92, 0x0F, 0x0D, 0x02, 0x5A, 0x2C, 0x14, 0xD5, + 0x38, 0x8B, 0xD2, 0xB5, 0x35, 0xC7, 0x2D, 0xEB, 0x97, 0x4C, + 0xC8, 0x53, 0xCF, 0x7C, 0x0C, 0xB3, 0x00, 0x90, 0x99, 0x0B, + 0xB1, 0xBE, 0x8B, 0xEA, 0x96, 0xB4, 0x75, 0x35, 0x9D, 0xA1, + 0x2E, 0xF3, 0xF3, 0xEA, 0xF5, 0x7B, 0x83, 0xEF, 0x03, 0x06, + 0x3C, 0x41, 0x1C, 0x32, 0x84, 0x4A, 0xB8, 0xB0, 0xAE, 0x67, + 0xE9, 0xE4, 0xEE, 0x58, 0x43, 0x0C, 0x0D, 0xAE, 0x6C, 0xB8, + 0x94, 0x7F, 0x80, 0x33, 0xD3, 0xDC, 0x04, 0x02, 0xDC, 0x6F, + 0x17, 0xDC, 0xAE, 0x79, 0xED, 0xE3, 0x99, 0xAA, 0xE8, 0x4E, + 0x6A, 0x43, 0x73, 0xE6, 0xF3, 0xF8, 0x5A, 0x51, 0x55, 0x5E, + 0x55, 0x2D, 0xD6, 0xF7, 0xD5, 0xAB, 0xBE, 0xBD, 0xC8, 0x7D, + 0xB0, 0xA7, 0x9A, 0x46, 0xC0, 0xDC, 0x16, 0x83, 0xE9, 0x2C, + 0x56, 0x6C, 0x45, 0x52, 0x3E, 0x05, 0x4D, 0x5F, 0x11, 0xD0, + 0x93, 0x0F, 0x82, 0x6D, 0x6E, 0xC0, 0x01, 0x38, 0x3B, 0x2F, + 0xD9, 0x80, 0x51, 0x6D, 0xD1, 0x1B, 0x22, 0x72, 0xBB, 0x15, + 0x5D, 0xBC, 0xB8, 0x07, 0xBB, 0x96 +}; +const int sizeof_ca_cert_sig = sizeof(ca_cert_sig); + +/* ./client-cert.der.sign, */ +const unsigned char client_cert_der_sign[] = +{ + 0x5D, 0x1F, 0x89, 0x41, 0xEC, 0x47, 0xC8, 0x90, 0x61, 0x79, + 0x8A, 0x16, 0x1F, 0x31, 0x96, 0x67, 0xD9, 0x3C, 0xEC, 0x6B, + 0x58, 0xC6, 0x5A, 0xED, 0x99, 0xB3, 0xEF, 0x27, 0x6F, 0x04, + 0x8C, 0xD9, 0x68, 0xB1, 0xD6, 0x23, 0x15, 0x84, 0x00, 0xE1, + 0x27, 0xD1, 0x1F, 0x68, 0xB7, 0x3F, 0x13, 0x53, 0x8A, 0x95, + 0x5A, 0x20, 0x7C, 0xB2, 0x76, 0x5B, 0xDC, 0xE0, 0xA6, 0x21, + 0x7C, 0x49, 0xCF, 0x93, 0xBA, 0xD5, 0x12, 0x9F, 0xEE, 0x90, + 0x5B, 0x3F, 0xA3, 0x9D, 0x13, 0x72, 0xAC, 0x72, 0x16, 0xFE, + 0x1D, 0xBE, 0xEB, 0x8E, 0xC7, 0xDC, 0xC4, 0xF8, 0x1A, 0xD8, + 0xA0, 0xA4, 0xF6, 0x04, 0x30, 0xF6, 0x7E, 0xB6, 0xC8, 0xE1, + 0xAB, 0x88, 0x37, 0x08, 0x63, 0x72, 0xAA, 0x46, 0xCC, 0xCA, + 0xF0, 0x9E, 0x02, 0x1E, 0x65, 0x67, 0xFF, 0x2C, 0x9D, 0x81, + 0x6C, 0x1E, 0xF1, 0x54, 0x05, 0x68, 0x68, 0x18, 0x72, 0x26, + 0x55, 0xB6, 0x2C, 0x95, 0xC0, 0xC9, 0xB2, 0xA7, 0x0B, 0x60, + 0xD7, 0xEB, 0x1D, 0x08, 0x1A, 0xA2, 0x54, 0x15, 0x89, 0xCB, + 0x83, 0x21, 0x5D, 0x15, 0x9B, 0x38, 0xAC, 0x89, 0x63, 0xD5, + 0x4B, 0xF4, 0x8B, 0x47, 0x93, 0x78, 0x43, 0xCB, 0x9B, 0x71, + 0xBF, 0x94, 0x76, 0xB5, 0xCE, 0x35, 0xA9, 0x1A, 0xD5, 0xA5, + 0xD8, 0x19, 0xA6, 0x04, 0x39, 0xB1, 0x09, 0x8C, 0x65, 0x02, + 0x58, 0x3A, 0x95, 0xEF, 0xA2, 0xC3, 0x85, 0x18, 0x61, 0x23, + 0x2D, 0xC5, 0xCD, 0x62, 0xC1, 0x19, 0x31, 0xE5, 0x36, 0x95, + 0x22, 0xDB, 0x3E, 0x1A, 0x3C, 0xE8, 0xC6, 0x2E, 0xDF, 0xD9, + 0x2F, 0x84, 0xC1, 0xF0, 0x38, 0x2B, 0xE5, 0x73, 0x35, 0x4F, + 0x05, 0xE2, 0xA5, 0x60, 0x79, 0xB0, 0x23, 0xDC, 0x56, 0x4C, + 0xE7, 0xD9, 0x1F, 0xCF, 0x6A, 0xFC, 0x55, 0xEB, 0xAA, 0x48, + 0x3E, 0x95, 0x2A, 0x10, 0x01, 0x05 +}; +const int sizeof_client_cert_der_sign = sizeof(client_cert_der_sign); + +uint32_t s_inst1[R_TSIP_SINST_WORD_SIZE] = { 0 }; +uint32_t s_inst2[R_TSIP_SINST2_WORD_SIZE]= { 0 }; +#endif diff --git a/IDE/Renesas/e2studio/Projects/test/src/key_data.h b/IDE/Renesas/e2studio/Projects/test/src/key_data.h new file mode 100644 index 000000000..7e96b02da --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/key_data.h @@ -0,0 +1,26 @@ + +#ifndef KEY_DATA_H_ +#define KEY_DATA_H_ +#include + +#ifdef WOLFSSL_RENESAS_TSIP +#include "r_tsip_rx_if.h" + +/** user key datas */ +typedef struct key_block_data +{ + uint8_t encrypted_session_key[R_TSIP_AES_CBC_IV_BYTE_SIZE * 2]; + uint8_t iv[R_TSIP_AES_CBC_IV_BYTE_SIZE]; + uint8_t encrypted_user_rsa2048_ne_key[R_TSIP_RSA2048_NE_KEY_BYTE_SIZE + 16]; +} st_key_block_data_t; + +extern const st_key_block_data_t g_key_block_data; +extern const uint32_t s_flash[]; +extern const unsigned char ca_cert_der[]; +extern const int sizeof_ca_cert_der; +extern const unsigned char ca_cert_sig[]; +extern const unsigned char client_cert_der_sign[]; + +#endif /* WOLFSSL_RENESAS_TSIP */ +#endif /* KEY_DATA_H_ */ + diff --git a/IDE/Renesas/e2studio/Projects/test/src/test_main.c b/IDE/Renesas/e2studio/Projects/test/src/test_main.c index e75c8ef4a..5957d14bb 100644 --- a/IDE/Renesas/e2studio/Projects/test/src/test_main.c +++ b/IDE/Renesas/e2studio/Projects/test/src/test_main.c @@ -26,6 +26,10 @@ #endif #include "stdio.h" +#include "stdint.h" +#include +#include "wolfssl/wolfcrypt/types.h" +#include "wolfssl_demo.h" void main(void); #ifdef __cplusplus @@ -34,6 +38,29 @@ void abort(void); } #endif + +#if defined(TLS_CLIENT) || defined(TLS_SERVER) + #include "r_t4_itcpip.h" + #include "r_sys_time_rx_if.h" + #include "Pin.h" + + #define T4_WORK_SIZE (14800) + static UW tcpudp_work[(T4_WORK_SIZE / 4) + 1]; + +#if defined(USE_TSIP_TLS) + #include "key_data.h" + #include + + extern const st_key_block_data_t g_key_block_data; +#endif +#endif + +static long tick; +static void timeTick(void *pdata) +{ + tick++; +} + typedef struct func_args { int argc; char** argv; @@ -42,13 +69,148 @@ typedef struct func_args { void wolfcrypt_test(func_args args); +int benchmark_test(void *args); + +double current_time(int reset) +{ + if(reset) tick = 0 ; + return ((double)tick/FREQ) ; +} + +#if defined(TLS_CLIENT) || defined(TLS_SERVER) + +int SetTsiptlsKey() +{ +#if defined(WOLFSSL_RENESAS_TSIP) && defined(TLS_CLIENT) + tsip_inform_cert_sing((const byte *)ca_cert_sig); + tsip_inform_user_keys((byte*)&g_key_block_data.encrypted_session_key, + (byte*)&g_key_block_data.iv, + (byte*)&g_key_block_data.encrypted_user_rsa2048_ne_key); +#elif defined(WOLFSSL_RENESAS_TSIP) && defined(TLS_SERVER) + tsip_inform_cert_sing((const byte *)client_cert_der_sign); + tsip_inform_user_keys((byte*)&g_key_block_data.encrypted_session_key, + (byte*)&g_key_block_data.iv, + (byte*)&g_key_block_data.encrypted_user_rsa2048_ne_key); +#endif + return 0; +} + +int Open_tcp( ) +{ + ER ercd; + W size; + sys_time_err_t sys_ercd; + char ver[128]; + + /* cast from uint8_t to char* */ + strcpy(ver, (char*)R_t4_version.library); + + sys_ercd = R_SYS_TIME_Open(); + if (sys_ercd != SYS_TIME_SUCCESS) { + printf("ERROR : R_SYS_TIME_Open() failed\n"); + return -1; + } + R_Pins_Create(); + /* start LAN controller */ + ercd = lan_open(); + /* initialize TCP/IP */ + size = tcpudp_get_ramsize(); + if (size > (sizeof(tcpudp_work))) { + printf("size > (sizeof(tcpudp_work))!\n"); + return -1; + } + ercd = tcpudp_open(tcpudp_work); + if (ercd != E_OK) { + printf("ERROR : tcpudp_open failed\n"); + return -1; + } + + return 0; +} + +void Close_tcp() +{ + /* end TCP/IP */ + tcpudp_close(); + lan_close(); + R_SYS_TIME_Close(); +} +#endif + void main(void) { - func_args args = {1}; + (void)timeTick; - printf("Start wolfCrypt Test\n"); - wolfcrypt_test(args); - printf("End wolfCrypt Test\n"); +#if defined(CRYPT_TEST) || defined(BENCHMARK) +#if defined(CRYPT_TEST) + int ret; + func_args args = { 0 }; + + if ((ret = wolfCrypt_Init()) != 0) { + printf("wolfCrypt_Init failed %d\n", ret); + } + + printf("Start wolfCrypt Test\n"); + wolfcrypt_test(args); + printf("End wolfCrypt Test\n"); + + if ((ret = wolfCrypt_Cleanup()) != 0) { + printf("wolfCrypt_Cleanup failed %d\n", ret); + } +#endif +#if defined(BENCHMARK) + #include "r_cmt_rx_if.h" + + uint32_t channel; + R_CMT_CreatePeriodic(FREQ, &timeTick, &channel); + + printf("Start wolfCrypt Benchmark\n"); + benchmark_test(NULL); + printf("End wolfCrypt Benchmark\n"); +#endif +#elif defined(TLS_CLIENT) +#if defined(USE_TSIP_TLS) + const char* cipherlist[] = { + /* NULL */ + "AES128-SHA", + "AES128-SHA256", + "AES256-SHA", + "AES256-SHA256" + }; + const int cipherlist_sz = 4; +#else + const char* cipherlist[] = { NULL }; + const int cipherlist_sz = 0; + +#endif + int i = 0; + + Open_tcp(); +#if defined(USE_TSIP_TLS) + SetTsiptlsKey(); +#endif + + do { + if(cipherlist_sz > 0 ) printf("cipher : %s\n", cipherlist[i]); + wolfSSL_TLS_client_init(cipherlist[i]); + wolfSSL_TLS_client(); + + i++; + } while (i < cipherlist_sz); + + Close_tcp(); +#elif defined(TLS_SERVER) + + Open_tcp(); +#if defined(USE_TSIP_TLS) + SetTsiptlsKey(); +#endif + + wolfSSL_TLS_server_init(); + wolfSSL_TLS_server(); + + Close_tcp(); +#endif } #ifdef __cplusplus diff --git a/IDE/Renesas/e2studio/Projects/test/src/wolf_client.c b/IDE/Renesas/e2studio/Projects/test/src/wolf_client.c new file mode 100644 index 000000000..4bff246c3 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/wolf_client.c @@ -0,0 +1,197 @@ +/* wolf_client.c + * + * Copyright (C) 2006-2019 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 +#include "r_t4_itcpip.h" + +#include "wolfssl/wolfcrypt/settings.h" +#include "wolfssl/ssl.h" +#include "wolfssl/certs_test.h" +#include "key_data.h" + +#define SIMPLE_TLSSEVER_IP "192.168.1.45" +#define SIMPLE_TLSSERVER_PORT "11111" + +ER t4_tcp_callback(ID cepid, FN fncd , VP p_parblk); +uint32_t g_encrypted_root_public_key[140]; + +static WOLFSSL_CTX *client_ctx; + +static int my_IORecv(WOLFSSL* ssl, char* buff, int sz, void* ctx) +{ + int ret; + ID cepid; + + if(ctx != NULL)cepid = *(ID *)ctx; + else return WOLFSSL_CBIO_ERR_GENERAL; + + ret = tcp_rcv_dat(cepid, buff, sz, TMO_FEVR); + if(ret > 0)return ret; + else return WOLFSSL_CBIO_ERR_GENERAL; +} + +static int my_IOSend(WOLFSSL* ssl, char* buff, int sz, void* ctx) +{ + int ret; + ID cepid; + + if(ctx != NULL)cepid = *(ID *)ctx; + else return WOLFSSL_CBIO_ERR_GENERAL; + + ret = tcp_snd_dat(cepid, buff, sz, TMO_FEVR); + if(ret == sz)return ret; + else return WOLFSSL_CBIO_ERR_GENERAL; +} + +static int getIPaddr(char *arg) +{ + int a1, a2, a3, a4; + if(sscanf(arg, "%d.%d.%d.%d", &a1, &a2, &a3, &a4) == 4) + return (a1 << 24) | (a2 << 16) | (a3 << 8) | a4; + else return 0; +} + +static int getPort(char *arg) +{ + int port; + if(sscanf(arg, "%d", &port) == 1) + return port; + else return 0; +} + +void wolfSSL_TLS_client_init(const char* cipherlist) +{ + + #ifndef NO_FILESYSTEM + #ifdef USE_ECC_CERT + char *cert = "./certs/ca-ecc-cert.pem"; + #else + char *cert = "./certs/ca-cert.pem"; + #endif + #else + #ifdef USE_ECC_CERT + const unsigned char *cert = ca_ecc_der_256; + #define SIZEOF_CERT sizeof_ca_ecc_der_256 + #else + const unsigned char *cert = ca_cert_der_2048; + #define SIZEOF_CERT sizeof_ca_cert_der_2048 + #endif + #endif + + wolfSSL_Init(); + #ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); + #endif + + /* Create and initialize WOLFSSL_CTX */ + if ((client_ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method_ex((void *)NULL))) == NULL) { + printf("ERROR: failed to create WOLFSSL_CTX\n"); + return; + } + + #if !defined(NO_FILESYSTEM) + if (wolfSSL_CTX_load_verify_locations(client_ctx, cert, 0) != SSL_SUCCESS) { + printf("ERROR: can't load \"%s\"\n", cert); + return NULL; + } + #else + if (wolfSSL_CTX_load_verify_buffer(client_ctx, cert, SIZEOF_CERT, SSL_FILETYPE_ASN1) != SSL_SUCCESS){ + printf("ERROR: can't load certificate data\n"); + return; + } + #endif + + /* Register callbacks */ + wolfSSL_SetIORecv(client_ctx, my_IORecv); + wolfSSL_SetIOSend(client_ctx, my_IOSend); + + /* use specific cipher */ + if (cipherlist != NULL && wolfSSL_CTX_set_cipher_list(client_ctx, cipherlist) != WOLFSSL_SUCCESS) { + wolfSSL_CTX_free(client_ctx); client_ctx = NULL; + printf("client can't set cipher list 1"); + } +} + +void wolfSSL_TLS_client( ) +{ + ID cepid = 1; + ER ercd; + int ret; + WOLFSSL_CTX *ctx = (WOLFSSL_CTX *)client_ctx; + WOLFSSL *ssl; + #define BUFF_SIZE 256 + static const char sendBuff[]= "Hello Server\n" ; + char rcvBuff[BUFF_SIZE] = {0}; + static T_IPV4EP my_addr = { 0, 0 }; + T_IPV4EP dst_addr; + + if((dst_addr.ipaddr = getIPaddr(SIMPLE_TLSSEVER_IP)) == 0){ + printf("ERROR: IP address\n"); + return; + } + if((dst_addr.portno = getPort(SIMPLE_TLSSERVER_PORT)) == 0){ + printf("ERROR: IP address\n"); + return; + } + + if((ercd = tcp_con_cep(cepid, &my_addr, &dst_addr, TMO_FEVR)) != E_OK) { + printf("ERROR TCP Connect: %d\n", ercd); + return; + } + + if((ssl = wolfSSL_new(ctx)) == NULL) { + printf("ERROR wolfSSL_new: %d\n", wolfSSL_get_error(ssl, 0)); + return; + } + + /* set callback context */ + wolfSSL_SetIOReadCtx(ssl, (void *)&cepid); + wolfSSL_SetIOWriteCtx(ssl, (void *)&cepid); + + if(wolfSSL_connect(ssl) != SSL_SUCCESS) { + printf("ERROR SSL connect: %d\n", wolfSSL_get_error(ssl, 0)); + return; + } + + if (wolfSSL_write(ssl, sendBuff, strlen(sendBuff)) != strlen(sendBuff)) { + printf("ERROR SSL write: %d\n", wolfSSL_get_error(ssl, 0)); + return; + } + + if ((ret=wolfSSL_read(ssl, rcvBuff, BUFF_SIZE)) < 0) { + printf("ERROR SSL read: %d\n", wolfSSL_get_error(ssl, 0)); + return; + } + + rcvBuff[ret] = '\0' ; + printf("Received: %s\n", rcvBuff); + + /* frees all data before client termination */ + wolfSSL_free(ssl); + wolfSSL_CTX_free(ctx); + wolfSSL_Cleanup(); + + tcp_sht_cep(cepid); + tcp_cls_cep(cepid, TMO_FEVR); + + return; +} diff --git a/IDE/Renesas/e2studio/Projects/test/src/wolf_server.c b/IDE/Renesas/e2studio/Projects/test/src/wolf_server.c new file mode 100755 index 000000000..301f35788 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/wolf_server.c @@ -0,0 +1,195 @@ +/* wolf_server.c + * + * Copyright (C) 2006-2019 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 +#include "r_t4_itcpip.h" + +#include "wolfssl/wolfcrypt/settings.h" +#include "wolfssl/ssl.h" +#include "wolfssl/certs_test.h" +#include "wolfssl_demo.h" + +static WOLFSSL_CTX *server_ctx; +static byte doCliCertCheck; + +static int my_IORecv(WOLFSSL* ssl, char* buff, int sz, void* ctx) +{ + int ret; + ID cepid; + + if(ctx != NULL)cepid = *(ID *)ctx; + else return WOLFSSL_CBIO_ERR_GENERAL; + + ret = tcp_rcv_dat(cepid, buff, sz, TMO_FEVR); + if(ret == sz)return ret; + else return WOLFSSL_CBIO_ERR_GENERAL; +} + +static int my_IOSend(WOLFSSL* ssl, char* buff, int sz, void* ctx) +{ + int ret; + ID cepid; + + if(ctx != NULL)cepid = *(ID *)ctx; + else return WOLFSSL_CBIO_ERR_GENERAL; + + ret = tcp_snd_dat(cepid, buff, sz, TMO_FEVR); + if(ret == sz)return ret; + else return WOLFSSL_CBIO_ERR_GENERAL; +} + + +void wolfSSL_TLS_server_init(byte doClientCheck) +{ + + int ret; + + + #ifndef NO_FILESYSTEM + #ifdef USE_ECC_CERT + char *cert = "./certs/server-ecc-cert.pem"; + char *key = "./certs/server-ecc-key.pem"; + #else + char *cert = "./certs/server-cert.pem"; + char *key = "./certs/server-key.pem"; + #endif + char *clientCert = "./certs/client-cert.pem"; + #else + #ifdef USE_ECC_CERT + char *cert = serv_ecc_der_256; + int sizeof_cert = sizeof_serv_ecc_der_256; + char *cert = serv_ecc_key_der_256; + int sizeof_key = sizeof_serv_ecc_key_der_256; + #else + const unsigned char *cert = server_cert_der_2048; + #define sizeof_cert sizeof_server_cert_der_2048 + const unsigned char *key = server_key_der_2048; + #define sizeof_key sizeof_server_key_der_2048 + const unsigned char *clientCert = client_cert_der_2048; + #define sizeof_clicert sizeof_client_cert_der_2048 + #endif + #endif + + + wolfSSL_Init(); + #ifdef DEBUG_WOLFSSL + wolfSSL_Debugging_ON(); + #endif + + /* Create and initialize WOLFSSL_CTX */ + if ((server_ctx = wolfSSL_CTX_new(wolfSSLv23_server_method_ex((void *)NULL))) + == NULL) { + printf("ERROR: failed to create WOLFSSL_CTX\n"); + return; + } + + #if !defined(NO_FILESYSTEM) + ret = wolfSSL_CTX_use_certificate_file(server_ctx, cert, 0); + #else + ret = wolfSSL_CTX_use_certificate_buffer(server_ctx, cert, + sizeof_cert, SSL_FILETYPE_ASN1); + #endif + if (ret != SSL_SUCCESS) { + printf("Error %d loading server-cert!\n", ret); + return; + } + + /* Load server key into WOLFSSL_CTX */ + #if !defined(NO_FILESYSTEM) + ret = wolfSSL_CTX_use_PrivateKey_file(server_ctx, key, 0); + #else + ret = wolfSSL_CTX_use_PrivateKey_buffer(server_ctx, key, sizeof_key, + SSL_FILETYPE_ASN1); + #endif + if (ret != SSL_SUCCESS) { + printf("Error %d loading server-key!\n", ret); + return; + } +#if defined(USE_TSIP_TLS) + doCliCertCheck = 1; +#endif + if (doCliCertCheck) { + wolfSSL_CTX_set_verify(server_ctx, WOLFSSL_VERIFY_PEER | + WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0); +#if !defined(NO_FILESYSTEM) + if (wolfSSL_CTX_load_verify_locations(server_ctx, clientCert, 0) + != WOLFSSL_SUCCESS) +#else + if (wolfSSL_CTX_load_verify_buffer(server_ctx, clientCert, + sizeof_clicert, + SSL_FILETYPE_ASN1) != SSL_SUCCESS) +#endif + printf("can't load ca file, Please run from wolfSSL home dir\n"); + } + + /* Register callbacks */ + wolfSSL_SetIORecv(server_ctx, my_IORecv); + wolfSSL_SetIOSend(server_ctx, my_IOSend); + +} + +void wolfSSL_TLS_server( ) +{ + ID cepid = 1; + ID repid = 1; + ER ercd; + WOLFSSL_CTX *ctx = (WOLFSSL_CTX *)server_ctx; + + WOLFSSL *ssl; + int len; + #define BUFF_SIZE 256 + char buff[BUFF_SIZE]; + T_IPV4EP dst_addr = {0, 0}; + + if((ercd = tcp_acp_cep(cepid, repid, &dst_addr, TMO_FEVR)) != E_OK) { + printf("ERROR TCP Accept: %d\n", ercd); + return; + } + + if((ssl = wolfSSL_new(ctx)) == NULL) { + printf("ERROR: failed wolfSSL_new\n"); + return; + } + + wolfSSL_SetIOReadCtx(ssl, (void *)&cepid); + wolfSSL_SetIOWriteCtx(ssl, (void *)&cepid); + + if (wolfSSL_accept(ssl) < 0) { + printf("ERROR: SSL Accept(%d)\n", wolfSSL_get_error(ssl, 0)); + return; + } + + if ((len = wolfSSL_read(ssl, buff, sizeof(buff) - 1)) < 0) { + printf("ERROR: SSL Read(%d)\n", wolfSSL_get_error(ssl, 0)); + return; + } + + buff[len] = '\0'; + printf("Received: %s\n", buff); + + if (wolfSSL_write(ssl, buff, len) != len) { + printf("ERROR: SSL Write(%d)\n", wolfSSL_get_error(ssl, 0)); + return; + } + + wolfSSL_free(ssl); + tcp_sht_cep(cepid); +} diff --git a/IDE/Renesas/e2studio/Projects/test/src/wolfssl_demo.h b/IDE/Renesas/e2studio/Projects/test/src/wolfssl_demo.h new file mode 100644 index 000000000..7a4bd8447 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/wolfssl_demo.h @@ -0,0 +1,24 @@ +/* + * wolfssl_demo.h + * + * Created on: 2019/07/28 + * Author: darkb + */ + +#ifndef WOLFSSL_DEMO_H_ +#define WOLFSSL_DEMO_H_ + +#define FREQ 10000 /* Hz */ + +//#define CRYPT_TEST +//#define BENCHMARK +//#define TLS_CLIENT +#define USE_TSIP_TLS +#define TLS_SERVER + +void wolfSSL_TLS_client_init(); +void wolfSSL_TLS_client(); +void wolfSSL_TLS_server_init(); +void wolfSSL_TLS_server(); + +#endif /* WOLFSSL_DEMO_H_ */ diff --git a/IDE/Renesas/e2studio/Projects/test/src/wolfssl_dummy.c b/IDE/Renesas/e2studio/Projects/test/src/wolfssl_dummy.c new file mode 100644 index 000000000..06bd446f0 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/test/src/wolfssl_dummy.c @@ -0,0 +1,41 @@ +/* wolfssl_dummy.c + * + * Copyright (C) 2006-2019 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 + */ + +typedef unsigned long time_t; + +#define YEAR 2019 +#define MON 5 + +static int tick = 0; + +time_t time(time_t *t) +{ + return ((YEAR-1970)*365+30*MON)*24*60*60 + tick++; +} + +#include +int strncasecmp(const char *s1, const char * s2, unsigned int sz) +{ + for( ; sz>0; sz--) + if(toupper(s1++) != toupper(s2++)) + return 1; + return 0; +} diff --git a/IDE/Renesas/e2studio/Projects/tools/generate_rsa_keypair.sh b/IDE/Renesas/e2studio/Projects/tools/generate_rsa_keypair.sh new file mode 100755 index 000000000..f69b288e4 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/tools/generate_rsa_keypair.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +function usage(){ + cat << _EOT_ + Usage : + $0 [-g] [-] + + Description: + Generate 2048 bit Rsa key pair and Display moduls and public exponet + + Options: + -g generate rsa key pair, default on + -s only show moduls and public exponent +_EOT_ +exit 1 +} + +FLAG_G="on" +FLAG_S="off" + + while getopts gsh OPT + do + case $OPT in + g) + FLAG_G="on" + ;; + s) + FLAG_S="on" + FLAG_G="off" + ;; + h) + usage + ;; + \?) + usage + ;; + esac + done + +if [ $FLAG_G = "on" ]; then + # generate 2048bit Rsa private key + openssl genrsa 2048 2> /dev/null > private-key.pem + # expose public key + openssl rsa -in private-key.pem -pubout -out public-key.pem 2> /dev/null +fi + +if [ $FLAG_S = "on" ]; then + # display moduls and exponent + openssl rsa -modulus < private-key.pem 2>/dev/null | grep Modulus= + openssl rsa -text < private-key.pem 2> /dev/null | grep publicExponent +fi + diff --git a/IDE/Renesas/e2studio/Projects/tools/genhexbuf.pl b/IDE/Renesas/e2studio/Projects/tools/genhexbuf.pl new file mode 100755 index 000000000..f73e09a0f --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/tools/genhexbuf.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +# genhexbuf.pl +# Copyright (C) 2019 wolfSSL Inc. +# + +use strict; +use warnings; + +# ---- SCRIPT SETTINGS ------------------------------------------------------- + +# output C header file to write cert/key buffers to +my $outputFile = "certs_sig_data.h"; + +# rsa keys and certs to be converted + +my @fileList = ( +# please add your der file and name of the data for C language + # der file name name of the data + #[ "./yourder.der", "your_der_name_in_C" ], + [ "./ca-cert.der", "ca_cert_der" ], + [ "./ca-cert.der.sign", "ca_cert_der_sign" ], + ); + + +# ---------------------------------------------------------------------------- + +my $num = @fileList; + +# open our output file, "+>" creates and/or truncates +open OUT_FILE, "+>", $outputFile or die $!; + +print OUT_FILE "/* certs_sig_data.h */\n\n"; +print OUT_FILE "#ifndef WOLFSSL_CERTS_SIG_DATA_H\n"; +print OUT_FILE "#define WOLFSSL_CERTS_SIG_DATA_H\n\n"; + + +# convert and print 1024-bit cert/keys +for (my $i = 0; $i < $num; $i++) { + + my $fname = $fileList[$i][0]; + my $sname = $fileList[$i][1]; + + print OUT_FILE "/* $fname, */\n"; + print OUT_FILE "static const unsigned char $sname\[] =\n"; + print OUT_FILE "{\n"; + file_to_hex($fname); + print OUT_FILE "};\n"; + print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n"; +} +print OUT_FILE "#endif /* WOLFSSL_CERTS_SIG_DATA_H */\n\n"; + + +# print file as hex, comma-separated, as needed by C buffer +sub file_to_hex { + my $fileName = $_[0]; + + open my $fp, "<", $fileName or die $!; + binmode($fp); + + my $fileLen = -s $fileName; + my $byte; + + for (my $i = 0, my $j = 1; $i < $fileLen; $i++, $j++) + { + if ($j == 1) { + print OUT_FILE " "; + } + if ($j != 1) { + print OUT_FILE " "; + } + read($fp, $byte, 1) or die "Error reading $fileName"; + my $output = sprintf("0x%02X", ord($byte)); + print OUT_FILE $output; + + if ($i != ($fileLen - 1)) { + print OUT_FILE ","; + } + + if ($j == 10) { + $j = 0; + print OUT_FILE "\n"; + } + } + + print OUT_FILE "\n"; + + close($fp); +} diff --git a/IDE/Renesas/e2studio/Projects/tools/rsa_pss_sign.sh b/IDE/Renesas/e2studio/Projects/tools/rsa_pss_sign.sh new file mode 100755 index 000000000..f8b0e2198 --- /dev/null +++ b/IDE/Renesas/e2studio/Projects/tools/rsa_pss_sign.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +SIGOPT=rsa_padding_mode:pss +SIGOPT2=rsa_pss_saltlen:-1 + +function usage() { + cat <<_EOT_ + Usage: + $0 + + pri key : private key for sign/verify + pub key : public key for sign/verify + file name : file name to be signed + +_EOT_ +exit 1 +} + +if [ $# -ne 3 ]; then + usage +fi + +# $1 private key for sign/verify +# $2 public key for verify +# $3 file for sign/verify + +openssl dgst -sha256 -sign $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -out $3.sign $3 + +echo verify by private key +openssl dgst -sha256 -prverify $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3 + +echo verifiy by public key +openssl dgst -sha256 -verify $2 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3 + diff --git a/IDE/Renesas/e2studio/Projects/wolfssl/.cproject b/IDE/Renesas/e2studio/Projects/wolfssl/.cproject index e07a08692..5aa84e6d9 100644 --- a/IDE/Renesas/e2studio/Projects/wolfssl/.cproject +++ b/IDE/Renesas/e2studio/Projects/wolfssl/.cproject @@ -14,7 +14,7 @@ @@ -33,6 +33,7 @@