4949static EVP_CIPHER * crypto_aes_128_gcm ;
5050static EVP_CIPHER * crypto_aes_256_gcm ;
5151static EVP_CIPHER * crypto_aes_128_ccm ;
52- static EVP_CIPHER * crypto_aes_128_ctr ;
53- static EVP_CIPHER * crypto_aes_256_ctr ;
52+ static EVP_CIPHER * crypto_aes_128_ecb ;
53+ static EVP_CIPHER * crypto_aes_256_ecb ;
5454#ifndef NGTCP2_NO_CHACHA_POLY1305
5555static EVP_CIPHER * crypto_chacha20_poly1305 ;
5656static EVP_CIPHER * crypto_chacha20 ;
@@ -66,8 +66,8 @@ int ngtcp2_crypto_ossl_init(void) {
6666 crypto_aes_128_gcm = EVP_CIPHER_fetch (NULL , "AES-128-GCM" , NULL );
6767 crypto_aes_256_gcm = EVP_CIPHER_fetch (NULL , "AES-256-GCM" , NULL );
6868 crypto_aes_128_ccm = EVP_CIPHER_fetch (NULL , "AES-128-CCM" , NULL );
69- crypto_aes_128_ctr = EVP_CIPHER_fetch (NULL , "AES-128-CTR " , NULL );
70- crypto_aes_256_ctr = EVP_CIPHER_fetch (NULL , "AES-256-CTR " , NULL );
69+ crypto_aes_128_ecb = EVP_CIPHER_fetch (NULL , "AES-128-ECB " , NULL );
70+ crypto_aes_256_ecb = EVP_CIPHER_fetch (NULL , "AES-256-ECB " , NULL );
7171#ifndef NGTCP2_NO_CHACHA_POLY1305
7272 crypto_chacha20_poly1305 = EVP_CIPHER_fetch (NULL , "ChaCha20-Poly1305" , NULL );
7373 crypto_chacha20 = EVP_CIPHER_fetch (NULL , "ChaCha20" , NULL );
@@ -113,20 +113,20 @@ static const EVP_CIPHER *crypto_aead_aes_128_ccm(void) {
113113 return EVP_aes_128_ccm ();
114114}
115115
116- static const EVP_CIPHER * crypto_cipher_aes_128_ctr (void ) {
117- if (crypto_aes_128_ctr ) {
118- return crypto_aes_128_ctr ;
116+ static const EVP_CIPHER * crypto_cipher_aes_128_ecb (void ) {
117+ if (crypto_aes_128_ecb ) {
118+ return crypto_aes_128_ecb ;
119119 }
120120
121- return EVP_aes_128_ctr ();
121+ return EVP_aes_128_ecb ();
122122}
123123
124- static const EVP_CIPHER * crypto_cipher_aes_256_ctr (void ) {
125- if (crypto_aes_256_ctr ) {
126- return crypto_aes_256_ctr ;
124+ static const EVP_CIPHER * crypto_cipher_aes_256_ecb (void ) {
125+ if (crypto_aes_256_ecb ) {
126+ return crypto_aes_256_ecb ;
127127 }
128128
129- return EVP_aes_256_ctr ();
129+ return EVP_aes_256_ecb ();
130130}
131131
132132#ifndef NGTCP2_NO_CHACHA_POLY1305
@@ -198,7 +198,7 @@ ngtcp2_crypto_md *ngtcp2_crypto_md_sha256(ngtcp2_crypto_md *md) {
198198ngtcp2_crypto_ctx * ngtcp2_crypto_ctx_initial (ngtcp2_crypto_ctx * ctx ) {
199199 ngtcp2_crypto_aead_init (& ctx -> aead , (void * )crypto_aead_aes_128_gcm ());
200200 ctx -> md .native_handle = (void * )crypto_md_sha256 ();
201- ctx -> hp .native_handle = (void * )crypto_cipher_aes_128_ctr ();
201+ ctx -> hp .native_handle = (void * )crypto_cipher_aes_128_ecb ();
202202 ctx -> max_encryption = 0 ;
203203 ctx -> max_decryption_failure = 0 ;
204204 return ctx ;
@@ -269,9 +269,9 @@ static const EVP_CIPHER *crypto_cipher_id_get_hp(uint32_t cipher_id) {
269269 switch (cipher_id ) {
270270 case TLS1_3_CK_AES_128_GCM_SHA256 :
271271 case TLS1_3_CK_AES_128_CCM_SHA256 :
272- return crypto_cipher_aes_128_ctr ();
272+ return crypto_cipher_aes_128_ecb ();
273273 case TLS1_3_CK_AES_256_GCM_SHA384 :
274- return crypto_cipher_aes_256_ctr ();
274+ return crypto_cipher_aes_256_ecb ();
275275#ifndef NGTCP2_NO_CHACHA_POLY1305
276276 case TLS1_3_CK_CHACHA20_POLY1305_SHA256 :
277277 return crypto_cipher_chacha20 ();
@@ -838,17 +838,31 @@ int ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
838838int ngtcp2_crypto_hp_mask (uint8_t * dest , const ngtcp2_crypto_cipher * hp ,
839839 const ngtcp2_crypto_cipher_ctx * hp_ctx ,
840840 const uint8_t * sample ) {
841- static const uint8_t PLAINTEXT [] = "\x00\x00\x00\x00\x00" ;
841+ static const uint8_t PLAINTEXT [16 ] = { 0 } ;
842842 EVP_CIPHER_CTX * actx = hp_ctx -> native_handle ;
843843 int len ;
844844
845845 (void )hp ;
846846
847- if (!EVP_EncryptInit_ex (actx , NULL , NULL , NULL , sample ) ||
848- !EVP_EncryptUpdate (actx , dest , & len , PLAINTEXT ,
849- ngtcp2_strlen_lit (PLAINTEXT )) ||
850- !EVP_EncryptFinal_ex (actx , dest + ngtcp2_strlen_lit (PLAINTEXT ), & len )) {
851- return -1 ;
847+ switch (EVP_CIPHER_CTX_nid (actx )) {
848+ case NID_aes_128_ecb :
849+ case NID_aes_256_ecb :
850+ if (!EVP_EncryptUpdate (actx , dest , & len , sample , NGTCP2_HP_SAMPLELEN )) {
851+ return -1 ;
852+ }
853+
854+ break ;
855+ case NID_chacha20 :
856+ if (!EVP_EncryptInit_ex (actx , NULL , NULL , NULL , sample ) ||
857+ !EVP_EncryptUpdate (actx , dest , & len , PLAINTEXT , sizeof (PLAINTEXT )) ||
858+ !EVP_EncryptFinal_ex (actx , dest + sizeof (PLAINTEXT ), & len )) {
859+ return -1 ;
860+ }
861+
862+ break ;
863+ default :
864+ assert (0 );
865+ abort ();
852866 }
853867
854868 return 0 ;
@@ -983,6 +997,19 @@ int ngtcp2_crypto_get_path_challenge_data_cb(ngtcp2_conn *conn, uint8_t *data,
983997 return 0 ;
984998}
985999
1000+ int ngtcp2_crypto_get_path_challenge_data2_cb (ngtcp2_conn * conn ,
1001+ ngtcp2_path_challenge_data * data ,
1002+ void * user_data ) {
1003+ (void )conn ;
1004+ (void )user_data ;
1005+
1006+ if (RAND_bytes (data -> data , NGTCP2_PATH_CHALLENGE_DATALEN ) != 1 ) {
1007+ return NGTCP2_ERR_CALLBACK_FAILURE ;
1008+ }
1009+
1010+ return 0 ;
1011+ }
1012+
9861013int ngtcp2_crypto_random (uint8_t * data , size_t datalen ) {
9871014 if (RAND_bytes (data , (int )datalen ) != 1 ) {
9881015 return -1 ;
0 commit comments