mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Add support for increasing CPU clock speed. New benchmarks with HiFive1 RevB hardware at 320MHz.
This commit is contained in:
@ -3,6 +3,7 @@ PROGRAM ?= wolfcrypt
|
||||
# This line must be added in your freedom-e-sdk/scripts/standalone.mk
|
||||
# RISCV_CFLAGS += -I$(WOLFSSL_SRC_DIR) -I$(WOLFSSL_SRC_DIR)/IDE/ECLIPSE/SIFIVE -DWOLFSSL_USER_SETTINGS
|
||||
# WOLFSSL_SRC_DIR variable must be set in the environment when GNU make is started.
|
||||
# export WOLFSSL_SRC_DIR=~/freedom-e-sdk/software/wolfssl
|
||||
|
||||
WOLFSSL_CFLAGS += -I$(WOLFSSL_SRC_DIR) \
|
||||
-I$(WOLFSSL_SRC_DIR)/IDE/ECLIPSE/SIFIVE \
|
||||
|
@ -1,4 +1,5 @@
|
||||
# SiFive RISC-V HiFive Port
|
||||
# SiFive RISC-V HiFive1 Port
|
||||
|
||||
## Overview
|
||||
You can enable the wolfSSL support for RISC-V using the `#define WOLFSSL_SIFIVE_RISC_V`.
|
||||
|
||||
@ -15,6 +16,7 @@ The `IDE/ECLIPSE/SIFIVE/main.c` example application provides a function to run t
|
||||
- #undef NO_CRYPT_TEST
|
||||
- #undef NO_CRYPT_BENCHMARK
|
||||
```
|
||||
|
||||
## Setup
|
||||
### Setting up the SDK with wolfSSL
|
||||
1. Download the wolfSSL source code or a zip file from GitHub and place it under your SDK `$HOME` directory. You can also copy or simlink to the source.
|
||||
@ -87,10 +89,16 @@ $sudo make install
|
||||
You can now build and link your software to the wolfSSL libwolfssl.a static library.
|
||||
|
||||
### `wolfcrypt_test()`
|
||||
|
||||
wolfcrypt_test() prints a message on the target console similar to the following output:
|
||||
|
||||
```
|
||||
wolfCrypt Test Started
|
||||
SiFive HiFive1 Demo
|
||||
Setting clock to 320MHz
|
||||
Actual Clock 320MHz
|
||||
|
||||
error test passed!
|
||||
MEMORY test passed!
|
||||
base64 test passed!
|
||||
asn test passed!
|
||||
SHA test passed!
|
||||
@ -109,73 +117,46 @@ ECC buffer test passed!
|
||||
logging test passed!
|
||||
mutex test passed!
|
||||
Test complete
|
||||
...
|
||||
wolfCrypt Test Completed
|
||||
```
|
||||
### `benchmark_test()`
|
||||
|
||||
benchmark_test() prints a message on the target console similar to the following output.
|
||||
|
||||
TARGET=sifive-hifive1-revb:
|
||||
|
||||
```
|
||||
------------------------------------------------------------------------------
|
||||
wolfSSL version 4.0.0
|
||||
------------------------------------------------------------------------------
|
||||
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
|
||||
RNG 25 KB took 3.000 seconds, 8.333 KB/s
|
||||
AES-128-CBC-enc 25 KB took 16.000 seconds, 1.562 KB/s
|
||||
AES-128-CBC-dec 25 KB took 17.000 seconds, 1.471 KB/s
|
||||
AES-192-CBC-enc 25 KB took 19.000 seconds, 1.316 KB/s
|
||||
AES-192-CBC-dec 25 KB took 18.000 seconds, 1.389 KB/s
|
||||
AES-256-CBC-enc 25 KB took 20.000 seconds, 1.250 KB/s
|
||||
AES-256-CBC-dec 25 KB took 21.000 seconds, 1.190 KB/s
|
||||
AES-128-GCM-enc 25 KB took 30.000 seconds, 0.833 KB/s
|
||||
AES-128-GCM-dec 25 KB took 30.000 seconds, 0.833 KB/s
|
||||
AES-192-GCM-enc 25 KB took 32.000 seconds, 0.781 KB/s
|
||||
AES-192-GCM-dec 25 KB took 32.000 seconds, 0.781 KB/s
|
||||
AES-256-GCM-enc 25 KB took 34.000 seconds, 0.735 KB/s
|
||||
AES-256-GCM-dec 25 KB took 34.000 seconds, 0.735 KB/s
|
||||
SHA 50 KB took 1.000 seconds, 50.000 KB/s
|
||||
SHA-256 25 KB took 1.000 seconds, 25.000 KB/s
|
||||
HMAC-SHA 50 KB took 1.000 seconds, 50.000 KB/s
|
||||
HMAC-SHA256 25 KB took 1.000 seconds, 25.000 KB/s
|
||||
ECC 256 key gen 1 ops took 11.000 sec, avg 11000.000 ms, 0.091 ops/sec
|
||||
ECDHE 256 agree 2 ops took 22.000 sec, avg 11000.000 ms, 0.091 ops/sec
|
||||
ECDSA 256 sign 2 ops took 23.000 sec, avg 11500.000 ms, 0.087 ops/sec
|
||||
ECDSA 256 verify 2 ops took 45.000 sec, avg 22500.000 ms, 0.044 ops/sec
|
||||
Benchmark complete
|
||||
```
|
||||
TARGET=sifive-hifive1
|
||||
```
|
||||
------------------------------------------------------------------------------
|
||||
wolfSSL version 4.0.0
|
||||
------------------------------------------------------------------------------
|
||||
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
|
||||
RNG 25 KB took 2.000 seconds, 12.500 KB/s
|
||||
AES-128-CBC-enc 25 KB took 17.000 seconds, 1.471 KB/s
|
||||
AES-128-CBC-dec 25 KB took 17.000 seconds, 1.471 KB/s
|
||||
AES-192-CBC-enc 25 KB took 18.000 seconds, 1.389 KB/s
|
||||
AES-192-CBC-dec 25 KB took 18.000 seconds, 1.389 KB/s
|
||||
AES-256-CBC-enc 25 KB took 20.000 seconds, 1.250 KB/s
|
||||
AES-256-CBC-dec 25 KB took 20.000 seconds, 1.250 KB/s
|
||||
AES-128-GCM-enc 25 KB took 31.000 seconds, 0.806 KB/s
|
||||
AES-128-GCM-dec 25 KB took 30.000 seconds, 0.833 KB/s
|
||||
AES-192-GCM-enc 25 KB took 33.000 seconds, 0.758 KB/s
|
||||
AES-192-GCM-dec 25 KB took 33.000 seconds, 0.758 KB/s
|
||||
AES-256-GCM-enc 25 KB took 34.000 seconds, 0.735 KB/s
|
||||
AES-256-GCM-dec 25 KB took 35.000 seconds, 0.714 KB/s
|
||||
SHA 50 KB took 1.000 seconds, 50.000 KB/s
|
||||
SHA-256 25 KB took 1.000 seconds, 25.000 KB/s
|
||||
HMAC-SHA 25 KB took 1.000 seconds, 25.000 KB/s
|
||||
HMAC-SHA256 25 KB took 1.000 seconds, 25.000 KB/s
|
||||
ECC 256 key gen 1 ops took 12.000 sec, avg 12000.000 ms, 0.083 ops/sec
|
||||
ECDHE 256 agree 2 ops took 24.000 sec, avg 12000.000 ms, 0.083 ops/sec
|
||||
ECDSA 256 sign 2 ops took 25.000 sec, avg 12500.000 ms, 0.080 ops/sec
|
||||
ECDSA 256 verify 2 ops took 48.000 sec, avg 24000.000 ms, 0.042 ops/sec
|
||||
RNG 12 MB took 1.000 seconds, 11.666 MB/s
|
||||
AES-128-CBC-enc 50 KB took 1.659 seconds, 30.131 KB/s
|
||||
AES-128-CBC-dec 50 KB took 1.657 seconds, 30.183 KB/s
|
||||
AES-192-CBC-enc 50 KB took 1.839 seconds, 27.189 KB/s
|
||||
AES-192-CBC-dec 50 KB took 1.836 seconds, 27.230 KB/s
|
||||
AES-256-CBC-enc 25 KB took 1.010 seconds, 24.759 KB/s
|
||||
AES-256-CBC-dec 25 KB took 1.008 seconds, 24.791 KB/s
|
||||
AES-128-GCM-enc 25 KB took 1.508 seconds, 16.576 KB/s
|
||||
AES-128-GCM-dec 25 KB took 1.510 seconds, 16.559 KB/s
|
||||
AES-192-GCM-enc 25 KB took 1.605 seconds, 15.573 KB/s
|
||||
AES-192-GCM-dec 25 KB took 1.607 seconds, 15.558 KB/s
|
||||
AES-256-GCM-enc 25 KB took 1.699 seconds, 14.716 KB/s
|
||||
AES-256-GCM-dec 25 KB took 1.700 seconds, 14.702 KB/s
|
||||
SHA 2 MB took 1.014 seconds, 1.589 MB/s
|
||||
SHA-256 425 KB took 1.009 seconds, 421.068 KB/s
|
||||
HMAC-SHA 1 MB took 1.013 seconds, 1.325 MB/s
|
||||
HMAC-SHA256 425 KB took 1.018 seconds, 417.420 KB/s
|
||||
ECC 256 key gen 2 ops took 1.393 sec, avg 696.503 ms, 1.436 ops/sec
|
||||
ECDHE 256 agree 2 ops took 1.386 sec, avg 692.917 ms, 1.443 ops/sec
|
||||
ECDSA 256 sign 2 ops took 1.406 sec, avg 703.064 ms, 1.422 ops/sec
|
||||
ECDSA 256 verify 2 ops took 2.773 sec, avg 1386.597 ms, 0.721 ops/sec
|
||||
Benchmark complete
|
||||
```
|
||||
|
||||
## Tested Configurations
|
||||
- SHA-1
|
||||
- SHA-256
|
||||
- AES CBC
|
||||
- AES CBC/GCM
|
||||
- ECC 256 sign/verify/shared secret with fast math library
|
||||
|
||||
## Known Caveats
|
||||
@ -185,6 +166,7 @@ The `IDE/ECLIPSE/SIFIVE/Makefile` overwrites the value with 0x1000 (4 KBytes)
|
||||
- Enabling RSA will cause the ECC test to fail due to memory shortage
|
||||
|
||||
## References
|
||||
|
||||
The test results were collected from a SiFive reference platform target with the following hardware, software and tool chains:
|
||||
- HiFive1 Rev A/Rev B: HiFive1 Development Board with the Freedom Everywhere SoC, E300
|
||||
- freedom-e-sdk
|
||||
|
@ -28,34 +28,33 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __METAL_MACHINE_HEADER
|
||||
#define __METAL_MACHINE_HEADER "../../../../bsp/sifive-hifive1-revb/metal.h"
|
||||
#endif
|
||||
#include <metal/machine.h>
|
||||
|
||||
#ifndef NO_CRYPT_BENCHMARK
|
||||
|
||||
/*-specs=nano.specs doesn’t include support for floating point in printf()*/
|
||||
asm (".global _printf_float");
|
||||
|
||||
#ifndef RTC_FREQ
|
||||
#define RTC_FREQ 32768
|
||||
#define RTC_FREQ 32768UL
|
||||
#endif
|
||||
|
||||
#define CLINT_MTIME_ADDR 0x200bff8
|
||||
/* CLINT Registers (Core Local Interruptor) for time */
|
||||
#define CLINT_BASE 0x02000000UL
|
||||
#define CLINT_REG_MTIME (*((volatile uint32_t *)(CLINT_BASE + 0xBFF8)))
|
||||
|
||||
#define WOLFSSL_SIFIVE_RISC_V_DEBUG 0
|
||||
|
||||
unsigned long get_cpu_freq(void)
|
||||
{
|
||||
/* If clocking up the CPU, you need to add a logic to measure cpu freq */
|
||||
|
||||
return RTC_FREQ;
|
||||
}
|
||||
|
||||
double current_time(int reset)
|
||||
{
|
||||
volatile uint64_t * mtime = (uint64_t*) (CLINT_MTIME_ADDR);
|
||||
uint64_t now = *mtime;
|
||||
double now = CLINT_REG_MTIME;
|
||||
(void)reset;
|
||||
/**/
|
||||
return now/get_cpu_freq();
|
||||
return now/RTC_FREQ;
|
||||
}
|
||||
#endif
|
||||
#endif /* !NO_CRYPT_BENCHMARK */
|
||||
|
||||
#if WOLFSSL_SIFIVE_RISC_V_DEBUG
|
||||
void check(int depth) {
|
||||
@ -70,9 +69,8 @@ void check(int depth) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void mtime_sleep( uint64_t ticks) {
|
||||
volatile uint64_t * mtime = (uint64_t*) (CLINT_MTIME_ADDR);
|
||||
uint64_t now = *mtime;
|
||||
void mtime_sleep(uint64_t ticks) {
|
||||
uint64_t now = CLINT_REG_MTIME;
|
||||
uint64_t then = now + ticks;
|
||||
|
||||
while((*mtime - now) < ticks) {
|
||||
@ -81,10 +79,10 @@ void mtime_sleep( uint64_t ticks) {
|
||||
}
|
||||
|
||||
void delay(int sec) {
|
||||
uint64_t ticks = sec * get_cpu_freq();
|
||||
uint64_t ticks = sec * RTC_FREQ;
|
||||
mtime_sleep(ticks);
|
||||
}
|
||||
#endif
|
||||
#endif /* WOLFSSL_SIFIVE_RISC_V_DEBUG */
|
||||
|
||||
/* RNG CODE */
|
||||
/* TODO: Implement real RNG */
|
||||
@ -124,9 +122,16 @@ int my_rng_gen_block(unsigned char* output, unsigned int sz)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(NO_CLOCK_SPEEDUP) && !defined(USE_CLOCK_HZ)
|
||||
/* 320MHz */
|
||||
#define USE_CLOCK_HZ 320000000UL
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
long clkHz = 16000000; /* default */
|
||||
|
||||
#if WOLFSSL_SIFIVE_RISC_V_DEBUG
|
||||
printf("check stack and heap addresses\n");
|
||||
@ -136,9 +141,19 @@ int main(void)
|
||||
printf("awake after sleeping for 10 seconds\n");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
#ifdef USE_CLOCK_HZ
|
||||
/* Speed up clock */
|
||||
printf("SiFive HiFive1 Demo\n");
|
||||
printf("Setting clock to %dMHz\n", USE_CLOCK_HZ/1000000);
|
||||
clkHz = metal_clock_set_rate_hz(
|
||||
&__METAL_DT_SIFIVE_FE310_G000_PLL_HANDLE->clock, USE_CLOCK_HZ
|
||||
);
|
||||
#endif
|
||||
printf("Actual Clock %dMHz\n", clkHz/1000000);
|
||||
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
wolfSSL_Debugging_ON();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if ((ret = wolfCrypt_Init()) != 0) {
|
||||
printf("wolfCrypt_Init failed %d\n", ret);
|
||||
@ -156,10 +171,10 @@ int main(void)
|
||||
benchmark_test(NULL);
|
||||
printf("\nBenchmark Test Completed\n");
|
||||
#endif
|
||||
|
||||
if ((ret = wolfCrypt_Cleanup()) != 0) {
|
||||
printf("wolfCrypt_Cleanup failed %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user