summaryrefslogtreecommitdiffstats
path: root/src/plugins/crypto_ia32/main.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-05-22 15:11:18 +0200
committerNeale Ranns <nranns@cisco.com>2019-05-23 08:56:46 +0000
commitd5023a72ddabe7e9a8698ad57c82d6be117fff73 (patch)
tree751aa38f2b9559099859449c0bc0ca88f8b55a11 /src/plugins/crypto_ia32/main.c
parent0ad4a439d68f906295656876cc3bb3092da2cf56 (diff)
crypto_ia32: multiarch
Change-Id: Iead43a2b524b735a2069e611d899cd41d3a8efdc Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/crypto_ia32/main.c')
-rw-r--r--src/plugins/crypto_ia32/main.c52
1 files changed, 14 insertions, 38 deletions
diff --git a/src/plugins/crypto_ia32/main.c b/src/plugins/crypto_ia32/main.c
index a02fc38f99e..b31c9019495 100644
--- a/src/plugins/crypto_ia32/main.c
+++ b/src/plugins/crypto_ia32/main.c
@@ -19,7 +19,6 @@
#include <vnet/plugin/plugin.h>
#include <vnet/crypto/crypto.h>
#include <crypto_ia32/crypto_ia32.h>
-#include <crypto_ia32/aesni.h>
crypto_ia32_main_t crypto_ia32_main;
@@ -29,17 +28,9 @@ crypto_ia32_key_handler (vlib_main_t * vm, vnet_crypto_key_op_t kop,
{
vnet_crypto_key_t *key = vnet_crypto_get_key (idx);
crypto_ia32_main_t *cm = &crypto_ia32_main;
- aesni_key_data_t *kd;
- switch (key->alg)
- {
- case VNET_CRYPTO_ALG_AES_128_CBC:
- case VNET_CRYPTO_ALG_AES_192_CBC:
- case VNET_CRYPTO_ALG_AES_256_CBC:
- break;
- default:
- return;
- }
+ if (cm->key_fn[key->alg] == 0)
+ return;
if (kop == VNET_CRYPTO_KEY_OP_DEL)
{
@@ -65,31 +56,7 @@ crypto_ia32_key_handler (vlib_main_t * vm, vnet_crypto_key_op_t kop,
clib_mem_free (cm->key_data[idx]);
}
- kd = cm->key_data[idx] = clib_mem_alloc_aligned (sizeof (aesni_key_data_t),
- CLIB_CACHE_LINE_BYTES);
-
- /* ADD or MODIFY */
- switch (key->alg)
- {
- case VNET_CRYPTO_ALG_AES_128_CBC:
- aes_key_expand (kd->encrypt_key, key->data, AESNI_KEY_128);
- aes_key_expand (kd->decrypt_key, key->data, AESNI_KEY_128);
- aes_key_enc_to_dec (kd->decrypt_key, AESNI_KEY_128);
- break;
- case VNET_CRYPTO_ALG_AES_192_CBC:
- aes_key_expand (kd->encrypt_key, key->data, AESNI_KEY_192);
- aes_key_expand (kd->decrypt_key, key->data, AESNI_KEY_192);
- aes_key_enc_to_dec (kd->decrypt_key, AESNI_KEY_192);
- break;
- case VNET_CRYPTO_ALG_AES_256_CBC:
- aes_key_expand (kd->encrypt_key, key->data, AESNI_KEY_256);
- aes_key_expand (kd->decrypt_key, key->data, AESNI_KEY_256);
- aes_key_enc_to_dec (kd->decrypt_key, AESNI_KEY_256);
- break;
- default:
- break;
- }
- return;
+ cm->key_data[idx] = cm->key_fn[key->alg] (key);
}
clib_error_t *
@@ -99,6 +66,9 @@ crypto_ia32_init (vlib_main_t * vm)
vlib_thread_main_t *tm = vlib_get_thread_main ();
clib_error_t *error = 0;
+ if (clib_cpu_supports_x86_aes () == 0)
+ return 0;
+
vec_validate_aligned (cm->per_thread_data, tm->n_vlib_mains - 1,
CLIB_CACHE_LINE_BYTES);
@@ -106,8 +76,14 @@ crypto_ia32_init (vlib_main_t * vm)
vnet_crypto_register_engine (vm, "ia32", 100,
"Intel IA32 ISA Optimized Crypto");
- if (clib_cpu_supports_x86_aes () &&
- (error = crypto_ia32_aesni_cbc_init (vm)))
+ if (clib_cpu_supports_avx512f ())
+ error = crypto_ia32_aesni_cbc_init_avx512 (vm);
+ else if (clib_cpu_supports_avx2 ())
+ error = crypto_ia32_aesni_cbc_init_avx2 (vm);
+ else
+ error = crypto_ia32_aesni_cbc_init_sse42 (vm);
+
+ if (error)
goto error;
vnet_crypto_register_key_handler (vm, cm->crypto_engine_index,