Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions embedded/signature/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ This directory includes the following examples under the sub-directories.Each ha
|Scheme|Directory|Description|
|---|---|---|
|RSA|rsa_vfy_only |verify signature|
||rsa_buffer|sign/verify signature |
|ECDSA|signature/ecc-sign-verify/|sign msg and verify signature|
|RSA|rsa_sign_verify|sign/verify signature |
||rsa_vfy_only |verify signature|
||rsa_vfy_only_nonblock|verify signature with non-blocking|
|ECDSA|ecc_sign_verify/|sign msg and verify signature|
||ecc_vfy_only|verify Signature|
||ecc_vfy_only_nonblock|verify signature with non-blocking|


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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# The path to the wolfssl directory must be set correctly for your environment.
WOLFROOT = ../../../../wolfssl

CFLAGS = $(EX_CFLAGS) -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFROOT) -Os
Expand Down Expand Up @@ -61,7 +62,7 @@ endif
all : ecc_sign_verify bench mem

ecc_sign_verify: clean $(OBJ)
$(CC) $(CFLAGS) -o ecc_sign_verify ecc_sign_verify.c $(OBJ) -lpthread
$(CC) $(CFLAGS) -o ecc_sign_verify ecc_sign_verify.c $(OBJ)

bench: clean $(OBJ)
$(CC) $(CFLAGS) -DBENCHMARK -o ecc_sign_verify_bench ecc_sign_verify.c $(OBJ) -lpthread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ Successfully verified signature w/ ecc key size 512!
Key size is 521, byteField = 66
Successfully verified signature w/ ecc key size 521!

total Allocs = 522
total Deallocs = 522
total Bytes = 243047
total Allocs = 422
total Deallocs = 422
total Bytes = 195047
peak Bytes = 5557
current Bytes = 0
stack used = 14448
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ecc_sign_verify.c
*
* Copyright (C) 2006-2020 wolfSSL Inc.
* Copyright (C) 2006-2023 wolfSSL Inc.
*
* This file is part of wolfSSL. (formerly known as CyaSSL)
*
Expand Down Expand Up @@ -117,6 +117,7 @@ int do_sig_ver_test(int eccKeySz)
WC_RNG rng;
int verified = 0;


/* Variables for Benchmark */
double start_time, total_time;
#ifndef BENCH_TIME_SEC
Expand Down Expand Up @@ -158,9 +159,6 @@ double start_time, total_time;
ret = wc_InitRng(&rng);
CHECK_RET(ret, 0, key_done, "wc_InitRng()");

ret = wc_ecc_make_key(&rng, byteField, &key);
CHECK_RET(ret, 0, rng_done, "wc_ecc_make_key()");

#ifdef BENCHMARK
count = 0;
start_time = current_time(1);
Expand All @@ -172,17 +170,17 @@ double start_time, total_time;

ret = wc_ecc_make_key(&rng, byteField, &key);
CHECK_RET(ret, 0, rng_done, "wc_ecc_make_key()");
// printf("%s\n",hash);
ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &maxSigSz, &rng, &key);
CHECK_RET(ret, 0, rng_done, "wc_ecc_sign_hash()");

#ifdef SHOW_SIGS_IN_EXAMPLE
hexdump(sig, maxSigSz, 16);
#endif


ret = wc_ecc_verify_hash(sig, maxSigSz, hash, sizeof(hash), &verified,
&key);
ret = wc_ecc_verify_hash(sig, maxSigSz, hash, sizeof(hash),
&verified, &key);


CHECK_RET(ret, 0, rng_done, "wc_ecc_verify_hash()");
CHECK_RET(verified, 1, rng_done, "verification check");
verified = 0;
Expand Down
77 changes: 77 additions & 0 deletions embedded/signature/ecc_vfy_only/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# The path to the wolfssl directory must be set correctly for your environment.
WOLFROOT = ../../../../wolfssl

CFLAGS = $(EX_CFLAGS) -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFROOT) -Os
ASFLAGS = -DWOLFSSL_USER_SETTINGS -I. -I$(WOLFROOT)

