@@ -210,8 +210,9 @@ NGTCP2_EXTERN int ngtcp2_crypto_derive_packet_protection_key(
210
210
*/
211
211
NGTCP2_EXTERN int ngtcp2_crypto_encrypt (uint8_t * dest ,
212
212
const ngtcp2_crypto_aead * aead ,
213
+ const ngtcp2_crypto_aead_ctx * aead_ctx ,
213
214
const uint8_t * plaintext ,
214
- size_t plaintextlen , const uint8_t * key ,
215
+ size_t plaintextlen ,
215
216
const uint8_t * nonce , size_t noncelen ,
216
217
const uint8_t * ad , size_t adlen );
217
218
@@ -227,9 +228,10 @@ NGTCP2_EXTERN int ngtcp2_crypto_encrypt(uint8_t *dest,
227
228
*/
228
229
NGTCP2_EXTERN int
229
230
ngtcp2_crypto_encrypt_cb (uint8_t * dest , const ngtcp2_crypto_aead * aead ,
231
+ const ngtcp2_crypto_aead_ctx * aead_ctx ,
230
232
const uint8_t * plaintext , size_t plaintextlen ,
231
- const uint8_t * key , const uint8_t * nonce ,
232
- size_t noncelen , const uint8_t * ad , size_t adlen );
233
+ const uint8_t * nonce , size_t noncelen ,
234
+ const uint8_t * ad , size_t adlen );
233
235
234
236
/**
235
237
* @function
@@ -243,11 +245,13 @@ ngtcp2_crypto_encrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
243
245
*
244
246
* This function returns 0 if it succeeds, or -1.
245
247
*/
246
- NGTCP2_EXTERN int
247
- ngtcp2_crypto_decrypt (uint8_t * dest , const ngtcp2_crypto_aead * aead ,
248
- const uint8_t * ciphertext , size_t ciphertextlen ,
249
- const uint8_t * key , const uint8_t * nonce , size_t noncelen ,
250
- const uint8_t * ad , size_t adlen );
248
+ NGTCP2_EXTERN int ngtcp2_crypto_decrypt (uint8_t * dest ,
249
+ const ngtcp2_crypto_aead * aead ,
250
+ const ngtcp2_crypto_aead_ctx * aead_ctx ,
251
+ const uint8_t * ciphertext ,
252
+ size_t ciphertextlen ,
253
+ const uint8_t * nonce , size_t noncelen ,
254
+ const uint8_t * ad , size_t adlen );
251
255
252
256
/**
253
257
* @function
@@ -261,9 +265,10 @@ ngtcp2_crypto_decrypt(uint8_t *dest, const ngtcp2_crypto_aead *aead,
261
265
*/
262
266
NGTCP2_EXTERN int
263
267
ngtcp2_crypto_decrypt_cb (uint8_t * dest , const ngtcp2_crypto_aead * aead ,
268
+ const ngtcp2_crypto_aead_ctx * aead_ctx ,
264
269
const uint8_t * ciphertext , size_t ciphertextlen ,
265
- const uint8_t * key , const uint8_t * nonce ,
266
- size_t noncelen , const uint8_t * ad , size_t adlen );
270
+ const uint8_t * nonce , size_t noncelen ,
271
+ const uint8_t * ad , size_t adlen );
267
272
268
273
/**
269
274
* @function
@@ -277,7 +282,7 @@ ngtcp2_crypto_decrypt_cb(uint8_t *dest, const ngtcp2_crypto_aead *aead,
277
282
*/
278
283
NGTCP2_EXTERN int ngtcp2_crypto_hp_mask (uint8_t * dest ,
279
284
const ngtcp2_crypto_cipher * hp ,
280
- const uint8_t * key ,
285
+ const ngtcp2_crypto_cipher_ctx * hp_ctx ,
281
286
const uint8_t * sample );
282
287
283
288
/**
@@ -290,10 +295,10 @@ NGTCP2_EXTERN int ngtcp2_crypto_hp_mask(uint8_t *dest,
290
295
* This function returns 0 if it succeeds, or
291
296
* :enum:`NGTCP2_ERR_CALLBACK_FAILURE`.
292
297
*/
293
- NGTCP2_EXTERN int ngtcp2_crypto_hp_mask_cb ( uint8_t * dest ,
294
- const ngtcp2_crypto_cipher * hp ,
295
- const uint8_t * key ,
296
- const uint8_t * sample );
298
+ NGTCP2_EXTERN int
299
+ ngtcp2_crypto_hp_mask_cb ( uint8_t * dest , const ngtcp2_crypto_cipher * hp ,
300
+ const ngtcp2_crypto_cipher_ctx * hp_ctx ,
301
+ const uint8_t * sample );
297
302
298
303
/**
299
304
* @function
@@ -381,10 +386,12 @@ NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_tx_key(
381
386
* The derived packet protection key for decryption is written to the
382
387
* buffer pointed by |rx_key|. The derived packet protection IV for
383
388
* decryption is written to the buffer pointed by |rx_iv|.
389
+ * |rx_aead_ctx| must be constructed with |rx_key|.
384
390
*
385
391
* The derived packet protection key for encryption is written to the
386
392
* buffer pointed by |tx_key|. The derived packet protection IV for
387
393
* encryption is written to the buffer pointed by |tx_iv|.
394
+ * |tx_aead_ctx| must be constructed with |rx_key|.
388
395
*
389
396
* |current_rx_secret| and |current_tx_secret| are the current traffic
390
397
* secrets for decryption and encryption. |secretlen| specifies the
@@ -397,12 +404,12 @@ NGTCP2_EXTERN int ngtcp2_crypto_derive_and_install_tx_key(
397
404
*
398
405
* This function returns 0 if it succeeds, or -1.
399
406
*/
400
- NGTCP2_EXTERN int
401
- ngtcp2_crypto_update_key ( ngtcp2_conn * conn , uint8_t * rx_secret ,
402
- uint8_t * tx_secret , uint8_t * rx_key , uint8_t * rx_iv ,
403
- uint8_t * tx_key , uint8_t * tx_iv ,
404
- const uint8_t * current_rx_secret ,
405
- const uint8_t * current_tx_secret , size_t secretlen );
407
+ NGTCP2_EXTERN int ngtcp2_crypto_update_key (
408
+ ngtcp2_conn * conn , uint8_t * rx_secret , uint8_t * tx_secret ,
409
+ ngtcp2_crypto_aead_ctx * rx_aead_ctx , uint8_t * rx_key , uint8_t * rx_iv ,
410
+ ngtcp2_crypto_aead_ctx * tx_aead_ctx , uint8_t * tx_key , uint8_t * tx_iv ,
411
+ const uint8_t * current_rx_secret , const uint8_t * current_tx_secret ,
412
+ size_t secretlen );
406
413
407
414
/**
408
415
* @function
@@ -415,8 +422,9 @@ ngtcp2_crypto_update_key(ngtcp2_conn *conn, uint8_t *rx_secret,
415
422
* :enum:`NGTCP2_ERR_CALLBACK_FAILURE`.
416
423
*/
417
424
NGTCP2_EXTERN int ngtcp2_crypto_update_key_cb (
418
- ngtcp2_conn * conn , uint8_t * rx_secret , uint8_t * tx_secret , uint8_t * rx_key ,
419
- uint8_t * rx_iv , uint8_t * tx_key , uint8_t * tx_iv ,
425
+ ngtcp2_conn * conn , uint8_t * rx_secret , uint8_t * tx_secret ,
426
+ ngtcp2_crypto_aead_ctx * rx_aead_ctx , uint8_t * rx_iv ,
427
+ ngtcp2_crypto_aead_ctx * tx_aead_ctx , uint8_t * tx_iv ,
420
428
const uint8_t * current_rx_secret , const uint8_t * current_tx_secret ,
421
429
size_t secretlen , void * user_data );
422
430
@@ -543,6 +551,69 @@ ngtcp2_crypto_write_retry(uint8_t *dest, size_t destlen, const ngtcp2_cid *dcid,
543
551
const ngtcp2_cid * scid , const ngtcp2_cid * odcid ,
544
552
const uint8_t * token , size_t tokenlen );
545
553
554
+ /**
555
+ * @function
556
+ *
557
+ * `ngtcp2_crypto_aead_ctx_encrypt_init` initializes |aead_ctx| with
558
+ * new AEAD cipher context object for encryption which is constructed
559
+ * to use |key| as encryption key. |aead| specifies AEAD cipher to
560
+ * use. |noncelen| is the length of nonce.
561
+ *
562
+ * This function returns 0 if it succeeds, or -1.
563
+ */
564
+ NGTCP2_EXTERN int
565
+ ngtcp2_crypto_aead_ctx_encrypt_init (ngtcp2_crypto_aead_ctx * aead_ctx ,
566
+ const ngtcp2_crypto_aead * aead ,
567
+ const uint8_t * key , size_t noncelen );
568
+
569
+ /**
570
+ * @function
571
+ *
572
+ * `ngtcp2_crypto_aead_ctx_decrypt_init` initializes |aead_ctx| with
573
+ * new AEAD cipher context object for decryption which is constructed
574
+ * to use |key| as encryption key. |aead| specifies AEAD cipher to
575
+ * use. |noncelen| is the length of nonce.
576
+ *
577
+ * This function returns 0 if it succeeds, or -1.
578
+ */
579
+ NGTCP2_EXTERN int
580
+ ngtcp2_crypto_aead_ctx_decrypt_init (ngtcp2_crypto_aead_ctx * aead_ctx ,
581
+ const ngtcp2_crypto_aead * aead ,
582
+ const uint8_t * key , size_t noncelen );
583
+
584
+ /**
585
+ * @function
586
+ *
587
+ * `ngtcp2_crypto_aead_ctx_free` frees up resources used by
588
+ * |aead_ctx|. This function does not free the memory pointed by
589
+ * |aead_ctx| itself.
590
+ */
591
+ NGTCP2_EXTERN void
592
+ ngtcp2_crypto_aead_ctx_free (ngtcp2_crypto_aead_ctx * aead_ctx );
593
+
594
+ /**
595
+ * @function
596
+ *
597
+ * `ngtcp2_crypto_delete_crypto_aead_ctx_cb` deletes the given |aead_ctx|.
598
+ *
599
+ * This function can be directly passed to delete_crypto_aead_ctx
600
+ * field in ngtcp2_callbacks.
601
+ */
602
+ NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_aead_ctx_cb (
603
+ ngtcp2_conn * conn , ngtcp2_crypto_aead_ctx * aead_ctx , void * user_data );
604
+
605
+ /**
606
+ * @function
607
+ *
608
+ * `ngtcp2_crypto_delete_crypto_cipher_ctx_cb` deletes the given
609
+ * |cipher_ctx|.
610
+ *
611
+ * This function can be directly passed to delete_crypto_cipher_ctx
612
+ * field in ngtcp2_callbacks.
613
+ */
614
+ NGTCP2_EXTERN void ngtcp2_crypto_delete_crypto_cipher_ctx_cb (
615
+ ngtcp2_conn * conn , ngtcp2_crypto_cipher_ctx * cipher_ctx , void * user_data );
616
+
546
617
#ifdef __cplusplus
547
618
}
548
619
#endif
0 commit comments