Skip to content

Commit 661dd3a

Browse files
committed
add wc_encrypt.o as target
add Makefile to make all
1 parent a322264 commit 661dd3a

File tree

11 files changed

+80
-57
lines changed

11 files changed

+80
-57
lines changed

embedded/signature/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CC = gcc
2+
#CC = clang
3+
SRCROOT = .
4+
ECCSRCDIRS := $(shell ls -d $(SRCROOT)/ecc_*)
5+
RSASRCDIRS := $(shell ls -d $(SRCROOT)/rsa_*)
6+
7+
all: ecc rsa
8+
9+
ecc:
10+
@for d in $(ECCSRCDIRS); do echo $$d ; $(MAKE) -C $$d CC=$(CC) ; done
11+
12+
rsa:
13+
@for d in $(RSASRCDIRS); do echo $$d ; $(MAKE) -C $$d CC=$(CC) ; done
14+
15+
clean: FORCE
16+
@for d in $(ECCSRCDIRS); do echo $$d ; $(MAKE) -C $$d clean; done
17+
@for d in $(RSASRCDIRS); do echo $$d ; $(MAKE) -C $$d clean; done
18+
19+
FORCE:
20+
.PHONY: FORCE

embedded/signature/ecc_sign_verify/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ OBJ=\
1414
$(WOLFROOT)/wolfcrypt/src/coding.o\
1515
$(WOLFROOT)/wolfcrypt/src/memory.o\
1616
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\
17+
$(WOLFROOT)/wolfcrypt/src/wc_encrypt.o\
1718

1819
OBJ_SP_C32 := \
1920
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
@@ -38,7 +39,7 @@ OBJ_TFM := \
3839

3940
.PHONY: all clean mem size bench
4041

41-
ifeq ($(math) $(arch),sp x64)
42+
ifeq ($(math) $(arch),sp x64)
4243
ASFLAGS+= -DSP_X86_64_FLAG
4344
CFLAGS += -DSP_X86_64_FLAG
4445
OBJ += $(OBJ_SP_X86_64)
@@ -54,15 +55,15 @@ OBJ += $(OBJ_SP_C32)
5455
else ifeq ($(math), tfm)
5556
CFLAGS += -DTFM_FLAG
5657
OBJ += $(OBJ_TFM)
57-
else
58+
else
5859
CFLAGS += -DSP_C64_FLAG
5960
OBJ += $(OBJ_SP_C64)
6061
endif
6162

6263
all : ecc_sign_verify bench mem
6364

6465
ecc_sign_verify: clean $(OBJ)
65-
$(CC) $(CFLAGS) -o ecc_sign_verify ecc_sign_verify.c $(OBJ)
66+
$(CC) $(CFLAGS) -o ecc_sign_verify ecc_sign_verify.c $(OBJ)
6667

6768
bench: clean $(OBJ)
6869
$(CC) $(CFLAGS) -DBENCHMARK -o ecc_sign_verify_bench ecc_sign_verify.c $(OBJ) -lpthread

embedded/signature/ecc_sign_verify/user_settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@
7878

7979
#ifdef BENCHMARK
8080
#undef DEBUG_MEMORY
81-
#endif
81+
#endif

embedded/signature/ecc_vfy_only/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ OBJ=\
1414
$(WOLFROOT)/wolfcrypt/src/coding.o\
1515
$(WOLFROOT)/wolfcrypt/src/memory.o\
1616
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\
17+
$(WOLFROOT)/wolfcrypt/src/wc_encrypt.o\
1718

1819
OBJ_SP_C32 := \
1920
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
@@ -38,7 +39,7 @@ OBJ_TFM := \
3839

3940
.PHONY: all clean mem size bench
4041

41-
ifeq ($(math) $(arch),sp x64)
42+
ifeq ($(math) $(arch),sp x64)
4243
ASFLAGS+= -DSP_X86_64_FLAG
4344
CFLAGS += -DSP_X86_64_FLAG
4445
OBJ += $(OBJ_SP_X86_64)
@@ -54,7 +55,7 @@ OBJ += $(OBJ_SP_C32)
5455
else ifeq ($(math), tfm)
5556
CFLAGS += -DTFM_FLAG
5657
OBJ += $(OBJ_TFM)
57-
else
58+
else
5859
CFLAGS += -DSP_C64_FLAG
5960
OBJ += $(OBJ_SP_C64)
6061
endif
@@ -66,7 +67,7 @@ ecc_verify: clean $(OBJ)
6667
$(CC) $(CFLAGS) -o ecc_verify ecc_verify.c $(OBJ)
6768