OBJ=\
$(WOLFROOT)/wolfcrypt/src/ecc.o\
$(WOLFROOT)/wolfcrypt/src/sha256.o\
$(WOLFROOT)/wolfcrypt/src/hash.o\
$(WOLFROOT)/wolfcrypt/src/random.o\
$(WOLFROOT)/wolfcrypt/src/asn.o\
$(WOLFROOT)/wolfcrypt/src/wc_port.o\
$(WOLFROOT)/wolfcrypt/src/coding.o\
$(WOLFROOT)/wolfcrypt/src/memory.o\
$(WOLFROOT)/wolfcrypt/src/wolfmath.o\

OBJ_SP_C32 := \
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
$(WOLFROOT)/wolfcrypt/src/sp_c32.o\

OBJ_SP_C64 := \
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
$(WOLFROOT)/wolfcrypt/src/sp_c64.o\

OBJ_SP_ARM64 := \
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
$(WOLFROOT)/wolfcrypt/src/sp_arm64.o\

OBJ_SP_X86_64 := \
$(WOLFROOT)/wolfcrypt/src/sp_int.o\
$(WOLFROOT)/wolfcrypt/src/cpuid.o\
$(WOLFROOT)/wolfcrypt/src/sp_x86_64.o\
$(WOLFROOT)/wolfcrypt/src/sp_x86_64_asm.o\

OBJ_TFM := \
$(WOLFROOT)/wolfcrypt/src/tfm.o\

.PHONY: all clean mem size bench

ifeq ($(math) $(arch),sp x64)
ASFLAGS+= -DSP_X86_64_FLAG
CFLAGS += -DSP_X86_64_FLAG
OBJ += $(OBJ_SP_X86_64)
else ifeq ($(math) $(arch),sp arm64)
CFLAGS += -DSP_ARM64_FLAG
OBJ += $(OBJ_SP_ARM64)
else ifeq ($(math) $(arch),sp c64)
CFLAGS += -DSP_C64_FLAG
OBJ += $(OBJ_SP_C64)
else ifeq ($(math) $(arch),sp c32)
CFLAGS += -DSP_C32_FLAG
OBJ += $(OBJ_SP_C32)
else ifeq ($(math), tfm)
CFLAGS += -DTFM_FLAG
OBJ += $(OBJ_TFM)
else
CFLAGS += -DSP_C64_FLAG
OBJ += $(OBJ_SP_C64)
endif

all : ecc_verify bench mem


ecc_verify: clean $(OBJ)
$(CC) $(CFLAGS) -o ecc_verify ecc_verify.c $(OBJ)

bench: clean $(OBJ)
$(CC) $(CFLAGS) -DBENCHMARK -o ecc_verify_bench ecc_verify.c $(OBJ)

