Fix for wc_ecc_import_x963_ex to handle ATECC508A raw public key. Cleanup of the ATECC508A encryption key support. Added new macro ATCA_TLS_GET_ENC_KEY to allow setting your own function at build-time for getting the encryption key.

This commit is contained in:
David Garske
2018-09-06 12:06:50 -07:00
parent be318abbc2
commit e78ddfce75
2 changed files with 26 additions and 16 deletions

View File

@ -6329,6 +6329,11 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
inLen -= 1; inLen -= 1;
in += 1; in += 1;
#ifdef WOLFSSL_ATECC508A
/* populate key->pubkey_raw */
XMEMCPY(key->pubkey_raw, (byte*)in, sizeof(key->pubkey_raw));
#endif
if (err == MP_OKAY) { if (err == MP_OKAY) {
#ifdef HAVE_COMP_KEY #ifdef HAVE_COMP_KEY
/* adjust inLen if compressed */ /* adjust inLen if compressed */

View File

@ -153,20 +153,24 @@ void atmel_ecc_free(int slot)
} }
/** /* The macros ATCA_TLS_GET_ENC_KEY can be set to override the default
* \brief Give enc key to read pms. encryption key with your own at build-time */
*/ #ifndef ATCA_TLS_GET_ENC_KEY
static ATCA_STATUS atmel_get_enc_key(uint8_t* enckey, int16_t keysize) #define ATCA_TLS_GET_ENC_KEY atmel_get_enc_key
{ /**
if (enckey == NULL || keysize != ATECC_KEY_SIZE) { * \brief Give enc key to read pms.
return -1; */
static ATCA_STATUS atmel_get_enc_key(uint8_t* enckey, int16_t keysize)
{
if (enckey == NULL || keysize != ATECC_KEY_SIZE) {
return -1;
}
XMEMSET(enckey, 0xFF, keysize); // use default values
return ATCA_SUCCESS;
} }
#endif
XMEMSET(enckey, 0xFF, keysize); // use default values
return SSL_SUCCESS;
}
/** /**
* \brief Write enc key before. * \brief Write enc key before.
@ -174,16 +178,17 @@ static ATCA_STATUS atmel_get_enc_key(uint8_t* enckey, int16_t keysize)
static int atmel_init_enc_key(void) static int atmel_init_enc_key(void)
{ {
uint8_t ret = 0; uint8_t ret = 0;
uint8_t read_key[ATECC_KEY_SIZE] = { 0 }; uint8_t read_key[ATECC_KEY_SIZE];
ATCA_TLS_GET_ENC_KEY(read_key, sizeof(read_key));
XMEMSET(read_key, 0xFF, sizeof(read_key));
ret = atcatls_set_enckey(read_key, TLS_SLOT_ENC_PARENT, 0); ret = atcatls_set_enckey(read_key, TLS_SLOT_ENC_PARENT, 0);
if (ret != ATCA_SUCCESS) { if (ret != ATCA_SUCCESS) {
WOLFSSL_MSG("Failed to write key"); WOLFSSL_MSG("Failed to write key");
return -1; return -1;
} }
ret = atcatlsfn_set_get_enckey(atmel_get_enc_key); ret = atcatlsfn_set_get_enckey(ATCA_TLS_GET_ENC_KEY);
if (ret != ATCA_SUCCESS) { if (ret != ATCA_SUCCESS) {
WOLFSSL_MSG("Failed to set enckey"); WOLFSSL_MSG("Failed to set enckey");
return -1; return -1;