6869
bench: clean $(OBJ)
69-
$(CC) $(CFLAGS) -DBENCHMARK -o ecc_verify_bench ecc_verify.c $(OBJ)
70+
$(CC) $(CFLAGS) -DBENCHMARK -o ecc_verify_bench ecc_verify.c $(OBJ)
7071

7172
mem: clean $(OBJ)
7273
$(CC) $(CFLAGS) -DDEBUG_MEMORY -o ecc_verify_mem ecc_verify.c $(OBJ) -lpthread

embedded/signature/ecc_vfy_only_nonblock/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ OBJ=\
1414
$(WOLFROOT)/wolfcrypt/src/coding.o\
1515
$(WOLFROOT)/wolfcrypt/src/memory.o\
1616
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\
17+
$(WOLFROOT)/wolfcrypt/src/wc_encrypt.o\
1718

1819
OBJ_SP_C32 := \
1920
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
@@ -37,7 +38,7 @@ OBJ_TFM := \
3738
$(WOLFROOT)/wolfcrypt/src/tfm.o\
3839

3940

40-
ifeq ($(math) $(arch),sp x64)
41+
ifeq ($(math) $(arch),sp x64)
4142
ASFLAGS+= -DSP_X86_64_FLAG
4243
CFLAGS += -DSP_X86_64_FLAG
4344
OBJ += $(OBJ_SP_X86_64)
@@ -53,7 +54,7 @@ OBJ += $(OBJ_SP_C32)
5354
else ifeq ($(math), tfm)
5455
CFLAGS += -DTFM_FLAG
5556
OBJ += $(OBJ_TFM)
56-
else
57+
else
5758
CFLAGS += -DSP_C64_FLAG
5859
OBJ += $(OBJ_SP_C64)
5960
endif

embedded/signature/rsa_buffer/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ OBJ = \
1212
$(WOLFROOT)/wolfcrypt/src/wc_port.o\
1313
$(WOLFROOT)/wolfcrypt/src/coding.o\
1414
$(WOLFROOT)/wolfcrypt/src/memory.o\
15+
$(WOLFROOT)/wolfcrypt/src/wc_encrypt.o\
1516

1617
OBJ_SP_C32 := \
1718
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
@@ -39,7 +40,7 @@ OBJ_TFM := \
3940

4041
.PHONY: all clean size mem bench
4142

42-
ifeq ($(math) $(arch),sp x64)
43+
ifeq ($(math) $(arch),sp x64)
4344
ASFLAGS+= -DSP_X86_64_FLAG
4445
CFLAGS += -DSP_X86_64_FLAG
4546
OBJ += $(OBJ_SP_X86_64)
@@ -55,22 +56,22 @@ OBJ += $(OBJ_SP_C32)
5556
else ifeq ($(math), tfm)
5657
CFLAGS += -DTFM_FLAG
5758
OBJ += $(OBJ_TFM)
58-
else
59+
else
5960
CFLAGS += -DSP_C64_FLAG
6061
OBJ += $(OBJ_SP_C64)
6162
endif
6263

6364
all: verify sign bench mem
6465

