Skip to content

Commit 7213cb3

Browse files
Merge pull request #6463 from dgarske/silabs_erf32
Updated support for Silicon Labs Simplicity Studio and the ERF32 Gecko SDK
2 parents 91fb241 + abe1bce commit 7213cb3

15 files changed

Lines changed: 1241 additions & 329 deletions

File tree

IDE/SimplicityStudio/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Silicon Labs Simplicity Studio
2+
3+
Tested with ERF32xG21 Starter Kit and Gecko SDK v3.2.2 and v4.2.3.
4+
5+
## Simplicity Studio Example
6+
7+
Based on `cli_kernel_freertos`.
8+
* Create a new example project for your board based on the CLI FreeRTOS example.
9+
* Create a new `wolfssl` and put wolfSSL into it. Tip: Use `./scripts/makedistsmall.sh` to produce a reduced bundle.
10+
* Exclude (or delete) all .S and asm.c files.
11+
* Exclude (or delete) directory not used (only the `src`, `wolfcrypt` and `wolfssl` directory are used).
12+
* Add the `IDE/SimplicityStudio/user_settings.h` into `wolfssl/user_settings.h`.
13+
* Add the `IDE/SimplicityStudio/test_wolf.c` to the project root.
14+
* Add C preprocessor `WOLFSSL_USER_SETTINGS`.
15+
* Add C include path `wolfssl`.
16+
* Disable UART flow control: `config/sl_iostream_usart_vcom_config.h` -> `#define SL_IOSTREAM_USART_VCOM_FLOW_CONTROL_TYPE usartHwFlowControlNone`
17+
* Adjust stack and heap to larger size 12KB:
18+
- Adjust the CLI stack. Edit `config/sl_cli_config_inst.h` to `#define SL_CLI_INST_TASK_STACK_SIZE (12*1024)`
19+
- Adjust the FreeRTOS heap. Edit `config/FreeRTOSConfig.h` to `#define configTOTAL_HEAP_SIZE (12*1024)`
20+
* Add the following code to `cli.c`:
21+
22+
```c
23+
extern void wolf_test(sl_cli_command_arg_t *arguments);
24+
extern void wolf_bench(sl_cli_command_arg_t *arguments);
25+
26+
static const sl_cli_command_info_t cmd_wolf_test =
27+
SL_CLI_COMMAND(wolf_test, "Run wolfCrypt tests", "",
28+
{ SL_CLI_ARG_WILDCARD, SL_CLI_ARG_END, });
29+
30+
static const sl_cli_command_info_t cmd_wolf_bench =
31+
SL_CLI_COMMAND(wolf_bench, "Run wolfCrypt benchmarks", "",
32+
{ SL_CLI_ARG_WILDCARD, SL_CLI_ARG_END, });
33+
34+
static sl_cli_command_entry_t a_table[] = {
35+
{ "wolf_test", &cmd_wolf_test, false },
36+
{ "wolf_bench", &cmd_wolf_bench, false },
37+
{ NULL, NULL, false },
38+
};
39+
```
40+
41+
* If running wolfCrypt benchmark enable printf float
42+
- `C/C++ Build Settings` -> `Settings` -> `Tool Settings` -> `GNU ARM C Linker` -> `General` -> `C Library "Printf float"`.
43+
44+
## SE Manager
45+
46+
For SE Manager cryptography hardware acceleration see [/wolfcrypt/src/port/silabs/README.md](/wolfcrypt/src/port/silabs/README.md).
47+
48+
Enabled with `WOLFSSL_SILABS_SE_ACCEL`. Requires the "SE Manager" component to be installed.
49+
50+
## Benchmarks with SE Accel
51+
52+
Tested on ERF32xG21 Starter Kit (Cortex M33 at 80 MHz) and Gecko SDK v3.2.2 (-Os).
53+
54+
```
55+
Benchmark Test
56+
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
57+
RNG 200 KiB took 1.057 seconds, 189.215 KiB/s
58+
AES-128-CBC-enc 6 MiB took 1.000 seconds, 5.542 MiB/s
59+
AES-128-CBC-dec 6 MiB took 1.000 seconds, 5.518 MiB/s
60+
AES-192-CBC-enc 5 MiB took 1.001 seconds, 5.415 MiB/s
61+
AES-192-CBC-dec 5 MiB took 1.001 seconds, 5.390 MiB/s
62+
AES-256-CBC-enc 5 MiB took 1.004 seconds, 5.301 MiB/s
63+
AES-256-CBC-dec 5 MiB took 1.001 seconds, 5.268 MiB/s
64+
AES-128-GCM-enc 5 MiB took 1.003 seconds, 4.844 MiB/s
65+
AES-128-GCM-dec 5 MiB took 1.003 seconds, 4.625 MiB/s
66+
AES-192-GCM-enc 5 MiB took 1.002 seconds, 4.751 MiB/s
67+
AES-192-GCM-dec 5 MiB took 1.002 seconds, 4.532 MiB/s
68+
AES-256-GCM-enc 5 MiB took 1.002 seconds, 4.654 MiB/s
69+
AES-256-GCM-dec 4 MiB took 1.000 seconds, 4.443 MiB/s
70+
AES-128-GCM-enc-no_AAD 5 MiB took 1.004 seconds, 4.888 MiB/s
71+
AES-128-GCM-dec-no_AAD 5 MiB took 1.001 seconds, 4.658 MiB/s
72+
AES-192-GCM-enc-no_AAD 5 MiB took 1.000 seconds, 4.785 MiB/s
73+
AES-192-GCM-dec-no_AAD 5 MiB took 1.000 seconds, 4.565 MiB/s
74+
AES-256-GCM-enc-no_AAD 5 MiB took 1.004 seconds, 4.693 MiB/s
75+
AES-256-GCM-dec-no_AAD 4 MiB took 1.003 seconds, 4.479 MiB/s
76+
GMAC Small 5 MiB took 1.000 seconds, 4.653 MiB/s
77+
CHACHA 2 MiB took 1.012 seconds, 1.809 MiB/s
78+
CHA-POLY 1 MiB took 1.006 seconds, 1.189 MiB/s
79+
POLY1305 5 MiB took 1.004 seconds, 5.082 MiB/s
80+
SHA 8 MiB took 1.000 seconds, 7.812 MiB/s
81+
SHA-256 8 MiB took 1.000 seconds, 8.032 MiB/s
82+
HMAC-SHA 7 MiB took 1.000 seconds, 7.056 MiB/s
83+
HMAC-SHA256 7 MiB took 1.002 seconds, 7.237 MiB/s
84+
RSA 2048 public 30 ops took 1.022 sec, avg 34.067 ms, 29.354 ops/sec
85+
RSA 2048 private 2 ops took 2.398 sec, avg 1199.000 ms, 0.834 ops/sec
86+
ECC [ SECP256R1] 256 key gen 172 ops took 1.004 sec, avg 5.837 ms, 171.315 ops/sec
87+
ECDHE [ SECP256R1] 256 agree 186 ops took 1.005 sec, avg 5.403 ms, 185.075 ops/sec
88+
ECDSA [ SECP256R1] 256 sign 174 ops took 1.007 sec, avg 5.787 ms, 172.790 ops/sec
89+
ECDSA [ SECP256R1] 256 verify 160 ops took 1.003 sec, avg 6.269 ms, 159.521 ops/sec
90+
Benchmark complete
91+
Benchmark Test: Return code 0
92+
```

