Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejbaczmanski committed Sep 3, 2024
1 parent b04344c commit d97f8fa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/crypto/PSASessionKeystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ CHIP_ERROR PSASessionKeystore::PersistICDKey(Aes128KeyHandle & key)
CHIP_ERROR err;
AesKeyAttributes attrs;
psa_key_id_t previousKeyId = key.As<psa_key_id_t>();
psa_key_attributes_t previousKeyAttrs;

psa_get_key_attributes(previousKeyId, &previousKeyAttrs);
// Exit early if key is already persistent
if (psa_get_key_lifetime(&previousKeyAttrs) == PSA_KEY_LIFETIME_PERSISTENT)
{
ExitNow(err = CHIP_NO_ERROR);
}

SuccessOrExit(err = Crypto::FindFreeKeySlotInRange(key.AsMutable<psa_key_id_t>(),
to_underlying(KeyIdOptional::ICDAesKeyRangeStart), kMaxICDClientKeys));
Expand All @@ -221,6 +229,14 @@ CHIP_ERROR PSASessionKeystore::PersistICDKey(Hmac128KeyHandle & key)
CHIP_ERROR err;
HmacKeyAttributes attrs;
psa_key_id_t previousKeyId = key.As<psa_key_id_t>();
psa_key_attributes_t previousKeyAttrs;

psa_get_key_attributes(previousKeyId, &previousKeyAttrs);
// Exit early if key is already persistent
if (psa_get_key_lifetime(&previousKeyAttrs) == PSA_KEY_LIFETIME_PERSISTENT)
{
ExitNow(err = CHIP_NO_ERROR);
}

SuccessOrExit(err = Crypto::FindFreeKeySlotInRange(key.AsMutable<psa_key_id_t>(),
to_underlying(KeyIdOptional::ICDHmacKeyRangeStart), kMaxICDClientKeys));
Expand Down

0 comments on commit d97f8fa

Please sign in to comment.