Merge pull request #2052 from dgarske/atecc_fixes

Fixes for ATECC with PMS outlen and `ATECC_MAX_SLOT`
This commit is contained in:
toddouska
2019-01-25 14:26:09 -08:00
committed by GitHub
6 changed files with 36 additions and 30 deletions

View File

@ -102,7 +102,7 @@ void my_atmel_free(int slotId)
{
ESP_LOGI(TAG, "Enter my_atmel_alloc");
if(slotId >= 0 && slotId <= ATECC_MAX_SLOT){
if(slotId >= 0 && slotId < ATECC_MAX_SLOT){
mSlotList[slotId] = ATECC_INVALID_SLOT;
}

View File

@ -111,7 +111,7 @@ int my_atmel_alloc(int slotType)
/* free slot array */
void my_atmel_free(int slotId)
{
if(slotId >= 0 && slotId <= ATECC_MAX_SLOT){
if(slotId >= 0 && slotId < ATECC_MAX_SLOT){
mSlotList[slotId] = ATECC_INVALID_SLOT;
}
}

View File

@ -115,7 +115,7 @@ int my_atmel_alloc(int slotType)
/* free slot array */
void my_atmel_free(int slotId)
{
if(slotId >= 0 && slotId <= ATECC_MAX_SLOT){
if(slotId >= 0 && slotId < ATECC_MAX_SLOT){
mSlotList[slotId] = ATECC_INVALID_SLOT;
}
}

View File

@ -3897,6 +3897,7 @@ static int wc_ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
#else
(void)curveIn;
err = NOT_COMPILED_IN;
#endif /* WOLFSSL_ATECC508A */
/* change key state if public part is cached */
@ -3927,7 +3928,7 @@ int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut)
int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
{
int err;
int err;
#ifndef WOLFSSL_ATECC508A
#ifndef WOLFSSL_SP_MATH
DECLARE_CURVE_SPECS(curve, ECC_CURVE_FIELD_COUNT);
@ -3974,19 +3975,24 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id)
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
#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);
if (curve_id == ECC_SECP256R1) {
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 */
if (err == 0 && key->pubkey.x) {
err = mp_read_unsigned_bin(key->pubkey.x, key->pubkey_raw,
ECC_MAX_CRYPTO_HW_SIZE);
/* populate key->pubkey */
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);
}
}
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 {
err = NOT_COMPILED_IN;
}
#else

View File

@ -402,7 +402,7 @@ int atmel_init(void)
#endif
/* Init the free slotId list */
for (i=0; i<=ATECC_MAX_SLOT; i++) {
for (i=0; i<ATECC_MAX_SLOT; i++) {
if (i == ATECC_SLOT_AUTH_PRIV || i == ATECC_SLOT_I2C_ENC) {
mSlotList[i] = i;
}
@ -603,7 +603,7 @@ int atcatls_create_pms_cb(WOLFSSL* ssl, ecc_key* otherKey,
}
ret = atmel_ecc_create_pms(tmpKey.slot, peerKey, out);
*outlen = ATECC_SIG_SIZE;
*outlen = ATECC_KEY_SIZE;
#ifndef WOLFSSL_ATECC508A_NOIDLE
/* put chip into idle to prevent watchdog situation on chip */

View File

@ -39,7 +39,7 @@
#define ATECC_PUBKEY_SIZE (ATECC_KEY_SIZE*2) /* X and Y */
#define ATECC_SIG_SIZE (ATECC_KEY_SIZE*2) /* R and S */
#ifndef ATECC_MAX_SLOT
#define ATECC_MAX_SLOT (0x7) /* Only use 0-7 */
#define ATECC_MAX_SLOT (0x8) /* Only use 0-7 */
#endif
#define ATECC_INVALID_SLOT (0xFF)