18 #include <picotls/openssl.h> 25 const void *, size_t);
32 ptls_cipher_context_t
super;
53 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
55 id = VNET_CRYPTO_OP_AES_128_CTR_ENC;
57 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
59 id = VNET_CRYPTO_OP_AES_256_CTR_ENC;
63 TLS_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
81 const void *input,
size_t _len)
96 const EVP_CIPHER * cipher,
103 ctx->
super.do_transform = do_transform;
107 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
109 algo = VNET_CRYPTO_ALG_AES_128_CTR;
111 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
113 algo = VNET_CRYPTO_ALG_AES_256_CTR;
117 TLS_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
124 (
u8 *) key, _ctx->algo->key_size);
132 const void *input,
size_t inlen,
const void *
iv,
133 const void *aad,
size_t aadlen)
137 int tag_size = ctx->
super.algo->tag_size;
139 ctx->
op.
dst = _output;
140 ctx->
op.
src = (
void *) input;
141 ctx->
op.
len = inlen - tag_size;;
142 ctx->
op.
iv = (
void *) iv;
143 ctx->
op.
aad = (
void *) aad;
145 ctx->
op.
tag = (
void *) input + inlen - tag_size;
151 return inlen - tag_size;
156 const void *aad,
size_t aadlen)
159 ctx->
op.
iv = (
void *) iv;
160 ctx->
op.
aad = (
void *) aad;
170 const void *input,
size_t inlen)
188 ctx->
op.
tag = _output;
194 return ctx->
super.algo->tag_size;
214 if (alg == VNET_CRYPTO_ALG_AES_128_GCM)
221 else if (alg == VNET_CRYPTO_ALG_AES_256_GCM)
232 TLS_DBG (1,
"%s, invalied aead cipher %s", __FUNCTION__,
256 int is_enc,
const void *
key)
264 int is_enc,
const void *
key)
272 int is_enc,
const void *
key)
275 VNET_CRYPTO_ALG_AES_128_GCM);
280 int is_enc,
const void *
key)
283 VNET_CRYPTO_ALG_AES_256_GCM);
287 PTLS_AES128_KEY_SIZE,
290 ptls_vpp_crypto_aes128ctr_setup_crypto
293 ptls_cipher_algorithm_t ptls_vpp_crypto_aes256ctr = {
"AES256-CTR",
294 PTLS_AES256_KEY_SIZE,
298 ptls_vpp_crypto_aes256ctr_setup_crypto
301 ptls_aead_algorithm_t ptls_vpp_crypto_aes128gcm = {
"AES128-GCM",
304 PTLS_AES128_KEY_SIZE,
306 PTLS_AESGCM_TAG_SIZE,
308 ptls_vpp_crypto_aead_aes128gcm_setup_crypto
311 ptls_aead_algorithm_t ptls_vpp_crypto_aes256gcm = {
"AES256-GCM",
314 PTLS_AES256_KEY_SIZE,
316 PTLS_AESGCM_TAG_SIZE,
318 ptls_vpp_crypto_aead_aes256gcm_setup_crypto
321 ptls_cipher_suite_t ptls_vpp_crypto_aes128gcmsha256 =
322 { PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
327 ptls_cipher_suite_t ptls_vpp_crypto_aes256gcmsha384 =
328 { PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
333 ptls_cipher_suite_t *ptls_vpp_crypto_cipher_suites[] =
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
static size_t ptls_vpp_crypto_aead_encrypt_update(ptls_aead_context_t *_ctx, void *output, const void *input, size_t inlen)
ptls_cipher_context_t super
static void ptls_vpp_crypto_aead_dispose_crypto(ptls_aead_context_t *_ctx)
static int ptls_vpp_crypto_aead_setup_crypto(ptls_aead_context_t *_ctx, int is_enc, const void *key, vnet_crypto_alg_t alg)
ptls_cipher_suite_t ptls_vpp_crypto_aes128gcmsha256
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
static void ptls_vpp_crypto_cipher_do_init(ptls_cipher_context_t *_ctx, const void *iv)
#define VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS
ptls_aead_algorithm_t ptls_vpp_crypto_aes128gcm
ptls_cipher_suite_t ptls_vpp_crypto_aes256gcmsha384
void(* ptls_vpp_do_transform_fn)(ptls_cipher_context_t *, void *, const void *, size_t)
size_t ptls_vpp_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)
static int ptls_vpp_crypto_aead_aes256gcm_setup_crypto(ptls_aead_context_t *ctx, int is_enc, const void *key)
static void ptls_vpp_crypto_cipher_dispose(ptls_cipher_context_t *_ctx)
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
static void ptls_vpp_crypto_aead_encrypt_init(ptls_aead_context_t *_ctx, const void *iv, const void *aad, size_t aadlen)
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
static void ptls_vpp_crypto_cipher_encrypt(ptls_cipher_context_t *_ctx, void *output, const void *input, size_t _len)
ptls_cipher_algorithm_t ptls_vpp_crypto_aes256ctr
static int ptls_vpp_crypto_cipher_setup_crypto(ptls_cipher_context_t *_ctx, int is_enc, const void *key, const EVP_CIPHER *cipher, ptls_vpp_do_transform_fn do_transform)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
ptls_cipher_algorithm_t ptls_vpp_crypto_aes128ctr
clib_rwlock_t crypto_keys_rw_lock
static int ptls_vpp_crypto_aes128ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
picotls_main_t picotls_main
u32 vnet_crypto_process_chained_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
static int ptls_vpp_crypto_aead_aes128gcm_setup_crypto(ptls_aead_context_t *ctx, int is_enc, const void *key)
static vlib_main_t * vlib_get_main(void)
static size_t ptls_vpp_crypto_aead_encrypt_final(ptls_aead_context_t *_ctx, void *_output)
ptls_aead_context_t super
ptls_aead_algorithm_t ptls_vpp_crypto_aes256gcm
vnet_crypto_op_chunk_t chunks[2]
vnet_crypto_op_status_t status
vnet_crypto_main_t crypto_main
#define TLS_DBG(_lvl, _fmt, _args...)
static int ptls_vpp_crypto_aes256ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)