forked from wolfSSL/wolfssl
Fixes for ATECC508A/608A CryptoAuthLib demo.
This commit is contained in:
@ -3978,15 +3978,19 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
|
|||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
key->type = ECC_PRIVATEKEY;
|
key->type = ECC_PRIVATEKEY;
|
||||||
|
key->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE);
|
||||||
err = atmel_ecc_create_key(key->slot, key->pubkey_raw);
|
err = atmel_ecc_create_key(key->slot, key->pubkey_raw);
|
||||||
|
|
||||||
/* populate key->pubkey */
|
/* populate key->pubkey */
|
||||||
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw,
|
if (err == 0 && key->pubkey.x) {
|
||||||
ECC_MAX_CRYPTO_HW_SIZE);
|
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw,
|
||||||
if (err == MP_OKAY)
|
ECC_MAX_CRYPTO_HW_SIZE);
|
||||||
|
}
|
||||||
|
if (err == 0 && key->pubkey.y) {
|
||||||
err = mp_read_unsigned_bin(key->pubkey.y,
|
err = mp_read_unsigned_bin(key->pubkey.y,
|
||||||
key->pubkey_raw + ECC_MAX_CRYPTO_HW_SIZE,
|
key->pubkey_raw + ECC_MAX_CRYPTO_HW_SIZE,
|
||||||
ECC_MAX_CRYPTO_HW_SIZE);
|
ECC_MAX_CRYPTO_HW_SIZE);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef WOLFSSL_HAVE_SP_ECC
|
#ifdef WOLFSSL_HAVE_SP_ECC
|
||||||
@ -4145,7 +4149,7 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
key->slot = -1;
|
key->slot = ATECC_INVALID_SLOT;
|
||||||
#else
|
#else
|
||||||
#ifdef ALT_ECC_SIZE
|
#ifdef ALT_ECC_SIZE
|
||||||
key->pubkey.x = (mp_int*)&key->pubkey.xyz[0];
|
key->pubkey.x = (mp_int*)&key->pubkey.xyz[0];
|
||||||
@ -4789,7 +4793,7 @@ int wc_ecc_free(ecc_key* key)
|
|||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
atmel_ecc_free(key->slot);
|
atmel_ecc_free(key->slot);
|
||||||
key->slot = -1;
|
key->slot = ATECC_INVALID_SLOT;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
mp_clear(key->pubkey.x);
|
mp_clear(key->pubkey.x);
|
||||||
|
@ -52,6 +52,10 @@
|
|||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ATECC508A_TLS
|
||||||
|
extern ATCA_STATUS device_init_default(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
static int mAtcaInitDone = 0;
|
static int mAtcaInitDone = 0;
|
||||||
|
|
||||||
/* ATECC slotId handling */
|
/* ATECC slotId handling */
|
||||||
@ -350,6 +354,11 @@ int atmel_ecc_create_key(int slotId, byte* peerKey)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* verify provided slotId */
|
||||||
|
if (slotId == ATECC_INVALID_SLOT) {
|
||||||
|
return WC_HW_WAIT_E;
|
||||||
|
}
|
||||||
|
|
||||||
/* generate new ephemeral key on device */
|
/* generate new ephemeral key on device */
|
||||||
ret = atcab_genkey(slotId, peerKey);
|
ret = atcab_genkey(slotId, peerKey);
|
||||||
ret = atmel_ecc_translate_err(ret);
|
ret = atmel_ecc_translate_err(ret);
|
||||||
@ -420,6 +429,14 @@ int atmel_init(void)
|
|||||||
return WC_HW_E;
|
return WC_HW_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* show revision information */
|
||||||
|
atmel_show_rev_info();
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ATECC508A_TLS
|
||||||
|
/* Configure the ECC508 for use with TLS API functions */
|
||||||
|
device_init_default();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Init the I2C pipe encryption key. */
|
/* Init the I2C pipe encryption key. */
|
||||||
/* Value is generated/stored during pair for the ATECC508A and stored
|
/* Value is generated/stored during pair for the ATECC508A and stored
|
||||||
on micro flash */
|
on micro flash */
|
||||||
@ -429,9 +446,6 @@ int atmel_init(void)
|
|||||||
return WC_HW_E;
|
return WC_HW_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* show revision information */
|
|
||||||
atmel_show_rev_info();
|
|
||||||
|
|
||||||
mAtcaInitDone = 1;
|
mAtcaInitDone = 1;
|
||||||
}
|
}
|
||||||
#endif /* WOLFSSL_ATECC508A */
|
#endif /* WOLFSSL_ATECC508A */
|
||||||
|
Reference in New Issue
Block a user