mem: clean $(OBJ)
$(CC) $(CFLAGS) -DDEBUG_MEMORY -o ecc_verify_mem ecc_verify.c $(OBJ) -lpthread
clean:
rm -f ecc_verify ecc_verify_bench ecc_verify_mem $(WOLFROOT)/wolfcrypt/src/*.o

size :
size $(OBJ) ecc_verify
150 changes: 150 additions & 0 deletions embedded/signature/ecc_vfy_only/ecc_pubKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
unsigned char ecc_PublicKey_112[] = {
0x04, 0x67, 0xa6, 0xdc, 0x12, 0x25, 0xdb, 0x81,
0x5c, 0x67, 0x7c, 0xbf, 0x55, 0x3b, 0xd9, 0x51,
0xb1, 0x61, 0xb4, 0x88, 0xb8, 0x6c, 0xa5, 0x4a,
0xb0, 0xe8, 0x79, 0x15, 0x4a, 0xfc, 0x6f, 0x01,
0x6b, 0xc0, 0xc5, 0xdd, 0xc2, 0xe3, 0x59, 0xda,
0x18, 0x82, 0x46, 0xa4, 0x32, 0xb5, 0x6d, 0x3b,
0xd1, 0x91, 0xcc, 0x19, 0xb7, 0xab, 0x8d, 0x99,
0xad,
};

unsigned char ecc_PublicKey_128[] = {
0x04, 0x0f, 0x31, 0xea, 0x92, 0x1d, 0x84, 0xcf,
0xce, 0xe1, 0xe5, 0x0b, 0x13, 0xda, 0xd3, 0xb2,
0xb0, 0x57, 0x0c, 0x02, 0xdb, 0x50, 0xaa, 0xaa,
0x65, 0x47, 0x6c, 0x2a, 0x41, 0xd4, 0x01, 0x72,
0xdb, 0xd3, 0xcf, 0x42, 0x81, 0x7c, 0x05, 0x67,
0x6e, 0x2a, 0x0a, 0x03, 0x0f, 0x91, 0x2b, 0x3b,
0xe3, 0x48, 0x87, 0xb3, 0xb3, 0x70, 0x58, 0x17,
0xed,
};

unsigned char ecc_PublicKey_160[] = {
0x04, 0xf8, 0x93, 0xf7, 0xf7, 0x1f, 0xc6, 0x56,
0x8c, 0x40, 0x11, 0x14, 0x74, 0xf5, 0x98, 0xa8,
0x12, 0xc3, 0xba, 0x06, 0x9e, 0x6d, 0xdc, 0x1b,
0xd3, 0x94, 0x9c, 0xf0, 0xc1, 0x99, 0x4e, 0x83,
0xe9, 0x42, 0x53, 0xcd, 0x8d, 0x26, 0x5a, 0x01,
0x4f, 0x82, 0x06, 0x42, 0x83, 0x65, 0x3c, 0x9e,
0xd5, 0x2d, 0x73, 0x52, 0xbc, 0x49, 0x1b, 0x99,
0x5c,
};

unsigned char ecc_PublicKey_192[] = {
0x04, 0xf7, 0xea, 0x10, 0xc6, 0x43, 0xba, 0xbb,
0x21, 0x14, 0x93, 0x11, 0xfe, 0x1a, 0x68, 0x59,
0x23, 0x71, 0x52, 0xde, 0x47, 0x08, 0x04, 0xd1,
0x77, 0xe4, 0x6f, 0x1f, 0x48, 0x4e, 0x8b, 0x92,
0x1a, 0xb9, 0xe9, 0x61, 0xf4, 0x3c, 0x1b, 0xcd,
0xe7, 0xaf, 0xc8, 0x59, 0x64, 0x9f, 0x80, 0x7e,
0x4e, 0x72, 0x98, 0x15, 0x18, 0x60, 0x01, 0x77,
0x8d,
};

unsigned char ecc_PublicKey_224[] = {
0x04, 0xf1, 0x25, 0xec, 0xac, 0x14, 0x47, 0x35,
0xcf, 0x32, 0x1a, 0xd2, 0x31, 0x60, 0xf6, 0x6b,
0xb6, 0x8c, 0x02, 0xd1, 0x46, 0xfa, 0xa6, 0xe3,
0xd9, 0xfd, 0x96, 0xbe, 0x44, 0x79, 0xc8, 0xbb,
0x0f, 0x41, 0xc6, 0x3d, 0x52, 0xd2, 0x8b, 0xc7,
0xe1, 0xfb, 0x03, 0x01, 0x07, 0x11, 0xaa, 0xba,
0xf9, 0x57, 0x90, 0x5f, 0xc2, 0xaf, 0x20, 0xe2,
0xd7,
};

unsigned char ecc_PublicKey_239[] = {
0x04, 0x01, 0xc2, 0x14, 0xbf, 0x8c, 0x36, 0x9c,
0x9d, 0xca, 0xb1, 0x20, 0xc8, 0x36, 0x45, 0x37,
0x79, 0x60, 0x97, 0xe9, 0x57, 0xc3, 0x1e, 0x86,
0xd1, 0x15, 0xc1, 0x57, 0xf1, 0x78, 0x91, 0x4e,
0x69, 0x8f, 0xee, 0xf3, 0xb2, 0xcd, 0xae, 0x00,
0x4e, 0x67, 0x47, 0x61, 0xab, 0xdd, 0x04, 0x79,
0x0b, 0xf9, 0xeb, 0x4b, 0x70, 0xa3, 0x22, 0xa0,
0xce, 0xb3, 0xc2, 0xd3, 0xd2,
};

unsigned char ecc_PublicKey_256[] = {
0x04, 0x80, 0xc7, 0xb7, 0x97, 0xe3, 0xc6, 0x63,
0x34, 0xcc, 0x72, 0x19, 0xb0, 0x3f, 0x4b, 0xe0,
0x68, 0x3e, 0xba, 0x8c, 0x0e, 0x60, 0xb0, 0xef,
0xfb, 0x6a, 0xb5, 0x5d, 0xaa, 0xaa, 0x27, 0x3b,
0x5d, 0x4c, 0x2d, 0x58, 0x0f, 0x96, 0x75, 0xe0,
0xe7, 0x5a, 0xab, 0xa0, 0xe9, 0x6a, 0x6a, 0x5f,
0xa7, 0xd7, 0x5d, 0xb1, 0x1a, 0x8b, 0x3b, 0x74,
0xcd, 0x75, 0x51, 0xa6, 0x89, 0xd4, 0x3d, 0x00,
0xeb,
};

unsigned char ecc_PublicKey_320[] = {
0x04, 0x5b, 0xf1, 0x32, 0x17, 0xf3, 0x63, 0x82,
0xfc, 0x1c, 0x93, 0xca, 0x30, 0x7d, 0x22, 0xf6,
0x97, 0xc9, 0x2d, 0x54, 0x35, 0x11, 0x77, 0x9c,
0x3f, 0x44, 0x37, 0x9f, 0x8b, 0x82, 0x8d, 0x50,
0x68, 0x2d, 0x0d, 0x1a, 0x19, 0x6d, 0xfc, 0xac,
0xde, 0xc1, 0x81, 0x13, 0x90, 0x31, 0xcc, 0x0f,
0x00, 0xa2, 0xf6, 0x7b, 0xc3, 0x51, 0x05, 0x46,
0x67, 0xd3, 0x91, 0xb7, 0xaa, 0xdd, 0xb9, 0x87,
0x03, 0x4e, 0x21, 0xd0, 0xa0, 0xfa, 0x31, 0x93,
0x04, 0xc8, 0xea, 0xc5, 0x71, 0x4b, 0x0f, 0x98,
0x4d, 0x16, 0x69, 0xe9, 0xc7, 0xda, 0xff, 0xfa,
0xe1, 0xf0, 0xa5, 0xdd, 0x36, 0xf2, 0x04, 0x62,
0xa6,
};

unsigned char ecc_PublicKey_384[] = {
0x04, 0x51, 0xb3, 0x72, 0xda, 0xd2, 0xd7, 0x81,
0x53, 0xe3, 0x4e, 0xa1, 0x27, 0x9a, 0x91, 0x42,
0x8a, 0x29, 0x62, 0x7c, 0x8f, 0x49, 0x47, 0x47,
0x4c, 0x0e, 0x23, 0x09, 0xf5, 0x13, 0x56, 0x08,
0x2d, 0x54, 0xc3, 0xac, 0x05, 0xc4, 0x1f, 0x16,
0x27, 0xd0, 0x4c, 0x3b, 0xed, 0xa0, 0x74, 0x62,
0xe3, 0x1b, 0xa3, 0xd5, 0xf2, 0xf2, 0x5d, 0x6a,
0x87, 0xa2, 0xf4, 0x09, 0x9a, 0x87, 0xee, 0xab,
0x20, 0xe7, 0x42, 0xd2, 0x6d, 0x1b, 0x1c, 0x75,
0x69, 0x46, 0x2e, 0x8c, 0x00, 0xe5, 0xd7, 0xc5,
0xc4, 0xfb, 0x46, 0xe7, 0xf8, 0xc1, 0x25, 0x7c,
0x94, 0x30, 0xd0, 0xd5, 0xdb, 0x8d, 0xe3, 0x15,
0xc8,
};

unsigned char ecc_PublicKey_512[] = {
0x04, 0x01, 0x5c, 0x37, 0xe0, 0x37, 0x3b, 0xad,
0x8a, 0xfe, 0x3c, 0x52, 0x5d, 0xe7, 0xab, 0x77,
0x39, 0x67, 0x94, 0x6c, 0x2a, 0x3f, 0xee, 0x95,
0x19, 0x8d, 0xcc, 0xdc, 0xad, 0x62, 0x50, 0x97,
0x79, 0xeb, 0xde, 0x70, 0xed, 0x2d, 0x44, 0x8f,
0xcf, 0x1d, 0x49, 0x46, 0x32, 0x96, 0xe3, 0xb6,
0xc5, 0x61, 0x4c, 0xfd, 0xcb, 0x65, 0x1f, 0x04,
0x97, 0x39, 0x54, 0x46, 0xde, 0x54, 0x2f, 0x0a,
0x51, 0xd5, 0xe6, 0x01, 0x1e, 0x78, 0x20, 0x15,
0x1c, 0xb3, 0x6f, 0x14, 0x8f, 0x2f, 0x95, 0x9c,
0x40, 0xea, 0x12, 0x52, 0x5a, 0xce, 0x7c, 0x43,
0x28, 0x22, 0x31, 0x00, 0xcb, 0xbf, 0x86, 0x56,
0xdc, 0x72, 0xa4, 0x49, 0x75, 0x80, 0xa4, 0x17,
0xde, 0xa6, 0xf8, 0x3b, 0x39, 0x88, 0xd0, 0x8b,
0x4e, 0x44, 0x69, 0x39, 0x7a, 0xcc, 0xcc, 0xc7,
0x15, 0x1e, 0x6c, 0x76, 0xf2, 0x8d, 0x1b, 0x6c,
0x64, 0x0a, 0x4c, 0x29, 0x35,
};


unsigned char ecc_PublicKey_521[] = {
0x04, 0x00, 0xf9, 0x56, 0xfb, 0x6c, 0x5a, 0x3d,
0xc4, 0xf3, 0xb8, 0x07, 0x19, 0x2f, 0x93, 0x07,
0x3c, 0x30, 0x7b, 0xd9, 0x9c, 0x11, 0xe8, 0xda,
0xbe, 0x1b, 0x1b, 0xa3, 0xf2, 0x81, 0xf9, 0xd0,
0x47, 0x0d, 0x06, 0xa4, 0x47, 0xa0, 0x8b, 0xca,
0x0f, 0x0a, 0x3a, 0xda, 0x68, 0x38, 0x67, 0x5d,
0x11, 0x77, 0xf8, 0x2f, 0x28, 0x0f, 0x31, 0xe5,
0x26, 0xf5, 0x88, 0x2a, 0x79, 0x5f, 0xce, 0x55,
0xe9, 0x71, 0x4c, 0x00, 0x9e, 0xfc, 0x7d, 0x00,
0x04, 0xb8, 0x89, 0x04, 0xfc, 0x06, 0x38, 0x3f,
0x9f, 0x0a, 0x80, 0x7f, 0x6b, 0x4c, 0xd2, 0x61,
0x69, 0x00, 0x7f, 0x9c, 0x7c, 0x9b, 0xab, 0xa6,
0x9c, 0x71, 0xa9, 0x15, 0x63, 0x4a, 0x03, 0xe8,
0x96, 0xbb, 0x79, 0x6a, 0x50, 0xa6, 0xd0, 0xdf,
0x66, 0xf5, 0xc8, 0xfa, 0x22, 0x94, 0xe0, 0x72,
0xa6, 0x15, 0x94, 0x1e, 0x3b, 0x47, 0x36, 0x8e,
0xcb, 0x10, 0x15, 0x27, 0x5b,
};
Loading