From ebe99cf5eff9496426940c45480b3e051d758f88 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 6 Sep 2019 14:53:39 -0700 Subject: [PATCH 1/5] Support for SiFive HiFive Unleashed board. --- IDE/RISCV/README.md | 116 ++++++++++++++++++++++++++++++++++++++ IDE/RISCV/include.am | 5 ++ IDE/include.am | 1 + wolfssl/wolfcrypt/types.h | 3 +- 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 IDE/RISCV/README.md create mode 100644 IDE/RISCV/include.am mode change 100644 => 100755 wolfssl/wolfcrypt/types.h diff --git a/IDE/RISCV/README.md b/IDE/RISCV/README.md new file mode 100644 index 000000000..86cdc2e1b --- /dev/null +++ b/IDE/RISCV/README.md @@ -0,0 +1,116 @@ +# SiFive HiFive Unleashed + +Instructions for cross-compiling and running wolfSSL on the HiFive Unleashed board. + +## Board SiFive HiFive Unleashed Board + +SiFive Freedom U540 SoC at 1.5GHz + +Getting started guide: +https://sifive.cdn.prismic.io/sifive%2Ffa3a584a-a02f-4fda-b758-a2def05f49f9_hifive-unleashed-getting-started-guide-v1p1.pdf + +## Building Freedom-U-SDK + +```sh +git clone https://github.com/sifive/freedom-u-sdk.git +cd freedom-u-sdk +git submodule update --recursive --init +make +``` + +See `freedom-u-sdk/README.md` file for instructions on updating the SD card U-Boot and Linux image. + +Here is a summary of the steps: + +Insert SD card from Unleashed into host and determine the assigned character sequence (X) for the media. + +From `freedom-u-sdk` directory: + +```sh +sudo make DISK=/dev/sdX format-boot-loader + +# Copy U-Boot .fit image to first FAT partition (32MB) +sudo mkdir /media/hifiveu_boot +sudo mount -t vfat /dev/sdX1 /media/hifiveu_boot +cp ./work/image-.fit /media/hifiveu_boot/hifiveu.fit +sudo umount /media/hifiveu_boot + +# Copy Linux FS +sudo dd if=./work/hifive-unleashed-.gpt of=/dev/sdX2 bs=1M +``` + +Note: Make sure S1 Switch 5 (MSEL2) is OFF, rest ON (MSEL=1011) to boot from SD + + +## Building wolfSSL + +```sh +./configure --host=riscv64 \ + CC="`pwd`/../freedom-u-sdk/work/buildroot_initramfs/host/bin/riscv64-sifive-linux-gnu-gcc" \ + --with-sysroot="`pwd`/../freedom-u-sdk/work/buildroot_initramfs_sysroot/" \ + --disable-shared \ + --enable-sp \ + CFLAGS="-mabi=lp64d -march=rv64imafdc" +make +``` + +Copy files to device: + +```sh +scp ./wolfcrypt/test/testwolfcrypt root@192.168.0.144:~ +scp ./wolfcrypt/benchmark/benchmark root@192.168.0.144:~ +scp ./examples/client/client root@192.168.0.144:~ +scp ./examples/server/server root@192.168.0.144:~ + +# manually `mkdir certs` on target +scp ./certs/* root@192.168.0.144:~/certs +``` + +## Benchmark Results + +```sh +# ./benchmark +------------------------------------------------------------------------------ + wolfSSL version 4.1.0 +------------------------------------------------------------------------------ +wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each) +RNG 10 MB took 1.709 seconds, 5.853 MB/s +AES-128-CBC-enc 5 MB took 1.578 seconds, 3.168 MB/s +AES-128-CBC-dec 10 MB took 1.330 seconds, 7.521 MB/s +AES-192-CBC-enc 5 MB took 1.739 seconds, 2.875 MB/s +AES-192-CBC-dec 10 MB took 1.485 seconds, 6.736 MB/s +AES-256-CBC-enc 5 MB took 1.869 seconds, 2.675 MB/s +AES-256-CBC-dec 10 MB took 1.636 seconds, 6.114 MB/s +AES-128-GCM-enc 5 MB took 2.328 seconds, 2.147 MB/s +AES-128-GCM-dec 5 MB took 2.210 seconds, 2.263 MB/s +AES-192-GCM-enc 5 MB took 2.592 seconds, 1.929 MB/s +AES-192-GCM-dec 5 MB took 2.369 seconds, 2.110 MB/s +AES-256-GCM-enc 5 MB took 2.633 seconds, 1.899 MB/s +AES-256-GCM-dec 5 MB took 2.607 seconds, 1.918 MB/s +CHACHA 15 MB took 1.013 seconds, 14.808 MB/s +CHA-POLY 15 MB took 1.286 seconds, 11.666 MB/s +MD5 55 MB took 1.026 seconds, 53.628 MB/s +POLY1305 60 MB took 1.090 seconds, 55.024 MB/s +SHA 30 MB took 1.121 seconds, 26.763 MB/s +SHA-256 15 MB took 1.134 seconds, 13.226 MB/s +SHA-384 20 MB took 1.270 seconds, 15.743 MB/s +SHA-512 20 MB took 1.270 seconds, 15.744 MB/s +HMAC-MD5 55 MB took 1.025 seconds, 53.635 MB/s +HMAC-SHA 30 MB took 1.120 seconds, 26.783 MB/s +HMAC-SHA256 15 MB took 1.135 seconds, 13.217 MB/s +HMAC-SHA384 20 MB took 1.270 seconds, 15.743 MB/s +HMAC-SHA512 20 MB took 1.271 seconds, 15.741 MB/s +RSA 2048 public 1400 ops took 1.077 sec, avg 0.769 ms, 1300.132 ops/sec +RSA 2048 private 100 ops took 2.562 sec, avg 25.615 ms, 39.040 ops/sec +DH 2048 key gen 91 ops took 1.007 sec, avg 11.063 ms, 90.394 ops/sec +DH 2048 agree 100 ops took 1.122 sec, avg 11.224 ms, 89.097 ops/sec +ECC 256 key gen 892 ops took 1.001 sec, avg 1.122 ms, 891.293 ops/sec +ECDHE 256 agree 300 ops took 1.392 sec, avg 4.640 ms, 215.516 ops/sec +ECDSA 256 sign 700 ops took 1.089 sec, avg 1.556 ms, 642.730 ops/sec +ECDSA 256 verify 200 ops took 1.102 sec, avg 5.508 ms, 181.568 ops/sec +Benchmark complete +``` + +## Support + +For questions please email us at support@wolfssl.com. diff --git a/IDE/RISCV/include.am b/IDE/RISCV/include.am new file mode 100644 index 000000000..5c0e8d8e4 --- /dev/null +++ b/IDE/RISCV/include.am @@ -0,0 +1,5 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST+= IDE/RISCV/README.md diff --git a/IDE/include.am b/IDE/include.am index a70a88fef..66f49e93b 100644 --- a/IDE/include.am +++ b/IDE/include.am @@ -24,5 +24,6 @@ include IDE/Renesas/cs+/Projects/include.am include IDE/Renesas/e2studio/Projects/include.am include IDE/WICED-STUDIO/include.am include IDE/CRYPTOCELL/include.am +include IDE/RISCV/include.am EXTRA_DIST+= IDE/IAR-EWARM IDE/MDK-ARM IDE/MDK5-ARM IDE/MYSQL IDE/LPCXPRESSO IDE/HEXIWEAR IDE/Espressif IDE/zephyr diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h old mode 100644 new mode 100755 index 33cfd6cc1..d909cb9ec --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -100,7 +100,8 @@ /* These platforms have 64-bit CPU registers. */ #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \ - defined(__aarch64__) || defined(__sparc64__) + defined(__aarch64__) || defined(__sparc64__) || \ + (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8) typedef word64 wolfssl_word; #define WC_64BIT_CPU #elif (defined(sun) || defined(__sun)) && \ From ab5c12fd17eec26225583c6039d0d70d07a4b638 Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 9 Sep 2019 09:01:18 -0700 Subject: [PATCH 2/5] Added parenthesis around types.h pointer size macro. --- IDE/RISCV/README.md | 12 +++++++++++- wolfssl/wolfcrypt/types.h | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/IDE/RISCV/README.md b/IDE/RISCV/README.md index 86cdc2e1b..c7b892f65 100644 --- a/IDE/RISCV/README.md +++ b/IDE/RISCV/README.md @@ -9,6 +9,8 @@ SiFive Freedom U540 SoC at 1.5GHz Getting started guide: https://sifive.cdn.prismic.io/sifive%2Ffa3a584a-a02f-4fda-b758-a2def05f49f9_hifive-unleashed-getting-started-guide-v1p1.pdf +Make sure your ethernet is attached and power up board. You can connecct the micro-usb to get a UART console that will display the DHCP IP address. Default login password is "sifive". + ## Building Freedom-U-SDK ```sh @@ -44,6 +46,14 @@ Note: Make sure S1 Switch 5 (MSEL2) is OFF, rest ON (MSEL=1011) to boot from SD ## Building wolfSSL +This example assumes the `wolfssl` root directory is along side the `freedom-u-sdk` directory. If not then adjust paths. + +``` +~\ + wolfssl + freedom-u-sdk +``` + ```sh ./configure --host=riscv64 \ CC="`pwd`/../freedom-u-sdk/work/buildroot_initramfs/host/bin/riscv64-sifive-linux-gnu-gcc" \ @@ -54,7 +64,7 @@ Note: Make sure S1 Switch 5 (MSEL2) is OFF, rest ON (MSEL=1011) to boot from SD make ``` -Copy files to device: +Copy files to device (replace IP address): ```sh scp ./wolfcrypt/test/testwolfcrypt root@192.168.0.144:~ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index d909cb9ec..df8e9f6f5 100755 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -101,7 +101,7 @@ #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \ defined(__aarch64__) || defined(__sparc64__) || \ - (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8) + (defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)) typedef word64 wolfssl_word; #define WC_64BIT_CPU #elif (defined(sun) || defined(__sun)) && \ From 645f8ddd31d7a65970d3e3ec2ac2021f17e7cf12 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 10 Sep 2019 07:47:28 -0700 Subject: [PATCH 3/5] Update RISC 64-bit detection to use `__riscv_xlen`. --- wolfssl/wolfcrypt/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index df8e9f6f5..2afc82b8c 100755 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -101,7 +101,7 @@ #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \ defined(__aarch64__) || defined(__sparc64__) || \ - (defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)) + (defined(__riscv_xlen) && (__riscv_xlen == 64)) typedef word64 wolfssl_word; #define WC_64BIT_CPU #elif (defined(sun) || defined(__sun)) && \ From def36ddfe891baa2c7e9408f6e6ab9b21f826eef Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 10 Sep 2019 09:16:35 -0700 Subject: [PATCH 4/5] Added instructions for installing Debian on Unleashed board. --- IDE/RISCV/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/IDE/RISCV/README.md b/IDE/RISCV/README.md index c7b892f65..9f68bac30 100644 --- a/IDE/RISCV/README.md +++ b/IDE/RISCV/README.md @@ -22,7 +22,7 @@ make See `freedom-u-sdk/README.md` file for instructions on updating the SD card U-Boot and Linux image. -Here is a summary of the steps: +### Installing U-Boot Insert SD card from Unleashed into host and determine the assigned character sequence (X) for the media. @@ -43,9 +43,23 @@ sudo dd if=./work/hifive-unleashed-.gpt of=/dev/sdX2 bs=1M Note: Make sure S1 Switch 5 (MSEL2) is OFF, rest ON (MSEL=1011) to boot from SD +### Installing Debian + +Insert SD card from Unleashed into host and determine the assigned character sequence (X) for the media. + +From `freedom-u-sdk` directory: + +```sh +sudo make DISK=/dev/sdX format-demo-image +``` ## Building wolfSSL +Make sure you are using wolfSSL sources based on this PR https://github.com/wolfSSL/wolfssl/pull/2456 +The PR 2456 includes a patch to `wolfssl/wolfcrypt/types.h` to detect 64-bit types based on the `__riscv_xlen` macro. + +### Cross Compiling + This example assumes the `wolfssl` root directory is along side the `freedom-u-sdk` directory. If not then adjust paths. ``` @@ -76,6 +90,13 @@ scp ./examples/server/server root@192.168.0.144:~ scp ./certs/* root@192.168.0.144:~/certs ``` +### Native Compiler + +```sh +./configure --enable-sp +make +``` + ## Benchmark Results ```sh From ed06f34f55b7cd1a15a121b30bdb778de1376da4 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 10 Sep 2019 16:09:18 -0700 Subject: [PATCH 5/5] Updated benchmarks running at 1.5GHz (default is 1 GHz). --- IDE/RISCV/README.md | 74 ++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/IDE/RISCV/README.md b/IDE/RISCV/README.md index 9f68bac30..a8f901313 100644 --- a/IDE/RISCV/README.md +++ b/IDE/RISCV/README.md @@ -99,46 +99,50 @@ make ## Benchmark Results +The following is running the wolfCrypt benchmark at 1.5GHz on a single thread (default CPU speed is 1.0GHz). + ```sh -# ./benchmark +echo 1500000000 > /sys/devices/platform/soc/10000000.prci/rate + +./benchmark ------------------------------------------------------------------------------ wolfSSL version 4.1.0 ------------------------------------------------------------------------------ wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each) -RNG 10 MB took 1.709 seconds, 5.853 MB/s -AES-128-CBC-enc 5 MB took 1.578 seconds, 3.168 MB/s -AES-128-CBC-dec 10 MB took 1.330 seconds, 7.521 MB/s -AES-192-CBC-enc 5 MB took 1.739 seconds, 2.875 MB/s -AES-192-CBC-dec 10 MB took 1.485 seconds, 6.736 MB/s -AES-256-CBC-enc 5 MB took 1.869 seconds, 2.675 MB/s -AES-256-CBC-dec 10 MB took 1.636 seconds, 6.114 MB/s -AES-128-GCM-enc 5 MB took 2.328 seconds, 2.147 MB/s -AES-128-GCM-dec 5 MB took 2.210 seconds, 2.263 MB/s -AES-192-GCM-enc 5 MB took 2.592 seconds, 1.929 MB/s -AES-192-GCM-dec 5 MB took 2.369 seconds, 2.110 MB/s -AES-256-GCM-enc 5 MB took 2.633 seconds, 1.899 MB/s -AES-256-GCM-dec 5 MB took 2.607 seconds, 1.918 MB/s -CHACHA 15 MB took 1.013 seconds, 14.808 MB/s -CHA-POLY 15 MB took 1.286 seconds, 11.666 MB/s -MD5 55 MB took 1.026 seconds, 53.628 MB/s -POLY1305 60 MB took 1.090 seconds, 55.024 MB/s -SHA 30 MB took 1.121 seconds, 26.763 MB/s -SHA-256 15 MB took 1.134 seconds, 13.226 MB/s -SHA-384 20 MB took 1.270 seconds, 15.743 MB/s -SHA-512 20 MB took 1.270 seconds, 15.744 MB/s -HMAC-MD5 55 MB took 1.025 seconds, 53.635 MB/s -HMAC-SHA 30 MB took 1.120 seconds, 26.783 MB/s -HMAC-SHA256 15 MB took 1.135 seconds, 13.217 MB/s -HMAC-SHA384 20 MB took 1.270 seconds, 15.743 MB/s -HMAC-SHA512 20 MB took 1.271 seconds, 15.741 MB/s -RSA 2048 public 1400 ops took 1.077 sec, avg 0.769 ms, 1300.132 ops/sec -RSA 2048 private 100 ops took 2.562 sec, avg 25.615 ms, 39.040 ops/sec -DH 2048 key gen 91 ops took 1.007 sec, avg 11.063 ms, 90.394 ops/sec -DH 2048 agree 100 ops took 1.122 sec, avg 11.224 ms, 89.097 ops/sec -ECC 256 key gen 892 ops took 1.001 sec, avg 1.122 ms, 891.293 ops/sec -ECDHE 256 agree 300 ops took 1.392 sec, avg 4.640 ms, 215.516 ops/sec -ECDSA 256 sign 700 ops took 1.089 sec, avg 1.556 ms, 642.730 ops/sec -ECDSA 256 verify 200 ops took 1.102 sec, avg 5.508 ms, 181.568 ops/sec +RNG 10 MB took 1.165 seconds, 8.585 MB/s +AES-128-CBC-enc 15 MB took 1.346 seconds, 11.141 MB/s +AES-128-CBC-dec 15 MB took 1.380 seconds, 10.867 MB/s +AES-192-CBC-enc 10 MB took 1.002 seconds, 9.983 MB/s +AES-192-CBC-dec 10 MB took 1.020 seconds, 9.805 MB/s +AES-256-CBC-enc 10 MB took 1.100 seconds, 9.091 MB/s +AES-256-CBC-dec 10 MB took 1.117 seconds, 8.952 MB/s +AES-128-GCM-enc 10 MB took 1.809 seconds, 5.528 MB/s +AES-128-GCM-dec 10 MB took 1.810 seconds, 5.524 MB/s +AES-192-GCM-enc 10 MB took 1.911 seconds, 5.233 MB/s +AES-192-GCM-dec 10 MB took 1.911 seconds, 5.232 MB/s +AES-256-GCM-enc 5 MB took 1.013 seconds, 4.935 MB/s +AES-256-GCM-dec 5 MB took 1.014 seconds, 4.933 MB/s +CHACHA 25 MB took 1.181 seconds, 21.168 MB/s +CHA-POLY 20 MB took 1.188 seconds, 16.833 MB/s +MD5 80 MB took 1.025 seconds, 78.066 MB/s +POLY1305 85 MB took 1.032 seconds, 82.357 MB/s +SHA 40 MB took 1.033 seconds, 38.728 MB/s +SHA-256 20 MB took 1.023 seconds, 19.557 MB/s +SHA-384 25 MB took 1.059 seconds, 23.597 MB/s +SHA-512 25 MB took 1.059 seconds, 23.597 MB/s +HMAC-MD5 80 MB took 1.026 seconds, 77.950 MB/s +HMAC-SHA 40 MB took 1.034 seconds, 38.700 MB/s +HMAC-SHA256 20 MB took 1.023 seconds, 19.559 MB/s +HMAC-SHA384 25 MB took 1.059 seconds, 23.598 MB/s +HMAC-SHA512 25 MB took 1.059 seconds, 23.599 MB/s +RSA 2048 public 2000 ops took 1.032 sec, avg 0.516 ms, 1938.304 ops/sec +RSA 2048 private 100 ops took 1.713 sec, avg 17.132 ms, 58.370 ops/sec +DH 2048 key gen 133 ops took 1.003 sec, avg 7.544 ms, 132.552 ops/sec +DH 2048 agree 200 ops took 1.531 sec, avg 7.653 ms, 130.676 ops/sec +ECC 256 key gen 1330 ops took 1.001 sec, avg 0.752 ms, 1329.260 ops/sec +ECDHE 256 agree 400 ops took 1.243 sec, avg 3.107 ms, 321.830 ops/sec +ECDSA 256 sign 1000 ops took 1.043 sec, avg 1.043 ms, 958.539 ops/sec +ECDSA 256 verify 300 ops took 1.104 sec, avg 3.680 ms, 271.766 ops/sec Benchmark complete ```