6566
verify: clean $(OBJ)
66-
$(CC) $(CFLAGS) -o verify verify.c $(OBJ)
67+
$(CC) $(CFLAGS) -o verify verify.c $(OBJ)
6768
sign: clean $(OBJ)
68-
$(CC) $(CFLAGS) -o sign sign.c $(OBJ)
69+
$(CC) $(CFLAGS) -o sign sign.c $(OBJ)
6970
bench: clean $(OBJ)
7071
$(CC) $(CFLAGS) -DBENCHMARK -o verify_bench verify.c $(OBJ) -lpthread
7172
mem: clean $(OBJ)
7273
$(CC) $(CFLAGS) -DDEBUG_MEMORY -o verify_mem verify.c $(OBJ) -lpthread
7374
clean:
7475
rm -f sign verify verify_bench verify_mem $(WOLFROOT)/wolfcrypt/src/*.o
7576
size :
76-
size $(OBJ) sign verify
77+
size $(OBJ) sign verify

embedded/signature/rsa_sign_verify/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ OBJ = \
1313
$(WOLFROOT)/wolfcrypt/src/coding.o\
1414
$(WOLFROOT)/wolfcrypt/src/memory.o\
1515
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\
16+
$(WOLFROOT)/wolfcrypt/src/wc_encrypt.o\
1617

1718
OBJ_SP_C32 := \
1819
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
@@ -39,7 +40,7 @@ OBJ_TFM := \
3940

4041
.PHONY: all clean size mem bench
4142

42-
ifeq ($(math) $(arch),sp x64)
43+
ifeq ($(math) $(arch),sp x64)
4344
ASFLAGS+= -DSP_X86_64_FLAG
4445
CFLAGS += -DSP_X86_64_FLAG
4546
OBJ += $(OBJ_SP_X86_64)
@@ -55,12 +56,12 @@ OBJ += $(OBJ_SP_C32)
5556
else ifeq ($(math), tfm)
5657
CFLAGS += -DTFM_FLAG
5758
OBJ += $(OBJ_TFM)
58-
else
59+
else
5960
CFLAGS += -DSP_C64_FLAG
6061
OBJ += $(OBJ_SP_C64)
6162
endif
6263

63-
all: rsa_sign_verify bench mem
64+
all: rsa_sign_verify bench mem
6465
rsa_sign_verify: clean $(OBJ)
6566
$(CC) $(CFLAGS) -o rsa_sign_verify rsa_sign_verify.c $(OBJ)
6667

@@ -70,10 +71,10 @@ mem: clean $(OBJ)
7071
$(CC) $(CFLAGS) -DDEBUG_MEMORY -o rsa_sign_verify_mem rsa_sign_verify.c $(OBJ) -lpthread
7172

7273
nonblock: CFLAGS += -DNONBLOCK
73-
nonblock: clean $(OBJ)
74+
nonblock: clean $(OBJ)
7475
$(CC) -DNONBLOCK $(CFLAGS) -DDEBUG_MEMORY -o rsa_sign_verify_nonblock rsa_sign_verify_nonblock.c $(OBJ) -lpthread
7576

7677
clean:
7778
rm -f rsa_sign_verify rsa_sign_verify_bench rsa_sign_verify_mem rsa_sign_verify_nonblock $(WOLFROOT)/wolfcrypt/src/*.o
7879
size :
79-
size $(OBJ) sign verify
80+
size $(OBJ) sign verify

embedded/signature/rsa_sign_verify/rsa_sign_verify.c

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
/* This file is an example of signing and verifying an RSA signature.
2323
* The signature can be PKCS#1.5 formatted and PSS formatted.
24-
*
24+
*
2525
* - PKCS#1.5
2626
* 1. hash -> encSig
27-
* 2. encSig -> signature
27+
* 2. encSig -> signature
2828
* 3. signature -> decSig
29-
*
29+
*
3030
* - PSS
31-
* 1. hash -> signature
31+
* 1. hash -> signature
3232
* 2. signature -> decSig
33-
*
33+
*
3434
* PKCS#1.5 is used for the Signature by default.
3535
* To turning on PSS, define PSS_PADDING
3636
*/
@@ -49,10 +49,6 @@
4949
/* RSA Key size bits */
5050
#define RSA_KEY_SIZE 2048
5151

