18 #include <picotls/openssl.h> 24 const void *, size_t);
30 ptls_cipher_context_t
super;
51 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
53 id = VNET_CRYPTO_OP_AES_128_CTR_ENC;
55 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
57 id = VNET_CRYPTO_OP_AES_256_CTR_ENC;
61 TLS_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
79 const void *input,
size_t _len)
94 const EVP_CIPHER * cipher,
101 ctx->
super.do_transform = do_transform;
105 if (!strcmp (ctx->
super.algo->name,
"AES128-CTR"))
107 algo = VNET_CRYPTO_ALG_AES_128_CTR;
109 else if (!strcmp (ctx->
super.algo->name,
"AES256-CTR"))
111 algo = VNET_CRYPTO_ALG_AES_256_CTR;
115 TLS_DBG (1,
"%s, Invalid crypto cipher : ", __FUNCTION__,
121 (
u8 *) key, _ctx->algo->key_size);
128 const void *input,
size_t inlen,
const void *
iv,
129 const void *aad,
size_t aadlen)
133 int tag_size = ctx->
super.algo->tag_size;
135 ctx->
op.
dst = _output;
136 ctx->
op.
src = (
void *) input;
137 ctx->
op.
len = inlen - tag_size;;
138 ctx->
op.
iv = (
void *) iv;
139 ctx->
op.
aad = (
void *) aad;
141 ctx->
op.
tag = (
void *) input + inlen - tag_size;
147 return inlen - tag_size;
152 const void *aad,
size_t aadlen)
155 ctx->
op.
iv = (
void *) iv;
156 ctx->
op.
aad = (
void *) aad;
166 const void *input,
size_t inlen)
184 ctx->
op.
tag = _output;
190 return ctx->
super.algo->tag_size;
206 u16 key_len = ctx->
super.algo->key_size;
210 if (alg == VNET_CRYPTO_ALG_AES_128_GCM)
217 else if (alg == VNET_CRYPTO_ALG_AES_256_GCM)
228 TLS_DBG (1,
"%s, invalied aead cipher %s", __FUNCTION__,
250 int is_enc,
const void *
key)
258 int is_enc,
const void *
key)
266 int is_enc,
const void *
key)
269 VNET_CRYPTO_ALG_AES_128_GCM);
274 int is_enc,
const void *
key)
277 VNET_CRYPTO_ALG_AES_256_GCM);
281 PTLS_AES128_KEY_SIZE,
284 ptls_vpp_crypto_aes128ctr_setup_crypto
287 ptls_cipher_algorithm_t ptls_vpp_crypto_aes256ctr = {
"AES256-CTR",
288 PTLS_AES256_KEY_SIZE,
292 ptls_vpp_crypto_aes256ctr_setup_crypto
295 ptls_aead_algorithm_t ptls_vpp_crypto_aes128gcm = {
"AES128-GCM",
298 PTLS_AES128_KEY_SIZE,
300 PTLS_AESGCM_TAG_SIZE,
302 ptls_vpp_crypto_aead_aes128gcm_setup_crypto
305 ptls_aead_algorithm_t ptls_vpp_crypto_aes256gcm = {
"AES256-GCM",
308 PTLS_AES256_KEY_SIZE,
310 PTLS_AESGCM_TAG_SIZE,
312 ptls_vpp_crypto_aead_aes256gcm_setup_crypto
315 ptls_cipher_suite_t ptls_vpp_crypto_aes128gcmsha256 =
316 { PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
321 ptls_cipher_suite_t ptls_vpp_crypto_aes256gcmsha384 =
322 { PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
327 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 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)
ptls_cipher_algorithm_t ptls_vpp_crypto_aes128ctr
static int ptls_vpp_crypto_aes128ctr_setup_crypto(ptls_cipher_context_t *ctx, int is_enc, const void *key)
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)