Skip to content

Commit

Permalink
add clarifications. rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs committed Nov 8, 2023
1 parent 2e100f0 commit fd19007
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/platform/silabs/efr32/Efr32OpaqueKeypair.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class EFR32OpaqueKeypair
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR Delete();
CHIP_ERROR DestroyKey();

protected:
void * mContext = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/silabs/efr32/Efr32PsaOpaqueKeypair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ EFR32OpaqueKeypair::~EFR32OpaqueKeypair()
// Delete volatile keys, since nobody else can after we drop the key ID.
if (!mIsPersistent)
{
Delete();
DestroyKey();
}

MemoryFree(mContext);
Expand All @@ -145,7 +145,7 @@ CHIP_ERROR EFR32OpaqueKeypair::Load(EFR32OpaqueKeyId opaque_id)
// If the object contains a volatile key, clean it up before reusing the object storage
if (mHasKey && !mIsPersistent)
{
Delete();
DestroyKey();
}

key_id = psa_key_id_from_opaque(opaque_id);
Expand Down Expand Up @@ -342,7 +342,7 @@ CHIP_ERROR EFR32OpaqueKeypair::Derive(const uint8_t * their_key, size_t their_ke
return error;
}

CHIP_ERROR EFR32OpaqueKeypair::Delete()
CHIP_ERROR EFR32OpaqueKeypair::DestroyKey()
{
CHIP_ERROR error = CHIP_NO_ERROR;
psa_status_t status = PSA_ERROR_BAD_STATE;
Expand Down
8 changes: 4 additions & 4 deletions src/platform/silabs/efr32/Efr32PsaOperationalKeystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::NewOpKeypairForFabric(FabricIndex fabric
}
else
{
mPendingKeypair->Delete();
mPendingKeypair->DestroyKey();
if (id == kEFR32OpaqueKeyIdVolatile)
{
id = kEFR32OpaqueKeyIdUnknown;
Expand Down Expand Up @@ -313,7 +313,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::CommitOpKeypairForFabric(FabricIndex fab
// There's a good chance we'll need the key again soon
mCachedKey->Load(id);

ResetPendingKey(true /* keepOpaqueKey */);
ResetPendingKey(true /* keepKeyPairInStorage */);

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::RemoveOpKeypairForFabric(FabricIndex fab
if (id == cachedId)
{
// Delete from persistent storage and unload
mCachedKey->Delete();
mCachedKey->DestroyKey();
return CHIP_NO_ERROR;
}

Expand All @@ -370,7 +370,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::RemoveOpKeypairForFabric(FabricIndex fab
return CHIP_ERROR_INTERNAL;
}

mCachedKey->Delete();
mCachedKey->DestroyKey();

return CHIP_NO_ERROR;
}
Expand Down
15 changes: 8 additions & 7 deletions src/platform/silabs/efr32/Efr32PsaOperationalKeystore.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ class Efr32PsaOperationalKeystore : public chip::Crypto::OperationalKeystore
bool mIsInitialized = false;

private:
void ResetPendingKey(bool keepOpaqueKey = false)
void ResetPendingKey(bool keepKeyPairInStorage = false)
{
if (mPendingKeypair != nullptr)
if (mPendingKeypair != nullptr && !keepKeyPairInStorage)
{
if (!keepOpaqueKey)
{
mPendingKeypair->Delete();
}
Platform::Delete(mPendingKeypair);
// This removes the PSA Keypair from storage and unloads it
// using the EFR32OpaqueKeypair context.
// We destroy it when the OperationKeyStore process failed.
mPendingKeypair->DestroyKey();
}

Platform::Delete(mPendingKeypair);
mPendingKeypair = nullptr;
mIsPendingKeypairActive = false;
mPendingFabricIndex = kUndefinedFabricIndex;
Expand Down

0 comments on commit fd19007

Please sign in to comment.