Skip to content

Commit

Permalink
Fix missing mInitialized = true flag in PSA LoadKeypairFromRaw() method
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Bridge <[email protected]>
  • Loading branch information
adbridge committed Jun 14, 2023
1 parent 8f19cc9 commit 0befd81
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/crypto/CHIPCryptoPALPSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,49 +715,49 @@ CHIP_ERROR P256Keypair::LoadKeypairFromRaw(ByteSpan private_key, ByteSpan public
psa_key_attributes_t attributes = configure_ecc_key_pair_attributes();
psa_key_id_t key_id;
psa_status_t status;
CHIP_ERROR error = CHIP_NO_ERROR;

status = psa_import_key(&attributes, private_key.data(), kP256_PrivateKey_Length, &key_id);
VerifyOrReturnError(status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

memcpy(mPublicKey.Bytes(), public_key.data(), kP256_PublicKey_Length);
memcpy(mKeypair.mBytes, &key_id, sizeof(psa_key_id_t));
mInitialized = true;

return error;
return CHIP_NO_ERROR;
}

CHIP_ERROR P256Keypair::LoadKeypairFromRaw(const ByteSpan & key_pair)
{
psa_key_attributes_t attributes = configure_ecc_key_pair_attributes();
psa_key_id_t key_id;
psa_status_t status;
CHIP_ERROR error = CHIP_NO_ERROR;

status = psa_import_key(&attributes, key_pair.data() + kP256_PublicKey_Length, kP256_PrivateKey_Length, &key_id);
VerifyOrReturnError(status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

memcpy(mPublicKey.Bytes(), key_pair.data(), kP256_PublicKey_Length);
memcpy(mKeypair.mBytes, &key_id, sizeof(psa_key_id_t));
mInitialized = true;

return error;
return CHIP_NO_ERROR;
}

CHIP_ERROR P256Keypair::LoadKeypairFromRaw(const uint8_t * key_data, size_t key_data_size)
{
psa_key_attributes_t attributes = configure_ecc_key_pair_attributes();
psa_key_id_t key_id;
psa_status_t status;
CHIP_ERROR error = CHIP_NO_ERROR;

VerifyOrReturnError(key_data_size == kP256_PublicKey_Length + kP256_PrivateKey_Length, error = CHIP_ERROR_INTERNAL);
VerifyOrReturnError(key_data_size == kP256_PublicKey_Length + kP256_PrivateKey_Length, CHIP_ERROR_INTERNAL);

status = psa_import_key(&attributes, key_data + kP256_PublicKey_Length, kP256_PrivateKey_Length, &key_id);
VerifyOrReturnError(status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

memcpy(mPublicKey.Bytes(), key_data, kP256_PublicKey_Length);
memcpy(mKeypair.mBytes, &key_id, sizeof(psa_key_id_t));
mInitialized = true;

return error;
return CHIP_NO_ERROR;
}

CHIP_ERROR P256Keypair::Serialize(P256SerializedKeypair & output) const
Expand Down

0 comments on commit 0befd81

Please sign in to comment.