@@ -177,9 +177,13 @@ aead_cipher_encrypt(cipher_ctx_t *cipher_ctx,
177177 // Otherwise, just use the mbedTLS one with crappy AES-NI.
178178 case AES192GCM :
179179 case AES128GCM :
180-
180+ #if MBEDTLS_VERSION_NUMBER < 0x03000000
181181 err = mbedtls_cipher_auth_encrypt (cipher_ctx -> evp , n , nlen , ad , adlen ,
182182 m , mlen , c , clen , c + mlen , tlen );
183+ #else
184+ err = mbedtls_cipher_auth_encrypt_ext (cipher_ctx -> evp , n , nlen , ad , adlen ,
185+ m , mlen , c , mlen + tlen , clen , tlen );
186+ #endif
183187 * clen += tlen ;
184188 break ;
185189 case CHACHA20POLY1305IETF :
@@ -226,8 +230,13 @@ aead_cipher_decrypt(cipher_ctx_t *cipher_ctx,
226230 // Otherwise, just use the mbedTLS one with crappy AES-NI.
227231 case AES192GCM :
228232 case AES128GCM :
233+ #if MBEDTLS_VERSION_NUMBER < 0x03000000
229234 err = mbedtls_cipher_auth_decrypt (cipher_ctx -> evp , n , nlen , ad , adlen ,
230235 m , mlen - tlen , p , plen , m + mlen - tlen , tlen );
236+ #else
237+ err = mbedtls_cipher_auth_decrypt_ext (cipher_ctx -> evp , n , nlen , ad , adlen ,
238+ m , mlen , p , mlen - tlen , plen , tlen );
239+ #endif
231240 break ;
232241 case CHACHA20POLY1305IETF :
233242 err = crypto_aead_chacha20poly1305_ietf_decrypt (p , & long_plen , NULL , m , mlen ,
@@ -721,17 +730,7 @@ aead_key_init(int method, const char *pass, const char *key)
721730 cipher_t * cipher = (cipher_t * )ss_malloc (sizeof (cipher_t ));
722731 memset (cipher , 0 , sizeof (cipher_t ));
723732
724- if (method >= CHACHA20POLY1305IETF ) {
725- cipher_kt_t * cipher_info = (cipher_kt_t * )ss_malloc (sizeof (cipher_kt_t ));
726- cipher -> info = cipher_info ;
727- cipher -> info -> base = NULL ;
728- cipher -> info -> key_bitlen = supported_aead_ciphers_key_size [method ] * 8 ;
729- cipher -> info -> iv_size = supported_aead_ciphers_nonce_size [method ];
730- } else {
731- cipher -> info = (cipher_kt_t * )aead_get_cipher_type (method );
732- }
733-
734- if (cipher -> info == NULL && cipher -> key_len == 0 ) {
733+ if (method < CHACHA20POLY1305IETF && aead_get_cipher_type (method ) == NULL ) {
735734 LOGE ("Cipher %s not found in crypto library" , supported_aead_ciphers [method ]);
736735 FATAL ("Cannot initialize cipher" );
737736 }
0 commit comments