diff --git a/.gitignore b/.gitignore index b22328702..a421b91ec 100644 --- a/.gitignore +++ b/.gitignore @@ -188,4 +188,8 @@ wolfcrypt/user-crypto/lib/libusercrypto.* wrapper/CSharp/x64/ # Visual Studio Code Workspace Files -*.vscode \ No newline at end of file +*.vscode + +# RIOT_OS workspace directories: +RIOT_Make/*/bin/* +RIOT_Make/*/*.c diff --git a/RIOT_Make/test-all.sh b/RIOT_Make/test-all.sh new file mode 100755 index 000000000..c8a0edae1 --- /dev/null +++ b/RIOT_Make/test-all.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +echo "Running wolfssl testsuite with RIOT" +cd testsuite/ +./wolf-build-and-run-test.sh +RESULT=$? +if [ $RESULT != 0 ] +then + echo "testsuite failed" + echo "" +fi + +cd .. + +echo "Running wolfcrypt tests with RIOT" +cd wolfcrypt-test +./wolf-build-and-run-test.sh +RESULT=$? +if [ $RESULT != 0 ] +then + echo "wolfcrypt test failed" + echo "" +fi + +cd .. + +exit 0 diff --git a/RIOT_Make/testsuite/README b/RIOT_Make/testsuite/README new file mode 100644 index 000000000..08db1ac67 --- /dev/null +++ b/RIOT_Make/testsuite/README @@ -0,0 +1,53 @@ +These are the steps to properly setup a test of wolfssl in RIOT OS: + +To test wolfSSL in RIOT build system get the RIOT source code from here: +git clone https://github.com/RIOT-OS/RIOT + +Then cd RIOT/examples + +clone wolfssl in that directory. You should end up with RIOT/examples/wolfssl + +git clone https://github.com/wolfssl/wolfssl + +cd /RIOT/examples/wolfssl/RIOT_Make/testsuite + +run the script ./wolf-build-and-run-test.sh + +That script will perform the following steps: +1. copy the source files from: + /src + /wolfcrypt/src + /wolfcrypt/test + /testsuite + /examples/[ echoserver/echoclient/client/server ] + +2. Use the provided Makefile to build the example application: + "testwolfcrypt.elf" + This application will be located here: + /RIOT/examples/wolfssl/RIOT_Make/wolfcrypt-test/bin/native/testwolfcrypt.elf + +3. Execute that application. You should see a pass or fail. + +4. Lastly that script will cleanup the source files it copied in for building. + NOTE: this is HIGHLY RECOMMENDED to prevent making changes on temporary + files. All development changes should be made to the actual source + files located in their respective directories: + /src + /wolfcrypt/src + /wolfcrypt/test + /testsuite + /examples/[ echoserver/echoclient/client/server ] + Then the script "wolf-build-and-run-test.sh" should be run again to + test those changes + If you do make changes to the temporary files those changes will be + ignored by /.gitignore + + +NOTE: This test is only for the "native" test. To build for a specific platform + cd to RIOT directory and run "make doc" to generate doxygen docs. + (You will need to install doxygen if you don't have it already) + Then open the file: RIOT/doc/doxygen/html/index.html + + This will provide you with the necessary help to setup and build for a + specific platform + diff --git a/RIOT_Make/testsuite/wolf-build-and-run-test.sh b/RIOT_Make/testsuite/wolf-build-and-run-test.sh new file mode 100755 index 000000000..2434f4c69 --- /dev/null +++ b/RIOT_Make/testsuite/wolf-build-and-run-test.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +wolf_riot_setup () { +#copy the test sources here +cp ../../wolfcrypt/test/test.c ./ +cp ../../examples/server/server.c ./ +cp ../../examples/client/client.c ./ +cp ../../examples/echoserver/echoserver.c ./ +cp ../../examples/echoclient/echoclient.c ./ + +cp ../../testsuite/testsuite.c ./ + +cp ../../wolfcrypt/src/*.c ./ + +cp ../../src/*.c ./ + +} + +wolf_riot_cleanup () { + rm ./*.c + #leave this line in for testing. Comment it out when you want to build + # a .elf for flashing to a device + make clean &> /dev/null +} +trap wolf_riot_cleanup INT TERM + +BACKUPCFLAGS=${CFLAGS} +export CFLAGS="${CFLAGS} -DNO_MAIN_DRIVER -DWOLFSSL_RIOT_OS" + +# copy the necessary files to this directory +wolf_riot_setup + +# build the test +make &> /dev/null +RESULT=$? + [ $RESULT != 0 ] && echo "Make FAILED: running verbose make" && + make +if [ $RESULT != 0 ]; +then + wolf_riot_cleanup && echo "cleanup done" && exit 2 +fi + +# run the test +./bin/native/wolftestsuite.elf + +# confirm success or failure +export CFLAGS="${BACKUPCFLAGS}" +RESULT=$? + [ $RESULT != 0 ] && echo "TEST FAILED" && wolf_riot_cleanup && + echo "cleanup done" && exit 2 + +echo "TEST PASSED!" + +# cleanup. All changes made should be to the files in: +# /src +# /wolfcrypt/src +# or other. Never make changes to the files copied here as they are only +# temporary. Once changes are made, to test them just run this script again. +wolf_riot_cleanup 0 + + diff --git a/RIOT_Make/wolfcrypt-test/README b/RIOT_Make/wolfcrypt-test/README new file mode 100644 index 000000000..2c4dcd31a --- /dev/null +++ b/RIOT_Make/wolfcrypt-test/README @@ -0,0 +1,49 @@ +These are the steps to properly setup a test of wolfssl in RIOT OS: + +To test wolfSSL in RIOT build system get the RIOT source code from here: +git clone https://github.com/RIOT-OS/RIOT + +Then cd RIOT/examples + +clone wolfssl in that directory. You should end up with RIOT/examples/wolfssl + +git clone https://github.com/wolfssl/wolfssl + +cd /RIOT/examples/wolfssl/RIOT_Make/wolfcrypt-test + +run the script ./wolf-build-and-run-test.sh + +That script will perform the following steps: +1. copy the source files from: + /src + /wolfcrypt/src + /wolfcrypt/test + +2. Use the provided Makefile to build the example application: + "testwolfcrypt.elf" + This application will be located here: + /RIOT/examples/wolfssl/RIOT_Make/wolfcrypt-test/bin/native/testwolfcrypt.elf + +3. Execute that application. You should see a pass or fail. + +4. Lastly that script will cleanup the source files it copied in for building. + NOTE: this is HIGHLY RECOMMENDED to prevent making changes on temporary + files. All development changes should be made to the actual source + files located in their respective directories: + /src + /wolfcrypt/src + /wolfcrypt/test + Then the script "build-and-run-test.sh" should be run again to test + those changes + If you do make changes to the temporary files those changes will be + ignored by /.gitignore + +. +NOTE: This test is only for the "native" test. To build for a specific platform + cd to RIOT directory and run "make doc" to generate doxygen docs. + (You will need to install doxygen if you don't have it already) + Then open the file: RIOT/doc/doxygen/html/index.html + + This will provide you with the necessary help to setup and build for a + specific platform + diff --git a/RIOT_Make/wolfcrypt-test/wolf-build-and-run-test.sh b/RIOT_Make/wolfcrypt-test/wolf-build-and-run-test.sh new file mode 100755 index 000000000..eaa5a115c --- /dev/null +++ b/RIOT_Make/wolfcrypt-test/wolf-build-and-run-test.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +wolf_riot_setup () { + #copy the test sources here + cp ../../wolfcrypt/test/*.c ./ + + cp ../../wolfcrypt/src/*.c ./ + + cp ../../src/*.c ./ +} + +wolf_riot_cleanup () { + rm ./*.c + #leave this line in for testing. Comment it out when you want to build + # a .elf for flashing to a device + make clean &> /dev/null +} + +BACKUPCFLAGS=${CFLAGS} +export CFLAGS="${CFLAGS} -DWOLFSSL_RIOT_OS" + + +# copy the necessary files to this directory +wolf_riot_setup + +# build the test +# change next line to just "make" to see verbose output +# NOTE: will throw a warning on every file that is empty if that feature +# is not enabled in wolfssl. +make &> /dev/null +RESULT=$? + [ $RESULT != 0 ] && echo "Make FAILED: running verbose make" && + make + +if [ $RESULT != 0 ]; +then + wolf_riot_cleanup && echo "cleanup done" && exit 2 +fi + +# run the test +./bin/native/testwolfcrypt.elf + +# confirm success or failure +RESULT=$? + [ $RESULT != 0 ] && echo "TEST FAILED" && wolf_riot_cleanup && exit 5 + +echo "ALL TEST PASSED!" + +# cleanup. All changes made should be to the files in: +# /src +# /wolfcrypt/src +# or other. Never make changes to the files copied here as they are only +# temporary. Once changes are made, to test them just run this script again. +wolf_riot_cleanup + +exit 0 + + diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 0fdc951c8..220ada67e 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -210,7 +210,11 @@ int testsuite_test(int argc, char** argv) #endif /* HAVE_WNR */ printf("\nAll tests passed!\n"); +#ifdef WOLFSSL_RIOT_OS + exit(0); +#else return EXIT_SUCCESS; +#endif } void simple_test(func_args* args) @@ -411,7 +415,11 @@ int main(int argc, char** argv) if (server_args.return_code != 0) return server_args.return_code; printf("\nAll tests passed!\n"); +#ifdef WOLFSSL_RIOT_OS + exit(0); +#else return EXIT_SUCCESS; +#endif } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 9a00a8539..bfd9c84ae 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -729,7 +729,11 @@ int wolfcrypt_test(void* args) err_sys("Failed to free netRandom context", -1238); #endif /* HAVE_WNR */ +#ifdef WOLFSSL_RIOT_OS + exit(0); +#else return args.return_code; +#endif } #endif /* NO_MAIN_DRIVER */ diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 839200393..dcd747929 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -1065,6 +1065,8 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL*, void* key, unsigned int len, #ifdef __PPU #include #include + #elif defined(WOLFSSL_RIOT_OS) + #include #elif !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_IAR_ARM) && \ !defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \ !defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index cc5283fac..6550ca80d 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -147,6 +147,9 @@ /* Uncomment next line if building for embOS */ /* #define WOLFSSL_EMBOS */ +/* Uncomment next line if building for RIOT-OS */ +/* #define WOLFSSL_RIOT_OS */ + #include #ifdef WOLFSSL_USER_SETTINGS @@ -404,6 +407,12 @@ #define SINGLE_THREADED /* Not ported at this time */ #endif +#ifdef WOLFSSL_RIOT_OS + #define USE_CERT_BUFFERS_2048 + #define HAVE_ECC + #define NO_INLINE +#endif + #ifdef WOLFSSL_NRF5x #define SIZEOF_LONG 4 #define SIZEOF_LONG_LONG 8