2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #include <vnet/crypto/crypto.h>
16 #include <vppinfra/lock.h>
18 #include <quic/quic.h>
19 #include <quic/quic_crypto.h>
22 #include <picotls/openssl.h>
24 #define QUICLY_EPOCH_1RTT 3
26 extern quic_main_t quic_main;
27 extern quic_ctx_t *quic_get_conn_ctx (quicly_conn_t * conn);
29 typedef void (*quicly_do_transform_fn) (ptls_cipher_context_t *, void *,
30 const void *, size_t);
32 struct cipher_context_t
34 ptls_cipher_context_t super;
39 struct aead_crypto_context_t
41 ptls_aead_context_t super;
47 quic_crypto_offload_aead_decrypt (quic_ctx_t * qctx,
48 ptls_aead_context_t * _ctx, void *_output,
49 const void *input, size_t inlen,
50 uint64_t decrypted_pn, const void *aad,
53 vnet_crypto_main_t *cm = &crypto_main;
56 quic_crypto_batch_tx_packets (quic_crypto_batch_ctx_t * batch_ctx)
58 vlib_main_t *vm = vlib_get_main ();
60 if (batch_ctx->nb_tx_packets <= 0)
63 clib_rwlock_reader_lock (&quic_main.crypto_keys_quic_rw_lock);
64 vnet_crypto_process_ops (vm, batch_ctx->aead_crypto_tx_packets_ops,
65 batch_ctx->nb_tx_packets);
66 clib_rwlock_reader_unlock (&quic_main.crypto_keys_quic_rw_lock);
68 for (int i = 0; i < batch_ctx->nb_tx_packets; i++)
69 clib_mem_free (batch_ctx->aead_crypto_tx_packets_ops[i].iv);
71 batch_ctx->nb_tx_packets = 0;
75 quic_crypto_batch_rx_packets (quic_crypto_batch_ctx_t * batch_ctx)
77 vlib_main_t *vm = vlib_get_main ();
79 if (batch_ctx->nb_rx_packets <= 0)
82 clib_rwlock_reader_lock (&quic_main.crypto_keys_quic_rw_lock);
83 vnet_crypto_process_ops (vm, batch_ctx->aead_crypto_rx_packets_ops,
84 batch_ctx->nb_rx_packets);
85 clib_rwlock_reader_unlock (&quic_main.crypto_keys_quic_rw_lock);
87 for (int i = 0; i < batch_ctx->nb_rx_packets; i++)
88 clib_mem_free (batch_ctx->aead_crypto_rx_packets_ops[i].iv);
90 batch_ctx->nb_rx_packets = 0;
94 build_iv (ptls_aead_context_t * ctx, uint8_t * iv, uint64_t seq)
96 size_t iv_size = ctx->algo->iv_size, i;
97 const uint8_t *s = ctx->static_iv;
100 for (i = iv_size - 8; i != 0; --i)
106 *d++ = *s++ ^ (uint8_t) (seq >> i);
112 do_finalize_send_packet (ptls_cipher_context_t * hp,
113 quicly_datagram_t * packet,
114 size_t first_byte_at, size_t payload_from)
116 uint8_t hpmask[1 + QUICLY_SEND_PN_SIZE] = {
121 ptls_cipher_init (hp,
122 packet->data.base + payload_from - QUICLY_SEND_PN_SIZE +
124 ptls_cipher_encrypt (hp, hpmask, hpmask, sizeof (hpmask));
126 packet->data.base[first_byte_at] ^=
128 (QUICLY_PACKET_IS_LONG_HEADER (packet->data.base[first_byte_at]) ? 0xf :
131 for (i = 0; i != QUICLY_SEND_PN_SIZE; ++i)
132 packet->data.base[payload_from + i - QUICLY_SEND_PN_SIZE] ^=
137 quic_crypto_finalize_send_packet (quicly_datagram_t * packet)
139 quic_encrypt_cb_ctx *encrypt_cb_ctx =
140 (quic_encrypt_cb_ctx *) ((uint8_t *) packet + sizeof (*packet));
142 for (int i = 0; i < encrypt_cb_ctx->snd_ctx_count; i++)
144 do_finalize_send_packet (encrypt_cb_ctx->snd_ctx[i].hp,
146 encrypt_cb_ctx->snd_ctx[i].first_byte_at,
147 encrypt_cb_ctx->snd_ctx[i].payload_from);
149 encrypt_cb_ctx->snd_ctx_count = 0;
153 quic_crypto_setup_cipher (quicly_crypto_engine_t * engine,
154 quicly_conn_t * conn, size_t epoch, int is_enc,
155 ptls_cipher_context_t ** hp_ctx,
156 ptls_aead_context_t ** aead_ctx,
157 ptls_aead_algorithm_t * aead,
158 ptls_hash_algorithm_t * hash, const void *secret)
160 uint8_t hpkey[PTLS_MAX_SECRET_SIZE];
165 /* generate new header protection key */
170 ptls_hkdf_expand_label (hash, hpkey, aead->ctr_cipher->key_size,
171 ptls_iovec_init (secret,
173 "quic hp", ptls_iovec_init (NULL, 0),
177 ptls_cipher_new (aead->ctr_cipher, is_enc, hpkey)) == NULL)
179 ret = PTLS_ERROR_NO_MEMORY;
184 /* generate new AEAD context */
186 ptls_aead_new (aead, hash, is_enc, secret,
187 QUICLY_AEAD_BASE_LABEL)) == NULL)
189 ret = PTLS_ERROR_NO_MEMORY;
193 if (epoch == QUICLY_EPOCH_1RTT && !is_enc)
195 quic_ctx_t *qctx = quic_get_conn_ctx (conn);
196 if (qctx->ingress_keys.aead_ctx != NULL)
198 qctx->key_phase_ingress++;
201 qctx->ingress_keys.aead_ctx = *aead_ctx;
203 qctx->ingress_keys.hp_ctx = *hp_ctx;
211 if (aead_ctx && *aead_ctx != NULL)
213 ptls_aead_free (*aead_ctx);
216 if (hp_ctx && *hp_ctx != NULL)
218 ptls_cipher_free (*hp_ctx);
222 ptls_clear_memory (hpkey, sizeof (hpkey));
227 quic_crypto_finalize_send_packet_cb (struct st_quicly_crypto_engine_t
228 *engine, quicly_conn_t * conn,
229 ptls_cipher_context_t * hp,
230 ptls_aead_context_t * aead,
231 quicly_datagram_t * packet,
232 size_t first_byte_at,
233 size_t payload_from, int coalesced)
235 quic_encrypt_cb_ctx *encrypt_cb_ctx =
236 (quic_encrypt_cb_ctx *) ((uint8_t *) packet + sizeof (*packet));
238 encrypt_cb_ctx->snd_ctx[encrypt_cb_ctx->snd_ctx_count].hp = hp;
239 encrypt_cb_ctx->snd_ctx[encrypt_cb_ctx->snd_ctx_count].first_byte_at =
241 encrypt_cb_ctx->snd_ctx[encrypt_cb_ctx->snd_ctx_count].payload_from =
243 encrypt_cb_ctx->snd_ctx_count++;
247 quic_crypto_decrypt_packet (quic_ctx_t * qctx, quic_rx_packet_ctx_t * pctx)
249 ptls_cipher_context_t *header_protection = NULL;
250 ptls_aead_context_t *aead = NULL;
253 /* Long Header packets are not decrypted by vpp */
254 if (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]))
257 uint64_t next_expected_packet_number =
258 quicly_get_next_expected_packet_number (qctx->conn);
259 if (next_expected_packet_number == UINT64_MAX)
262 aead = qctx->ingress_keys.aead_ctx;
263 header_protection = qctx->ingress_keys.hp_ctx;
265 if (!aead || !header_protection)
268 size_t encrypted_len = pctx->packet.octets.len - pctx->packet.encrypted_off;
269 uint8_t hpmask[5] = { 0 };
271 size_t pnlen, ptlen, i;
273 /* decipher the header protection, as well as obtaining pnbits, pnlen */
274 if (encrypted_len < header_protection->algo->iv_size + QUICLY_MAX_PN_SIZE)
276 ptls_cipher_init (header_protection,
277 pctx->packet.octets.base + pctx->packet.encrypted_off +
279 ptls_cipher_encrypt (header_protection, hpmask, hpmask, sizeof (hpmask));
280 pctx->packet.octets.base[0] ^=
281 hpmask[0] & (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]) ?
283 pnlen = (pctx->packet.octets.base[0] & 0x3) + 1;
284 for (i = 0; i != pnlen; ++i)
286 pctx->packet.octets.base[pctx->packet.encrypted_off + i] ^=
289 (pnbits << 8) | pctx->packet.octets.base[pctx->packet.encrypted_off +
293 size_t aead_off = pctx->packet.encrypted_off + pnlen;
296 quicly_determine_packet_number (pnbits, pnlen * 8,
297 next_expected_packet_number);
300 (pctx->packet.octets.base[0] & QUICLY_KEY_PHASE_BIT) != 0;
302 if (key_phase_bit != (qctx->key_phase_ingress & 1))
304 pctx->packet.octets.base[0] ^=
306 (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]) ? 0xf :
308 for (i = 0; i != pnlen; ++i)
310 pctx->packet.octets.base[pctx->packet.encrypted_off + i] ^=
317 quic_crypto_offload_aead_decrypt (qctx, aead,
318 pctx->packet.octets.base + aead_off,
319 pctx->packet.octets.base + aead_off,
320 pctx->packet.octets.len - aead_off,
321 pn, pctx->packet.octets.base,
322 aead_off)) == SIZE_MAX)
325 "%s: aead decryption failure (pn: %d)\n", __FUNCTION__, pn);
329 pctx->packet.encrypted_off = aead_off;
330 pctx->packet.octets.len = ptlen + aead_off;
332 pctx->packet.decrypted.pn = pn;
333 pctx->packet.decrypted.key_phase = qctx->key_phase_ingress;
336 #ifdef QUIC_HP_CRYPTO
338 quic_crypto_cipher_do_init (ptls_cipher_context_t * _ctx, const void *iv)
340 struct cipher_context_t *ctx = (struct cipher_context_t *) _ctx;
341 vnet_crypto_op_id_t id;
342 if (!strcmp (ctx->super.algo->name, "AES128-CTR"))
344 id = VNET_CRYPTO_OP_AES_128_CTR_ENC;
346 else if (!strcmp (ctx->super.algo->name, "AES256-CTR"))
348 id = VNET_CRYPTO_OP_AES_256_CTR_ENC;
352 QUIC_DBG (1, "%s, Invalid crypto cipher : ", __FUNCTION__,
356 vnet_crypto_op_init (&ctx->op, id);
357 ctx->op.iv = (u8 *) iv;
358 ctx->op.key_index = ctx->key_index;
362 quic_crypto_cipher_dispose (ptls_cipher_context_t * _ctx)
368 quic_crypto_cipher_encrypt (ptls_cipher_context_t * _ctx, void *output,
369 const void *input, size_t _len)
371 vlib_main_t *vm = vlib_get_main ();
372 struct cipher_context_t *ctx = (struct cipher_context_t *) _ctx;
374 ctx->op.src = (u8 *) input;
375 ctx->op.dst = output;
378 vnet_crypto_process_ops (vm, &ctx->op, 1);
382 quic_crypto_cipher_setup_crypto (ptls_cipher_context_t * _ctx, int is_enc,
383 const void *key, const EVP_CIPHER * cipher,
384 quicly_do_transform_fn do_transform)
386 struct cipher_context_t *ctx = (struct cipher_context_t *) _ctx;
388 ctx->super.do_dispose = quic_crypto_cipher_dispose;
389 ctx->super.do_init = quic_crypto_cipher_do_init;
390 ctx->super.do_transform = do_transform;
392 vlib_main_t *vm = vlib_get_main ();
393 vnet_crypto_alg_t algo;
394 if (!strcmp (ctx->super.algo->name, "AES128-CTR"))
396 algo = VNET_CRYPTO_ALG_AES_128_CTR;
398 else if (!strcmp (ctx->super.algo->name, "AES256-CTR"))
400 algo = VNET_CRYPTO_ALG_AES_256_CTR;
404 QUIC_DBG (1, "%s, Invalid crypto cipher : ", __FUNCTION__,
409 ctx->key_index = vnet_crypto_key_add (vm, algo,
410 (u8 *) key, _ctx->algo->key_size);
416 quic_crypto_aes128ctr_setup_crypto (ptls_cipher_context_t * ctx, int is_enc,
419 return quic_crypto_cipher_setup_crypto (ctx, 1, key, EVP_aes_128_ctr (),
420 quic_crypto_cipher_encrypt);
424 quic_crypto_aes256ctr_setup_crypto (ptls_cipher_context_t * ctx, int is_enc,
427 return quic_crypto_cipher_setup_crypto (ctx, 1, key, EVP_aes_256_ctr (),
428 quic_crypto_cipher_encrypt);
431 #endif // QUIC_HP_CRYPTO
434 quic_crypto_aead_encrypt_init (ptls_aead_context_t * _ctx, const void *iv,
435 const void *aad, size_t aadlen)
437 quic_main_t *qm = &quic_main;
438 u32 thread_index = vlib_get_thread_index ();
440 struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
442 vnet_crypto_op_id_t id;
443 if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
445 id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
447 else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
449 id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
456 quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
457 &qm->wrk_ctx[thread_index].crypto_context_batch;
459 vnet_crypto_op_t *vnet_op =
460 &quic_crypto_batch_ctx->aead_crypto_tx_packets_ops
461 [quic_crypto_batch_ctx->nb_tx_packets];
462 vnet_crypto_op_init (vnet_op, id);
463 vnet_op->aad = (u8 *) aad;
464 vnet_op->aad_len = aadlen;
465 vnet_op->iv = clib_mem_alloc (PTLS_MAX_IV_SIZE);
466 clib_memcpy (vnet_op->iv, iv, PTLS_MAX_IV_SIZE);
467 vnet_op->key_index = ctx->key_index;
471 quic_crypto_aead_encrypt_update (ptls_aead_context_t * _ctx, void *output,
472 const void *input, size_t inlen)
474 struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
476 quic_main_t *qm = &quic_main;
477 u32 thread_index = vlib_get_thread_index ();
478 quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
479 &qm->wrk_ctx[thread_index].crypto_context_batch;
481 vnet_crypto_op_t *vnet_op =
482 &quic_crypto_batch_ctx->aead_crypto_tx_packets_ops
483 [quic_crypto_batch_ctx->nb_tx_packets];
484 vnet_op->src = (u8 *) input;
485 vnet_op->dst = output;
486 vnet_op->len = inlen;
487 vnet_op->tag_len = ctx->super.algo->tag_size;
489 vnet_op->tag = vnet_op->src + inlen;
495 quic_crypto_aead_encrypt_final (ptls_aead_context_t * _ctx, void *output)
497 quic_main_t *qm = &quic_main;
498 u32 thread_index = vlib_get_thread_index ();
499 quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
500 &qm->wrk_ctx[thread_index].crypto_context_batch;
502 vnet_crypto_op_t *vnet_op =
503 &quic_crypto_batch_ctx->
504 aead_crypto_tx_packets_ops[quic_crypto_batch_ctx->nb_tx_packets];
505 quic_crypto_batch_ctx->nb_tx_packets++;
506 return vnet_op->len + vnet_op->tag_len;
510 quic_crypto_aead_decrypt (ptls_aead_context_t * _ctx, void *_output,
511 const void *input, size_t inlen, const void *iv,
512 const void *aad, size_t aadlen)
514 vlib_main_t *vm = vlib_get_main ();
515 struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
517 vnet_crypto_op_id_t id;
518 if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
520 id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
522 else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
524 id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
531 vnet_crypto_op_init (&ctx->op, id);
532 ctx->op.aad = (u8 *) aad;
533 ctx->op.aad_len = aadlen;
534 ctx->op.iv = (u8 *) iv;
536 ctx->op.src = (u8 *) input;
537 ctx->op.dst = _output;
538 ctx->op.key_index = ctx->key_index;
539 ctx->op.len = inlen - ctx->super.algo->tag_size;
541 ctx->op.tag_len = ctx->super.algo->tag_size;
542 ctx->op.tag = ctx->op.src + ctx->op.len;
544 vnet_crypto_process_ops (vm, &ctx->op, 1);
546 if (ctx->op.status != VNET_CRYPTO_OP_STATUS_COMPLETED)
553 quic_crypto_offload_aead_decrypt (quic_ctx_t * qctx,
554 ptls_aead_context_t * _ctx, void *_output,
555 const void *input, size_t inlen,
556 uint64_t decrypted_pn, const void *aad,
559 struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
560 vnet_crypto_op_id_t id;
561 if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
563 id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
565 else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
567 id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
574 quic_main_t *qm = &quic_main;
575 quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
576 &qm->wrk_ctx[qctx->c_thread_index].crypto_context_batch;
578 vnet_crypto_op_t *vnet_op =
579 &quic_crypto_batch_ctx->aead_crypto_rx_packets_ops
580 [quic_crypto_batch_ctx->nb_rx_packets];
582 vnet_crypto_op_init (vnet_op, id);
583 vnet_op->aad = (u8 *) aad;
584 vnet_op->aad_len = aadlen;
585 vnet_op->iv = clib_mem_alloc (PTLS_MAX_IV_SIZE);
586 build_iv (_ctx, vnet_op->iv, decrypted_pn);
587 vnet_op->src = (u8 *) input;
588 vnet_op->dst = _output;
589 vnet_op->key_index = ctx->key_index;
590 vnet_op->len = inlen - ctx->super.algo->tag_size;
591 vnet_op->tag_len = ctx->super.algo->tag_size;
592 vnet_op->tag = vnet_op->src + vnet_op->len;
593 quic_crypto_batch_ctx->nb_rx_packets++;
598 quic_crypto_aead_dispose_crypto (ptls_aead_context_t * _ctx)
604 quic_crypto_aead_setup_crypto (ptls_aead_context_t * _ctx, int is_enc,
605 const void *key, const EVP_CIPHER * cipher)
607 vlib_main_t *vm = vlib_get_main ();
608 struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
610 vnet_crypto_alg_t algo;
611 if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
613 algo = VNET_CRYPTO_ALG_AES_128_GCM;
615 else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
617 algo = VNET_CRYPTO_ALG_AES_256_GCM;
621 QUIC_DBG (1, "%s, invalied aead cipher %s", __FUNCTION__,
626 ctx->super.do_decrypt = quic_crypto_aead_decrypt;
628 ctx->super.do_encrypt_init = quic_crypto_aead_encrypt_init;
629 ctx->super.do_encrypt_update = quic_crypto_aead_encrypt_update;
630 ctx->super.do_encrypt_final = quic_crypto_aead_encrypt_final;
631 ctx->super.dispose_crypto = quic_crypto_aead_dispose_crypto;
633 clib_rwlock_writer_lock (&quic_main.crypto_keys_quic_rw_lock);
634 ctx->key_index = vnet_crypto_key_add (vm, algo,
635 (u8 *) key, _ctx->algo->key_size);
636 clib_rwlock_writer_unlock (&quic_main.crypto_keys_quic_rw_lock);
642 quic_crypto_aead_aes128gcm_setup_crypto (ptls_aead_context_t * ctx,
643 int is_enc, const void *key)
645 return quic_crypto_aead_setup_crypto (ctx, is_enc, key, EVP_aes_128_gcm ());
649 quic_crypto_aead_aes256gcm_setup_crypto (ptls_aead_context_t * ctx,
650 int is_enc, const void *key)
652 return quic_crypto_aead_setup_crypto (ctx, is_enc, key, EVP_aes_256_gcm ());
655 #ifdef QUIC_HP_CRYPTO
656 ptls_cipher_algorithm_t quic_crypto_aes128ctr = {
658 PTLS_AES128_KEY_SIZE,
660 sizeof (struct cipher_context_t), aes128ctr_setup_crypto
663 ptls_cipher_algorithm_t quic_crypto_aes256ctr = {
664 "AES256-CTR", PTLS_AES256_KEY_SIZE, 1 /* block size */ ,
665 PTLS_AES_IV_SIZE, sizeof (struct cipher_context_t), aes256ctr_setup_crypto
669 ptls_aead_algorithm_t quic_crypto_aes128gcm = {
671 #ifdef QUIC_HP_CRYPTO
672 &quic_crypto_aes128ctr,
674 &ptls_openssl_aes128ctr,
676 &ptls_openssl_aes128ecb,
677 PTLS_AES128_KEY_SIZE,
679 PTLS_AESGCM_TAG_SIZE,
680 sizeof (struct aead_crypto_context_t),
681 quic_crypto_aead_aes128gcm_setup_crypto
684 ptls_aead_algorithm_t quic_crypto_aes256gcm = {
686 #ifdef QUIC_HP_CRYPTO
687 &quic_crypto_aes256ctr,
689 &ptls_openssl_aes256ctr,
691 &ptls_openssl_aes256ecb,
692 PTLS_AES256_KEY_SIZE,
694 PTLS_AESGCM_TAG_SIZE,
695 sizeof (struct aead_crypto_context_t),
696 quic_crypto_aead_aes256gcm_setup_crypto
699 ptls_cipher_suite_t quic_crypto_aes128gcmsha256 = {
700 PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
701 &quic_crypto_aes128gcm, &ptls_openssl_sha256
704 ptls_cipher_suite_t quic_crypto_aes256gcmsha384 = {
705 PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
706 &quic_crypto_aes256gcm, &ptls_openssl_sha384
709 ptls_cipher_suite_t *quic_crypto_cipher_suites[] = {
710 &quic_crypto_aes256gcmsha384, &quic_crypto_aes128gcmsha256, NULL
713 quicly_crypto_engine_t quic_crypto_engine = {
714 quic_crypto_setup_cipher, quic_crypto_finalize_send_packet_cb
718 quic_encrypt_ticket_cb (ptls_encrypt_ticket_t * _self, ptls_t * tls,
719 int is_encrypt, ptls_buffer_t * dst, ptls_iovec_t src)
721 quic_session_cache_t *self = (void *) _self;
727 /* replace the cached entry along with a newly generated session id */
728 clib_mem_free (self->data.base);
729 if ((self->data.base = clib_mem_alloc (src.len)) == NULL)
730 return PTLS_ERROR_NO_MEMORY;
732 ptls_get_context (tls)->random_bytes (self->id, sizeof (self->id));
733 clib_memcpy (self->data.base, src.base, src.len);
734 self->data.len = src.len;
736 /* store the session id in buffer */
737 if ((ret = ptls_buffer_reserve (dst, sizeof (self->id))) != 0)
739 clib_memcpy (dst->base + dst->off, self->id, sizeof (self->id));
740 dst->off += sizeof (self->id);
746 /* check if session id is the one stored in cache */
747 if (src.len != sizeof (self->id))
748 return PTLS_ERROR_SESSION_NOT_FOUND;
749 if (clib_memcmp (self->id, src.base, sizeof (self->id)) != 0)
750 return PTLS_ERROR_SESSION_NOT_FOUND;
752 /* return the cached value */
753 if ((ret = ptls_buffer_reserve (dst, self->data.len)) != 0)
755 clib_memcpy (dst->base + dst->off, self->data.base, self->data.len);
756 dst->off += self->data.len;
763 * fd.io coding-style-patch-verification: ON
766 * eval: (c-set-style "gnu")