@@ -106,15 +106,14 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c
106
106
const Aes128KeyHandle & key, const uint8_t * nonce, size_t nonce_length, uint8_t * ciphertext,
107
107
uint8_t * tag, size_t tag_length)
108
108
{
109
- ChipLogDetail (Crypto, " ~~~ AES_CCM_encrypt, pl:%u" , (unsigned )plaintext_length);
110
109
VerifyOrReturnError (IsBufferNonEmpty (nonce, nonce_length), CHIP_ERROR_INVALID_ARGUMENT);
111
110
VerifyOrReturnError (IsValidTag (tag, tag_length), CHIP_ERROR_INVALID_ARGUMENT);
112
111
VerifyOrReturnError ((ciphertext != nullptr && plaintext != nullptr ) || plaintext_length == 0 , CHIP_ERROR_INVALID_ARGUMENT);
113
112
VerifyOrReturnError (aad != nullptr || aad_length == 0 , CHIP_ERROR_INVALID_ARGUMENT);
114
113
115
114
const psa_algorithm_t algorithm = PSA_ALG_AEAD_WITH_SHORTENED_TAG (PSA_ALG_CCM, tag_length);
116
- psa_status_t status = PSA_SUCCESS;
117
115
psa_aead_operation_t operation = PSA_AEAD_OPERATION_INIT;
116
+ psa_status_t status = PSA_SUCCESS;
118
117
size_t out_length = 0 ;
119
118
size_t tag_out_length = 0 ;
120
119
@@ -127,14 +126,14 @@ CHIP_ERROR AES_CCM_encrypt(const uint8_t * plaintext, size_t plaintext_length, c
127
126
status = psa_aead_set_nonce (&operation, nonce, nonce_length);
128
127
VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
129
128
130
- if (aad_length != 0 )
129
+ if (0 == aad_length )
131
130
{
132
- status = psa_aead_update_ad (&operation, aad, aad_length);
133
- VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
131
+ ChipLogDetail (Crypto, " AES_CCM_encrypt: Using aad == null path" );
134
132
}
135
133
else
136
134
{
137
- ChipLogDetail (Crypto, " AES_CCM_encrypt: Using aad == null path" );
135
+ status = psa_aead_update_ad (&operation, aad, aad_length);
136
+ VerifyOrReturnError (status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);
138
137
}
139
138
140
139
if (0 == plaintext_length)
0 commit comments