Skip to content

Commit 016f810

Browse files
author
Shingo Morimoto
committed
Add benchmarks and memory tracking feature to Signature Examples.
Add becnmark and memory tranking to the following program: signature/rsa_vfy_only/verify signature/rsa_buffer/verify signature/ecc-sign-verify/ecc_sign_verify
1 parent c3666a6 commit 016f810

32 files changed

+1925
-0
lines changed

embedded/signature/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Signature Examples for Embedded Systems
2+
3+
This directory includes the following examples under the sub-directories.Each has a Makefile and source files to build and execute the example and a README to show how to build and Example output.
4+
5+
|Scheme|Directory|Description|
6+
|---|---|---|
7+
|RSA|rsa_vfy_only |verify signature|
8+
||rsa_buffer|sign/verify signature |
9+
|ECDSA|signature/ecc-sign-verify/ecc_sign_verify.c|sign msg and verify signature|
10+
11+
You can specify a target function of Simple example, Benchemark or Memory track program.It also has options for optimized code for MCU architectures such as Intel x86, ARM64 or a generic code by default, as well as Math library of Single Precision or TFM.
12+
13+
```
14+
$ make <Function> math=<Mathlib> arch=<MCU>
15+
```
16+
17+
## Functions
18+
19+
|Function name|Description|
20+
|---|---|
21+
|Default|Simple Execution|
22+
|mem|Memory Track on heap and stack usage|
23+
|bench|Performance benchmark|
24+
25+
26+
## Math library
27+
|math|Description|
28+
|---|---|
29+
|Default|Generic architecture by pure C language source code|
30+
|sp| SP for specified archtecture|
31+
|tfm|TFM for generic architecture|
32+
## MCU Architectures
33+
NOTE: No architecture specification is required when using TFM.
34+
|arch|Description|
35+
|---|---|
36+
|Default|Generic architecture by pure C language source code|
37+
|arm64|SP for ARM64 |
38+
|x64|SP for x86 64bit|
39+
40+
41+
The Makefile is self-contained without libwolfssl. Put your wolfSSL source filesin parallel with wolfssl-examples directory. It is defined by WOLFROOT in Makefile.It compiles only needed files for the target. OBJ and OBJ_xxx macro in Makefiledefine object files for the common and specific target.
42+
43+
Example programs are hard coded for a hash algorithm or signature scheme.Sha256 is for the hash by default. PKCS #1 v1.5 or ECDSA for the signature scheme.You can refer to the following API tables for modifying the examples for other algorithms or schemes.
44+
45+
## Table 1: Hash algorithms for PKCS#1 Signature
46+
|Algorithm|Src File|Macro SW<br>Enable|<br>Disable|Note|
47+
|---|---|---|---|---|
48+
|MD2|md2.c|WOLFSSL_MD2||Only for v1.5 Backward compatibility|
49+
|MD5|md5.c||NO_MD5|Only for v1.5 Backward compatibility|
50+
|SHA1|sha.c||NO_SHA|||SHA256|sha256.c||NO_SHA256|
51+
||SHA384|sha512.c|WOLFSSL_SHA384||Disabled by default|
52+
|SHA512|sha512.c|WOLFSSL_SHA512||Disabled by default|
53+
54+
55+
## Table 2: Hash Algorithm APIs
56+
|Algorithm|<br>Init|API<br>Update|<br>Final|
57+
|---|---|---|---|
58+
|MD2|wc_InitMd2|wc_Md2Update|wc_Md2Final|
59+
|MD5|wc_InitMd5|wc_Md5Update|wc_Md5Final|
60+
|SHA1|wc_InitSha|wc_ShaUpdate|wc_ShaFinal|
61+
|SHA256|wc_InitSha256|wc_Sha256Update|wc_Sha256Final|
62+
|SHA384|wc_initSha384|wc_Sha384Update|wc_Sha384Final|
63+
|SHA512|wc_InitSha512|wc_Sha512Update|wc_Sha512Final|
64+
65+
66+
## Table 3: RSA Signature APIs
67+
68+
|Padding|API|Description|
69+
|---|---|---|
70+
|PKCS #1 v1.5|wc_RsaSSL_Verify|Decrypt input signature to verify|
71+
||wc_RsaSSL_VerifyInline|The output uses the same byte array as the input|
72+
|PSS|wc_RsaPSS_Verify|Decrypt input signature to verify with PSS|
73+
| |wc_RsaPSS_VerifyCheck|Verify the message signed|
74+
| |wc_RsaPSS_VerifyCheck_ex|with Salt length argument|
75+
| |wc_RsaPSS_VerifyInline|The output uses the same byte array as the input|
76+
| |wc_RsaPSS_VerifyCheckInline|Verify the message signed|
77+
| |wc_RsaPSS_VerifyCheckPadding|Checks the PSS data to ensure that the signature matches|
78+
| |wc_RsaPSS_VerifyCheckPadding_ex|with Salt length argument|
79+
80+
81+
## Table 4: ECC Signature APIs
82+
83+
|Algorithm|API|Hash|
84+
|---|---|---|
85+
|ECDSA|wc_ecc_sign_hash|SHA512|
86+
|Ed25519|wc_ed25519_sign_hash|SHA512|
87+
|Ed488|wc_ed488_sign_hash|SHAKE256|
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
WOLFROOT = ../../../../wolfssl
2+
3+
CFLAGS = -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFROOT) -Os
4+
ASFLAGS = -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFROOT)
5+
6+
OBJ=\
7+
$(WOLFROOT)/wolfcrypt/src/ecc.o\
8+
$(WOLFROOT)/wolfcrypt/src/sha256.o\
9+
$(WOLFROOT)/wolfcrypt/src/hash.o\
10+
$(WOLFROOT)/wolfcrypt/src/random.o\
11+
$(WOLFROOT)/wolfcrypt/src/asn.o\
12+
$(WOLFROOT)/wolfcrypt/src/wc_port.o\
13+
$(WOLFROOT)/wolfcrypt/src/coding.o\
14+
$(WOLFROOT)/wolfcrypt/src/memory.o\
15+
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\
16+
17+
18+
OBJ_SP_C32 := \
19+
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
20+
$(WOLFROOT)/wolfcrypt/src/sp_c32.o\
21+
22+
OBJ_SP_ARM64 := \
23+
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
24+
$(WOLFROOT)/wolfcrypt/src/sp_arm64.o\
25+
26+
27+
OBJ_SP_X86_64 := \
28+
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
29+
$(WOLFROOT)/wolfcrypt/src/cpuid.o\
30+
$(WOLFROOT)/wolfcrypt/src/sp_x86_64.o\
31+
$(WOLFROOT)/wolfcrypt/src/sp_x86_64_asm.o\
32+
33+
OBJ_TFM := \
34+
$(WOLFROOT)/wolfcrypt/src/tfm.o\
35+
36+
.PHONY: all clean mem size
37+
38+
ifeq ($(math) $(arch),sp x64)
39+
ASFLAGS+= -DSP_X86_64_FLAG
40+
OBJ += $(OBJ_SP_X86_64)
41+
else ifeq ($(math) $(arch),sp arm64)
42+
CFLAGS += -DSP_ARM64_FLAG
43+
OBJ += $(OBJ_SP_ARM64)
44+
else ifeq ($(math), tfm)
45+
CFLAGS += -DTFM_FLAG
46+
OBJ += $(OBJ_TFM)
47+
else
48+
CFLAGS += -DSP_FLAG
49+
OBJ += $(OBJ_SP_C32)
50+
endif
51+
52+
all : ecc_sign_verify bench
53+
mem:CFLAGS+= -DDEBUG_MEMORY
54+
mem: ecc_sign_verify
55+
56+
ecc_sign_verify: $(OBJ)
57+
$(CC) $(CFLAGS) -o ecc_sign_verify ecc_sign_verify.c $(OBJ)
58+
59+
bench: $(OBJ)
60+
$(CC) $(CFLAGS) -DBENCHMARK -o bench ecc_sign_verify.c $(OBJ)
61+
62+
clean:
63+
rm -f ecc_sign_verify bench $(WOLFROOT)/wolfcrypt/src/*.o
64+
65+
size :
66+
size $(OBJ)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Signature Test Example
2+
3+
Demonstrates using a hash digest to sign and verify a signature using ECC
4+
5+
First, set the path to wolfssl directory to variable WOLFROOT in the Makefile.
6+
## Building
7+
8+
### Build example
9+
10+
```
11+
make
12+
```
13+
14+
## Usage
15+
16+
```
17+
./ecc_sign_verify
18+
Key size is 112, byteField = 14, maxSigSz = 44
19+
Successfully verified signature w/ ecc key size 112!
20+
Key size is 128, byteField = 16, maxSigSz = 48
21+
Successfully verified signature w/ ecc key size 128!
22+
Key size is 160, byteField = 20, maxSigSz = 56
23+
Successfully verified signature w/ ecc key size 160!
24+
Key size is 192, byteField = 24, maxSigSz = 64
25+
Successfully verified signature w/ ecc key size 192!
26+
Key size is 224, byteField = 28, maxSigSz = 72
27+
Successfully verified signature w/ ecc key size 224!
28+
Key size is 239, byteField = 36, maxSigSz = 88
29+
Successfully verified signature w/ ecc key size 239!
30+
Key size is 256, byteField = 32, maxSigSz = 80
31+
Successfully verified signature w/ ecc key size 256!
32+
Key size is 320, byteField = 40, maxSigSz = 96
33+
Successfully verified signature w/ ecc key size 320!
34+
Key size is 384, byteField = 48, maxSigSz = 112
35+
Successfully verified signature w/ ecc key size 384!
36+
Key size is 512, byteField = 64, maxSigSz = 144
37+
Successfully verified signature w/ ecc key size 512!
38+
Key size is 521, byteField = 66, maxSigSz = 148
39+
Successfully verified signature w/ ecc key size 521!
40+
```
41+
42+
NOTE: Also an option to dump out the signatures. For more verbose output
43+
uncomment define in example "SHOW_SIGS_IN_EXAMPLE"
44+
45+
46+
47+
# Signature verification Benchmark
48+
49+
You can generate benchmark program to compare the speed of signature verification between TFM and SP
50+
### SP
51+
Faster math library
52+
53+
If you build for x86_64 system:
54+
```
55+
make bench math=sp arch=x64
56+
```
57+
else if Aarch64 system:
58+
```
59+
make bench math=sp arch=arm64
60+
```
61+
then a benchmark program is generated.
62+
### TFM
63+
64+
```
65+
make bench math=tfm
66+
```
67+
NOTE: When using TFM, No Architecture specification is required.
68+
69+
## Example Output
70+
built with the option `math=sp arch=arm64`
71+
```
72+
./bench
73+
---------------------------------------------------------------
74+
Enabled WOLFSSL_SP_ARM64
75+
---------------------------------------------------------------
76+
Running ECC Sign Verify Benchmarks...
77+
ECC Key Size 112 1275.78 Cycles/sec
78+
ECC Key Size 128 1351.68 Cycles/sec
79+
ECC Key Size 160 1368.65 Cycles/sec
80+
ECC Key Size 192 1382.20 Cycles/sec
81+
ECC Key Size 224 1385.06 Cycles/sec
82+
ECC Key Size 239 1401.38 Cycles/sec
83+
ECC Key Size 256 12830.67 Cycles/sec
84+
ECC Key Size 320 626.52 Cycles/sec
85+
ECC Key Size 384 634.85 Cycles/sec
86+
ECC Key Size 512 279.71 Cycles/sec
87+
ECC Key Size 521 279.15 Cycles/sec
88+
```
89+
90+
# Tracking memory
91+
To see a stack and heap memory usage.
92+
93+
```
94+
make mem
95+
```
96+
## Example Output
97+
```
98+
./ecc_sign_verify
99+
Key size is 112, byteField = 14
100+
Successfully verified signature w/ ecc key size 112!
101+
Key size is 128, byteField = 16
102+
Successfully verified signature w/ ecc key size 128!
103+
Key size is 160, byteField = 20
104+
Successfully verified signature w/ ecc key size 160!
105+
Key size is 192, byteField = 24
106+
Successfully verified signature w/ ecc key size 192!
107+
Key size is 224, byteField = 28
108+
Successfully verified signature w/ ecc key size 224!
109+
Key size is 239, byteField = 30
110+
Successfully verified signature w/ ecc key size 239!
111+
Key size is 256, byteField = 32
112+
Successfully verified signature w/ ecc key size 256!
113+
Key size is 320, byteField = 40
114+
Successfully verified signature w/ ecc key size 320!
115+
Key size is 384, byteField = 48
116+
Successfully verified signature w/ ecc key size 384!
117+
Key size is 512, byteField = 64
118+
Successfully verified signature w/ ecc key size 512!
119+
Key size is 521, byteField = 66
120+
Successfully verified signature w/ ecc key size 521!
121+
122+
total Allocs = 522
123+
total Deallocs = 522
124+
total Bytes = 225047
125+
peak Bytes = 5161
126+
current Bytes = 0
127+
stack used = 16752
128+
```
129+
130+
131+
Best wishes in all your testing!
132+
133+
- The wolfSSL Team

0 commit comments

Comments
 (0)