@@ -353,7 +353,7 @@ int ataes132a_aes_ccm_decrypt(const struct device *dev,
353353 return - EINVAL ;
354354 }
355355
356- if (out_len < 2 || out_len > 33 ) {
356+ if (! IN_RANGE ( out_len , 2 , 33 ) ) {
357357 LOG_ERR ("decrypt command response has invalid"
358358 " size %d" , out_len );
359359 k_sem_give (& data -> device_sem );
@@ -394,7 +394,14 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
394394 uint8_t buf_len ;
395395 uint8_t out_len ;
396396 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 ];
398405
399406 if (!aead_op ) {
400407 LOG_ERR ("Parameter cannot be null" );
@@ -525,7 +532,7 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
525532 return - EINVAL ;
526533 }
527534
528- if (out_len < 33 || out_len > 49 ) {
535+ if (! IN_RANGE ( out_len , 33 , 49 ) ) {
529536 LOG_ERR ("encrypt command response has invalid"
530537 " size %d" , out_len );
531538 k_sem_give (& data -> device_sem );
@@ -542,6 +549,7 @@ int ataes132a_aes_ccm_encrypt(const struct device *dev,
542549 if (aead_op -> tag ) {
543550 memcpy (aead_op -> tag , param_buffer + 1 , 16 );
544551 }
552+
545553 memcpy (aead_op -> pkt -> out_buf , param_buffer + 17 , out_len - 17U );
546554
547555 if (mac_mode ) {
0 commit comments