21 #include <picotls/openssl.h> 25 const void *, size_t);
49 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
51 id = VNET_CRYPTO_OP_AES_128_CTR_ENC;
53 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
55 id = VNET_CRYPTO_OP_AES_256_CTR_ENC;
59 QUIC_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
77 const void *input,
size_t _len)
91 const void *
key,
const EVP_CIPHER * cipher,
98 ctx->
super.do_transform = do_transform;
102 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
104 algo = VNET_CRYPTO_ALG_AES_128_CTR;
106 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
108 algo = VNET_CRYPTO_ALG_AES_256_CTR;
112 QUIC_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
118 (
u8 *) key, _ctx->algo->key_size);
141 const void *aad,
size_t aadlen)
146 if (!strcmp (ctx->
super.algo->name,
"AES128-GCM"))
148 id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
150 else if (!strcmp (ctx->
super.algo->name,
"AES256-GCM"))
152 id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
168 const void *input,
size_t inlen)
173 ctx->
op.
dst = output;
194 const void *input,
size_t inlen,
const void *
iv,
195 const void *aad,
size_t aadlen)
201 if (!strcmp (ctx->
super.algo->name,
"AES128-GCM"))
203 id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
205 else if (!strcmp (ctx->
super.algo->name,
"AES256-GCM"))
207 id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
220 ctx->
op.
dst = _output;
222 ctx->
op.
len = inlen - ctx->
super.algo->tag_size;
240 const void *
key,
const EVP_CIPHER * cipher)
246 if (!strcmp (ctx->
super.algo->name,
"AES128-GCM"))
248 algo = VNET_CRYPTO_ALG_AES_128_GCM;
250 else if (!strcmp (ctx->
super.algo->name,
"AES256-GCM"))
252 algo = VNET_CRYPTO_ALG_AES_256_GCM;
256 QUIC_DBG (1,
"%s, invalied aead cipher %s", __FUNCTION__,
268 (
u8 *) key, _ctx->algo->key_size);
275 int is_enc,
const void *
key)
282 int is_enc,
const void *
key)
288 PTLS_AES128_KEY_SIZE,
291 aes128ctr_setup_crypto
294 ptls_cipher_algorithm_t quic_crypto_aes256ctr = {
"AES256-CTR",
295 PTLS_AES256_KEY_SIZE,
299 aes256ctr_setup_crypto
302 ptls_aead_algorithm_t quic_crypto_aes128gcm = {
"AES128-GCM",
305 PTLS_AES128_KEY_SIZE,
307 PTLS_AESGCM_TAG_SIZE,
309 quic_crypto_aead_aes128gcm_setup_crypto
312 ptls_aead_algorithm_t quic_crypto_aes256gcm = {
"AES256-GCM",
315 PTLS_AES256_KEY_SIZE,
317 PTLS_AESGCM_TAG_SIZE,
319 quic_crypto_aead_aes256gcm_setup_crypto
322 ptls_cipher_suite_t quic_crypto_aes128gcmsha256 =
323 { PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
328 ptls_cipher_suite_t quic_crypto_aes256gcmsha384 =
329 { PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
334 ptls_cipher_suite_t *quic_crypto_cipher_suites[] =
342 int is_encrypt, ptls_buffer_t *
dst, ptls_iovec_t
src)
353 return PTLS_ERROR_NO_MEMORY;
355 ptls_get_context (tls)->random_bytes (self->id, sizeof (self->id));
357 self->data.len = src.len;
360 if ((ret = ptls_buffer_reserve (dst,
sizeof (self->id))) != 0)
362 clib_memcpy (dst->base + dst->off, self->id, sizeof (self->id));
363 dst->off +=
sizeof (
self->id);
370 if (src.len != sizeof (self->id))
371 return PTLS_ERROR_SESSION_NOT_FOUND;
372 if (
clib_memcmp (self->id, src.base, sizeof (self->id)) != 0)
373 return PTLS_ERROR_SESSION_NOT_FOUND;
376 if ((ret = ptls_buffer_reserve (dst, self->data.len)) != 0)
378 clib_memcpy (dst->base + dst->off, self->data.base, self->data.len);
379 dst->off +=
self->data.len;
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
ptls_cipher_context_t super
static int aes256ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
size_t quic_crypto_aead_decrypt(ptls_aead_context_t *_ctx, void *_output, const void *input, size_t inlen, const void *iv, const void *aad, size_t aadlen)
#define QUIC_DBG(_lvl, _fmt, _args...)
size_t quic_crypto_aead_encrypt_update(ptls_aead_context_t *_ctx, void *output, const void *input, size_t inlen)
#define clib_memcpy(d, s, n)
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
ptls_cipher_algorithm_t quic_crypto_aes128ctr
size_t quic_crypto_aead_encrypt_final(ptls_aead_context_t *_ctx, void *output)
static int quic_crypto_aead_setup_crypto(ptls_aead_context_t *_ctx, int is_enc, const void *key, const EVP_CIPHER *cipher)
static int quic_crypto_aead_aes256gcm_setup_crypto(ptls_aead_context_t *ctx, int is_enc, const void *key)
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
ptls_cipher_suite_t quic_crypto_aes256gcmsha384
void quic_crypto_aead_encrypt_init(ptls_aead_context_t *_ctx, const void *iv, const void *aad, size_t aadlen)
static int quic_crypto_aead_aes128gcm_setup_crypto(ptls_aead_context_t *ctx, int is_enc, const void *key)
#define clib_memcmp(s1, s2, m1)
void(* quicly_do_transform_fn)(ptls_cipher_context_t *, void *, const void *, size_t)
ptls_cipher_suite_t quic_crypto_aes128gcmsha256
static void clib_mem_free(void *p)
static void quic_crypto_cipher_do_init(ptls_cipher_context_t *_ctx, const void *iv)
static void * clib_mem_alloc(uword size)
static vlib_main_t * vlib_get_main(void)
static void quic_crypto_aead_dispose_crypto(ptls_aead_context_t *_ctx)
ptls_cipher_algorithm_t quic_crypto_aes256ctr
static void quic_crypto_cipher_dispose(ptls_cipher_context_t *_ctx)
ptls_aead_algorithm_t quic_crypto_aes256gcm
ptls_aead_context_t super
int quic_encrypt_ticket_cb(ptls_encrypt_ticket_t *_self, ptls_t *tls, int is_encrypt, ptls_buffer_t *dst, ptls_iovec_t src)
vnet_crypto_main_t crypto_main
static int quic_crypto_cipher_setup_crypto(ptls_cipher_context_t *_ctx, int is_enc, const void *key, const EVP_CIPHER *cipher, quicly_do_transform_fn do_transform)
ptls_aead_algorithm_t quic_crypto_aes128gcm
static int aes128ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
static void quic_crypto_cipher_encrypt(ptls_cipher_context_t *_ctx, void *output, const void *input, size_t _len)