mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 03:34:39 +02:00
Merge pull request #1969 from dgarske/atecc508a_fixes
Fixes for ATECC508A/ATECC608A and latest CryptoAuthLib
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
|
||||
key->type = ECC_PRIVATEKEY;
|
||||
key->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE);
|
||||
err = atmel_ecc_create_key(key->slot, key->pubkey_raw);
|
||||
|
||||
/* populate key->pubkey */
|
||||
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw,
|
||||
ECC_MAX_CRYPTO_HW_SIZE);
|
||||
if (err == MP_OKAY)
|
||||
if (err == 0 && key->pubkey.x) {
|
||||
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw,
|
||||
ECC_MAX_CRYPTO_HW_SIZE);
|
||||
}
|
||||
if (err == 0 && key->pubkey.y) {
|
||||
err = mp_read_unsigned_bin(key->pubkey.y,
|
||||
key->pubkey_raw + ECC_MAX_CRYPTO_HW_SIZE,
|
||||
ECC_MAX_CRYPTO_HW_SIZE);
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef WOLFSSL_HAVE_SP_ECC
|
||||
@@ -4145,7 +4149,7 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_ATECC508A
|
||||
key->slot = -1;
|
||||
key->slot = ATECC_INVALID_SLOT;
|
||||
#else
|
||||
#ifdef ALT_ECC_SIZE
|
||||
key->pubkey.x = (mp_int*)&key->pubkey.xyz[0];
|
||||
@@ -4789,7 +4793,7 @@ int wc_ecc_free(ecc_key* key)
|
||||
|
||||
#ifdef WOLFSSL_ATECC508A
|
||||
atmel_ecc_free(key->slot);
|
||||
key->slot = -1;
|
||||
key->slot = ATECC_INVALID_SLOT;
|
||||
#else
|
||||
|
||||
mp_clear(key->pubkey.x);
|
||||
|
@@ -52,6 +52,10 @@
|
||||
|
||||
#ifdef WOLFSSL_ATECC508A
|
||||
|
||||
#ifdef WOLFSSL_ATECC508A_TLS
|
||||
extern ATCA_STATUS device_init_default(void);
|
||||
#endif
|
||||
|
||||
static int mAtcaInitDone = 0;
|
||||
|
||||
/* ATECC slotId handling */
|
||||
@@ -114,6 +118,8 @@ int atmel_get_random_block(unsigned char* output, unsigned int sz)
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_ATMEL) && defined(WOLFSSL_ATMEL_TIME)
|
||||
#include "asf.h"
|
||||
#include "rtc_calendar.h"
|
||||
extern struct rtc_module *_rtc_instance[RTC_INST_NUM];
|
||||
|
||||
long atmel_get_curr_time_and_date(long* tm)
|
||||
@@ -348,6 +354,11 @@ int atmel_ecc_create_key(int slotId, byte* peerKey)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* verify provided slotId */
|
||||
if (slotId == ATECC_INVALID_SLOT) {
|
||||
return WC_HW_WAIT_E;
|
||||
}
|
||||
|
||||
/* generate new ephemeral key on device */
|
||||
ret = atcab_genkey(slotId, peerKey);
|
||||
ret = atmel_ecc_translate_err(ret);
|
||||
@@ -418,6 +429,14 @@ int atmel_init(void)
|
||||
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. */
|
||||
/* Value is generated/stored during pair for the ATECC508A and stored
|
||||
on micro flash */
|
||||
@@ -427,9 +446,6 @@ int atmel_init(void)
|
||||
return WC_HW_E;
|
||||
}
|
||||
|
||||
/* show revision information */
|
||||
atmel_show_rev_info();
|
||||
|
||||
mAtcaInitDone = 1;
|
||||
}
|
||||
#endif /* WOLFSSL_ATECC508A */
|
||||
|
@@ -72,7 +72,10 @@ struct ecc_key;
|
||||
int atmel_init(void);
|
||||
void atmel_finish(void);
|
||||
int atmel_get_random_number(uint32_t count, uint8_t* rand_out);
|
||||
int atmel_get_random_block(unsigned char* output, unsigned int sz);
|
||||
#ifndef ATMEL_GET_RANDOM_BLOCK_DEFINED
|
||||
int atmel_get_random_block(unsigned char* output, unsigned int sz);
|
||||
#define ATMEL_GET_RANDOM_BLOCK_DEFINED
|
||||
#endif
|
||||
long atmel_get_curr_time_and_date(long* tm);
|
||||
|
||||
#ifdef WOLFSSL_ATECC508A
|
||||
|
@@ -443,8 +443,7 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
||||
#endif
|
||||
#define XGMTIME(c, t) gmtime((c))
|
||||
|
||||
#elif defined(WOLFSSL_ATMEL)
|
||||
extern long atmel_get_curr_time_and_date(long* tm);
|
||||
#elif defined(WOLFSSL_ATMEL) && defined(WOLFSSL_ATMEL_TIME)
|
||||
#define XTIME(t1) atmel_get_curr_time_and_date((t1))
|
||||
#define WOLFSSL_GMTIME
|
||||
#define USE_WOLF_TM
|
||||
|
Reference in New Issue
Block a user