diff --git a/pk/ecc/README.md b/pk/ecc/README.md index d400a978..2f8b3771 100644 --- a/pk/ecc/README.md +++ b/pk/ecc/README.md @@ -20,8 +20,12 @@ The `ecc_keys.c` example shows how to work with storing and loading keys after t ## ecc_sign -The `ecc_verify.c` example uses NIST test vectors to demonstrate hashing a message and verifying an ECC signature. +The `ecc_sign.c:` example takes a random message and private key, creates a signature then verifies it. ## ecc_verify -The `ecc_sign.c:` example takes a random message and private key, creates a signature then verifies it. +The `ecc_verify.c` example uses NIST test vectors to demonstrate hashing a message and verifying an ECC signature. + +## ecc_pub + +The `ecc_pub` example code shows how to extracting an ECC public key from private key. diff --git a/pk/ecc/ecc_sign.c b/pk/ecc/ecc_sign.c index cd131e0c..fc602fe3 100644 --- a/pk/ecc/ecc_sign.c +++ b/pk/ecc/ecc_sign.c @@ -295,7 +295,7 @@ int main() int ret; uint8_t hash[WC_SHA256_DIGEST_SIZE]; uint8_t sig[ECC_CURVE_SZ*2]; - uint32_t sigSz = sizeof(sig); + uint32_t sigSz = 0; #ifdef DEBUG_WOLFSSL wolfSSL_Debugging_ON(); @@ -303,6 +303,8 @@ int main() printf("Running NIST P-256,SHA-256 Sign Test\n"); + memset(sig, 0, sizeof(sig)); + ret = crypto_sha256( kMsg, sizeof(kMsg), /* input message */ hash, sizeof(hash), /* hash digest result */ @@ -313,6 +315,7 @@ int main() /* Note: result of an ECC sign varies for each call even with same private key and hash. This is because a new random public key is used for each operation. */ + sigSz = sizeof(sig); ret = crypto_ecc_sign( kPrivKey, sizeof(kPrivKey), /* private key */ hash, sizeof(hash), /* computed hash digest */ @@ -333,16 +336,18 @@ int main() ); } - printf("Signature %d\n", sigSz); - print_hex(sig, sigSz); + if (ret == 0) { + printf("Signature %d\n", sigSz); + print_hex(sig, sigSz); - if (ret != 0) { - printf("Failure %d: %s\n", ret, wc_GetErrorString(ret)); - return -1; + printf("Success\n"); + } + else { + printf("Failure %d: %s\n", ret, wc_GetErrorString(ret)); + ret = -1; } - printf("Success\n"); - return 0; + return ret; #else printf("wolfSSL requires ECC and SHA256\n"); return -1; diff --git a/pk/ecc/ecc_verify.c b/pk/ecc/ecc_verify.c index 236b2076..3658b283 100644 --- a/pk/ecc/ecc_verify.c +++ b/pk/ecc/ecc_verify.c @@ -231,11 +231,13 @@ int main() ); } - if (ret != 0) { - printf("Failure %d: %s\n", ret, wc_GetErrorString(ret)); - return -1; + if (ret == 0) { + printf("Success\n"); + } + else { + printf("Failure %d: %s\n", ret, wc_GetErrorString(ret)); + ret = -1; } - printf("Success\n"); return ret; #else