Update code to v1.0.14 (10)

This commit is contained in:
Caten
2024-02-29 19:35:00 +08:00
parent c2ee3b694c
commit a956d26f6d
3188 changed files with 2317293 additions and 146 deletions

View File

@@ -0,0 +1,345 @@
wolfSSL for Renesas RA Evaluation Kit (EK-RA6M4)
=================================================
## Description
This directory contains e2studio projects targeted at the Renesas RA 32-bit MCUs.
The example projects include a wolfSSL TLS client.
They also include benchmark and cryptography tests for the wolfCrypt library.
The wolfssl project contains both the wolfSSL and wolfCrypt libraries.
It is built as a `Renesas RA C Library Project` and contains the Renesas RA
configuration. The wolfssl project uses `Secure Cryptography Engine on RA6 Protected Mode`
as hardware acceleration for cypto and TLS operation.
The other projects (benchmark, client, and test) are built as a
`Renesas RA C Project Using RA Library`, where the RA library is the wolfssl project.
The wolfssl Project Summary is listed below and is relevant for every project.
### Project Summary
|Item|Name/Version|
|:--|:--|
|Board|EK-RA6M4|
|Device|R7FA6M4AF3CFB|
|Toolchain|GCC ARM Embedded|
|FSP Version|3.5.0|
#### Selected software components
|Components|Version|
|:--|:--|
|Board Support Package Common Files|v3.5.0|
|Secure Cryptography Engine on RA6 Protected Mode|v3.5.0|
|I/O Port|v3.5.0|
|Arm CMSIS Version 5 - Core (M)|v5.8.0+fsp.3.5.0|
|RA6M4-EK Board Support Files|v3.5.0|
|Board support package for R7FA6M4AF3CFB|v3.5.0|
|Board support package for RA6M4|v3.5.0|
|Board support package for RA6M4 - FSP Data|v3.5.0|
|FreeRTOS|v10.4.3-LTS.Patch.2+fsp.3.5.0|
|FreeRTOS - Memory Management - Heap 4|v10.4.3-LTS.Patch.2+fsp.3.5.0|
|r_ether to FreeRTOS+TCP Wrapper|v3.5.0|
|Ethernet|v3.5.0|
|Ethernet PHY|v3.5.0|
|FreeRTOS+TCP|v2.3.2-LTS.Patch.1+fsp.3.5.0|
|FreeRTOS - Buffer Allocation 2|v2.3.2-LTS.Patch.1+fsp.3.5.0|
## Setup Steps and Build wolfSSL Library
1.) Import projects from [File]->[Open projects from File System]
+ Select folder at /path/to/wolfssl/IDE/Renesas/e2studio/RA6M4
+ Deselect the Non-Eclipse project, RA6M4, by clicking the checkbox\
Only the folders with 'Eclipse project' under 'Import as' need to be selected.
2.) Create a `dummy_library` Static Library.
+ Click File->New->`RA C/C++ Project`.
+ Select `EK-RA6M4` from Drop-down list.
+ Check `Static Library`.
+ Select FreeRTOS from RTOS selection. Click Next.
+ Check `FreeRTOS minimal - Static Allocation`. Click Finish.
+ Open Smart Configurator by clicking configuration.xml in the project
+ Go to `BSP` tab and increase Heap Size under `RA Common` on Properties page, e.g. 0x1000
+ Go to `Stacks` tab
+ Add `SCE Protected Mode` stack from `New Stack` -> `Security`
+ Add New thead and set properties
|Property|Value|
|:--|:--|
|Thread Symbol|sce_tst_thread|
|Thread Name|sce_tst_thread|
|Thread Stack size|increase depending on your environment<br> e.g. 0xA000|
|Thread MemoryAllocation|Dyamic|
|Common General Use Mutexes|Enabled|
|Common General Enable Backward Compatibility|Enabled|
|Common Memory Allocation Support Dynamic Allocation|Enabled|
|Common Memory Allocation Total Heap Size|increase depending on your environment<br> e.g. 0x20000, <br> e.g. 0x30000 when using multi thread example|
+ Add `Heap 4` stack to sce_tst_thread from `New Stack` -> `RTOS` -> `FreeRTOS Heap 4`
+ Add `FreeRTOS + TCP` stack to sce_tst_thread from `New Stack` -> `Networking` -> `FreeRTOS+TCP` and set properties
|Property|Value|
|:--|:--|
|Network Events call vApplicationIPNetworkEventHook|Disable|
|Use DHCP|Disable|
+ Save `dummy_library` FSP configuration
+ Copy <u>configuration.xml</u> and pincfg under `dummy_library` to `wolfSSL_RA6M4`
+ Open Smart Configurator by clicking copied configuration.xml
+ Click `Generate Project Content` on Smart Configurator
3.) Build the wolfSSL project
4.) Create a 'dummy_application' Renesas RA C Project Using RA Library.
+ Click File->New->`RA C/C++ Project`.
+ Select `EK-RA6M4` from Drop-down list.
+ Check `Executable Using an RA Static Library`.
+ Select FreeRTOS from RTOS selection. Click Finish.
+ Enter `dummy_application` as the project name. Click Next.
+ Under `RA library project`, select `wolfSSL_RA6M4`.
+ Click Finish.
+ Copy the followng folder and file at `dummy_application` to `test_RA6M4`\
script/\
src/sce_tst_thread_entry.c
+ Add `sce_test()` call under /* TODO: add your own code here */ line at sce_tst_thread_entry.c
```
...
/* TODO: add your own code here */
sce_test();
...
```
5.) Prepare SEGGER_RTT to logging
+ Download J-Link software from [Segger](https://www.segger.com/downloads/jlink)
+ Choose `J-Link Software and Documentation Pack`
+ Copy sample program files below from `Installed SEGGER` folder, `e.g C:\Program Files\SEGGER\JLink\Samples\RTT`, to /path/to/wolfssl/IDE/Reenesas/e2studio/RA6M4/test/src/SEGGER_RTT\
SEGGER_RTT.c\
SEGGER_RTT.h\
SEGGER_RTT_Conf.h\
SEGGER_RTT_printf.c
+ To connect RTT block, you can configure RTT viewer configuration based on where RTT block is in map file\
e.g.\
[test_RA6M4.map]
```
COMMON 0x200232a8 0xa8 ./src/SEGGER_RTT/SEGGER_RTT.o\
````
you can specify "RTT control block" to 0x200232a8 by Address\
OR\
you can specify "RTT control block" to 0x20020000 0x10000 by Search Range
## Run Client
1.) Enable TLS_CLIENT definition in wolfssl_demo.h of test_RA6M4 projet
2.) Client IP address and Server IP address
+ Client IP address can be changed by the following line in wolf_client.c.
```
static const byte ucIPAddress[4] = { 192, 168, 11, 241 };
```
+ Client IP address can be changed by the following line in wolf_client.c.
```
#define SERVER_IP "192.168.11.40"
```
3.) Build test_RA6M4 project
4.) Prepare peer wolfssl server
+ On Linux
```
$ autogen.sh
$ ./configure --enable-extended-master=no CFLAGS="-DWOLFSSL_STATIC_RSA -DHAVE_AES_CBC"
```
Run peer wolfSSL server
RSA sign and verify use, launch server with the following option
```
$./examples/server/server -b -d -i
```
ECDSA sign and verify use, launch server with the following option
```
$./examples/server/server -b -d -c -i ./certs/server-ecc.pem -k ./certs/ecc-key.pem
```
5.) Run the example Client
You will see the following message on J-LinK RTT Viewer when using RSA sign and verify.
```
Start Client Example,
Connecting to 192.168.11.xx
[wolfSSL_TLS_client_do(00)][00] Start to connect to the server.
[wolfSSL_TLS_client_do(00)][00] Cipher : NULL
[wolfSSL_TLS_client_do(00)][00] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(01)][01] Start to connect to the server.
[wolfSSL_TLS_client_do(01)][01] Cipher : ECDHE-RSA-AES128-GCM-SHA256
[wolfSSL_TLS_client_do(01)][01] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(02)][02] Start to connect to the server.
[wolfSSL_TLS_client_do(02)][02] Cipher : ECDHE-RSA-AES256-SHA
[wolfSSL_TLS_client_do(02)][02] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(03)][03] Start to connect to the server.
[wolfSSL_TLS_client_do(03)][03] Cipher : ECDHE-RSA-AES128-SHA256
[wolfSSL_TLS_client_do(03)][03] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(04)][04] Start to connect to the server.
[wolfSSL_TLS_client_do(04)][04] Cipher : AES128-SHA256
[wolfSSL_TLS_client_do(04)][04] Received: I hear you fa shizzle!
End of Client Example
```
You will see the following message on J-LinK RTT Viewer when using ECDSA sign and verify.
```
Start Client Example,
Connecting to 192.168.11.xx
[wolfSSL_TLS_client_do(00)][00] Start to connect to the server.
[wolfSSL_TLS_client_do(00)][00] Cipher : NULL
[wolfSSL_TLS_client_do(00)][00] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(01)][01] Start to connect to the server.
[wolfSSL_TLS_client_do(01)][01] Cipher : ECDHE-ECDSA-AES128-GCM-SHA256
[wolfSSL_TLS_client_do(01)][01] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(02)][02] Start to connect to the server.
[wolfSSL_TLS_client_do(02)][02] Cipher : ECDHE-ECDSA-AES256-SHA
[wolfSSL_TLS_client_do(02)][02] Received: I hear you fa shizzle!
[wolfSSL_TLS_client_do(03)][03] Start to connect to the server.
[wolfSSL_TLS_client_do(03)][03] Cipher : ECDHE-ECDSA-AES128-SHA256
[wolfSSL_TLS_client_do(03)][03] Received: I hear you fa shizzle!
End of Client Exampl
```
**Note**\
To run "RSA verify" client, enable "#define USE_CERT_BUFFERS_2048" in wolfssl_demo.h\
To run "ECDSA verify" client, enable "#define USE_CERT_BUFFERS_256" in wolfssl_demo.h
### Run Multi Client Session example
1.) Enable TLS_CLIENT and TLS_MULTITHREAD_TEST definition in wolfssl_demo.h of test_RA6M4 projet
2.) Follow [Run Client](#run-client) instruction
3.) Prepare peer wolfssl server
RSA sign and verify use, launch server with the following option
```
$./examples/server/server -b -d -i -p 11111
Open another terminal and launch another server example
$./examples/server/server -b -d -i -p 11112
```
ECDSA sign and verify use, launch server with the following option
```
$./examples/server/server -b -d -c -i ./certs/server-ecc.pem -k ./certs/ecc-key.pem -p 11111
Open another terminal and launch another server example
$./examples/server/server -b -d -c -i ./certs/server-ecc.pem -k ./certs/ecc-key.pem -p 11112
```
4.) Run Multi Client Session Example
You will see similar following message on J-LinK RTT Viewer when using ECDSA sign and verify.
```
Start Client Example,
Connecting to 192.168.11.xx
clt_thd_taskA connecting to 11111 port
clt_thd_taskB connecting to 11112 port
[clt_thd_taskA][00] Ready to connect.
[clt_thd_taskA][00] Start to connect to the server.
[clt_thd_taskA][00] Cipher : ECDHE-RSA-AES128-GCM-SHA256
[clt_thd_taskB][00] Ready to connect.
[clt_thd_taskB][00] Start to connect to the server.
[clt_thd_taskB][00] Cipher : ECDHE-RSA-AES128-SHA256
[clt_thd_taskB][00] Received: I hear you fa shizzle!
[clt_thd_taskA][00] Received: I hear you fa shizzle!
clt_thd_taskA connecting to 11111 port
clt_thd_taskB connecting to 11112 port
[clt_thd_taskA][00] Ready to connect.
[clt_thd_taskA][00] Start to connect to the server.
[clt_thd_taskA][00] Cipher : AES128-SHA256
[clt_thd_taskB][00] Ready to connect.
[clt_thd_taskB][00] Start to connect to the server.
[clt_thd_taskB][00] Cipher : AES256-SHA256
[clt_thd_taskA][00] Received: I hear you fa shizzle!
[clt_thd_taskB][00] Received: I hear you fa shizzle!
End of Client Example
```
You will see similar following message on J-LinK RTT Viewer when using ECDSA sign and verify.
```
Start Client Example,
Connecting to 192.168.11.xx
clt_thd_taskA connecting to 11111 port
clt_thd_taskB connecting to 11112 port
[clt_thd_taskA][00] Ready to connect.
[clt_thd_taskA][00] Start to connect to the server.
[clt_thd_taskA][00] Cipher : ECDHE-ECDSA-AES128-GCM-SHA256
[clt_thd_taskB][00] Ready to connect.
[clt_thd_taskB][00] Start to connect to the server.
[clt_thd_taskB][00] Cipher : ECDHE-ECDSA-AES128-SHA256
[clt_thd_taskB][00] Received: I hear you fa shizzle!
[clt_thd_taskA][00] Received: I hear you fa shizzle!
End of Client Example
```
**Note**\
Multi Client session use case is only able to run threads that all use either SCE cipher suite or SW cipher suite.
The example program runs two threads that use SCE cipher suite.
## Run Crypt test and Benchmark
1.) Enable CRYPT_TEST and/or BENCHMARK definition in wolfssl_demo.h
2.) Enable SCEKEY_INSTALLED definition in user_settings.h if you have installed key for AES
In the example code for benchmark, it assumes that AES key is installed at DIRECT_KEY_ADDRESS which is 0x08000000U as follows:
```
#if defined(SCEKEY_INSTALLED)
/* aes 256 */
memcpy(guser_PKCbInfo.sce_wrapped_key_aes256.value,
(uint32_t *)DIRECT_KEY_ADDRESS, HW_SCE_AES256_KEY_INDEX_WORD_SIZE*4);
guser_PKCbInfo.sce_wrapped_key_aes256.type = SCE_KEY_INDEX_TYPE_AES256;
guser_PKCbInfo.aes256_installedkey_set = 1;
/* aes 128 */
guser_PKCbInfo.aes128_installedkey_set = 0;
#endif
```
To install key, please refer [Installing and Updating Secure Keys](https://www.renesas.com/us/en/document/apn/installing-and-updating-secure-keys-ra-family).
You can update code above to handle AES128 key when you install its key.
3.) Run Benchmark and Crypto Test
## Support
For support inquiries and questions, please email support@wolfssl.com. Feel free to reach out to info@wolfssl.jp as well.

View File

@@ -0,0 +1,80 @@
/* user_settings.h
*
* Copyright (C) 2006-2022 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
*/
/* Operating Environment and Threading */
#define FREERTOS
#define FREERTOS_TCP
#define NO_MAIN_DRIVER
#define BENCH_EMBEDDED
#define NO_WRITEV
#define NO_DEV_RANDOM
#define SIZEOF_LONG_LONG 8
#define NO_WOLFSSL_DIR
#define WOLFSSL_NO_CURRDIR
#define NO_WOLF_C99
#define NO_MULTIBYTE_PRINT
#define NO_FILESYSTEM
#define XVALIDATEDATE(d, f,t) (0)
#define TFM_TIMING_RESISTANT
#define ECC_TIMING_RESISTANT
#define WC_RSA_BLINDING
#define HAVE_AESGCM
#define WOLFSSL_SHA512
#define HAVE_ECC
#define HAVE_CURVE25519
#define CURVE25519_SMALL
#define WOLFSSL_SMALL_STACK
#define USE_FAST_MATH
/* static RSA */
#define WOLFSSL_STATIC_RSA
/* SEGGER printf */
#define USE_SEGGER_RTT_PRINTF
#ifdef USE_SEGGER_RTT_PRINTF
int myprintf(const char * sFormat, ...);
#undef printf
#define printf myprintf
#endif
/* #define WOLFSSL_TLS13 */
#if defined(WOLFSSL_TLS13)
#include <sys/time.h>
#define HAVE_FFDHE_2048
#define HAVE_HKDF
#define WC_RSA_PSS
#define HAVE_TLS_EXTENSIONS
#define HAVE_SUPPORTED_CURVES
#endif
#define WOLF_CRYPTO_CB
/* Enable SCEKEY_INSTALLED if keys are installed */
#define SCEKEY_INSTALLED
#if defined(WOLFSSL_RENESAS_SCEPROTECT) && defined(SCEKEY_INSTALLED)
#define HAVE_RENESAS_SYNC
#endif

View File

@@ -0,0 +1,111 @@
/* wolfssl_demo.h
*
* Copyright (C) 2006-2022 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
*/
#ifndef WOLFSSL_DEMO_H_
#define WOLFSSL_DEMO_H_
#include <wolfssl/ssl.h>
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#define FREQ 10000 /* Hz */
#define FLASH_HP_DF_BLOCK_0 0x08000000U /* 64 B: 0x40100000 - 0x4010003F */
#define FLASH_HP_DF_BLOCK_1 0x08000040U /* 64 B: 0x40100040 - 0x4010007F */
#define FLASH_HP_DF_BLOCK_2 0x08000080U /* 64 B: 0x40100080 - 0x401000BF */
#define FLASH_HP_DF_BLOCK_3 0x080000C0U /* 64 B: 0x401000C0 - 0x401000FF */
#define DIRECT_KEY_ADDRESS_256 FLASH_HP_DF_BLOCK_1
#define DIRECT_KEY_ADDRESS_128 FLASH_HP_DF_BLOCK_2
/* Client connects to the server with these details. */
#define SERVER_IP "192.168.11.49"
#define DEFAULT_PORT 11111
/* Enable wolfcrypt test */
/* can be enabled with benchmark test */
/*#define CRYPT_TEST*/
/* Enable benchmark */
/* can be enabled with cyrpt test */
/*#define BENCHMARK*/
/* Enable TLS client */
/* cannot enable with CRYPT_TEST or BENCHMARK */
#define TLS_CLIENT
/* use multi-thread example */
/*#define TLS_MULTITHREAD_TEST*/
#if defined(TLS_MULTITHREAD_TEST)
#define THREAD_STACK_SIZE (5 * 1024)
#endif
/* Use RSA certificates */
#define USE_CERT_BUFFERS_2048
/* Use ECC certificates */
/*#define USE_CERT_BUFFERS_256*/
#if defined(USE_CERT_BUFFERS_2048) && defined(USE_CERT_BUFFERS_256)
#error please set either macro USE_CERT_BUFFERS_2048 or USE_CERT_BUFFERS_256
#endif
typedef struct tagTestInfo
{
int id;
int port;
char name[32];
const char* cipher;
WOLFSSL_CTX* ctx;
wolfSSL_Logging_cb log_f;
#if defined(TLS_MULTITHREAD_TEST)
SemaphoreHandle_t xBinarySemaphore;
#endif
} TestInfo;
void sce_test();
void TCPInit();
void wolfSSL_TLS_client_init();
void wolfSSL_TLS_client_do(void *pvParam);
void wolfSSL_TLS_cleanup();
extern WOLFSSL_CTX *client_ctx;
#ifdef TLS_MULTITHREAD_TEST
extern xSemaphoreHandle exit_semaph;
#endif
static void util_Cleanup(xSocket_t xSock, WOLFSSL_CTX *ctx, WOLFSSL *ssl) {
printf("Cleaning up socket and wolfSSL objects.\n");
if (xSock != NULL)
FreeRTOS_closesocket(xSock);
if (ssl != NULL)
wolfSSL_free(ssl);
if (ctx != NULL)
wolfSSL_CTX_free(ctx);
wolfSSL_Cleanup();
}
static inline void util_inf_loop(xSocket_t xClientSocket, WOLFSSL_CTX *ctx,
WOLFSSL *ssl) {
util_Cleanup(xClientSocket, ctx, ssl);
printf("Reached infinite loop.\n");
while (1)
;
}
#endif /* WOLFSSL_DEMO_H_ */

View File

@@ -0,0 +1,19 @@
# vim:ft=automake
# included from Top Level Makefile.am
# All paths should be given relative to the root
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/README.md
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/wolfssl/.cproject
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/wolfssl/.project
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/.cproject
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/.project
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/test_RA6M4Debug.launch
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/src/test_main.c
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/src/wolf_client.c
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/src/wolfssl_sce_unit_test.c
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/src/SEGGER_RTT/myprint.c
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/src/common/.gitignore
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/test/key_data/key_data.h
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h
EXTRA_DIST+= IDE/Renesas/e2studio/RA6M4/common/user_settings.h

View File

@@ -0,0 +1,20 @@
#ifndef __KEY_DATA_H__
#include "r_sce.h"
/** Firmware update data and user key datas */
typedef struct user_key_block_data
{
/* Provisioning key wapped by Renesas DLM */
uint8_t encrypted_provisioning_key[HW_SCE_AES_CBC_IV_BYTE_SIZE * 2];
/* Initial vector to be used when creating encrypted key */
uint8_t iv[HW_SCE_AES_CBC_IV_BYTE_SIZE];
/* RSA 2048 bit key, encrypted by AES128-ECB */
uint8_t encrypted_user_rsa2048_ne_key[HW_SCE_RSA2048_NE_KEY_BYTE_SIZE + 16];
} st_user_key_block_data_t;
extern const unsigned char ca_cert_der_sign[];
extern const unsigned char ca_ecc_cert_der_sign[];
#endif /* __KEY_DATA_H__ */

View File

@@ -0,0 +1,139 @@
/* key_data.h
*
* Copyright (C) 2006-2022 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 "key_data.h"
#include "wolfssl_demo.h"
/*******************************************************************************
* SCE Key Information
*******************************************************************************/
const st_user_key_block_data_t g_key_block_data =
{
/* uint8_t encrypted_provisioning_key[R_TSIP_AES_CBC_IV_BYTE_SIZE * 2]; */
{
0xE7, 0x1C, 0xEB, 0xCA, 0x3A, 0x64, 0x0B, 0xD2, 0xC5, 0xB8, 0xF2, 0xD0,
0xF7, 0x1B, 0xA9, 0x4A, 0x98, 0xFF, 0xF3, 0x48, 0x81, 0xAD, 0xAF, 0x63,
0x19, 0x24, 0x4B, 0x2B, 0xC0, 0x8B, 0x9C, 0x6B
},
/* uint8_t iv[R_TSIP_AES_CBC_IV_BYTE_SIZE]; */
{
0xD7, 0x97, 0x56, 0x82, 0x5B, 0x4B, 0x7F, 0xB2, 0x1C, 0x1F, 0xEE, 0x85,
0x02, 0xC5, 0xD0, 0xBA
},
/* uint8_t encrypted_user_rsa2048_ne_key[R_TSIP_RSA2048_NE_KEY_BYTE_SIZE + 16]; */
{
0x3F, 0xA5, 0xBE, 0xBF, 0x86, 0xEC, 0x23, 0x37, 0x82, 0x37, 0x71, 0x0C,
0x83, 0xA7, 0x8E, 0x86, 0xF0, 0x16, 0xD3, 0x7B, 0xF1, 0x25, 0xA4, 0x37,
0x7A, 0x2D, 0x16, 0xF2, 0xFF, 0x3D, 0xEE, 0x46, 0xE0, 0x05, 0x58, 0x56,
0xC2, 0xE7, 0x9D, 0x2C, 0x01, 0x84, 0x59, 0x8E, 0xA8, 0x9E, 0xEE, 0x3F,
0x22, 0x83, 0x68, 0xDA, 0x9E, 0xCE, 0xEA, 0x99, 0xFD, 0xAF, 0xDF, 0x67,
0x1E, 0x73, 0x25, 0x68, 0xBF, 0x0A, 0xDF, 0xAF, 0xC4, 0x3D, 0xF1, 0xBD,
0x41, 0xF5, 0xAC, 0xAC, 0xA4, 0x36, 0xF8, 0x96, 0xC0, 0x8C, 0x2F, 0x1A,
0x79, 0x75, 0x28, 0xAE, 0x67, 0xC9, 0x5A, 0xDE, 0x2A, 0xB4, 0x99, 0xDB,
0x8C, 0x25, 0x53, 0x58, 0x8C, 0xDC, 0xA8, 0x0D, 0xFE, 0xEE, 0x0F, 0x6C,
0x61, 0xE6, 0x43, 0x66, 0xE8, 0x4A, 0xE3, 0xEB, 0xAB, 0xA2, 0x52, 0xE4,
0x67, 0xC2, 0x9A, 0x57, 0xA4, 0x1F, 0xE0, 0xFC, 0x2B, 0xBE, 0x25, 0xBF,
0xF0, 0x70, 0x18, 0x88, 0x93, 0xB7, 0x2F, 0x74, 0xF8, 0xF3, 0x88, 0xB8,
0xFA, 0x18, 0xBE, 0xC1, 0xB2, 0x24, 0x4B, 0xBC, 0x89, 0x2D, 0xC4, 0x02,
0xB3, 0x82, 0xEC, 0xDB, 0xC9, 0xF0, 0xA9, 0xC3, 0x30, 0x7C, 0xF5, 0x15,
0xEB, 0x9B, 0x16, 0x8C, 0x9D, 0xEF, 0x42, 0x8A, 0xCA, 0x5D, 0x28, 0xDF,
0x68, 0xEA, 0xE0, 0xB8, 0x76, 0x7C, 0xBB, 0x4A, 0x51, 0xDD, 0x55, 0x14,
0xB7, 0xAB, 0xD2, 0xF1, 0xB9, 0x51, 0x19, 0x05, 0x26, 0x87, 0xF7, 0x5C,
0x69, 0x45, 0x3C, 0x82, 0xE8, 0x82, 0x05, 0x5D, 0x33, 0x8E, 0xD1, 0x42,
0x71, 0xD6, 0x96, 0xDA, 0xAB, 0xB8, 0xC0, 0x0F, 0xF7, 0x85, 0x8A, 0x12,
0xEF, 0xB9, 0x53, 0xFF, 0xD2, 0x95, 0x18, 0x2F, 0x0C, 0xA6, 0x72, 0x98,
0xC3, 0xC6, 0x9B, 0x95, 0x70, 0x69, 0xC5, 0xB7, 0xD5, 0x24, 0x77, 0x05,
0xD0, 0x68, 0x85, 0x36, 0xB8, 0x57, 0xE3, 0xED, 0x2E, 0x4D, 0x95, 0xD3,
0xFC, 0x24, 0x1B, 0x22, 0xFA, 0x43, 0xD8, 0x62, 0x28, 0x57, 0x6B, 0x34,
0xBF, 0xD1, 0x63, 0x4B, 0xB5, 0xF5, 0x88, 0xBC, 0xB8, 0x69, 0xF3, 0xB5
},
};
#ifndef USE_CERT_BUFFERS_256
/* ca-cert.der.sign,
* ca-cert.der signed by RSA2048 PSS with SHA256
* This is used for Root Certificate verify by SCE */
const unsigned char ca_cert_der_sign[] =
{
0x0E, 0x7F, 0xB2, 0x0B, 0x4E, 0x8C, 0x11, 0x5E, 0xAC, 0xD7,
0x77, 0x3D, 0x9E, 0xA0, 0x4B, 0xA5, 0xE2, 0x9F, 0x97, 0xEB,
0xD0, 0x1B, 0x65, 0x08, 0x7D, 0x39, 0x2E, 0xD0, 0x97, 0x19,
0xB6, 0x47, 0xF4, 0xCC, 0xA0, 0x24, 0xFA, 0xA6, 0x08, 0x11,
0xF4, 0xDC, 0x82, 0xCC, 0xB6, 0x14, 0xF1, 0x4A, 0x63, 0x67,
0xF2, 0x87, 0x0C, 0xA9, 0x31, 0x03, 0xAF, 0xD5, 0x4B, 0x1B,
0xD9, 0x99, 0x6E, 0xB4, 0xBD, 0xAB, 0x7F, 0x64, 0xB8, 0x8B,
0xFF, 0x45, 0xFC, 0xE5, 0x86, 0xE8, 0x95, 0x4E, 0xBD, 0x7F,
0x21, 0xB5, 0xCD, 0x25, 0x85, 0x16, 0x32, 0x6C, 0x8A, 0xC5,
0xE7, 0xEB, 0x58, 0xA8, 0xCC, 0xD2, 0x33, 0xFC, 0xBB, 0x88,
0xBC, 0x15, 0xDB, 0xDD, 0x6B, 0x15, 0xE3, 0x43, 0x31, 0xA9,
0xA2, 0x2E, 0x9C, 0x8C, 0x44, 0x69, 0x1A, 0x72, 0x49, 0xAD,
0x94, 0x8B, 0xD9, 0xA7, 0x47, 0x91, 0xA1, 0xF0, 0xAA, 0xA4,
0xAB, 0x5B, 0xC9, 0x8F, 0x48, 0xFE, 0x6B, 0x06, 0x7A, 0xF0,
0xC0, 0x39, 0xEF, 0xF1, 0x38, 0x96, 0x03, 0xC8, 0xDC, 0xBE,
0xF7, 0xDB, 0xBA, 0x09, 0xA4, 0x62, 0xD1, 0x39, 0xAD, 0x1D,
0xEB, 0x28, 0x85, 0x53, 0x76, 0xF2, 0x52, 0x3B, 0x26, 0xF2,
0x16, 0x01, 0xB0, 0xEF, 0x2B, 0x09, 0x2F, 0x30, 0x17, 0x6F,
0x04, 0x5C, 0x75, 0xE5, 0x7D, 0xD0, 0xCB, 0x84, 0xDE, 0xEB,
0x24, 0x45, 0x3D, 0x3A, 0x56, 0xC4, 0x64, 0x63, 0xD9, 0x00,
0x23, 0x5F, 0xEE, 0xD9, 0x2E, 0xA9, 0xDC, 0x94, 0xA7, 0x8D,
0xB6, 0xD9, 0xDF, 0x96, 0x8F, 0x8B, 0x81, 0x83, 0x8A, 0x8E,
0x36, 0x45, 0xC7, 0xB7, 0x59, 0xA0, 0x9D, 0xE8, 0xFE, 0x62,
0x5C, 0x7A, 0xF2, 0x9E, 0xF9, 0xB6, 0x75, 0x46, 0x44, 0x6D,
0x96, 0xFC, 0x3E, 0xE2, 0x17, 0x52, 0x0D, 0x70, 0x37, 0xD9,
0xAE, 0x1D, 0x25, 0x30, 0xF7, 0xD9
};
const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign);
#else
/* ca-ecc-cert.der.sign,
* ca-ecc-cert.der signed by RSA2048 PSS with SHA256
* This is used for Root Certificate verify by SCE
*/
const unsigned char ca_ecc_cert_der_sign[] =
{
0x41, 0xFC, 0x2C, 0xFD, 0x21, 0xFB, 0xF2, 0x98, 0xF3, 0x25,
0x06, 0x8C, 0x2C, 0x4A, 0x12, 0xDB, 0xDD, 0x38, 0x39, 0x83,
0xD5, 0x80, 0xB4, 0x52, 0xA5, 0x35, 0xA6, 0x5C, 0x38, 0x41,
0xDA, 0xBE, 0x64, 0x84, 0x7C, 0x63, 0x7D, 0x2A, 0xBB, 0xB9,
0x93, 0xED, 0x27, 0xE3, 0x2B, 0xAB, 0xC4, 0xBC, 0x08, 0xBE,
0xA6, 0xF7, 0x40, 0xA3, 0x1E, 0xB1, 0x8C, 0xF8, 0x4B, 0x78,
0x9F, 0xFE, 0xAA, 0x86, 0x15, 0xF5, 0xDD, 0xB3, 0xCD, 0xF5,
0x3A, 0x81, 0x26, 0x3E, 0x04, 0x05, 0x65, 0xF9, 0x53, 0x8E,
0x10, 0x1F, 0xE8, 0xD9, 0x3F, 0xA1, 0x6E, 0x8C, 0xAD, 0xFA,
0x50, 0x36, 0xFE, 0x89, 0x4E, 0xAC, 0x27, 0xDB, 0x59, 0x80,
0xE3, 0x77, 0x20, 0x4F, 0xC1, 0x03, 0xA4, 0x1D, 0xE5, 0x34,
0xCB, 0x8F, 0x88, 0xD6, 0x38, 0x2A, 0x31, 0xE0, 0xC2, 0xAA,
0x78, 0x34, 0x9C, 0xFE, 0x8F, 0x8D, 0x76, 0xDB, 0x24, 0x38,
0xE1, 0xAB, 0xAE, 0xBA, 0xD0, 0xA9, 0x1C, 0x59, 0x01, 0xE3,
0x49, 0x9B, 0x13, 0x7D, 0x25, 0x7C, 0x8D, 0x12, 0x36, 0xA1,
0xEF, 0x7B, 0xD4, 0x16, 0x58, 0x3A, 0x0E, 0xE7, 0x5A, 0x36,
0xDD, 0xD4, 0x31, 0x23, 0xBF, 0xC9, 0x49, 0x62, 0xA4, 0x01,
0xA3, 0xAC, 0x62, 0xAB, 0xA0, 0x48, 0xE3, 0xDA, 0x72, 0xD3,
0x6D, 0xF3, 0x57, 0x61, 0x9E, 0xEA, 0x31, 0xA7, 0x82, 0xDD,
0x79, 0x3C, 0x8E, 0x01, 0xE9, 0xE5, 0xB2, 0x49, 0x2F, 0x3F,
0x3F, 0x16, 0x2C, 0xCC, 0x3D, 0x78, 0x6E, 0xB6, 0x6D, 0x34,
0x38, 0x46, 0xCC, 0xFF, 0xEF, 0x26, 0x74, 0xD8, 0x68, 0x90,
0xF1, 0x2A, 0xAA, 0xF3, 0xF3, 0x5A, 0xFC, 0x75, 0x00, 0xE6,
0x11, 0xE7, 0x21, 0x05, 0x6B, 0xAA, 0x53, 0x25, 0x59, 0x33,
0xB0, 0xC0, 0x66, 0x14, 0x2F, 0x00, 0x59, 0xF3, 0xFF, 0x5E,
0xCC, 0x10, 0x84, 0x0E, 0xE6, 0x17
};
static const int sizeof_ca_ecc_cert_der_sign = sizeof(ca_ecc_cert_der_sign);
#endif /* USE_CERT_BUFFERS_256 */

View File

@@ -0,0 +1,36 @@
/* myprintf.c
*
* Copyright (C) 2006-2022 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 "SEGGER_RTT.h"
#define SEGGER_INDEX (0)
int myprintf(const char * sFormat, ...);
int myprintf(const char * sFormat, ...)
{
int r;
va_list ParamList;
va_start(ParamList, sFormat);
r = SEGGER_RTT_vprintf(0, sFormat, &ParamList);
va_end(ParamList);
return r;
}

View File

@@ -0,0 +1,2 @@
*
!.gitignore

View File

@@ -0,0 +1,356 @@
/* test_main.c
*
* Copyright (C) 2006-2022 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 "stdio.h"
#include "stdint.h"
#include "wolfssl_demo.h"
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#if defined(WOLFSSL_RENESAS_SCEPROTECT)
#include <wolfssl/wolfcrypt/port/Renesas/renesas-sce-crypt.h>
#if defined(TLS_MULTITHREAD_TEST)
User_SCEPKCbInfo guser_PKCbInfo_taskA;
User_SCEPKCbInfo guser_PKCbInfo_taskB;
#else
User_SCEPKCbInfo guser_PKCbInfo;
#endif
#endif
#include <wolfssl_demo.h>
#include "key_data.h"
#include "hal_data.h"
#ifdef __cplusplus
extern "C" {
void abort(void);
}
#endif
#if defined(SCE_CRYPT_UNIT_TEST)
int sce_crypt_test();
int sce_crypt_sha256_multitest();
int sce_crypt_AesCbc_multitest();
int sce_crypt_AesGcm_multitest();
int sce_crypt_Sha_AesCbcGcm_multitest();
void tskSha256_Test1(void *pvParam);
#endif
void R_BSP_WarmStart(bsp_warm_start_event_t event);
/* the function is called just before main() to set up pins */
/* this needs to be called to setup IO Port */
void R_BSP_WarmStart (bsp_warm_start_event_t event)
{
if (BSP_WARM_START_POST_C == event) {
/* C runtime environment and system clocks are setup. */
/* Configure pins. */
R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
}
}
#if defined(TLS_CLIENT)
extern const st_user_key_block_data_t g_key_block_data;
/* Key type of the encrypted user_public_key 0: RSA-2048 2: ECDSA-P256*/
uint32_t encrypted_user_key_type = 0;
static int SetScetlsKey()
{
#if defined(WOLFSSL_RENESAS_SCEPROTECT)
#if defined(TLS_CLIENT)
#if defined(USE_CERT_BUFFERS_256)
wc_sce_inform_cert_sign((const byte *)ca_ecc_cert_der_sign);
encrypted_user_key_type = 2;
#else
wc_sce_inform_cert_sign((const byte *)ca_cert_der_sign);
#endif
wc_sce_inform_user_keys(
(byte*)&g_key_block_data.encrypted_provisioning_key,
(byte*)&g_key_block_data.iv,
(byte*)&g_key_block_data.encrypted_user_rsa2048_ne_key,
encrypted_user_key_type);
#elif defined(TLS_SERVER)
wc_sce_inform_cert_sign((const byte *)client_cert_der_sign);
wc_sce_inform_user_keys(
(byte*)&g_key_block_data.encrypted_provisioning_key,
(byte*)&g_key_block_data.iv,
(byte*)&g_key_block_data.encrypted_user_rsa2048_ne_key,
encrypted_user_key_type);
#endif
#endif
return 0;
}
#endif
typedef struct func_args {
int argc;
char** argv;
int return_code;
} func_args;
void wolfcrypt_test(func_args args);
int benchmark_test(void *args);
#ifdef TLS_MULTITHREAD_TEST
static void my_Logging_cb(const int logLevel, const char *const logMessage)
{
(void)logLevel;
printf("custom-log: %s\n", logMessage);
}
#endif
void sce_test(void)
{
#if defined(SCE_CRYPT_UNIT_TEST) && defined(WOLFSSL_RENESAS_SCEPROTECT)
int ret = 0;
BaseType_t xRet;
if ((ret = wolfCrypt_Init()) != 0) {
printf("wolfCrypt_Init failed %d\n", ret);
}
printf("Start wolf sce crypt Test\n");
printf(" \n");
printf(" simple crypt test by using SCE\n");
sce_crypt_test();
printf(" \n");
printf(" multi sha thread test\n");
sce_crypt_sha256_multitest();
printf(" \n");
printf(" multi aes cbc thread test\n");
sce_crypt_AesCbc_multitest();
printf(" \n");
printf(" multi aes gcm thread test\n");
sce_crypt_AesGcm_multitest();
printf(" \n");
printf(" multi sha aescbc aesgcm thread test\n");
sce_crypt_Sha_AesCbcGcm_multitest();
printf(" \n");
printf("End wolf sce crypt Test\n");
if ((ret = wolfCrypt_Cleanup()) != 0) {
printf("wolfCrypt_Cleanup failed %d\n", ret);
}
#elif 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);
}
#elif defined(BENCHMARK)
#include "hal_data.h"
#include "r_sce.h"
printf("Prepare Installed key\n");
#if defined(WOLFSSL_RENESAS_SCEPROTECT) && defined(SCEKEY_INSTALLED)
/* aes 256 */
memcpy(guser_PKCbInfo.sce_wrapped_key_aes256.value,
(uint32_t *)DIRECT_KEY_ADDRESS_256,
HW_SCE_AES256_KEY_INDEX_WORD_SIZE*4);
guser_PKCbInfo.sce_wrapped_key_aes256.type = SCE_KEY_INDEX_TYPE_AES256;
guser_PKCbInfo.aes256_installedkey_set = 1;
/* aes 128 */
memcpy(guser_PKCbInfo.sce_wrapped_key_aes128.value,
(uint32_t *)DIRECT_KEY_ADDRESS_128,
HW_SCE_AES128_KEY_INDEX_WORD_SIZE*4);
guser_PKCbInfo.sce_wrapped_key_aes128.type = SCE_KEY_INDEX_TYPE_AES128;
guser_PKCbInfo.aes128_installedkey_set = 1;
#endif
printf("Start wolfCrypt Benchmark\n");
benchmark_test(NULL);
printf("End wolfCrypt Benchmark\n");
#elif defined(TLS_CLIENT)
#include "hal_data.h"
#include "r_sce.h"
#if defined(USE_CERT_BUFFERS_256)
#if !defined(TLS_MULTITHREAD_TEST)
const char* cipherlist[] = {
NULL,
"ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-ECDSA-AES256-SHA", /* sw only */
"ECDHE-ECDSA-AES128-SHA256"
};
const int cipherlist_sz = 3;
TestInfo info[cipherlist_sz];
#else
const char* cipherlist[] = {
"ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-ECDSA-AES128-SHA256"
};
const int cipherlist_sz = 2;
TestInfo info[cipherlist_sz];
#endif
#else
#if !defined(TLS_MULTITHREAD_TEST)
const char* cipherlist[] = {
NULL,
"ECDHE-RSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES256-SHA", /* sw only */
"ECDHE-RSA-AES128-SHA256",
"AES128-SHA256",
"AES256-SHA256",
};
const int cipherlist_sz = 6;
TestInfo info[cipherlist_sz];
#else
const char* cipherlist[] = {
"ECDHE-RSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES128-SHA256",
"AES128-SHA256",
"AES256-SHA256",
};
const int cipherlist_sz = 4;
TestInfo info[cipherlist_sz];
#endif
#endif
#ifdef TLS_MULTITHREAD_TEST
BaseType_t xReturned;
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
int j = 0;
#endif
int i = 0;
printf("\n Start Client Example, ");
printf("\n Connecting to %s\n\n", SERVER_IP);
SetScetlsKey();
TCPInit();
#ifdef TLS_MULTITHREAD_TEST
wolfSSL_TLS_client_init();
exit_semaph = xSemaphoreCreateCounting(cipherlist_sz, 0);
do {
for(j = i; j < (i+2); j++) {
info[j].port = DEFAULT_PORT + (j%2);
info[j].cipher = cipherlist[j];
info[j].ctx = client_ctx;
info[j].xBinarySemaphore = xSemaphoreCreateBinary();
info[j].log_f = my_Logging_cb;
memset(info[j].name, 0, sizeof(info[j].name));
sprintf(info[j].name, "clt_thd_%s", ((j%2) == 0) ?
"taskA" : "taskB");
printf(" %s connecting to %d port\n", info[j].name, info[j].port);
xReturned = xTaskCreate(wolfSSL_TLS_client_do, info[j].name,
THREAD_STACK_SIZE, &info[j], 2, NULL);
if (xReturned != pdPASS) {
printf("Failed to create task\n");
}
}
for(j = i; j < (i+2); j++) {
xSemaphoreGiveFromISR(info[j].xBinarySemaphore,
&xHigherPriorityTaskWoken);
}
/* check if all tasks are completed */
for(j = i; j < (i+2); j++) {
if(!xSemaphoreTake(exit_semaph, portMAX_DELAY)) {
printf("exit semaphore not released by test task");
}
}
i+=2;
} while (i < cipherlist_sz);
vSemaphoreDelete(exit_semaph);
#else
wolfSSL_TLS_client_init();
do {
info[i].port = DEFAULT_PORT;
info[i].cipher = cipherlist[i];
info[i].ctx = client_ctx;
info[i].id = i;
memset(info[i].name, 0, sizeof(info[i].name));
sprintf(info[i].name, "wolfSSL_TLS_client_do(%02d)", i);
wolfSSL_TLS_client_do(&info[i]);
i++;
} while (i < cipherlist_sz);
#endif /* SCE_MULTITHREAD_TEST */
printf("\n End of Client Example");
wolfSSL_TLS_cleanup();
#endif
}
#ifdef __cplusplus
void abort(void)
{
}
#endif

View File

@@ -0,0 +1,284 @@
/* wolf_client.c
*
* Copyright (C) 2006-2022 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 "wolfssl_demo.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "wolfssl/wolfcrypt/settings.h"
#include "wolfssl/ssl.h"
#include "wolfssl/certs_test.h"
uint32_t g_encrypted_root_public_key[140];
WOLFSSL_CTX *client_ctx = NULL;
extern uint8_t g_ether0_mac_address[6];
static const byte ucIPAddress[4] = { 192, 168, 11, 241 };
static const byte ucNetMask[4] = { 255, 255, 255, 0 };
static const byte ucGatewayAddress[4] = { 192, 168, 11, 1 };
static const byte ucDNSServerAddress[4] = { 192, 168, 11, 1 };
#define FR_SOCKET_SUCCESS 0
#ifdef TLS_MULTITHREAD_TEST
xSemaphoreHandle exit_semaph;
extern User_SCEPKCbInfo guser_PKCbInfo_taskA;
extern User_SCEPKCbInfo guser_PKCbInfo_taskB;
#else
extern User_SCEPKCbInfo guser_PKCbInfo;
#endif
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
static int msg(const char* pname, int l,
const char * sFormat, ...)
{
int r = 0;
va_list ParamList;
va_start(ParamList, sFormat);
printf("[%s][%02d] ", pname, l);
r = SEGGER_RTT_vprintf(0, sFormat, &ParamList);
va_end(ParamList);
return r;
}
void TCPInit( )
{
BaseType_t fr_status;
/* FreeRTOS+TCP Ethernet and IP Setup */
fr_status = FreeRTOS_IPInit(ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
g_ether0_mac_address);
if (pdPASS != fr_status) {
printf("Error [%ld]: FreeRTOS_IPInit.\n",fr_status);
}
}
void wolfSSL_TLS_client_init()
{
#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_CERT_BUFFERS_256
const unsigned char *cert = ca_ecc_cert_der_256;
#define SIZEOF_CERT sizeof_ca_ecc_cert_der_256
#else
const unsigned char *cert = ca_cert_der_2048;
#define SIZEOF_CERT sizeof_ca_cert_der_2048
#endif
#endif
wolfSSL_Init();
/* Create and initialize WOLFSSL_CTX */
if ((client_ctx = wolfSSL_CTX_new(
wolfSSLv23_client_method_ex((void *)NULL))) == NULL) {
printf("ERROR: failed to create WOLFSSL_CTX\n");
return;
}
#if defined(WOLFSSL_RENESAS_SCEPROTECT)
/* set callback functions for ECC */
wc_sce_set_callbacks(client_ctx);
#endif
#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
}
void wolfSSL_TLS_client_do(void *pvParam)
{
int ret;
int i = 0;
#if defined(TLS_MULTITHREAD_TEST)
BaseType_t xStatus;
#endif
TestInfo* p = (TestInfo*)pvParam;
/* FreeRTOS+TCP Objects */
socklen_t xSize = sizeof(struct freertos_sockaddr);
xSocket_t xClientSocket = NULL;
struct freertos_sockaddr xRemoteAddress;
WOLFSSL_CTX *ctx = (WOLFSSL_CTX *)p->ctx;
WOLFSSL *ssl = NULL;
const char* pcName = p->name;
#define BUFF_SIZE 256
static const char sendBuff[]= "Hello Server\n" ;
char rcvBuff[BUFF_SIZE] = {0};
i = p->id;
/* Client Socket Setup */
xRemoteAddress.sin_port = FreeRTOS_htons(p->port);
xRemoteAddress.sin_addr = FreeRTOS_inet_addr(SERVER_IP);
/* Create a FreeRTOS TCP Socket and connect */
xClientSocket = FreeRTOS_socket(FREERTOS_AF_INET,
FREERTOS_SOCK_STREAM,
FREERTOS_IPPROTO_TCP);
configASSERT(xClientSocket != FREERTOS_INVALID_SOCKET);
FreeRTOS_bind(xClientSocket, NULL, sizeof(xSize));
/* Client Socket Connect */
ret = FreeRTOS_connect(xClientSocket,
&xRemoteAddress,
sizeof(xRemoteAddress));
if (ret != FR_SOCKET_SUCCESS) {
msg(pcName, i, " Error [%d]: FreeRTOS_connect.\n", ret);
goto out;
}
#if defined(TLS_MULTITHREAD_TEST)
msg(pcName, i, " Ready to connect.\n");
xStatus = xSemaphoreTake(p->xBinarySemaphore, portMAX_DELAY);
if (xStatus != pdTRUE) {
msg(pcName, i, " Error : Failed to xSemaphoreTake\n");
goto out;
}
#endif
msg(pcName, i, " Start to connect to the server.\n");
if((ssl = wolfSSL_new(ctx)) == NULL) {
msg(pcName, i, " ERROR wolfSSL_new: %d\n", wolfSSL_get_error(ssl, 0));
goto out;
}
#if defined(WOLFSSL_RENESAS_SCEPROTECT)
/* Set callback CTX */
#if !defined(TLS_MULTITHREAD_TEST)
memset(&guser_PKCbInfo, 0, sizeof(User_SCEPKCbInfo));
guser_PKCbInfo.devId = 0;
wc_sce_set_callback_ctx(ssl, (void*)&guser_PKCbInfo);
#else
if (p->port - DEFAULT_PORT == 0) {
memset(&guser_PKCbInfo_taskA, 0, sizeof(User_SCEPKCbInfo));
wc_sce_set_callback_ctx(ssl, (void*)&guser_PKCbInfo_taskA);
}
else {
memset(&guser_PKCbInfo_taskB, 0, sizeof(User_SCEPKCbInfo));
wc_sce_set_callback_ctx(ssl, (void*)&guser_PKCbInfo_taskB);
}
#endif
#endif
/* Attach wolfSSL to the socket */
ret = wolfSSL_set_fd(ssl, (int) xClientSocket);
if (ret != WOLFSSL_SUCCESS) {
msg(pcName, i, " Error [%d]: wolfSSL_set_fd.\n",ret);
}
msg(pcName, i, " Cipher : %s\n",
(p->cipher == NULL) ? "NULL" : p->cipher);
/* use specific cipher */
if (p->cipher != NULL && wolfSSL_set_cipher_list(ssl, p->cipher)
!= WOLFSSL_SUCCESS) {
msg(pcName, i, " client can't set cipher list 1");
goto out;
}
#ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_ON();
#endif
if(wolfSSL_connect(ssl) != SSL_SUCCESS) {
msg(pcName, i, " ERROR SSL connect: %d\n", wolfSSL_get_error(ssl, 0));
goto out;
}
#ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_OFF();
#endif
if (wolfSSL_write(ssl, sendBuff, (int)strlen(sendBuff))
!= (int)strlen(sendBuff)) {
msg(pcName, i, " ERROR SSL write: %d\n", wolfSSL_get_error(ssl, 0));
goto out;
}
if ((ret=wolfSSL_read(ssl, rcvBuff, BUFF_SIZE)) < 0) {
msg(pcName, i, " ERROR SSL read: %d\n", wolfSSL_get_error(ssl, 0));
goto out;
}
rcvBuff[ret] = '\0' ;
msg(pcName, i, " Received: %s\n\n", rcvBuff);
out:
if (ssl) {
wolfSSL_shutdown(ssl);
wolfSSL_free(ssl);
ssl = NULL;
/* need to reset callback */
wc_sce_set_callbacks(client_ctx);
}
/* clean up socket */
if (xClientSocket) {
FreeRTOS_shutdown(xClientSocket, FREERTOS_SHUT_RDWR);
FreeRTOS_closesocket(xClientSocket);
xClientSocket = NULL;
}
#ifdef TLS_MULTITHREAD_TEST
xSemaphoreGive(exit_semaph);
vTaskDelete(NULL);
#endif
}
void wolfSSL_TLS_cleanup()
{
if (client_ctx) {
wolfSSL_CTX_free(client_ctx);
}
wolfSSL_Cleanup();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.renesas.cdt.launch.dsf.gdbremote.launchConfigurationType">
<booleanAttribute key=".setStepMode" value="false"/>
<stringAttribute key="com.renesas.cdt.core.initCommands" value=""/>
<stringAttribute key="com.renesas.cdt.core.ipAddress" value="localhost"/>
<stringAttribute key="com.renesas.cdt.core.jtagDeviceId" value="com.renesas.hardwaredebug.rz.jlink"/>
<stringAttribute key="com.renesas.cdt.core.optionInitCommands" value="monitor force_rtos_off&#10;&#10;"/>
<intAttribute key="com.renesas.cdt.core.portNumber" value="61234"/>
<stringAttribute key="com.renesas.cdt.core.runCommands" value=""/>
<stringAttribute key="com.renesas.cdt.core.secondGDBExe" value="green_dsp-elf-gdb"/>
<intAttribute key="com.renesas.cdt.core.secondGdbPortNumber" value="61237"/>
<stringAttribute key="com.renesas.cdt.core.serverParam" value="-g SEGGERJLINKARM -t R7FA6M4AF -uSelect= USB -uJLinkSetting= ${workspace_loc:/${ProjName}}/${LaunchConfigName}.jlink -uLowPower= 0 -uInteface= SWD -uIfSpeed= 4000 -uNoReset= 1 -uResetPreRun= 1 -uResetCon= 1 -uResetBefDownload= 1 -uReleaseCM3= 0 -uSWOcoreClock= 0 -uresetOnReload= 1 -n 0 -uFlashBp= 1 -uSimulation= 0 -ueraseRomOnDownload= 0 -ueraseDataRomOnDownload= 0 -uOSRestriction= 0 -uProgReWriteIRom= 0 -uCPUFrequency= 0 -uCECycle= 1"/>
<booleanAttribute key="com.renesas.cdt.core.setResume" value="true"/>
<stringAttribute key="com.renesas.cdt.core.targetDevice" value="R7FA6M4AF"/>
<booleanAttribute key="com.renesas.cdt.core.useRemoteTarget" value="true"/>
<stringAttribute key="com.renesas.cdt.launch.dsf.IO_MAP" value="${support_area_loc}"/>
<booleanAttribute key="com.renesas.cdt.launch.dsf.USE_DEFAULT_IO_MAP" value="true"/>
<stringAttribute key="com.renesas.cdt.launch.dsf.launchSeqType" value="com.renesas.cdt.launch.dsf.launchSequence.e2GdbServer"/>
<stringAttribute key="com.renesas.cdt.launch.dsf.serverPath" value="${renesas.support.targetLoc:com.renesas.ide.supportfiles.ra.debug.debugSupportFileTarget}\e2-server-gdb"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.break.allowSimulation" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.break.useFlashBreakpoints.resetorrepurposed" value="true"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.id_code2" value="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.jlinkScript" value=""/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.registerInit" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.reset" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.resetAfterDownload" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.resetCon" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.resetPreRun" value="true"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.connection.swv.coreClockSpeed" value="0"/>
<intAttribute key="com.renesas.hardwaredebug.arm.jlink.interface.speed" value="4000"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.interface.type" value="SWD"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.jlink.lowPowerHandling" value="No"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.jlink.scriptFile" value=""/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.jlink.settingsFile" value="${workspace_loc:/${ProjName}}/${LaunchConfigName}.jlink"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.memory.isLittleEndian" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.options.ArmJLinkDebugToolSettingsTree.prog_rewrite_irom" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.options.ArmJLinkDebugToolSettingsTree.resetAfterReload" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.options.ArmJLinkDebugToolSettingsTree.rtosIntegrationInDebugView" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.options.ArmJLinkDebugToolSettingsTree.rtosintegrationthreadsrunning" value="false"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.release.reset" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.scanChain.multiDevices" value="false"/>
<stringAttribute key="com.renesas.hardwaredebug.arm.jlink.semihosting.breakpointAddress" value=""/>
<booleanAttribute key="com.renesas.hardwaredebug.arm.jlink.setTZBoundaries" value="true"/>
<booleanAttribute key="com.renesas.hardwaredebug.timemeasurement" value="true"/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.delay" value="3"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/test_RA6M4.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="test_RA6M4"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/test_RA6M4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>