@@ -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,9 +305,18 @@ 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 != PSA_SUCCESS)
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 ());
319
+ LogPsaError (status);
318
320
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
319
321
320
322
return CHIP_NO_ERROR;
@@ -323,6 +325,7 @@ CHIP_ERROR PsaKdf::DeriveBytes(const MutableByteSpan & output)
323
325
CHIP_ERROR PsaKdf::DeriveKey (const psa_key_attributes_t & attributes, psa_key_id_t & keyId)
324
326
{
325
327
psa_status_t status = psa_key_derivation_output_key (&attributes, &mOperation , &keyId);
328
+ LogPsaError (status);
326
329
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
327
330
328
331
return CHIP_NO_ERROR;
@@ -367,6 +370,7 @@ CHIP_ERROR HMAC_sha::HMAC_SHA256(const uint8_t * key, size_t key_length, const u
367
370
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
368
371
369
372
exit :
373
+ LogPsaError (status);
370
374
psa_destroy_key (keyId);
371
375
psa_reset_key_attributes (&attrs);
372
376
@@ -476,6 +480,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length
476
480
}
477
481
478
482
exit :
483
+ LogPsaError (status);
479
484
psa_destroy_key (keyId);
480
485
psa_reset_key_attributes (&attrs);
481
486
@@ -519,7 +524,7 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_len
519
524
error = out_signature.SetLength (outputLen);
520
525
521
526
exit :
522
- logPsaError (status);
527
+ LogPsaError (status);
523
528
return error;
524
529
}
525
530
@@ -544,7 +549,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, cons
544
549
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
545
550
546
551
exit :
547
- logPsaError (status);
552
+ LogPsaError (status);
548
553
psa_destroy_key (keyId);
549
554
psa_reset_key_attributes (&attributes);
550
555
@@ -573,7 +578,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, co
573
578
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
574
579
575
580
exit :
576
- logPsaError (status);
581
+ LogPsaError (status);
577
582
psa_destroy_key (keyId);
578
583
psa_reset_key_attributes (&attributes);
579
584
@@ -596,7 +601,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
596
601
SuccessOrExit (error = out_secret.SetLength (outputLength));
597
602
598
603
exit :
599
- logPsaError (status);
604
+ LogPsaError (status);
600
605
601
606
return error;
602
607
}
@@ -671,7 +676,7 @@ CHIP_ERROR P256Keypair::Initialize(ECPKeyTarget key_target)
671
676
mInitialized = true ;
672
677
673
678
exit :
674
- logPsaError (status);
679
+ LogPsaError (status);
675
680
psa_reset_key_attributes (&attributes);
676
681
677
682
return error;
@@ -697,7 +702,7 @@ CHIP_ERROR P256Keypair::Serialize(P256SerializedKeypair & output) const
697
702
error = output.SetLength (bbuf.Needed ());
698
703
699
704
exit :
700
- logPsaError (status);
705
+ LogPsaError (status);
701
706
702
707
return error;
703
708
}
@@ -728,7 +733,7 @@ CHIP_ERROR P256Keypair::Deserialize(P256SerializedKeypair & input)
728
733
mInitialized = true ;
729
734
730
735
exit :
731
- logPsaError (status);
736
+ LogPsaError (status);
732
737
733
738
return error;
734
739
}
0 commit comments