IDE/SimplicityStudio/include.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# vim:ft=automake
2+
# included from Top Level Makefile.am
3+
# All paths should be given relative to the root
4+
5+
EXTRA_DIST+= IDE/SimplicityStudio/README.md
6+
EXTRA_DIST+= IDE/SimplicityStudio/test_wolf.c
7+
EXTRA_DIST+= IDE/SimplicityStudio/user_settings.h

IDE/SimplicityStudio/test_wolf.c

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/* test_wolf.c
2+
*
3+
* Copyright (C) 2006-2023 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
/* Example for running wolfCrypt test and benchmark from
23+
* SiLabs Simplicity Studio's CLI example */
24+
25+
#include <wolfssl/wolfcrypt/settings.h>
26+
#include <wolfssl/wolfcrypt/signature.h>
27+
#include <wolfssl/wolfcrypt/ecc.h>
28+
#include <wolfssl/wolfcrypt/asn_public.h>
29+
#include <wolfssl/wolfcrypt/logging.h>
30+
#include <wolfssl/wolfcrypt/wc_port.h>
31+
#include <wolfssl/wolfcrypt/error-crypt.h>
32+
#include <wolfcrypt/test/test.h>
33+
#include <wolfcrypt/benchmark/benchmark.h>
34+
#include <stdio.h>
35+
36+
#include "sl_cli.h"
37+
#include "sl_cli_instances.h"
38+
#include "sl_cli_arguments.h"
39+
#include "sl_cli_handles.h"
40+
41+
#ifndef NO_CRYPT_TEST
42+
typedef struct func_args {
43+
int argc;
44+
char** argv;
45+
int return_code;
46+
} func_args;
47+
48+
static func_args args = { 0 };
49+
#endif
50+
51+
void wolf_test(sl_cli_command_arg_t *arguments)
52+
{
53+
int ret;
54+
#ifndef NO_CRYPT_TEST
55+
wolfCrypt_Init();
56+
57+
printf("\nCrypt Test\n");
58+
wolfcrypt_test(&args);
59+
ret = args.return_code;
60+
printf("Crypt Test: Return code %d\n", ret);
61+
62+
wolfCrypt_Cleanup();
63+
#else
64+
ret = NOT_COMPILED_IN;
65+
#endif
66+
(void)arguments;
67+
(void)ret;
68+
}
69+
70+
void wolf_bench(sl_cli_command_arg_t *arguments)
71+
{
72+
int ret;
73+
#ifndef NO_CRYPT_BENCHMARK
74+
wolfCrypt_Init();
75+
76+
printf("\nBenchmark Test\n");
77+
benchmark_test(&args);
78+
ret = args.return_code;
79+
printf("Benchmark Test: Return code %d\n", ret);
80+
81+
wolfCrypt_Cleanup();
82+
#else
83+
ret = NOT_COMPILED_IN;
84+
#endif
85+
(void)arguments;
86+
(void)ret;
87+
}
88+
89+
/* ecc key gen, sign and verify examples */
90+
#define TEST_ECC_KEYSZ 32
91+
#define TEST_DATA_SIZE 128
92+
#define TEST_KEYGEN_TRIES 100
93+
#define TEST_ECDSA_TRIES 100
94+
/* #define TEST_VERIFY_ONLY */
95+
/* #define TEST_PRIVATE_IMPORT */
96+
97+
void wolf_ecc_test(sl_cli_command_arg_t *arguments)
98+
{
99+
int ret = 0, i, j;
100+
byte data[TEST_DATA_SIZE];
101+
word32 dataLen = (word32)sizeof(data);
102+
WC_RNG rng;
103+
ecc_key eccKey;
104+
word32 inOutIdx;
105+
#ifdef TEST_PRIVATE_IMPORT
106+
/* ./certs/ecc-client-key.der, ECC */
107+
const unsigned char ecc_clikey_der_256[] = {
108+
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xF8, 0xCF, 0x92,
109+
0x6B, 0xBD, 0x1E, 0x28, 0xF1, 0xA8, 0xAB, 0xA1, 0x23, 0x4F,
110+
0x32, 0x74, 0x18, 0x88, 0x50, 0xAD, 0x7E, 0xC7, 0xEC, 0x92,
111+
0xF8, 0x8F, 0x97, 0x4D, 0xAF, 0x56, 0x89, 0x65, 0xC7, 0xA0,
112+
0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01,
113+
0x07, 0xA1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
114+
0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
115+
0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
116+
0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
117+
0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
118+
0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
119+
0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
120+
0xB4
121+
};
122+
const int sizeof_ecc_clikey_der_256 = sizeof(ecc_clikey_der_256);
123+
#endif
124+
#ifdef TEST_VERIFY_ONLY
125+
/* ./certs/ecc-client-keyPub.der, ECC */
126+
const unsigned char ecc_clikeypub_der_256[] = {
127+
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
128+
0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
129+
0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
130+
0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
131+
0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
132+
0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
133+
0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
134+
0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
135+
0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
136+
0xB4
137+
};
138+
const int sizeof_ecc_clikeypub_der_256 = sizeof(ecc_clikeypub_der_256);
139+
140+
/* Signature for hash of 128-bytes data 0,1,2.... */
141+
const byte sig[] = {
142+
0x30, 0x45,
143+
0x02, 0x20,
144+
0x5e, 0x01, 0x3d, 0xfb, 0x18, 0x61, 0xe3, 0xe3,
145+
0xa0, 0xff, 0x9b, 0x99, 0xb5, 0x2f, 0x89, 0xba,
146+
0xb3, 0xbb, 0x62, 0x08, 0x9b, 0x94, 0x0e, 0x61,
147+
0x9c, 0x00, 0x7b, 0x43, 0x9c, 0x28, 0xcb, 0xf6,
148+
0x02, 0x21,
149+
0x00,
150+
0xb4, 0x72, 0x2f, 0x22, 0x92, 0xa2, 0x8d, 0x01,
151+
0x6b, 0x01, 0x35, 0x5c, 0xcb, 0x34, 0xa2, 0x21,
152+
0x32, 0xe2, 0xe6, 0x66, 0xd0, 0x9e, 0x3e, 0x8e,
153+
0x84, 0x5d, 0xa4, 0x69, 0x54, 0x52, 0xfc, 0xef
154+
};
155+
word32 sigLen = (word32)sizeof(sig);
156+
#else
157+
byte sig[ECC_MAX_SIG_SIZE];
158+
word32 sigLen;
159+
#endif
160+
161+
memset(&rng, 0, sizeof(rng));
162+
memset(&eccKey, 0, sizeof(eccKey));
163+
164+
wolfSSL_Debugging_ON();
165+
166+
wolfCrypt_Init();
167+
168+
/* test data */
169+
for (i=0; i<(int)dataLen; i++) {
170+
data[i] = (byte)i;
171+
}
172+
173+
ret = wc_InitRng(&rng);
174+
if (ret != 0) {
175+
goto exit;
176+
}
177+
178+
for (i=0; i<TEST_KEYGEN_TRIES; i++) {
179+
ret = wc_ecc_init_ex(&eccKey, NULL, 0);
180+
if (ret == 0) {
181+
inOutIdx = 0;
182+
#ifdef TEST_VERIFY_ONLY
183+
ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &inOutIdx,
184+
&eccKey, sizeof_ecc_clikeypub_der_256);
185+
#else
186+
#if (defined(_SILICON_LABS_SECURITY_FEATURE) && \
187+
_SILICON_LABS_SECURITY_FEATURE == _SILICON_LABS_SECURITY_FEATURE_VAULT)
188+
/* Load ecc_key with vault's public key.
189+
* When only the public area of a key is loaded silabs_ecc.c
190+
* (silabs_ecc_sign_hash) will use the vault key to sign */
191+
ret = silabs_ecc_load_vault(&eccKey);
192+
#elif defined(TEST_PRIVATE_IMPORT)
193+
ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &inOutIdx,
194+
&eccKey, sizeof_ecc_clikey_der_256);
195+
#else
196+
ret = wc_ecc_make_key(&rng, TEST_ECC_KEYSZ, &eccKey);
197+
#endif
198+
#endif
199+
}
200+
201+
for (j=0; j<TEST_ECDSA_TRIES; j++) {
202+
#ifndef TEST_VERIFY_ONLY
203+
if (ret == 0) {
204+
/* generate signature using ecc key */
205+
sigLen = (word32)sizeof(sig);
206+
207+
ret = wc_SignatureGenerate(
208+
WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
209+
data, dataLen,
210+
sig, &sigLen,
211+
&eccKey, (word32)sizeof(eccKey),
212+
&rng);
213+
}
214+
#endif
215+
if (ret == 0) {
216+
ret = wc_SignatureVerify(
217+
WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
218+
data, dataLen,
219+
sig, sigLen,
220+
&eccKey, (word32)sizeof(eccKey));
221+
}
222+
223+
if (ret == 0) {
224+
fprintf(stderr, "Verification Passed %d %d\n", i, j);
225+
}
226+
else {
227+
fprintf(stderr, "Verification failed!! (ret %d) %d %d\n",
228+
ret, i, j);
229+
break;
230+
}
231+
} /* sign/verify tries */
232+
233+
wc_ecc_free(&eccKey);
234+
if (ret != 0)
235+
break;
236+
} /* key gen tries */
237+
238+
exit:
239+
wc_FreeRng(&rng);
240+
241+
wolfCrypt_Cleanup();
242+
243+
(void)arguments;
244+
}

0 commit comments

Comments
 (0)