2
0

wolfssl-arduino.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # this script will reformat the wolfSSL source code to be compatible with
  3. # an Arduino project
  4. # run as bash ./wolfssl-arduino.sh
  5. DIR=${PWD##*/}
  6. space(){
  7. echo "" >> "$1"
  8. }
  9. if [ "$DIR" = "ARDUINO" ]; then
  10. if [ ! -d "wolfSSL" ]; then
  11. mkdir wolfSSL
  12. fi
  13. cp ../../src/*.c ./wolfSSL
  14. cp ../../wolfcrypt/src/*.c ./wolfSSL
  15. if [ ! -d "wolfSSL/wolfssl" ]; then
  16. mkdir wolfSSL/wolfssl
  17. fi
  18. cp ../../wolfssl/*.h ./wolfSSL/wolfssl
  19. if [ ! -d "wolfSSL/wolfssl/wolfcrypt" ]; then
  20. mkdir wolfSSL/wolfssl/wolfcrypt
  21. fi
  22. cp ../../wolfssl/wolfcrypt/*.h ./wolfSSL/wolfssl/wolfcrypt
  23. # support misc.c as include in wolfcrypt/src
  24. if [ ! -d "./wolfSSL/wolfcrypt" ]; then
  25. mkdir ./wolfSSL/wolfcrypt
  26. fi
  27. if [ ! -d "./wolfSSL/wolfcrypt/src" ]; then
  28. mkdir ./wolfSSL/wolfcrypt/src
  29. fi
  30. cp ../../wolfcrypt/src/misc.c ./wolfSSL/wolfcrypt/src
  31. cp ../../wolfcrypt/src/asm.c ./wolfSSL/wolfcrypt/src
  32. # put bio and evp as includes
  33. mv ./wolfSSL/bio.c ./wolfSSL/wolfssl
  34. mv ./wolfSSL/evp.c ./wolfSSL/wolfssl
  35. # make a copy of evp.c and bio.c for ssl.c to include inline
  36. cp ./wolfSSL/wolfssl/evp.c ./wolfSSL/wolfcrypt/src/evp.c
  37. cp ./wolfSSL/wolfssl/bio.c ./wolfSSL/wolfcrypt/src/bio.c
  38. # copy openssl compatibility headers to their appropriate location
  39. if [ ! -d "./wolfSSL/wolfssl/openssl" ]; then
  40. mkdir ./wolfSSL/wolfssl/openssl
  41. fi
  42. cp ../../wolfssl/openssl/* ./wolfSSL/wolfssl/openssl
  43. echo "/* Generated wolfSSL header file for Arduino */" > ./wolfSSL/wolfssl.h
  44. echo "#include <user_settings.h>" >> ./wolfSSL/wolfssl.h
  45. echo "#include <wolfssl/wolfcrypt/settings.h>" >> ./wolfSSL/wolfssl.h
  46. echo "#include <wolfssl/ssl.h>" >> ./wolfSSL/wolfssl.h
  47. if [ ! -f "./wolfSSL/user_settings.h" ]; then
  48. echo "/* Generated wolfSSL user_settings.h file for Arduino */" > ./wolfSSL/user_settings.h
  49. echo "#ifndef ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h
  50. echo "#define ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h
  51. space ./wolfSSL/user_settings.h
  52. echo "/* Platform */" >> ./wolfSSL/user_settings.h
  53. echo "#define WOLFSSL_ARDUINO" >> ./wolfSSL/user_settings.h
  54. space ./wolfSSL/user_settings.h
  55. echo "/* Math library (remove this to use normal math)*/" >> ./wolfSSL/user_settings.h
  56. echo "#define USE_FAST_MATH" >> ./wolfSSL/user_settings.h
  57. echo "#define TFM_NO_ASM" >> ./wolfSSL/user_settings.h
  58. space ./wolfSSL/user_settings.h
  59. echo "/* RNG DEFAULT !!FOR TESTING ONLY!! */" >> ./wolfSSL/user_settings.h
  60. echo "/* comment out the error below to get started w/ bad entropy source" >> ./wolfSSL/user_settings.h
  61. echo " * This will need fixed before distribution but is OK to test with */" >> ./wolfSSL/user_settings.h
  62. echo "#error \"needs solved, see: https://www.wolfssl.com/docs/porting-guide/\"" >> ./wolfSSL/user_settings.h
  63. echo "#define WOLFSSL_GENSEED_FORTEST" >> ./wolfSSL/user_settings.h
  64. space ./wolfSSL/user_settings.h
  65. echo "#endif /* ARDUINO_USER_SETTINGS_H */" >> ./wolfSSL/user_settings.h
  66. fi
  67. cp wolfSSL/wolfssl/wolfcrypt/settings.h wolfSSL/wolfssl/wolfcrypt/settings.h.bak
  68. echo " /* wolfSSL Generated ARDUINO settings */" > ./wolfSSL/wolfssl/wolfcrypt/settings.h
  69. echo "#ifndef WOLFSSL_USER_SETTINGS" >> ./wolfSSL/wolfssl/wolfcrypt/settings.h
  70. echo " #define WOLFSSL_USER_SETTINGS" >> ./wolfSSL/wolfssl/wolfcrypt/settings.h
  71. echo "#endif /* WOLFSSL_USER_SETTINGS */" >> ./wolfSSL/wolfssl/wolfcrypt/settings.h
  72. echo " /* wolfSSL Generated ARDUINO settings: END */" >> ./wolfSSL/wolfssl/wolfcrypt/settings.h
  73. cat ./wolfSSL/wolfssl/wolfcrypt/settings.h.bak >> ./wolfSSL/wolfssl/wolfcrypt/settings.h
  74. else
  75. echo "ERROR: You must be in the IDE/ARDUINO directory to run this script"
  76. fi