@@ -353,7 +353,7 @@ int ataes132a_aes_ccm_decrypt(const struct device *dev,
353
353
return - EINVAL ;
354
354
}
355
355
356
- if (out_len < 2 || out_len > 33 ) {
356
+ if (! IN_RANGE ( out_len , 2 , 33 ) ) {
357
357
LOG_ERR ("decrypt command response has invalid"
358
358
" size %d" , out_len );
359
359
k_sem_give (& data -> device_sem );
@@ -394,7 +394,14 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
394
394
uint8_t buf_len ;
395
395
uint8_t out_len ;
396
396
uint8_t return_code ;
397
- uint8_t param_buffer [40 ];
397
+
398
+ const uint8_t key_id_len = 1 ;
399
+ const uint8_t buf_len_len = 1 ;
400
+ const uint8_t max_input_len = 32 ;
401
+ const uint8_t nonce_len = 12 ;
402
+ const uint8_t tag_len = 16 ;
403
+
404
+ uint8_t param_buffer [key_id_len + buf_len_len + max_input_len + nonce_len + tag_len ];
398
405
399
406
if (!aead_op ) {
400
407
LOG_ERR ("Parameter cannot be null" );
@@ -525,7 +532,7 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
525
532
return - EINVAL ;
526
533
}
527
534
528
- if (out_len < 33 || out_len > 49 ) {
535
+ if (! IN_RANGE ( out_len , 33 , 49 ) ) {
529
536
LOG_ERR ("encrypt command response has invalid"
530
537
" size %d" , out_len );
531
538
k_sem_give (& data -> device_sem );
@@ -542,6 +549,7 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
542
549
if (aead_op -> tag ) {
543
550
memcpy (aead_op -> tag , param_buffer + 1 , 16 );
544
551
}
552
+
545
553
memcpy (aead_op -> pkt -> out_buf , param_buffer + 17 , out_len - 17U );
546
554
547
555
if (mac_mode ) {
0 commit comments