@@ -48,14 +48,6 @@ namespace Crypto {
48
48
49
49
namespace {
50
50
51
- void logPsaError (psa_status_t status)
52
- {
53
- if (status != 0 )
54
- {
55
- ChipLogError (Crypto, " PSA error: %d" , static_cast <int >(status));
56
- }
57
- }
58
-
59
51
bool isBufferNonEmpty (const uint8_t * data, size_t data_length)
60
52
{
61
53
return data != nullptr && data_length > 0 ;
@@ -281,6 +273,7 @@ CHIP_ERROR PsaKdf::Init(const ByteSpan & secret, const ByteSpan & salt, const By
281
273
psa_set_key_usage_flags (&attrs, PSA_KEY_USAGE_DERIVE);
282
274
283
275
status = psa_import_key (&attrs, secret.data (), secret.size (), &mSecretKeyId );
276
+ LogPsaError (status);
284
277
psa_reset_key_attributes (&attrs);
285
278
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
286
279
@@ -312,6 +305,14 @@ CHIP_ERROR PsaKdf::InitOperation(psa_key_id_t hkdfKey, const ByteSpan & salt, co
312
305
return CHIP_NO_ERROR;
313
306
}
314
307
308
+ void LogPsaError (psa_status_t status)
309
+ {
310
+ if (status != 0 )
311
+ {
312
+ ChipLogError (Crypto, " PSA error: %d" , static_cast <int >(status));
313
+ }
314
+ }
315
+
315
316
CHIP_ERROR PsaKdf::DeriveBytes (const MutableByteSpan & output)
316
317
{
317
318
psa_status_t status = psa_key_derivation_output_bytes (&mOperation , output.data (), output.size ());
@@ -367,6 +368,7 @@ CHIP_ERROR HMAC_sha::HMAC_SHA256(const uint8_t * key, size_t key_length, const u
367
368
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
368
369
369
370
exit :
371
+ LogPsaError (status);
370
372
psa_destroy_key (keyId);
371
373
psa_reset_key_attributes (&attrs);
372
374
@@ -476,6 +478,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length
476
478
}
477
479
478
480
exit :
481
+ LogPsaError (status);
479
482
psa_destroy_key (keyId);
480
483
psa_reset_key_attributes (&attrs);
481
484
@@ -519,7 +522,7 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_len
519
522
error = out_signature.SetLength (outputLen);
520
523
521
524
exit :
522
- logPsaError (status);
525
+ LogPsaError (status);
523
526
return error;
524
527
}
525
528
@@ -544,7 +547,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, cons
544
547
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
545
548
546
549
exit :
547
- logPsaError (status);
550
+ LogPsaError (status);
548
551
psa_destroy_key (keyId);
549
552
psa_reset_key_attributes (&attributes);
550
553
@@ -573,7 +576,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, co
573
576
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
574
577
575
578
exit :
576
- logPsaError (status);
579
+ LogPsaError (status);
577
580
psa_destroy_key (keyId);
578
581
psa_reset_key_attributes (&attributes);
579
582
@@ -596,7 +599,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
596
599
SuccessOrExit (error = out_secret.SetLength (outputLength));
597
600
598
601
exit :
599
- logPsaError (status);
602
+ LogPsaError (status);
600
603
601
604
return error;
602
605
}
@@ -671,7 +674,7 @@ CHIP_ERROR P256Keypair::Initialize(ECPKeyTarget key_target)
671
674
mInitialized = true ;
672
675
673
676
exit :
674
- logPsaError (status);
677
+ LogPsaError (status);
675
678
psa_reset_key_attributes (&attributes);
676
679
677
680
return error;
@@ -697,7 +700,7 @@ CHIP_ERROR P256Keypair::Serialize(P256SerializedKeypair & output) const
697
700
error = output.SetLength (bbuf.Needed ());
698
701
699
702
exit :
700
- logPsaError (status);
703
+ LogPsaError (status);
701
704
702
705
return error;
703
706
}
@@ -728,7 +731,7 @@ CHIP_ERROR P256Keypair::Deserialize(P256SerializedKeypair & input)
728
731
mInitialized = true ;
729
732
730
733
exit :
731
- logPsaError (status);
734
+ LogPsaError (status);
732
735
733
736
return error;
734
737
}
0 commit comments