aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ipsec
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ipsec')
-rw-r--r--src/vnet/ipsec/ah.h6
-rw-r--r--src/vnet/ipsec/ah_decrypt.c6
-rw-r--r--src/vnet/ipsec/ah_encrypt.c6
-rw-r--r--src/vnet/ipsec/esp.h108
-rw-r--r--src/vnet/ipsec/esp_decrypt.c52
-rw-r--r--src/vnet/ipsec/esp_encrypt.c53
-rw-r--r--src/vnet/ipsec/ipsec.c71
-rw-r--r--src/vnet/ipsec/ipsec.h54
8 files changed, 123 insertions, 233 deletions
diff --git a/src/vnet/ipsec/ah.h b/src/vnet/ipsec/ah.h
index f74ad9b01c1..d0b4c21a4bc 100644
--- a/src/vnet/ipsec/ah.h
+++ b/src/vnet/ipsec/ah.h
@@ -15,15 +15,9 @@
#ifndef __AH_H__
#define __AH_H__
-
#include <vnet/ip/ip.h>
#include <vnet/ipsec/ipsec.h>
-#include <openssl/hmac.h>
-#include <openssl/rand.h>
-#include <openssl/evp.h>
-
-
typedef struct
{
unsigned char nexthdr;
diff --git a/src/vnet/ipsec/ah_decrypt.c b/src/vnet/ipsec/ah_decrypt.c
index 0fc4f48571d..2488fa918f6 100644
--- a/src/vnet/ipsec/ah_decrypt.c
+++ b/src/vnet/ipsec/ah_decrypt.c
@@ -84,7 +84,6 @@ ah_decrypt_inline (vlib_main_t * vm,
{
u32 n_left_from, *from, next_index, *to_next, thread_index;
ipsec_main_t *im = &ipsec_main;
- ipsec_proto_main_t *em = &ipsec_proto_main;
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
int icv_size;
@@ -173,8 +172,7 @@ ah_decrypt_inline (vlib_main_t * vm,
(&ipsec_sa_counters, thread_index, sa_index0,
1, i_b0->current_length);
- icv_size =
- em->ipsec_proto_main_integ_algs[sa0->integ_alg].trunc_size;
+ icv_size = im->integ_algs[sa0->integ_alg].trunc_size;
if (PREDICT_TRUE (sa0->integ_alg != IPSEC_INTEG_ALG_NONE))
{
u8 sig[64];
@@ -205,7 +203,7 @@ ah_decrypt_inline (vlib_main_t * vm,
icv_padding_len =
ah_calc_icv_padding_len (icv_size, 0 /* is_ipv6 */ );
}
- hmac_calc (sa0->integ_alg, sa0->integ_key.data,
+ hmac_calc (vm, sa0->integ_alg, sa0->integ_key.data,
sa0->integ_key.len, (u8 *) ih4, i_b0->current_length,
sig, sa0->use_esn, sa0->seq_hi);
diff --git a/src/vnet/ipsec/ah_encrypt.c b/src/vnet/ipsec/ah_encrypt.c
index 2e561deb8b6..ce930bd5529 100644
--- a/src/vnet/ipsec/ah_encrypt.c
+++ b/src/vnet/ipsec/ah_encrypt.c
@@ -89,7 +89,6 @@ ah_encrypt_inline (vlib_main_t * vm,
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
ipsec_main_t *im = &ipsec_main;
- ipsec_proto_main_t *em = &ipsec_proto_main;
next_index = node->cached_next_index;
thread_index = vm->thread_index;
@@ -153,8 +152,7 @@ ah_encrypt_inline (vlib_main_t * vm,
adv = -sizeof (ah_header_t);
}
- icv_size =
- em->ipsec_proto_main_integ_algs[sa0->integ_alg].trunc_size;
+ icv_size = im->integ_algs[sa0->integ_alg].trunc_size;
const u8 padding_len = ah_calc_icv_padding_len (icv_size, is_ip6);
adv -= padding_len;
/* transport mode save the eth header before it is overwritten */
@@ -267,7 +265,7 @@ ah_encrypt_inline (vlib_main_t * vm,
sizeof (ah_header_t);
clib_memset (digest, 0, icv_size);
- unsigned size = hmac_calc (sa0->integ_alg, sa0->integ_key.data,
+ unsigned size = hmac_calc (vm, sa0->integ_alg, sa0->integ_key.data,
sa0->integ_key.len,
vlib_buffer_get_current (i_b0),
i_b0->current_length, sig, sa0->use_esn,
diff --git a/src/vnet/ipsec/esp.h b/src/vnet/ipsec/esp.h
index 00472654554..17300383e16 100644
--- a/src/vnet/ipsec/esp.h
+++ b/src/vnet/ipsec/esp.h
@@ -16,6 +16,7 @@
#define __ESP_H__
#include <vnet/ip/ip.h>
+#include <vnet/crypto/crypto.h>
#include <vnet/ipsec/ipsec.h>
typedef struct
@@ -202,106 +203,25 @@ esp_seq_advance (ipsec_sa_t * sa)
return 0;
}
-always_inline void
-ipsec_proto_init ()
-{
- ipsec_proto_main_t *em = &ipsec_proto_main;
- vlib_thread_main_t *tm = vlib_get_thread_main ();
-
- clib_memset (em, 0, sizeof (em[0]));
-
- vec_validate (em->ipsec_proto_main_crypto_algs, IPSEC_CRYPTO_N_ALG - 1);
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_128].type =
- EVP_aes_128_cbc ();
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_192].type =
- EVP_aes_192_cbc ();
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_256].type =
- EVP_aes_256_cbc ();
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_128].iv_size = 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_192].iv_size = 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_256].iv_size = 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_128].block_size =
- 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_192].block_size =
- 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_AES_CBC_256].block_size =
- 16;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_DES_CBC].type =
- EVP_des_cbc ();
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_3DES_CBC].type =
- EVP_des_ede3_cbc ();
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_DES_CBC].block_size = 8;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_3DES_CBC].block_size = 8;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_DES_CBC].iv_size = 8;
- em->ipsec_proto_main_crypto_algs[IPSEC_CRYPTO_ALG_3DES_CBC].iv_size = 8;
-
- vec_validate (em->ipsec_proto_main_integ_algs, IPSEC_INTEG_N_ALG - 1);
- ipsec_proto_main_integ_alg_t *i;
-
- i = &em->ipsec_proto_main_integ_algs[IPSEC_INTEG_ALG_SHA1_96];
- i->md = EVP_sha1 ();
- i->trunc_size = 12;
-
- i = &em->ipsec_proto_main_integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
- i->md = EVP_sha256 ();
- i->trunc_size = 12;
-
- i = &em->ipsec_proto_main_integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
- i->md = EVP_sha256 ();
- i->trunc_size = 16;
-
- i = &em->ipsec_proto_main_integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
- i->md = EVP_sha384 ();
- i->trunc_size = 24;
-
- i = &em->ipsec_proto_main_integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
- i->md = EVP_sha512 ();
- i->trunc_size = 32;
-
- vec_validate_aligned (em->per_thread_data, tm->n_vlib_mains - 1,
- CLIB_CACHE_LINE_BYTES);
- int thread_id;
-
- for (thread_id = 0; thread_id < tm->n_vlib_mains; thread_id++)
- {
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- em->per_thread_data[thread_id].encrypt_ctx = EVP_CIPHER_CTX_new ();
- em->per_thread_data[thread_id].decrypt_ctx = EVP_CIPHER_CTX_new ();
- em->per_thread_data[thread_id].hmac_ctx = HMAC_CTX_new ();
-#else
- EVP_CIPHER_CTX_init (&(em->per_thread_data[thread_id].encrypt_ctx));
- EVP_CIPHER_CTX_init (&(em->per_thread_data[thread_id].decrypt_ctx));
- HMAC_CTX_init (&(em->per_thread_data[thread_id].hmac_ctx));
-#endif
- }
-}
always_inline unsigned int
-hmac_calc (ipsec_integ_alg_t alg,
- u8 * key,
- int key_len,
+hmac_calc (vlib_main_t * vm, ipsec_integ_alg_t alg, u8 * key, int key_len,
u8 * data, int data_len, u8 * signature, u8 use_esn, u32 seq_hi)
{
- ipsec_proto_main_t *em = &ipsec_proto_main;
- u32 thread_index = vlib_get_thread_index ();
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- HMAC_CTX *ctx = em->per_thread_data[thread_index].hmac_ctx;
-#else
- HMAC_CTX *ctx = &(em->per_thread_data[thread_index].hmac_ctx);
-#endif
- const EVP_MD *md = NULL;
- unsigned int len;
-
+ ipsec_main_t *im = &ipsec_main;
+ vnet_crypto_op_t _op, *op = &_op;
ASSERT (alg < IPSEC_INTEG_N_ALG);
- if (PREDICT_FALSE (em->ipsec_proto_main_integ_algs[alg].md == 0))
+ if (PREDICT_FALSE (im->integ_algs[alg].op_type == 0))
return 0;
- if (PREDICT_FALSE (alg != em->per_thread_data[thread_index].last_integ_alg))
- {
- md = em->ipsec_proto_main_integ_algs[alg].md;
- em->per_thread_data[thread_index].last_integ_alg = alg;
- }
+ op->op = im->integ_algs[alg].op_type;
+ op->key = key;
+ op->key_len = key_len;
+ op->src = data;
+ op->len = data_len;
+ op->dst = signature;
+#if 0
HMAC_Init_ex (ctx, key, key_len, md, NULL);
@@ -311,7 +231,9 @@ hmac_calc (ipsec_integ_alg_t alg,
HMAC_Update (ctx, (u8 *) & seq_hi, sizeof (seq_hi));
HMAC_Final (ctx, signature, &len);
- return em->ipsec_proto_main_integ_algs[alg].trunc_size;
+#endif
+ vnet_crypto_process_ops (vm, op, 1);
+ return im->integ_algs[alg].trunc_size;
}
#endif /* __ESP_H__ */
diff --git a/src/vnet/ipsec/esp_decrypt.c b/src/vnet/ipsec/esp_decrypt.c
index 7e5114ce2cf..1ee7ce8fd0a 100644
--- a/src/vnet/ipsec/esp_decrypt.c
+++ b/src/vnet/ipsec/esp_decrypt.c
@@ -82,35 +82,28 @@ format_esp_decrypt_trace (u8 * s, va_list * args)
}
always_inline void
-esp_decrypt_cbc (ipsec_crypto_alg_t alg,
+esp_decrypt_cbc (vlib_main_t * vm, ipsec_crypto_alg_t alg,
u8 * in, u8 * out, size_t in_len, u8 * key, u8 * iv)
{
- ipsec_proto_main_t *em = &ipsec_proto_main;
- u32 thread_index = vlib_get_thread_index ();
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- EVP_CIPHER_CTX *ctx = em->per_thread_data[thread_index].decrypt_ctx;
-#else
- EVP_CIPHER_CTX *ctx = &(em->per_thread_data[thread_index].decrypt_ctx);
-#endif
- const EVP_CIPHER *cipher = NULL;
- int out_len;
+ ipsec_main_t *im = &ipsec_main;
+ ipsec_main_crypto_alg_t *a;
+ vnet_crypto_op_t _op, *op = &_op;
ASSERT (alg < IPSEC_CRYPTO_N_ALG);
- if (PREDICT_FALSE (em->ipsec_proto_main_crypto_algs[alg].type == 0))
- return;
+ a = &im->crypto_algs[alg];
- if (PREDICT_FALSE
- (alg != em->per_thread_data[thread_index].last_decrypt_alg))
- {
- cipher = em->ipsec_proto_main_crypto_algs[alg].type;
- em->per_thread_data[thread_index].last_decrypt_alg = alg;
- }
+ if (PREDICT_FALSE (a->dec_op_type == VNET_CRYPTO_OP_NONE))
+ return;
- EVP_DecryptInit_ex (ctx, cipher, NULL, key, iv);
+ op->op = a->dec_op_type;
+ op->iv = iv;
+ op->src = in;
+ op->dst = out;
+ op->len = in_len;
+ op->key = key;
- EVP_DecryptUpdate (ctx, out, &out_len, in, in_len);
- EVP_DecryptFinal_ex (ctx, out + out_len, &out_len);
+ vnet_crypto_process_ops (vm, op, 1);
}
always_inline uword
@@ -119,7 +112,6 @@ esp_decrypt_inline (vlib_main_t * vm,
int is_ip6)
{
ipsec_main_t *im = &ipsec_main;
- ipsec_proto_main_t *em = &ipsec_proto_main;
u32 *from = vlib_frame_vector_args (from_frame);
u32 n_left_from = from_frame->n_vectors;
u32 new_bufs[VLIB_FRAME_SIZE];
@@ -189,15 +181,13 @@ esp_decrypt_inline (vlib_main_t * vm,
if (PREDICT_TRUE (sa0->integ_alg != IPSEC_INTEG_ALG_NONE))
{
u8 sig[64];
- int icv_size =
- em->ipsec_proto_main_integ_algs[sa0->integ_alg].trunc_size;
+ int icv_size = im->integ_algs[sa0->integ_alg].trunc_size;
clib_memset (sig, 0, sizeof (sig));
- u8 *icv =
- vlib_buffer_get_current (ib[0]) + ib[0]->current_length -
+ u8 *icv = vlib_buffer_get_current (ib[0]) + ib[0]->current_length -
icv_size;
ib[0]->current_length -= icv_size;
- hmac_calc (sa0->integ_alg, sa0->integ_key.data,
+ hmac_calc (vm, sa0->integ_alg, sa0->integ_key.data,
sa0->integ_key.len, (u8 *) esp0,
ib[0]->current_length, sig, sa0->use_esn, sa0->seq_hi);
@@ -227,10 +217,8 @@ esp_decrypt_inline (vlib_main_t * vm,
(sa0->crypto_alg >= IPSEC_CRYPTO_ALG_DES_CBC &&
sa0->crypto_alg <= IPSEC_CRYPTO_ALG_3DES_CBC))
{
- const int BLOCK_SIZE =
- em->ipsec_proto_main_crypto_algs[sa0->crypto_alg].block_size;;
- const int IV_SIZE =
- em->ipsec_proto_main_crypto_algs[sa0->crypto_alg].iv_size;
+ const int BLOCK_SIZE = im->crypto_algs[sa0->crypto_alg].block_size;
+ const int IV_SIZE = im->crypto_algs[sa0->crypto_alg].iv_size;
esp_footer_t *f0;
u8 ip_hdr_size = 0;
@@ -263,7 +251,7 @@ esp_decrypt_inline (vlib_main_t * vm,
}
}
- esp_decrypt_cbc (sa0->crypto_alg,
+ esp_decrypt_cbc (vm, sa0->crypto_alg,
esp0->data + IV_SIZE,
(u8 *) vlib_buffer_get_current (ob[0]) +
ip_hdr_size, BLOCK_SIZE * blocks,
diff --git a/src/vnet/ipsec/esp_encrypt.c b/src/vnet/ipsec/esp_encrypt.c
index 080a3458926..37c2c953c87 100644
--- a/src/vnet/ipsec/esp_encrypt.c
+++ b/src/vnet/ipsec/esp_encrypt.c
@@ -20,6 +20,8 @@
#include <vnet/ip/ip.h>
#include <vnet/udp/udp.h>
+#include <vnet/crypto/crypto.h>
+
#include <vnet/ipsec/ipsec.h>
#include <vnet/ipsec/esp.h>
@@ -88,33 +90,26 @@ always_inline void
esp_encrypt_cbc (vlib_main_t * vm, ipsec_crypto_alg_t alg,
u8 * in, u8 * out, size_t in_len, u8 * key, u8 * iv)
{
- ipsec_proto_main_t *em = &ipsec_proto_main;
- u32 thread_index = vm->thread_index;
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- EVP_CIPHER_CTX *ctx = em->per_thread_data[thread_index].encrypt_ctx;
-#else
- EVP_CIPHER_CTX *ctx = &(em->per_thread_data[thread_index].encrypt_ctx);
-#endif
- const EVP_CIPHER *cipher = NULL;
- int out_len;
+ ipsec_main_t *im = &ipsec_main;
+ ipsec_main_crypto_alg_t *a;
+ vnet_crypto_op_t _op, *op = &_op;
ASSERT (alg < IPSEC_CRYPTO_N_ALG);
- if (PREDICT_FALSE
- (em->ipsec_proto_main_crypto_algs[alg].type == IPSEC_CRYPTO_ALG_NONE))
- return;
+ a = &im->crypto_algs[alg];
- if (PREDICT_FALSE
- (alg != em->per_thread_data[thread_index].last_encrypt_alg))
- {
- cipher = em->ipsec_proto_main_crypto_algs[alg].type;
- em->per_thread_data[thread_index].last_encrypt_alg = alg;
- }
+ if (PREDICT_FALSE (a->enc_op_type == VNET_CRYPTO_OP_NONE))
+ return;
- EVP_EncryptInit_ex (ctx, cipher, NULL, key, iv);
+ op->op = a->enc_op_type;
+ op->flags = VNET_CRYPTO_OP_FLAG_INIT_IV;
+ op->iv = iv;
+ op->src = in;
+ op->dst = out;
+ op->len = in_len;
+ op->key = key;
- EVP_EncryptUpdate (ctx, out, &out_len, in, in_len);
- EVP_EncryptFinal_ex (ctx, out + out_len, &out_len);
+ vnet_crypto_process_ops (vm, op, 1);
}
always_inline uword
@@ -125,7 +120,6 @@ esp_encrypt_inline (vlib_main_t * vm,
u32 *from = vlib_frame_vector_args (from_frame);
u32 n_left_from = from_frame->n_vectors;
ipsec_main_t *im = &ipsec_main;
- ipsec_proto_main_t *em = &ipsec_proto_main;
u32 new_bufs[VLIB_FRAME_SIZE];
vlib_buffer_t *i_bufs[VLIB_FRAME_SIZE], **ib = i_bufs;
vlib_buffer_t *o_bufs[VLIB_FRAME_SIZE], **ob = o_bufs;
@@ -288,10 +282,8 @@ esp_encrypt_inline (vlib_main_t * vm,
if (PREDICT_TRUE (sa0->crypto_alg != IPSEC_CRYPTO_ALG_NONE))
{
- const int BLOCK_SIZE =
- em->ipsec_proto_main_crypto_algs[sa0->crypto_alg].block_size;
- const int IV_SIZE =
- em->ipsec_proto_main_crypto_algs[sa0->crypto_alg].iv_size;
+ const int BLOCK_SIZE = im->crypto_algs[sa0->crypto_alg].block_size;
+ const int IV_SIZE = im->crypto_algs[sa0->crypto_alg].iv_size;
int blocks = 1 + (ib[0]->current_length + 1) / BLOCK_SIZE;
/* pad packet in input buffer */
@@ -314,13 +306,12 @@ esp_encrypt_inline (vlib_main_t * vm,
vnet_buffer (ob[0])->sw_if_index[VLIB_RX] =
vnet_buffer (ib[0])->sw_if_index[VLIB_RX];
- u8 iv[em->ipsec_proto_main_crypto_algs[sa0->crypto_alg].iv_size];
- RAND_bytes (iv, sizeof (iv));
+ u8 *iv = vlib_buffer_get_current (ob[0]) + ip_udp_hdr_size +
+ sizeof (esp_header_t);
clib_memcpy_fast ((u8 *) vlib_buffer_get_current (ob[0]) +
ip_udp_hdr_size + sizeof (esp_header_t), iv,
- em->ipsec_proto_main_crypto_algs[sa0->
- crypto_alg].iv_size);
+ im->crypto_algs[sa0->crypto_alg].iv_size);
esp_encrypt_cbc (vm, sa0->crypto_alg,
(u8 *) vlib_buffer_get_current (ib[0]),
@@ -331,7 +322,7 @@ esp_encrypt_inline (vlib_main_t * vm,
}
ob[0]->current_length +=
- hmac_calc (sa0->integ_alg, sa0->integ_key.data,
+ hmac_calc (vm, sa0->integ_alg, sa0->integ_key.data,
sa0->integ_key.len, (u8 *) o_esp0,
ob[0]->current_length - ip_udp_hdr_size,
vlib_buffer_get_current (ob[0]) + ob[0]->current_length,
diff --git a/src/vnet/ipsec/ipsec.c b/src/vnet/ipsec/ipsec.c
index ce93f32b429..e9d13a4e717 100644
--- a/src/vnet/ipsec/ipsec.c
+++ b/src/vnet/ipsec/ipsec.c
@@ -26,24 +26,6 @@
#include <vnet/ipsec/ah.h>
ipsec_main_t ipsec_main;
-ipsec_proto_main_t ipsec_proto_main;
-
-static void
-ipsec_rand_seed (void)
-{
- struct
- {
- time_t time;
- pid_t pid;
- void *p;
- } seed_data;
-
- seed_data.time = time (NULL);
- seed_data.pid = getpid ();
- seed_data.p = (void *) &seed_data;
-
- RAND_seed ((const void *) &seed_data, sizeof (seed_data));
-}
static clib_error_t *
ipsec_check_ah_support (ipsec_sa_t * sa)
@@ -240,8 +222,7 @@ ipsec_init (vlib_main_t * vm)
{
clib_error_t *error;
ipsec_main_t *im = &ipsec_main;
-
- ipsec_rand_seed ();
+ ipsec_main_crypto_alg_t *a;
clib_memset (im, 0, sizeof (im[0]));
@@ -287,7 +268,55 @@ ipsec_init (vlib_main_t * vm)
if ((error = vlib_call_init_function (vm, ipsec_tunnel_if_init)))
return error;
- ipsec_proto_init ();
+ vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1);
+
+ a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC;
+ a->enc_op_type = VNET_CRYPTO_OP_DES_CBC_ENC;
+ a->dec_op_type = VNET_CRYPTO_OP_DES_CBC_DEC;
+ a->iv_size = a->block_size = 8;
+
+ a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC;
+ a->enc_op_type = VNET_CRYPTO_OP_3DES_CBC_ENC;
+ a->dec_op_type = VNET_CRYPTO_OP_3DES_CBC_DEC;
+ a->iv_size = a->block_size = 8;
+
+ a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128;
+ a->enc_op_type = VNET_CRYPTO_OP_AES_128_CBC_ENC;
+ a->dec_op_type = VNET_CRYPTO_OP_AES_128_CBC_DEC;
+ a->iv_size = a->block_size = 16;
+
+ a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192;
+ a->enc_op_type = VNET_CRYPTO_OP_AES_192_CBC_ENC;
+ a->dec_op_type = VNET_CRYPTO_OP_AES_192_CBC_DEC;
+ a->iv_size = a->block_size = 16;
+
+ a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256;
+ a->enc_op_type = VNET_CRYPTO_OP_AES_256_CBC_ENC;
+ a->dec_op_type = VNET_CRYPTO_OP_AES_256_CBC_DEC;
+ a->iv_size = a->block_size = 16;
+
+ vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1);
+ ipsec_main_integ_alg_t *i;
+
+ i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96];
+ i->op_type = VNET_CRYPTO_OP_SHA1_HMAC;
+ i->trunc_size = 12;
+
+ i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
+ i->op_type = VNET_CRYPTO_OP_SHA1_HMAC;
+ i->trunc_size = 12;
+
+ i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
+ i->op_type = VNET_CRYPTO_OP_SHA256_HMAC;
+ i->trunc_size = 16;
+
+ i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
+ i->op_type = VNET_CRYPTO_OP_SHA384_HMAC;
+ i->trunc_size = 24;
+
+ i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
+ i->op_type = VNET_CRYPTO_OP_SHA512_HMAC;
+ i->trunc_size = 32;
return 0;
}
diff --git a/src/vnet/ipsec/ipsec.h b/src/vnet/ipsec/ipsec.h
index c877139ba12..e38a4a8771e 100644
--- a/src/vnet/ipsec/ipsec.h
+++ b/src/vnet/ipsec/ipsec.h
@@ -16,12 +16,9 @@
#define __IPSEC_H__
#include <vnet/ip/ip.h>
+#include <vnet/crypto/crypto.h>
#include <vnet/feature/feature.h>
-#include <openssl/hmac.h>
-#include <openssl/rand.h>
-#include <openssl/evp.h>
-
#include <vppinfra/types.h>
#include <vppinfra/cache.h>
@@ -69,50 +66,17 @@ typedef struct
typedef struct
{
- const EVP_CIPHER *type;
+ vnet_crypto_op_type_t enc_op_type;
+ vnet_crypto_op_type_t dec_op_type;
u8 iv_size;
u8 block_size;
-} ipsec_proto_main_crypto_alg_t;
+} ipsec_main_crypto_alg_t;
typedef struct
{
- const EVP_MD *md;
+ vnet_crypto_op_type_t op_type;
u8 trunc_size;
-} ipsec_proto_main_integ_alg_t;
-
-typedef struct
-{
- CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- EVP_CIPHER_CTX *encrypt_ctx;
-#else
- EVP_CIPHER_CTX encrypt_ctx;
-#endif
- CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- EVP_CIPHER_CTX *decrypt_ctx;
-#else
- EVP_CIPHER_CTX decrypt_ctx;
-#endif
- CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
- HMAC_CTX *hmac_ctx;
-#else
- HMAC_CTX hmac_ctx;
-#endif
- ipsec_crypto_alg_t last_encrypt_alg;
- ipsec_crypto_alg_t last_decrypt_alg;
- ipsec_integ_alg_t last_integ_alg;
-} ipsec_proto_main_per_thread_data_t;
-
-typedef struct
-{
- ipsec_proto_main_crypto_alg_t *ipsec_proto_main_crypto_algs;
- ipsec_proto_main_integ_alg_t *ipsec_proto_main_integ_algs;
- ipsec_proto_main_per_thread_data_t *per_thread_data;
-} ipsec_proto_main_t;
-
-extern ipsec_proto_main_t ipsec_proto_main;
+} ipsec_main_integ_alg_t;
typedef struct
{
@@ -171,6 +135,12 @@ typedef struct
u32 ah_default_backend;
/* index of default esp backend */
u32 esp_default_backend;
+
+ /* crypto alg data */
+ ipsec_main_crypto_alg_t *crypto_algs;
+
+ /* crypto integ data */
+ ipsec_main_integ_alg_t *integ_algs;
} ipsec_main_t;
extern ipsec_main_t ipsec_main;