diff --git a/IDE/ECLIPSE/RTTHREAD/README.md b/IDE/ECLIPSE/RTTHREAD/README.md new file mode 100644 index 000000000..e329aff57 --- /dev/null +++ b/IDE/ECLIPSE/RTTHREAD/README.md @@ -0,0 +1,175 @@ +# RT-Thread Port +## Overview +You can enable the wolfSSL support for RT-Thread available [here](https://www.rt-thread.io) using the define `RTTHREAD`. + +## Usage + +wolfSSL supports a compile-time user configurable options in the `IDE/ECLIPSE/RTTHREAD/user_settings.h` file. + +The `wolfssl_test.c` example application provides a simple function to run the test and benchmark. + +1. Open your IDE-based example project for RT-Thread. + +2. Create the following folder and sub-folders structures in your project. +``` +wolfssl + |src + |wolfcrypt + |benchmark + |src + |test + |wolfssl + |openssl + |wolfcrypt + |example +``` +The folder hierarchy is the same as the wolfSSL folders with an exception of the example folder. + +3. Add or link all of the header and source files in `IDE/ECLIPSE/RTTHREAD/` folder into the example folder. + +4. Add or link all the source code in the corresponding folder in wolfSSL. + +5. Remove non-C platform dependent files from your build. + +6. In your C/C++ compiler preprocessor settings, add the wolfSSL directories to your include paths. +Here's an example of the paths that must be added. + +``` +$PROJ_DIR$\... +$PROJ_DIR$\...\wolfcrypt +$PROJ_DIR$\...\wolfssl +$PROJ_DIR$\...\IDE\ECLIPSE\RTTHREAD +``` + +7. In your C/C++ compiler preprocessor settings, define the WOLFSSL_USER_SETTINGS symbol to add user_settings.h file in your project. + +8. Add a call to `wolfssl_test()` from your startup task. Here's an example: + +```c +static void test_task (void *p_arg) +{ + ... + while (1) { + wolfssl_test(); + rt_thread_mdelay(500); + } +} +``` +9. Rebuild all your project. + +10. Now you are ready to download and debug your image on the board. + + +The test results below were collected from the RT-Thread ART-Pi with the following software and tool chains: + +- STM32H750XBH6 + +- RT-Thread Studio (Version: 2.0.0) + +- GNU ARM Cross C Compiler (Optimization level: -O0) + +- The starting project is based on [RT-Thread ART-Pi SDK](https://github.com/RT-Thread-Studio/sdk-bsp-stm32h750-realthread-artpi) (./projects/art_pi_wifi) + +- wolfssl [latest version](https://github.com/wolfSSL/wolfssl) + + +### `WOLFSSL_WOLFCRYPT_TEST` output of wolfcrypt_test() +``` +error test passed! +MEMORY test passed! +base64 test passed! +asn test passed! +RANDOM test passed! +MD5 test passed! +MD4 test passed! +SHA test passed! +SHA-256 test passed! +SHA-512 test passed! +Hash test passed! +HMAC-MD5 test passed! +HMAC-SHA test passed! +HMAC-SHA256 test passed! +HMAC-SHA512 test passed! +X963-KDF test passed! +GMAC test passed! +ARC4 test passed! +HC-128 test passed! +Rabbit test passed! +DES test passed! +DES3 test passed! +AES test passed! +AES192 test passed! +AES256 test passed! +AES-GCM test passed! +AES Key Wrap test passed! +RSA test passed! +DH test passed! +DSA test passed! +PWDBASED test passed! +ECC test passed! +ECC buffer test passed! +CURVE25519 test passed! +ED25519 test passed! +PKCS7encrypted test passed! +PKCS7signed test passed! +PKCS7enveloped test passed! +PKCS7authenveloped test passed! +logging test passed! +mutex test passed! +memcb test passed! +``` +### `WOLFSSL_BENCHMARK_TEST` output of benchmark_test() +``` +------------------------------------------------------------------------------ + wolfSSL version 4.5.0 +------------------------------------------------------------------------------ +wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each) +RNG 50 KB took 1.000 seconds, 50.000 KB/s +AES-128-CBC-enc 2 MB took 1.000 seconds, 2.075 MB/s +AES-128-CBC-dec 2 MB took 1.000 seconds, 1.611 MB/s +AES-192-CBC-enc 2 MB took 1.000 seconds, 2.002 MB/s +AES-192-CBC-dec 2 MB took 1.000 seconds, 1.514 MB/s +AES-256-CBC-enc 2 MB took 1.000 seconds, 1.855 MB/s +AES-256-CBC-dec 1 MB took 1.000 seconds, 1.465 MB/s +AES-128-GCM-enc 700 KB took 1.000 seconds, 700.000 KB/s +AES-128-GCM-dec 675 KB took 1.000 seconds, 675.000 KB/s +AES-192-GCM-enc 675 KB took 1.000 seconds, 675.000 KB/s +AES-192-GCM-dec 675 KB took 1.000 seconds, 675.000 KB/s +AES-256-GCM-enc 650 KB took 1.000 seconds, 650.000 KB/s +AES-256-GCM-dec 650 KB took 1.000 seconds, 650.000 KB/s +AES-128-ECB-enc 2 MB took 1.000 seconds, 1.902 MB/s +AES-128-ECB-dec 2 MB took 1.000 seconds, 1.521 MB/s +AES-192-ECB-enc 2 MB took 1.000 seconds, 1.780 MB/s +AES-192-ECB-dec 1 MB took 1.000 seconds, 1.433 MB/s +AES-256-ECB-enc 2 MB took 1.000 seconds, 1.638 MB/s +AES-256-ECB-dec 1 MB took 1.000 seconds, 1.405 MB/s +ARC4 5 MB took 1.000 seconds, 4.956 MB/s +RABBIT 6 MB took 1.000 seconds, 6.470 MB/s +3DES 750 KB took 1.000 seconds, 750.000 KB/s +MD5 12 MB took 1.000 seconds, 12.061 MB/s +SHA 4 MB took 1.000 seconds, 3.979 MB/s +SHA-256 2 MB took 1.000 seconds, 1.782 MB/s +SHA-512 1 MB took 1.000 seconds, 1.001 MB/s +HMAC-MD5 12 MB took 1.000 seconds, 12.329 MB/s +HMAC-SHA 4 MB took 1.000 seconds, 3.662 MB/s +HMAC-SHA256 2 MB took 1.000 seconds, 1.758 MB/s +HMAC-SHA512 1 MB took 1.000 seconds, 1.001 MB/s +PBKDF2 224 bytes took 1.000 seconds, 224.000 bytes/s +RSA 2048 public 20 ops took 1.000 sec, avg 50.000 ms, 20.000 ops/sec +RSA 2048 private 2 ops took 1.000 sec, avg 500.000 ms, 2.000 ops/sec +DH 2048 key gen 4 ops took 1.000 sec, avg 250.000 ms, 4.000 ops/sec +DH 2048 agree 4 ops took 1.000 sec, avg 250.000 ms, 4.000 ops/sec +ECC 256 key gen 6 ops took 1.000 sec, avg 166.667 ms, 6.000 ops/sec +ECDHE 256 agree 6 ops took 1.000 sec, avg 166.667 ms, 6.000 ops/sec +ECDSA 256 sign 6 ops took 1.000 sec, avg 166.667 ms, 6.000 ops/sec +ECDSA 256 verify 4 ops took 1.000 sec, avg 250.000 ms, 4.000 ops/sec +CURVE 25519 key gen 4 ops took 1.000 sec, avg 250.000 ms, 4.000 ops/sec +CURVE 25519 agree 2 ops took 1.000 sec, avg 500.000 ms, 2.000 ops/sec +ED 25519 key gen 4 ops took 1.000 sec, avg 250.000 ms, 4.000 ops/sec +ED 25519 sign 2 ops took 1.000 sec, avg 500.000 ms, 2.000 ops/sec +ED 25519 verify 2 ops took 1.000 sec, avg 500.000 ms, 2.000 ops/sec +``` + +## References + +For more information please contact info@wolfssl.com. \ No newline at end of file diff --git a/IDE/ECLIPSE/RTTHREAD/include.am b/IDE/ECLIPSE/RTTHREAD/include.am new file mode 100644 index 000000000..13b8657e7 --- /dev/null +++ b/IDE/ECLIPSE/RTTHREAD/include.am @@ -0,0 +1,8 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST += \ + IDE/ECLIPSE/RTTHREAD/README.md \ + IDE/ECLIPSE/RTTHREAD/user_settings.h \ + IDE/ECLIPSE/RTTHREAD/wolfssl_test.c diff --git a/IDE/ECLIPSE/RTTHREAD/user_settings.h b/IDE/ECLIPSE/RTTHREAD/user_settings.h new file mode 100644 index 000000000..f28c968c6 --- /dev/null +++ b/IDE/ECLIPSE/RTTHREAD/user_settings.h @@ -0,0 +1,81 @@ +/* user_setting.h + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#ifndef WOLFSSL_USER_SETTINGS_H_ +#define WOLFSSL_USER_SETTINGS_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#define RTTHREAD + +/* You can select one or all of the following tests */ +#define WOLFSSL_WOLFCRYPT_TEST +#define WOLFSSL_BENCHMARK_TEST +#define WOLFSSL_CLIENT_TEST +#define WOLFSSL_SERVER_TEST +#define USE_TEST_GENSEED +#define NO_DEV_RANDOM +#define HAVE_PKCS7 +#define HAVE_AES_KEYWRAP +#define HAVE_X963_KDF +#define WOLFSSL_AES_DIRECT +/* adjust CURRENT_UNIX_TS to seconds since Jan 01 1970. (UTC) +You can get the current time from https://www.unixtimestamp.com/ +*/ +#define CURRENT_UNIX_TS 1542605837UL + +/* When using Windows simulator, you must define USE_WINDOWS_API for test.h to build */ +#ifdef _WIN32 +#define USE_WINDOWS_API +#endif + +#define NO_FILESYSTEM +#define SIZEOF_LONG_LONG 8 + +/* prevents from including multiple definition of main() */ +#define NO_MAIN_DRIVER +#define NO_TESTSUITE_MAIN_DRIVER + +/* includes certificate test buffers via header files */ +#define USE_CERT_BUFFERS_2048 +/*use kB instead of mB for embedded benchmarking*/ +#define BENCH_EMBEDDED + +#define NO_WRITE_TEMP_FILES + +#define XSNPRINTF snprintf +#define NO_WRITEV + +#define HAVE_AESGCM +#define WOLFSSL_SHA512 +#define HAVE_ECC +#define HAVE_CURVE25519 +#define CURVE25519_SMALL +#define HAVE_ED25519 +#define ED25519_SMALL + +#ifdef __cplusplus + } /* extern "C" */ +#endif + +#endif diff --git a/IDE/ECLIPSE/RTTHREAD/wolfssl_test.c b/IDE/ECLIPSE/RTTHREAD/wolfssl_test.c new file mode 100644 index 000000000..0dce7d0d0 --- /dev/null +++ b/IDE/ECLIPSE/RTTHREAD/wolfssl_test.c @@ -0,0 +1,33 @@ +/* wolfsslRunTests.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ +#include +#include +#include + +int wolfssl_test(void) { +#if !defined(NO_CRYPT_TEST) + wolfcrypt_test(NULL); +#endif +#if !defined(NO_CRYPT_BENCHMARK) + benchmark_test(NULL); +#endif + return 0; +} diff --git a/IDE/include.am b/IDE/include.am index 5af057d6b..3814a1f63 100644 --- a/IDE/include.am +++ b/IDE/include.am @@ -20,6 +20,7 @@ include IDE/CSBENCH/include.am include IDE/ECLIPSE/DEOS/include.am include IDE/ECLIPSE/MICRIUM/include.am include IDE/ECLIPSE/SIFIVE/include.am +include IDE/ECLIPSE/RTTHREAD/include.am include IDE/mynewt/include.am include IDE/Renesas/e2studio/DK-S7G2/include.am include IDE/Renesas/cs+/Projects/include.am diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 36c2fe9f6..9538cacb3 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -971,6 +971,40 @@ int wolfSSL_CryptHwMutexUnLock(void) return 0; } +#elif defined(RTTHREAD) + + int wc_InitMutex(wolfSSL_Mutex* m) + { + int iReturn; + + *m = ( wolfSSL_Mutex ) rt_mutex_create("mutex",RT_IPC_FLAG_FIFO); + if( *m != NULL ) + iReturn = 0; + else + iReturn = BAD_MUTEX_E; + + + return iReturn; + } + + int wc_FreeMutex(wolfSSL_Mutex* m) + { + rt_mutex_delete( *m ); + return 0; + } + + + int wc_LockMutex(wolfSSL_Mutex* m) + { + /* Assume an infinite block, or should there be zero block? */ + return rt_mutex_take( *m, RT_WAITING_FOREVER ); + } + + int wc_UnLockMutex(wolfSSL_Mutex* m) + { + return rt_mutex_release( *m ); + } + #elif defined(WOLFSSL_SAFERTOS) int wc_InitMutex(wolfSSL_Mutex* m) diff --git a/wolfssl/internal.h b/wolfssl/internal.h index aea8a6478..084beceea 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -146,6 +146,8 @@ /* do nothing, just don't pick Unix */ #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) /* do nothing */ +#elif defined(RTTHREAD) + /* do nothing */ #elif defined(EBSNET) /* do nothing */ #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 2657739ca..1e8aabca2 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -228,6 +228,8 @@ /* do nothing, just don't pick Unix */ #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS) /* do nothing */ +#elif defined(RTTHREAD) + /* do nothing */ #elif defined(EBSNET) /* do nothing */ #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) @@ -333,6 +335,9 @@ #include "FreeRTOS.h" #include "semphr.h" typedef SemaphoreHandle_t wolfSSL_Mutex; + #elif defined (RTTHREAD) + #include "rtthread.h" + typedef rt_mutex_t wolfSSL_Mutex; #elif defined(WOLFSSL_SAFERTOS) typedef struct wolfSSL_Mutex { signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];