From 58c05123da1fc6eacf20f118beb57e24d06d63ff Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 10 Jul 2017 11:07:24 -0700 Subject: [PATCH] Fixes for building with ATECC508A. Allow ECC check key to pass if slot numb is valid. --- wolfcrypt/src/ecc.c | 20 ++++++++++++++++++-- wolfcrypt/test/test.c | 7 ++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index a91c9a861..3fc2f5038 100755 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -4707,8 +4707,11 @@ int wc_ecc_check_key(ecc_key* key) return BAD_FUNC_ARG; #ifdef WOLFSSL_ATECC508A - /* TODO: Implement equiv call to ATECC508A */ - err = BAD_COND_E; + + if (key->slot == ATECC_INVALID_SLOT) + return ECC_BAD_ARG_E; + + err = 0; /* consider key check success on ECC508A */ #else @@ -5014,13 +5017,25 @@ static int wc_ecc_export_raw(ecc_key* key, byte* qx, word32* qxLen, *dLen = numLen; XMEMSET(d, 0, *dLen); + #ifdef WOLFSSL_ATECC508A + /* TODO: Implement equiv call to ATECC508A */ + return BAD_COND_E; + + #else + /* private key, d */ err = mp_to_unsigned_bin(&key->k, d + (numLen - mp_unsigned_bin_size(&key->k))); if (err != MP_OKAY) return err; + #endif /* WOLFSSL_ATECC508A */ } +#ifdef WOLFSSL_ATECC508A + /* TODO: Implement equiv call to ATECC508A */ + return BAD_COND_E; + +#else /* public x component */ err = mp_to_unsigned_bin(key->pubkey.x, qx + (numLen - mp_unsigned_bin_size(key->pubkey.x))); @@ -5034,6 +5049,7 @@ static int wc_ecc_export_raw(ecc_key* key, byte* qx, word32* qxLen, return err; return 0; +#endif /* WOLFSSL_ATECC508A */ } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 942f4e0b3..ab639b94d 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -1088,6 +1088,7 @@ int asn_test() return -1302; } if (now == 0) { + printf("RTC/Time not set!\n"); return -1303; } #endif @@ -10664,6 +10665,7 @@ done: } #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */ +#ifndef WOLFSSL_ATECC508A #ifdef HAVE_ECC_KEY_IMPORT static int ecc_mulmod_test(ecc_key* key1) { @@ -10705,7 +10707,6 @@ done: } #endif -#ifndef WOLFSSL_ATECC508A static int ecc_ssh_test(ecc_key* key) { int ret; @@ -10757,16 +10758,16 @@ static int ecc_def_curve_test(WC_RNG *rng) if (ret < 0) goto done; #endif +#ifndef WOLFSSL_ATECC508A #ifdef HAVE_ECC_KEY_IMPORT ret = ecc_mulmod_test(&key); if (ret < 0) goto done; #endif -#ifndef WOLFSSL_ATECC508A ret = ecc_ssh_test(&key); if (ret < 0) goto done; -#endif +#endif /* WOLFSSL_ATECC508A */ done: wc_ecc_free(&key); return ret;