From e78ddfce75cbe8cdfcc06023c27add3141f93fa4 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 6 Sep 2018 12:06:50 -0700 Subject: [PATCH] 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. --- wolfcrypt/src/ecc.c | 5 +++++ wolfcrypt/src/port/atmel/atmel.c | 37 ++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index b2db1674c..e32da813a 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -6329,6 +6329,11 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key, inLen -= 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) { #ifdef HAVE_COMP_KEY /* adjust inLen if compressed */ diff --git a/wolfcrypt/src/port/atmel/atmel.c b/wolfcrypt/src/port/atmel/atmel.c index e45a716ba..d3b1dcbf4 100644 --- a/wolfcrypt/src/port/atmel/atmel.c +++ b/wolfcrypt/src/port/atmel/atmel.c @@ -153,20 +153,24 @@ void atmel_ecc_free(int slot) } -/** - * \brief Give enc key to read pms. - */ -static ATCA_STATUS atmel_get_enc_key(uint8_t* enckey, int16_t keysize) -{ - if (enckey == NULL || keysize != ATECC_KEY_SIZE) { - return -1; +/* The macros ATCA_TLS_GET_ENC_KEY can be set to override the default + encryption key with your own at build-time */ +#ifndef ATCA_TLS_GET_ENC_KEY + #define ATCA_TLS_GET_ENC_KEY atmel_get_enc_key + /** + * \brief Give enc key to read pms. + */ + 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; } - - XMEMSET(enckey, 0xFF, keysize); // use default values - - return SSL_SUCCESS; -} - +#endif /** * \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) { 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); if (ret != ATCA_SUCCESS) { WOLFSSL_MSG("Failed to write key"); 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) { WOLFSSL_MSG("Failed to set enckey"); return -1;