@@ -2755,7 +2755,9 @@ coap_crypto_aead_encrypt(const coap_crypto_param_t *params,
27552755 size_t * max_result_len ) {
27562756 mbedtls_cipher_context_t ctx ;
27572757 const coap_crypto_aes_ccm_t * ccm ;
2758+ #if (MBEDTLS_VERSION_NUMBER < 0x02150000 )
27582759 unsigned char tag [16 ];
2760+ #endif /* MBEDTLS_VERSION_NUMBER < 0x02150000 */
27592761 int ret = 0 ;
27602762 size_t result_len = * max_result_len ;
27612763 coap_bin_const_t laad ;
@@ -2785,6 +2787,7 @@ coap_crypto_aead_encrypt(const coap_crypto_param_t *params,
27852787 laad .length = 0 ;
27862788 }
27872789
2790+ #if (MBEDTLS_VERSION_NUMBER < 0x02150000 )
27882791 C (mbedtls_cipher_auth_encrypt (& ctx ,
27892792 ccm -> nonce ,
27902793 15 - ccm -> l , /* iv */
@@ -2797,7 +2800,6 @@ coap_crypto_aead_encrypt(const coap_crypto_param_t *params,
27972800 tag ,
27982801 ccm -> tag_len /* tag */
27992802 ));
2800-
28012803 /* check if buffer is sufficient to hold tag */
28022804 if ((result_len + ccm -> tag_len ) > * max_result_len ) {
28032805 coap_log (LOG_ERR , "coap_encrypt: buffer too small\n" );
@@ -2807,6 +2809,23 @@ coap_crypto_aead_encrypt(const coap_crypto_param_t *params,
28072809 memcpy (result + result_len , tag , ccm -> tag_len );
28082810 * max_result_len = result_len + ccm -> tag_len ;
28092811 ret = 1 ;
2812+ #else /* MBEDTLS_VERSION_NUMBER >= 0x02150000 */
2813+ C (mbedtls_cipher_auth_encrypt_ext (& ctx ,
2814+ ccm -> nonce ,
2815+ 15 - ccm -> l , /* iv */
2816+ laad .s ,
2817+ laad .length , /* ad */
2818+ data -> s ,
2819+ data -> length , /* input */
2820+ result ,
2821+ result_len ,
2822+ & result_len , /* output */
2823+ ccm -> tag_len /* tag */
2824+ ));
2825+ * max_result_len = result_len ;
2826+ ret = 1 ;
2827+ #endif /* MBEDTLS_VERSION_NUMBER >= 0x02150000 */
2828+
28102829error :
28112830 mbedtls_cipher_free (& ctx );
28122831 return ret ;
@@ -2820,7 +2839,9 @@ coap_crypto_aead_decrypt(const coap_crypto_param_t *params,
28202839 size_t * max_result_len ) {
28212840 mbedtls_cipher_context_t ctx ;
28222841 const coap_crypto_aes_ccm_t * ccm ;
2842+ #if (MBEDTLS_VERSION_NUMBER < 0x02150000 )
28232843 const unsigned char * tag ;
2844+ #endif /* MBEDTLS_VERSION_NUMBER < 0x02150000 */
28242845 int ret = 0 ;
28252846 size_t result_len = * max_result_len ;
28262847 coap_bin_const_t laad ;
@@ -2856,6 +2877,7 @@ coap_crypto_aead_decrypt(const coap_crypto_param_t *params,
28562877 laad .length = 0 ;
28572878 }
28582879
2880+ #if (MBEDTLS_VERSION_NUMBER < 0x02150000 )
28592881 tag = data -> s + data -> length - ccm -> tag_len ;
28602882 C (mbedtls_cipher_auth_decrypt (& ctx ,
28612883 ccm -> nonce ,
@@ -2869,6 +2891,21 @@ coap_crypto_aead_decrypt(const coap_crypto_param_t *params,
28692891 tag ,
28702892 ccm -> tag_len /* tag */
28712893 ));
2894+ #else /* MBEDTLS_VERSION_NUMBER >= 0x02150000 */
2895+ C (mbedtls_cipher_auth_decrypt_ext (& ctx ,
2896+ ccm -> nonce ,
2897+ 15 - ccm -> l , /* iv */
2898+ laad .s ,
2899+ laad .length , /* ad */
2900+ data -> s ,
2901+ // data->length - ccm->tag_len, /* input */
2902+ data -> length , /* input */
2903+ result ,
2904+ result_len ,
2905+ & result_len , /* output */
2906+ ccm -> tag_len /* tag */
2907+ ));
2908+ #endif /* MBEDTLS_VERSION_NUMBER >= 0x02150000 */
28722909
28732910 * max_result_len = result_len ;
28742911 ret = 1 ;
0 commit comments