@@ -67,7 +67,6 @@ bool isValidTag(const uint8_t * tag, size_t tag_length)
67
67
}
68
68
69
69
} // namespace
70
-
71
70
CHIP_ERROR AES_CCM_encrypt (const uint8_t * plaintext, size_t plaintext_length, const uint8_t * aad, size_t aad_length,
72
71
const Aes128KeyHandle & key, const uint8_t * nonce, size_t nonce_length, uint8_t * ciphertext,
73
72
uint8_t * tag, size_t tag_length)
@@ -84,38 +83,45 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c
84
83
size_t tag_out_length;
85
84
86
85
status = psa_aead_encrypt_setup (&operation, key.As <psa_key_id_t >(), algorithm);
86
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_encrypt_setup status: %d" , status);
87
87
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
88
88
89
89
status = psa_aead_set_lengths (&operation, aad_length, plaintext_length);
90
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_set_lengths status: %d" , status);
90
91
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
91
92
92
93
status = psa_aead_set_nonce (&operation, nonce, nonce_length);
94
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_set_nonce status: %d" , status);
93
95
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
94
96
95
97
if (aad_length != 0 )
96
98
{
97
99
status = psa_aead_update_ad (&operation, aad, aad_length);
100
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_update_ad status: %d" , status);
98
101
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
99
102
}
100
103
else
101
104
{
102
- ChipLogDetail (Crypto, " AES_CCM_encrypt: Using aad == null path" );
105
+ ChipLogError (Crypto, " AES_CCM_encrypt: Using aad == null path" );
103
106
}
104
107
105
108
if (plaintext_length != 0 )
106
109
{
107
110
status = psa_aead_update (&operation, plaintext, plaintext_length, ciphertext,
108
111
PSA_AEAD_UPDATE_OUTPUT_SIZE (PSA_KEY_TYPE_AES, algorithm, plaintext_length), &out_length);
112
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_update status: %d" , status);
109
113
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
110
114
111
115
ciphertext += out_length;
112
116
113
117
status = psa_aead_finish (&operation, ciphertext, PSA_AEAD_FINISH_OUTPUT_SIZE (PSA_KEY_TYPE_AES, algorithm), &out_length, tag,
114
118
tag_length, &tag_out_length);
119
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_finish status: %d" , status);
115
120
}
116
121
else
117
122
{
118
123
status = psa_aead_finish (&operation, nullptr , 0 , &out_length, tag, tag_length, &tag_out_length);
124
+ ChipLogError (Crypto, " AES_CCM_encrypt: psa_aead_finish status: %d" , status);
119
125
}
120
126
VerifyOrReturnError (status == PSA_SUCCESS && tag_length == tag_out_length, CHIP_ERROR_INTERNAL);
121
127
@@ -137,38 +143,45 @@ CHIP_ERROR AES_CCM_decrypt(const uint8_t * ciphertext, size_t ciphertext_length,
137
143
size_t outLength;
138
144
139
145
status = psa_aead_decrypt_setup (&operation, key.As <psa_key_id_t >(), algorithm);
146
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_decrypt_setup status: %d" , status);
140
147
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
141
148
142
149
status = psa_aead_set_lengths (&operation, aad_length, ciphertext_length);
150
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_set_lengths status: %d" , status);
143
151
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
144
152
145
153
status = psa_aead_set_nonce (&operation, nonce, nonce_length);
154
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_set_nonce status: %d" , status);
146
155
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
147
156
148
157
if (aad_length != 0 )
149
158
{
150
159
status = psa_aead_update_ad (&operation, aad, aad_length);
160
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_update_ad status: %d" , status);
151
161
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
152
162
}
153
163
else
154
164
{
155
- ChipLogDetail (Crypto, " AES_CCM_decrypt: Using aad == null path" );
165
+ ChipLogError (Crypto, " AES_CCM_decrypt: Using aad == null path" );
156
166
}
157
167
158
168
if (ciphertext_length != 0 )
159
169
{
160
170
status = psa_aead_update (&operation, ciphertext, ciphertext_length, plaintext,
161
171
PSA_AEAD_UPDATE_OUTPUT_SIZE (PSA_KEY_TYPE_AES, algorithm, ciphertext_length), &outLength);
172
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_update status: %d" , status);
162
173
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
163
174
164
175
plaintext += outLength;
165
176
166
177
status = psa_aead_verify (&operation, plaintext, PSA_AEAD_VERIFY_OUTPUT_SIZE (PSA_KEY_TYPE_AES, algorithm), &outLength, tag,
167
178
tag_length);
179
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_verify status: %d" , status);
168
180
}
169
181
else
170
182
{
171
183
status = psa_aead_verify (&operation, nullptr , 0 , &outLength, tag, tag_length);
184
+ ChipLogError (Crypto, " AES_CCM_decrypt: psa_aead_verify status: %d" , status);
172
185
}
173
186
174
187
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
@@ -182,6 +195,7 @@ CHIP_ERROR Hash_SHA256(const uint8_t * data, const size_t data_length, uint8_t *
182
195
183
196
const psa_status_t status =
184
197
psa_hash_compute (PSA_ALG_SHA_256, data, data_length, out_buffer, PSA_HASH_LENGTH (PSA_ALG_SHA_256), &outLength);
198
+ ChipLogError (Crypto, " Hash_SHA256: psa_hash_compute status: %d" , status);
185
199
186
200
return status == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL;
187
201
}
@@ -192,6 +206,7 @@ CHIP_ERROR Hash_SHA1(const uint8_t * data, const size_t data_length, uint8_t * o
192
206
193
207
const psa_status_t status =
194
208
psa_hash_compute (PSA_ALG_SHA_1, data, data_length, out_buffer, PSA_HASH_LENGTH (PSA_ALG_SHA_1), &outLength);
209
+ ChipLogError (Crypto, " Hash_SHA1: psa_hash_compute status: %d" , status);
195
210
196
211
return status == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL;
197
212
}
@@ -220,13 +235,15 @@ CHIP_ERROR Hash_SHA256_stream::Begin()
220
235
{
221
236
toHashOperation (mContext ) = PSA_HASH_OPERATION_INIT;
222
237
const psa_status_t status = psa_hash_setup (toHashOperation (&mContext ), PSA_ALG_SHA_256);
238
+ ChipLogError (Crypto, " Hash_SHA256_stream::Begin: psa_hash_setup status: %d" , status);
223
239
224
240
return status == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL;
225
241
}
226
242
227
243
CHIP_ERROR Hash_SHA256_stream::AddData (const ByteSpan data)
228
244
{
229
245
const psa_status_t status = psa_hash_update (toHashOperation (&mContext ), data.data (), data.size ());
246
+ ChipLogError (Crypto, " Hash_SHA256_stream::AddData: psa_hash_update status: %d" , status);
230
247
231
248
return status == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL;
232
249
}
@@ -241,9 +258,11 @@ CHIP_ERROR Hash_SHA256_stream::GetDigest(MutableByteSpan & out_buffer)
241
258
size_t outLength;
242
259
243
260
status = psa_hash_clone (toHashOperation (&mContext ), &operation);
261
+ ChipLogError (Crypto, " Hash_SHA256_stream::GetDigest: psa_hash_clone status: %d" , status);
244
262
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
245
263
246
264
status = psa_hash_finish (&operation, out_buffer.data (), out_buffer.size (), &outLength);
265
+ ChipLogError (Crypto, " Hash_SHA256_stream::GetDigest: psa_hash_finish status: %d" , status);
247
266
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
248
267
out_buffer.reduce_size (outLength);
249
268
@@ -260,6 +279,7 @@ CHIP_ERROR Hash_SHA256_stream::Finish(MutableByteSpan & out_buffer)
260
279
size_t outLength;
261
280
262
281
const psa_status_t status = psa_hash_finish (toHashOperation (&mContext ), out_buffer.data (), out_buffer.size (), &outLength);
282
+ ChipLogError (Crypto, " Hash_SHA256_stream::Finish: psa_hash_finish status: %d" , status);
263
283
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
264
284
out_buffer.reduce_size (outLength);
265
285
@@ -281,6 +301,7 @@ CHIP_ERROR PsaKdf::Init(const ByteSpan & secret, const ByteSpan & salt, const By
281
301
psa_set_key_usage_flags (&attrs, PSA_KEY_USAGE_DERIVE);
282
302
283
303
status = psa_import_key (&attrs, secret.data (), secret.size (), &mSecretKeyId );
304
+ ChipLogError (Crypto, " PsaKdf::Init: psa_import_key status: %d" , status);
284
305
psa_reset_key_attributes (&attrs);
285
306
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
286
307
@@ -291,22 +312,25 @@ CHIP_ERROR PsaKdf::Init(const HkdfKeyHandle & hkdfKey, const ByteSpan & salt, co
291
312
{
292
313
return InitOperation (hkdfKey.As <psa_key_id_t >(), salt, info);
293
314
}
294
-
295
315
CHIP_ERROR PsaKdf::InitOperation (psa_key_id_t hkdfKey, const ByteSpan & salt, const ByteSpan & info)
296
316
{
297
317
psa_status_t status = psa_key_derivation_setup (&mOperation , PSA_ALG_HKDF (PSA_ALG_SHA_256));
318
+ ChipLogError (Crypto, " PsaKdf::InitOperation: psa_key_derivation_setup status: %d" , status);
298
319
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
299
320
300
321
if (salt.size () > 0 )
301
322
{
302
323
status = psa_key_derivation_input_bytes (&mOperation , PSA_KEY_DERIVATION_INPUT_SALT, salt.data (), salt.size ());
324
+ ChipLogError (Crypto, " PsaKdf::InitOperation: psa_key_derivation_input_bytes (salt) status: %d" , status);
303
325
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
304
326
}
305
327
306
328
status = psa_key_derivation_input_key (&mOperation , PSA_KEY_DERIVATION_INPUT_SECRET, hkdfKey);
329
+ ChipLogError (Crypto, " PsaKdf::InitOperation: psa_key_derivation_input_key status: %d" , status);
307
330
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
308
331
309
332
status = psa_key_derivation_input_bytes (&mOperation , PSA_KEY_DERIVATION_INPUT_INFO, info.data (), info.size ());
333
+ ChipLogError (Crypto, " PsaKdf::InitOperation: psa_key_derivation_input_bytes (info) status: %d" , status);
310
334
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
311
335
312
336
return CHIP_NO_ERROR;
@@ -315,6 +339,7 @@ CHIP_ERROR PsaKdf::InitOperation(psa_key_id_t hkdfKey, const ByteSpan & salt, co
315
339
CHIP_ERROR PsaKdf::DeriveBytes (const MutableByteSpan & output)
316
340
{
317
341
psa_status_t status = psa_key_derivation_output_bytes (&mOperation , output.data (), output.size ());
342
+ ChipLogError (Crypto, " PsaKdf::DeriveBytes: psa_key_derivation_output_bytes status: %d" , status);
318
343
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
319
344
320
345
return CHIP_NO_ERROR;
@@ -323,6 +348,7 @@ CHIP_ERROR PsaKdf::DeriveBytes(const MutableByteSpan & output)
323
348
CHIP_ERROR PsaKdf::DeriveKey (const psa_key_attributes_t & attributes, psa_key_id_t & keyId)
324
349
{
325
350
psa_status_t status = psa_key_derivation_output_key (&attributes, &mOperation , &keyId);
351
+ ChipLogError (Crypto, " PsaKdf::DeriveKey: psa_key_derivation_output_key status: %d" , status);
326
352
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
327
353
328
354
return CHIP_NO_ERROR;
@@ -361,9 +387,11 @@ CHIP_ERROR HMAC_sha::HMAC_SHA256(const uint8_t * key, size_t key_length, const u
361
387
psa_set_key_usage_flags (&attrs, PSA_KEY_USAGE_SIGN_HASH);
362
388
363
389
status = psa_import_key (&attrs, key, key_length, &keyId);
390
+ ChipLogError (Crypto, " HMAC_sha::HMAC_SHA256: psa_import_key status: %d" , status);
364
391
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
365
392
366
393
status = psa_mac_compute (keyId, algorithm, message, message_length, out_buffer, out_length, &out_length);
394
+ ChipLogError (Crypto, " HMAC_sha::HMAC_SHA256: psa_mac_compute status: %d" , status);
367
395
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
368
396
369
397
exit :
@@ -383,6 +411,7 @@ CHIP_ERROR HMAC_sha::HMAC_SHA256(const Hmac128KeyHandle & key, const uint8_t * m
383
411
psa_status_t status = PSA_SUCCESS;
384
412
385
413
status = psa_mac_compute (key.As <psa_key_id_t >(), algorithm, message, message_length, out_buffer, out_length, &out_length);
414
+ ChipLogError (Crypto, " HMAC_sha::HMAC_SHA256: psa_mac_compute status: %d" , status);
386
415
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
387
416
388
417
return CHIP_NO_ERROR;
@@ -423,7 +452,6 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length
423
452
424
453
return error;
425
454
*/
426
-
427
455
VerifyOrReturnError (isBufferNonEmpty (pass, pass_length), CHIP_ERROR_INVALID_ARGUMENT);
428
456
VerifyOrReturnError (salt != nullptr && salt_length >= kSpake2p_Min_PBKDF_Salt_Length &&
429
457
salt_length <= kSpake2p_Max_PBKDF_Salt_Length ,
@@ -442,6 +470,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length
442
470
psa_set_key_usage_flags (&attrs, PSA_KEY_USAGE_SIGN_HASH);
443
471
444
472
status = psa_import_key (&attrs, pass, pass_length, &keyId);
473
+ ChipLogError (Crypto, " pbkdf2_sha256: psa_import_key status: %d" , status);
445
474
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
446
475
447
476
for (uint32_t blockNo = 1 ; key_length != 0 ; ++blockNo)
@@ -458,6 +487,7 @@ CHIP_ERROR PBKDF2_sha256::pbkdf2_sha256(const uint8_t * pass, size_t pass_length
458
487
for (size_t iteration = 0 ; iteration < iteration_count; ++iteration)
459
488
{
460
489
status = psa_mac_compute (keyId, algorithm, in, inLength, out, sizeof (out), &outLength);
490
+ ChipLogError (Crypto, " pbkdf2_sha256: psa_mac_compute status: %d" , status);
461
491
VerifyOrExit (status == PSA_SUCCESS && outLength == kMacLength , error = CHIP_ERROR_INTERNAL);
462
492
463
493
for (size_t byteNo = 0 ; byteNo < kMacLength ; ++byteNo)
@@ -492,6 +522,7 @@ CHIP_ERROR DRBG_get_bytes(uint8_t * out_buffer, const size_t out_length)
492
522
VerifyOrReturnError (isBufferNonEmpty (out_buffer, out_length), CHIP_ERROR_INVALID_ARGUMENT);
493
523
494
524
const psa_status_t status = psa_generate_random (out_buffer, out_length);
525
+ ChipLogError (Crypto, " DRBG_get_bytes: psa_generate_random status: %d" , status);
495
526
496
527
return status == PSA_SUCCESS ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL;
497
528
}
@@ -513,6 +544,7 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_len
513
544
514
545
status = psa_sign_message (context.key_id , PSA_ALG_ECDSA (PSA_ALG_SHA_256), msg, msg_length, out_signature.Bytes (),
515
546
out_signature.Capacity (), &outputLen);
547
+ ChipLogError (Crypto, " ECDSA_sign_msg: psa_sign_message status: %d" , status);
516
548
517
549
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
518
550
VerifyOrExit (outputLen == kP256_ECDSA_Signature_Length_Raw , error = CHIP_ERROR_INTERNAL);
@@ -538,9 +570,11 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, cons
538
570
psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_VERIFY_MESSAGE);
539
571
540
572
status = psa_import_key (&attributes, ConstBytes (), Length (), &keyId);
573
+ ChipLogError (Crypto, " ECDSA_validate_msg_signature: psa_import_key status: %d" , status);
541
574
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
542
575
543
576
status = psa_verify_message (keyId, PSA_ALG_ECDSA (PSA_ALG_SHA_256), msg, msg_length, signature.ConstBytes (), signature.Length ());
577
+ ChipLogError (Crypto, " ECDSA_validate_msg_signature: psa_verify_message status: %d" , status);
544
578
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
545
579
546
580
exit :
@@ -567,9 +601,11 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, co
567
601
psa_set_key_algorithm (&attributes, PSA_ALG_ECDSA (PSA_ALG_SHA_256));
568
602
569
603
status = psa_import_key (&attributes, ConstBytes (), Length (), &keyId);
604
+ ChipLogError (Crypto, " ECDSA_validate_hash_signature: psa_import_key status: %d" , status);
570
605
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
571
606
572
607
status = psa_verify_hash (keyId, PSA_ALG_ECDSA (PSA_ALG_SHA_256), hash, hash_length, signature.ConstBytes (), signature.Length ());
608
+ ChipLogError (Crypto, " ECDSA_validate_hash_signature: psa_verify_hash status: %d" , status);
573
609
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INVALID_SIGNATURE);
574
610
575
611
exit :
@@ -592,6 +628,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
592
628
593
629
status = psa_raw_key_agreement (PSA_ALG_ECDH, context.key_id , remote_public_key.ConstBytes (), remote_public_key.Length (),
594
630
out_secret.Bytes (), outputSize, &outputLength);
631
+ ChipLogError (Crypto, " ECDH_derive_secret: psa_raw_key_agreement status: %d" , status);
595
632
VerifyOrExit (status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
596
633
SuccessOrExit (error = out_secret.SetLength (outputLength));
597
634
0 commit comments