52-
53-
54-
55-
5652
#define CHECK_RET(a, b, eLabel, msg) { \
5753
if (a != b) { \
5854
printf("failed %s\n", msg); \
@@ -115,21 +111,21 @@ int sign(){
115111
ret = wc_MakeRsaKey(&key, RSA_KEY_SIZE, e, &rng);
116112
CHECK_RET(ret, 0, finish, "wc_MakeRsaKey()");
117113

118-
/* Encode digest with algorithm information as per PKCS#1.5 */
119-
encSigLen = wc_EncodeSignature(encSig, hash, sizeof(hash), SHA256h);
120-
if ((int)encSigLen < 0)
121-
ret = (int)encSigLen;
122-
CHECK_RET(ret, 0, finish, "wc_EncodeSignature()");
123-
124114
#ifdef PSS_PADDING
125-
sigLen = wc_RsaPSS_Sign(hash, sizeof(hash), signature, sizeof(signature)\
126-
, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng);
115+
sigLen = wc_RsaPSS_Sign(hash, sizeof(hash), signature, sizeof(signature),
116+
WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng);
127117
if ((int)sigLen < 0)
128118
ret = (int)sigLen;
129119
CHECK_RET(ret, 0, finish, "wc_RsaPSS_Sign()");
130120

131121
#else /* PKCS#1.5 */
132-
sigLen = wc_RsaSSL_Sign(encSig, encSigLen, signature, sizeof(signature),\
122+
/* Encode digest with algorithm information as per PKCS#1.5 */
123+
encSigLen = wc_EncodeSignature(encSig, hash, sizeof(hash), SHA256h);
124+
if ((int)encSigLen < 0)
125+
ret = (int)encSigLen;
126+
CHECK_RET(ret, 0, finish, "wc_EncodeSignature()");
127+
128+
sigLen = wc_RsaSSL_Sign(encSig, encSigLen, signature, sigBuffLen,
133129
&key, NULL);
134130
if ((int)sigLen < 0)
135131
ret = (int)sigLen;
@@ -182,7 +178,7 @@ int verify(){
182178
return -1;
183179
}
184180

185-
#ifdef BENCHMARK
181+
#ifdef BENCHMARK
186182
count = 0;
187183
printf("Running benchmark...\n");
188184
printf("Please Wait %.2f seconds\n", (double)BENCH_TIME_SEC);
@@ -191,15 +187,16 @@ int verify(){
191187
#endif
192188

193189
/* Verify the signature by decrypting the value. */
194-
190+
195191
#ifdef PSS_PADDING
196192
decSigLen = wc_RsaPSS_VerifyCheck(signature, sizeof(signature),
197-
decSig, sizeof(decSig), hash, sizeof(hash), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key);
198-
193+
decSig, sizeof(decSig), hash, sizeof(hash),
194+
WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key);
195+
199196
if ((int)decSigLen < 0)
200197
ret = (int)decSigLen;
201198
CHECK_RET(ret, 0, finish, "wc_RsaPSS_VerifyCheck()");
202-
199+
203200
#else /* PKCS#1.5 */
204201
decSigLen = wc_RsaSSL_Verify(signature, sizeof(signature),
205202
decSig, sizeof(decSig), &key);
@@ -220,11 +217,11 @@ int verify(){
220217

221218
#endif
222219

223-
#ifdef BENCHMARK
220+
#ifdef BENCHMARK
224221
count++;
225222
}
226-
227-
printf("Takes %1.2f Sec for %d times, %6.2f Cycles/sec\n", total_time, count, count/total_time);
223+
printf("Takes %1.2f Sec for %d times, %6.2f Cycles/sec\n",
224+
total_time, count, count/total_time);
228225
printf("Finished Benchmark \n");
229226
#elif defined(DEBUG_MEMORY)
230227

@@ -248,8 +245,6 @@ int verify(){
248245
return ret;
249246
}
250247

251-
252-
253248
int main(){
254249
int ret = 0;
255250
#ifdef BENCHMARK
@@ -270,7 +265,7 @@ int main(){
270265

271266
#ifdef DEBUG_MEMORY
272267
ret = StackSizeCheck(NULL, (thread_func)sign);
273-
#else
268+
#else
274269
ret = sign();
275270
#endif
276271

@@ -280,7 +275,7 @@ int main(){
280275

281276
#ifdef DEBUG_MEMORY
282277
ret = StackSizeCheck(NULL, (thread_func)verify);
283-
#else
278+
#else
284279
ret = verify();
285280
#endif
286281
return ret;

embedded/signature/rsa_sign_verify/user_settings.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/* asn */
2323
#define NO_ASN_TIME
2424
#define IGNORE_NAME_CONSTRAINTS
25-
#define WOLFSSL_NO_ASN_STRICT
25+
#define WOLFSSL_NO_ASN_STRICT
2626

2727

2828
#ifdef DEBUG_MEMORY
@@ -33,11 +33,11 @@
3333
#endif
3434

3535

36-
#ifdef SP_C32_FLAG
36+
#ifdef SP_C32_FLAG
3737
#define WOLFSSL_HAVE_SP_RSA
3838
#define WOLFSSL_SP_MATH_ALL
3939
#undef USE_FAST_MATH
40-
#endif
40+
#endif
4141

4242
#ifdef SP_C64_FLAG
4343
#define WOLFSSL_HAVE_SP_RSA
@@ -76,7 +76,7 @@
7676
#undef DEBUG_MEMORY
7777
#endif
7878

79-
// #define PSS_PADDING
79+
#define PSS_PADDING
8080
#ifdef PSS_PADDING
8181
#define WC_RSA_PSS
8282
#define WC_RSA_BLINDING
@@ -91,3 +91,4 @@
9191
#define WOLFSSL_SP_NO_MALLOC
9292
#undef BENCHMARK
9393
#endif /* NONBLOCK */
94+

0 commit comments

Comments
 (0)