Skip to content

Commit 51b3eff

Browse files
committed
addressed review comments
add file header fix wc_RsaSSL_Verify
1 parent f6a2790 commit 51b3eff

File tree

18 files changed

+136
-196
lines changed

18 files changed

+136
-196
lines changed

embedded/signature/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Signature Examples for Embedded Systems
22
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.
3+
This directory includes the following examples. Each subdirectory has a Makefile, source files, and a README to show how to build the example, along with expected example output.
44
55
|Scheme|Directory|Description|
66
|---|---|---|
@@ -12,7 +12,8 @@ This directory includes the following examples under the sub-directories.Each ha
1212
||ecc_vfy_only_nonblock|verify signature with non-blocking|
1313

1414

15-
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.
15+
When building each example, you can specify arguments to control the build. Specify a target function to run either a simple example, benchmark, or memory tracking example. Specify an "arch" option to build optimized code for MCU architectures such as Intel x86, ARM64 or a generic code by default. And specify a "math" option to choose an underlying wolfCrypt math library to use, between Single Precision or TFM.
16+
1617

1718
```
1819
$ make <Function> math=<Mathlib> arch=<MCU>
@@ -30,7 +31,7 @@ $ make <Function> math=<Mathlib> arch=<MCU>
3031
|math|Description|
3132
|---|---|
3233
|Default|Generic architecture by pure C language source code|
33-
|sp| SP for generic or specified archtecture|
34+
|sp| SP for generic or specified architecture|
3435
|tfm|TFM for generic architecture|
3536
## MCU Architectures
3637
NOTE: No architecture specification is required when using TFM.
@@ -43,10 +44,10 @@ NOTE: No architecture specification is required when using TFM.
4344
|x64|SP for x86 64bit|
4445

4546

46-
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.
47-
48-
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.
47+
Each Makefile is self-contained to statically link wolfCrypt source files (without using a shared libwolfssl.so). Put your wolfSSL source files in parallel with the wolfssl-examples directory. The location of the primary wolfSSL source directory is defined by WOLFROOT in each Makefile. Each build compiles only the needed files for the target. OBJ and OBJ_xxx macros in each Makefile define object files for the common and specific target.
4948
49+
Example programs are hard coded to use a specific hash algorithm or signature scheme. Sha256 is used for the hash by default. PKCS#1 v1.5 or ECDSA is used for the signature scheme. You can refer to the following API tables for modifying the examples for other algorithms or schemes.
50+
5051
## Table 1: Hash algorithms for PKCS#1 Signature
5152
|Algorithm|Src File|Macro SW<br>Enable|<br>Disable|Note|
5253
|---|---|---|---|---|

embedded/signature/ecc_sign_verify/ecc_sign_verify.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ecc_sign_verify.c
22
*
3-
* Copyright (C) 2006-2024 wolfSSL Inc.
3+
* Copyright (C) 2006-2025 wolfSSL Inc.
44
*
55
* This file is part of wolfSSL. (formerly known as CyaSSL)
66
*
@@ -27,9 +27,7 @@
2727
#include <wolfssl/wolfcrypt/hash.h>
2828
#include <wolfssl/wolfcrypt/logging.h>
2929
#include <wolfssl/wolfcrypt/error-crypt.h>
30-
#include<wolfssl/test.h>
31-
32-
30+
#include <wolfssl/test.h>
3331

3432
/* uncomment to show signatures */
3533
/* #define SHOW_SIGS_IN_EXAMPLE */
@@ -91,7 +89,6 @@ int ecc_sign_verify(void)
9189
ret = do_sig_ver_test(ECC_KEY_SIZE_521);
9290
CHECK_RET(ret, 0, finished, "521 test");
9391

94-
9592
finished:
9693
#ifdef DEBUG_MEMORY
9794
printf("\n");
@@ -117,15 +114,12 @@ int do_sig_ver_test(int eccKeySz)
117114
WC_RNG rng;
118115
int verified = 0;
119116

120-
121117
/* Variables for Benchmark */
122118
double start_time, total_time;
123119
#ifndef BENCH_TIME_SEC
124120
#define BENCH_TIME_SEC 1
125121
#endif
126122
int count;
127-
128-
129123
/*
130124
* for odd curve sizes account for mod EG:
131125
* Case 1) curve field of 256:
@@ -152,10 +146,6 @@ double start_time, total_time;
152146
printf("Failed to allocate sig buff\n");
153147
return -1001;
154148
}
155-
156-
157-
158-
159149
ret = wc_InitRng(&rng);
160150
CHECK_RET(ret, 0, key_done, "wc_InitRng()");
161151

@@ -179,22 +169,16 @@ double start_time, total_time;
179169

180170
ret = wc_ecc_verify_hash(sig, maxSigSz, hash, sizeof(hash),
181171
&verified, &key);
182-
183-
184172
CHECK_RET(ret, 0, rng_done, "wc_ecc_verify_hash()");
185173
CHECK_RET(verified, 1, rng_done, "verification check");
186174
verified = 0;
187175
maxSigSz = ECC_MAX_SIG_SIZE;
188176
#ifdef BENCHMARK
189177
count++;
190178
}
191-
192179
printf("ECC Key Size %d %9.2f Cycles/sec\n", eccKeySz, count/total_time);
193-
194180
#else
195-
196-
printf("Successfully verified signature w/ ecc key size %d!\n", eccKeySz);
197-
181+
printf("Successfully verified signature w/ ecc key size %d!\n", eccKeySz);
198182
#endif
199183

200184
rng_done:
@@ -222,8 +206,8 @@ static void hexdump(const void *buffer, word32 len, byte cols)
222206
}
223207
#endif
224208

225-
226-
int main(){
209+
int main()
210+
{
227211
#ifdef BENCHMARK
228212
printf("---------------------------------------------------------------\n");
229213
#if defined(SP_C64_FLAG)

embedded/signature/ecc_sign_verify/user_settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define NO_SHA
88

99
/* rsa */
10-
#define WOLFSSL_RSA_VERIFY_INLINE
1110
#define WC_NO_RSA_OAEP
1211
#define WC_NO_HARDEN
1312
#define NO_RSA

embedded/signature/ecc_vfy_only/ecc_verify.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ecc_verify.c
22
*
3-
* Copyright (C) 2006-2024 wolfSSL Inc.
3+
* Copyright (C) 2006-2025 wolfSSL Inc.
44
*
55
* This file is part of wolfSSL. (formerly known as CyaSSL)
66
*
@@ -27,10 +27,9 @@
2727
#include <wolfssl/wolfcrypt/hash.h>
2828
#include <wolfssl/wolfcrypt/logging.h>
2929
#include <wolfssl/wolfcrypt/error-crypt.h>
30-
#include<wolfssl/test.h>
30+
#include <wolfssl/test.h>
3131
#include "signature.h"
3232

33-
3433
#define HEAP_HINT NULL
3534
#define ECC_KEY_SIZE_112 112
3635
#define ECC_KEY_SIZE_128 128
@@ -45,10 +44,8 @@
4544
#define ECC_KEY_SIZE_521 521
4645
#define BYTE_SZ 8
4746

48-
4947
int idx_key(int keysize);
5048

51-
5249
#define CHECK_RET(a, b, eLabel, msg) { \
5350
if (a != b) { \
5451
printf("failed %s\n", msg); \
@@ -59,7 +56,6 @@ int idx_key(int keysize);
5956

6057
int do_sig_ver_test(int eccKeySz);
6158

62-
6359
int ecc_verify(void)
6460
{
6561
int ret = 0;
@@ -90,7 +86,6 @@ int ecc_verify(void)
9086
ret = do_sig_ver_test(ECC_KEY_SIZE_521);
9187
CHECK_RET(ret, 0, finished, "521 test");
9288

93-
9489
finished:
9590
#ifdef DEBUG_MEMORY
9691
printf("\n");
@@ -119,15 +114,12 @@ int do_sig_ver_test(int eccKeySz)
119114
int key_size;
120115
unsigned char *pKeybuff;
121116

122-
123117
/* Variables for Benchmark */
124-
double start_time, total_time;
118+
double start_time, total_time;
119+
int count;
125120
#ifndef BENCH_TIME_SEC
126121
#define BENCH_TIME_SEC 1
127122
#endif
128-
int count;
129-
130-
131123
/*
132124
* for odd curve sizes account for mod EG:
133125
* Case 1) curve field of 256:
@@ -148,22 +140,19 @@ double start_time, total_time;
148140
printf("Key size is %d, byteField = %d\n", eccKeySz, byteField);
149141
#endif
150142

151-
152143
ret = wc_InitRng(&rng);
153144
CHECK_RET(ret, 0, key_done, "wc_InitRng()");
154145

155146
#ifdef BENCHMARK
156147
count = 0;
157148
start_time = current_time(1);
158149

159-
while( (double)BENCH_TIME_SEC > (total_time = current_time(0) - start_time ) ){
150+
while((double)BENCH_TIME_SEC > (total_time = current_time(0) - start_time)){
160151
#endif
161152
ret = wc_ecc_init(&key);
162153
CHECK_RET(ret, 0, sig_done, "wc_ecc_init()");
163154

164-
165-
/* Import signature and ecc_key */
166-
155+
/* Import signature and ecc_key */
167156
sig = sig_keys[idx_key(eccKeySz)].sig;
168157
sig_size = sig_keys[idx_key(eccKeySz)].sig_size;
169158
pKeybuff = sig_keys[idx_key(eccKeySz)].pubkey;
@@ -172,24 +161,18 @@ double start_time, total_time;
172161
ret = wc_ecc_import_x963(pKeybuff, key_size, &key);
173162
CHECK_RET(ret, 0, rng_done, "wc_ecc_import_x963()");
174163

175-
176164
ret = wc_ecc_verify_hash(sig, sig_size, hash, sizeof(hash),
177-
&verified, &key);
178-
165+
&verified, &key);
179166
CHECK_RET(ret, 0, rng_done, "wc_ecc_verify_hash()");
180167
CHECK_RET(verified, 1, rng_done, "verification check");
181168
verified = 0;
182169
maxSigSz = ECC_MAX_SIG_SIZE;
183170
#ifdef BENCHMARK
184171
count++;
185172
}
186-
187173
printf("ECC Key Size %d %9.2f Cycles/sec\n", eccKeySz, count/total_time);
188-
189174
#else
190-
191-
printf("Successfully verified signature w/ ecc key size %d!\n", eccKeySz);
192-
175+
printf("Successfully verified signature w/ ecc key size %d!\n", eccKeySz);
193176
#endif /* BENCHMARK */
194177

195178
rng_done:
@@ -200,8 +183,8 @@ printf("Successfully verified signature w/ ecc key size %d!\n", eccKeySz);
200183
return ret;
201184
}
202185

203-
204-
int main(){
186+
int main()
187+
{
205188
#ifdef BENCHMARK
206189
printf("---------------------------------------------------------------\n");
207190
#if defined(SP_C64_FLAG)
@@ -253,6 +236,4 @@ int idx_key(int keysize){
253236
default:
254237
return -1;
255238
}
256-
257239
}
258-

embedded/signature/ecc_vfy_only/user_settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define NO_SHA
88

99
/* rsa */
10-
#define WOLFSSL_RSA_VERIFY_INLINE
1110
#define WC_NO_RSA_OAEP
1211
#define WC_NO_HARDEN
1312
#define NO_RSA

embedded/signature/ecc_vfy_only_nonblock/ecc_pubKey.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/* ecc_pubkey.h
2+
*
3+
* Copyright (C) 2006-2025 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL. (formerly known as CyaSSL)
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-1301, USA
20+
*/
121
unsigned char ecc_PublicKey_112[] = {
222
0x04, 0x67, 0xa6, 0xdc, 0x12, 0x25, 0xdb, 0x81,
323
0x5c, 0x67, 0x7c, 0xbf, 0x55, 0x3b, 0xd9, 0x51,
@@ -9,7 +29,7 @@ unsigned char ecc_PublicKey_112[] = {
929
0xad,
1030
};
1131

12-
unsigned char ecc_PublicKey_128[] = {
32+
unsigned char ecc_PublicKey_128[] = {
1333
0x04, 0x0f, 0x31, 0xea, 0x92, 0x1d, 0x84, 0xcf,
1434
0xce, 0xe1, 0xe5, 0x0b, 0x13, 0xda, 0xd3, 0xb2,
1535
0xb0, 0x57, 0x0c, 0x02, 0xdb, 0x50, 0xaa, 0xaa,

0 commit comments

Comments
 (0)