summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/crypto_openssl/main.c86
-rw-r--r--src/plugins/unittest/CMakeLists.txt1
-rw-r--r--src/plugins/unittest/crypto/aes_cbc.c48
-rw-r--r--src/plugins/unittest/crypto/aes_gcm.c91
-rw-r--r--src/plugins/unittest/crypto/crypto.h7
-rw-r--r--src/plugins/unittest/crypto/rfc2202_hmac_md5.c42
-rw-r--r--src/plugins/unittest/crypto/rfc2202_hmac_sha1.c49
-rw-r--r--src/plugins/unittest/crypto/rfc4231.c172
-rw-r--r--src/plugins/unittest/crypto_test.c210
-rw-r--r--src/vnet/crypto/cli.c59
-rw-r--r--src/vnet/crypto/crypto.c118
-rw-r--r--src/vnet/crypto/crypto.h116
-rw-r--r--src/vnet/crypto/format.c39
-rw-r--r--src/vnet/ipsec/esp.h8
-rw-r--r--src/vnet/ipsec/esp_decrypt.c11
-rw-r--r--src/vnet/ipsec/esp_encrypt.c13
-rw-r--r--src/vnet/ipsec/ipsec.c30
-rw-r--r--src/vnet/ipsec/ipsec.h6
-rw-r--r--src/vnet/ipsec/ipsec_sa.c6
-rw-r--r--src/vnet/ipsec/ipsec_sa.h6
-rw-r--r--src/vnet/lisp-cp/control.c10
21 files changed, 760 insertions, 368 deletions
diff --git a/src/plugins/crypto_openssl/main.c b/src/plugins/crypto_openssl/main.c
index 850ec6520d6..9a78cb46dd9 100644
--- a/src/plugins/crypto_openssl/main.c
+++ b/src/plugins/crypto_openssl/main.c
@@ -37,11 +37,14 @@ typedef struct
static openssl_per_thread_data_t *per_thread_data = 0;
#define foreach_openssl_evp_op \
- _(DES_CBC, EVP_des_cbc) \
- _(3DES_CBC, EVP_des_ede3_cbc) \
- _(AES_128_CBC, EVP_aes_128_cbc) \
- _(AES_192_CBC, EVP_aes_192_cbc) \
- _(AES_256_CBC, EVP_aes_256_cbc)
+ _(cbc, DES_CBC, EVP_des_cbc) \
+ _(cbc, 3DES_CBC, EVP_des_ede3_cbc) \
+ _(cbc, AES_128_CBC, EVP_aes_128_cbc) \
+ _(cbc, AES_192_CBC, EVP_aes_192_cbc) \
+ _(cbc, AES_256_CBC, EVP_aes_256_cbc) \
+ _(gcm, AES_128_GCM, EVP_aes_128_gcm) \
+ _(gcm, AES_192_GCM, EVP_aes_192_gcm) \
+ _(gcm, AES_256_GCM, EVP_aes_256_gcm)
#define foreach_openssl_hmac_op \
_(MD5, EVP_md5) \
@@ -99,6 +102,62 @@ openssl_ops_dec_cbc (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
}
static_always_inline u32
+openssl_ops_enc_gcm (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
+ const EVP_CIPHER * cipher)
+{
+ openssl_per_thread_data_t *ptd = vec_elt_at_index (per_thread_data,
+ vm->thread_index);
+ EVP_CIPHER_CTX *ctx = ptd->evp_cipher_ctx;
+ u32 i;
+ for (i = 0; i < n_ops; i++)
+ {
+ vnet_crypto_op_t *op = ops[i];
+ int len;
+
+ if (op->flags & VNET_CRYPTO_OP_FLAG_INIT_IV)
+ RAND_bytes (op->iv, op->iv_len);
+
+ EVP_EncryptInit_ex (ctx, cipher, 0, 0, 0);
+ EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_SET_IVLEN, op->iv_len, NULL);
+ EVP_EncryptInit_ex (ctx, 0, 0, op->key, op->iv);
+ EVP_EncryptUpdate (ctx, NULL, &len, op->aad, op->aad_len);
+ EVP_EncryptUpdate (ctx, op->dst, &len, op->src, op->len);
+ EVP_EncryptFinal_ex (ctx, op->dst + len, &len);
+ EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_GET_TAG, op->tag_len, op->tag);
+ op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
+ }
+ return n_ops;
+}
+
+static_always_inline u32
+openssl_ops_dec_gcm (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
+ const EVP_CIPHER * cipher)
+{
+ openssl_per_thread_data_t *ptd = vec_elt_at_index (per_thread_data,
+ vm->thread_index);
+ EVP_CIPHER_CTX *ctx = ptd->evp_cipher_ctx;
+ u32 i;
+ for (i = 0; i < n_ops; i++)
+ {
+ vnet_crypto_op_t *op = ops[i];
+ int len;
+
+ EVP_DecryptInit_ex (ctx, cipher, 0, 0, 0);
+ EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_SET_IVLEN, op->iv_len, 0);
+ EVP_DecryptInit_ex (ctx, 0, 0, op->key, op->iv);
+ EVP_DecryptUpdate (ctx, 0, &len, op->aad, op->aad_len);
+ EVP_DecryptUpdate (ctx, op->dst, &len, op->src, op->len);
+ EVP_CIPHER_CTX_ctrl (ctx, EVP_CTRL_GCM_SET_TAG, op->tag_len, op->tag);
+
+ if (EVP_DecryptFinal_ex (ctx, op->dst + len, &len) > 0)
+ op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
+ else
+ op->status = VNET_CRYPTO_OP_STATUS_FAIL_DECRYPT;
+ }
+ return n_ops;
+}
+
+static_always_inline u32
openssl_ops_hmac (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
const EVP_MD * md)
{
@@ -111,7 +170,7 @@ openssl_ops_hmac (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
{
vnet_crypto_op_t *op = ops[i];
unsigned int out_len;
- size_t sz = op->hmac_trunc_len ? op->hmac_trunc_len : EVP_MD_size (md);
+ size_t sz = op->digest_len ? op->digest_len : EVP_MD_size (md);
HMAC_Init_ex (ctx, op->key, op->key_len, md, NULL);
HMAC_Update (ctx, op->src, op->len);
@@ -119,7 +178,7 @@ openssl_ops_hmac (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
if (op->flags & VNET_CRYPTO_OP_FLAG_HMAC_CHECK)
{
- if ((memcmp (op->dst, buffer, sz)))
+ if ((memcmp (op->digest, buffer, sz)))
{
n_fail++;
op->status = VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC;
@@ -127,20 +186,20 @@ openssl_ops_hmac (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
}
}
else
- clib_memcpy_fast (op->dst, buffer, sz);
+ clib_memcpy_fast (op->digest, buffer, sz);
op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
}
return n_ops - n_fail;
}
-#define _(a, b) \
+#define _(m, a, b) \
static u32 \
openssl_ops_enc_##a (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops) \
-{ return openssl_ops_enc_cbc (vm, ops, n_ops, b ()); } \
+{ return openssl_ops_enc_##m (vm, ops, n_ops, b ()); } \
\
u32 \
openssl_ops_dec_##a (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops) \
-{ return openssl_ops_dec_cbc (vm, ops, n_ops, b ()); }
+{ return openssl_ops_dec_##m (vm, ops, n_ops, b ()); }
foreach_openssl_evp_op;
#undef _
@@ -160,17 +219,16 @@ crypto_openssl_init (vlib_main_t * vm)
vlib_thread_main_t *tm = vlib_get_thread_main ();
openssl_per_thread_data_t *ptd;
u8 *seed_data = 0;
+ clib_error_t *error;
time_t t;
pid_t pid;
- clib_error_t *error;
-
if ((error = vlib_call_init_function (vm, vnet_crypto_init)))
return error;
u32 eidx = vnet_crypto_register_engine (vm, "openssl", 50, "OpenSSL");
-#define _(a, b) \
+#define _(m, a, b) \
vnet_crypto_register_ops_handler (vm, eidx, VNET_CRYPTO_OP_##a##_ENC, \
openssl_ops_enc_##a); \
vnet_crypto_register_ops_handler (vm, eidx, VNET_CRYPTO_OP_##a##_DEC, \
diff --git a/src/plugins/unittest/CMakeLists.txt b/src/plugins/unittest/CMakeLists.txt
index 5c8825f4f3f..55766176fff 100644
--- a/src/plugins/unittest/CMakeLists.txt
+++ b/src/plugins/unittest/CMakeLists.txt
@@ -17,6 +17,7 @@ add_vpp_plugin(unittest
bihash_test.c
crypto_test.c
crypto/aes_cbc.c
+ crypto/aes_gcm.c
crypto/rfc2202_hmac_sha1.c
crypto/rfc2202_hmac_md5.c
crypto/rfc4231.c
diff --git a/src/plugins/unittest/crypto/aes_cbc.c b/src/plugins/unittest/crypto/aes_cbc.c
index 465f91e675f..b52f728a1cb 100644
--- a/src/plugins/unittest/crypto/aes_cbc.c
+++ b/src/plugins/unittest/crypto/aes_cbc.c
@@ -54,23 +54,15 @@ static u8 ciphertext128[] = {
};
/* *INDENT-OFF* */
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes128_cbc_enc) = {
+UNITTEST_REGISTER_CRYPTO_TEST (nist_aes128_cbc) = {
.name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_128_CBC_ENC,
+ .alg = VNET_CRYPTO_ALG_AES_128_CBC,
.iv = TEST_DATA (iv),
.key = TEST_DATA (key128),
- .data = TEST_DATA (plaintext),
- .expected = TEST_DATA (ciphertext128),
+ .plaintext = TEST_DATA (plaintext),
+ .ciphertext = TEST_DATA (ciphertext128),
};
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes128_cbc_dec) = {
- .name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_128_CBC_DEC,
- .iv = TEST_DATA (iv),
- .key = TEST_DATA (key128),
- .data = TEST_DATA (ciphertext128),
- .expected = TEST_DATA (plaintext),
-};
/* *INDENT-ON* */
static u8 key192[24] = {
@@ -91,23 +83,15 @@ static u8 ciphertext192[64] = {
};
/* *INDENT-OFF* */
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes192_cbc_enc) = {
+UNITTEST_REGISTER_CRYPTO_TEST (nist_aes192_cbc) = {
.name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_192_CBC_ENC,
+ .alg = VNET_CRYPTO_ALG_AES_192_CBC,
.iv = TEST_DATA (iv),
.key = TEST_DATA (key192),
- .data = TEST_DATA (plaintext),
- .expected = TEST_DATA (ciphertext192),
+ .plaintext = TEST_DATA (plaintext),
+ .ciphertext = TEST_DATA (ciphertext192),
};
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes192_cbc_dec) = {
- .name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_192_CBC_DEC,
- .iv = TEST_DATA (iv),
- .key = TEST_DATA (key192),
- .data = TEST_DATA (ciphertext192),
- .expected = TEST_DATA (plaintext),
-};
/* *INDENT-ON* */
static u8 key256[32] = {
@@ -129,23 +113,15 @@ static u8 ciphertext256[64] = {
};
/* *INDENT-OFF* */
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes256_cbc_enc) = {
+UNITTEST_REGISTER_CRYPTO_TEST (nist_aes256_cbc) = {
.name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_256_CBC_ENC,
+ .alg = VNET_CRYPTO_ALG_AES_256_CBC,
.iv = TEST_DATA (iv),
.key = TEST_DATA (key256),
- .data = TEST_DATA (plaintext),
- .expected = TEST_DATA (ciphertext256),
+ .plaintext = TEST_DATA (plaintext),
+ .ciphertext = TEST_DATA (ciphertext256),
};
-UNITTEST_REGISTER_CRYPTO_TEST (nist_aes256_cbc_dec) = {
- .name = "NIST SP 800-38A",
- .op = VNET_CRYPTO_OP_AES_256_CBC_DEC,
- .iv = TEST_DATA (iv),
- .key = TEST_DATA (key256),
- .data = TEST_DATA (ciphertext256),
- .expected = TEST_DATA (plaintext),
-};
/* *INDENT-ON* */
/*
diff --git a/src/plugins/unittest/crypto/aes_gcm.c b/src/plugins/unittest/crypto/aes_gcm.c
new file mode 100644
index 00000000000..826979e74e7
--- /dev/null
+++ b/src/plugins/unittest/crypto/aes_gcm.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Test vectors published in GCM Specification */
+
+#include <vppinfra/clib.h>
+#include <vnet/crypto/crypto.h>
+#include <unittest/crypto/crypto.h>
+
+static u8 tc6_iv[] = {
+ 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
+ 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
+ 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
+ 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
+ 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
+ 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
+ 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
+ 0xa6, 0x37, 0xb3, 0x9b
+};
+
+static u8 tc6_plaintext[] = {
+ 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
+ 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
+ 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
+ 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
+ 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
+ 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
+ 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
+ 0xba, 0x63, 0x7b, 0x39,
+};
+
+static u8 tc6_key[] = {
+ 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
+ 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
+};
+
+static u8 tc6_aad[] = {
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
+ 0xab, 0xad, 0xda, 0xd2
+};
+
+static u8 tc6_ciphertext[] = {
+ 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
+ 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
+ 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
+ 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
+ 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
+ 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
+ 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
+ 0x4c, 0x34, 0xae, 0xe5
+};
+
+static u8 tc6_tag[] = {
+ 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
+ 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50,
+};
+
+/* *INDENT-OFF* */
+UNITTEST_REGISTER_CRYPTO_TEST (aes_gcm_tc6) = {
+ .name = "GCM Spec. TC6",
+ .alg = VNET_CRYPTO_ALG_AES_128_GCM,
+ .iv = TEST_DATA (tc6_iv),
+ .key = TEST_DATA (tc6_key),
+ .plaintext = TEST_DATA (tc6_plaintext),
+ .ciphertext = TEST_DATA (tc6_ciphertext),
+ .tag = TEST_DATA (tc6_tag),
+ .aad = TEST_DATA (tc6_aad),
+};
+
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/unittest/crypto/crypto.h b/src/plugins/unittest/crypto/crypto.h
index 1945c69fd4c..587d7b76a2f 100644
--- a/src/plugins/unittest/crypto/crypto.h
+++ b/src/plugins/unittest/crypto/crypto.h
@@ -26,10 +26,9 @@ typedef struct
typedef struct unittest_crypto_test_registration
{
char *name;
- vnet_crypto_alg_t alg:8;
- vnet_crypto_op_type_t op:8;
- unittest_crypto_test_data_t iv, key, data, expected;
- u8 hmac_trunc_len;
+ vnet_crypto_alg_t alg;
+ unittest_crypto_test_data_t iv, key, digest, plaintext, ciphertext, aad,
+ tag;
/* next */
struct unittest_crypto_test_registration *next;
diff --git a/src/plugins/unittest/crypto/rfc2202_hmac_md5.c b/src/plugins/unittest/crypto/rfc2202_hmac_md5.c
index da6da7e47f4..76bd8a5f443 100644
--- a/src/plugins/unittest/crypto/rfc2202_hmac_md5.c
+++ b/src/plugins/unittest/crypto/rfc2202_hmac_md5.c
@@ -34,10 +34,10 @@ static u8 md5_tc1_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc1) = {
.name = "RFC2202 HMAC-MD5 TC1",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc1_key),
- .data = TEST_DATA (md5_tc1_data),
- .expected = TEST_DATA (md5_tc1_digest),
+ .plaintext = TEST_DATA (md5_tc1_data),
+ .digest = TEST_DATA (md5_tc1_digest),
};
/* *INDENT-ON* */
@@ -53,10 +53,10 @@ static u8 md5_tc2_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc2) = {
.name = "RFC2202 HMAC-MD5 TC2",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc2_key),
- .data = TEST_DATA (md5_tc2_data),
- .expected = TEST_DATA (md5_tc2_digest),
+ .plaintext = TEST_DATA (md5_tc2_data),
+ .digest = TEST_DATA (md5_tc2_digest),
};
/* *INDENT-ON* */
@@ -83,10 +83,10 @@ static u8 md5_tc3_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc3) = {
.name = "RFC2202 HMAC-MD5 TC3",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc3_key),
- .data = TEST_DATA (md5_tc3_data),
- .expected = TEST_DATA (md5_tc3_digest),
+ .plaintext = TEST_DATA (md5_tc3_data),
+ .digest = TEST_DATA (md5_tc3_digest),
};
/* *INDENT-ON* */
@@ -115,10 +115,10 @@ static u8 md5_tc4_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc4) = {
.name = "RFC2202 HMAC-MD5 TC4",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc4_key),
- .data = TEST_DATA (md5_tc4_data),
- .expected = TEST_DATA (md5_tc4_digest),
+ .plaintext = TEST_DATA (md5_tc4_data),
+ .digest = TEST_DATA (md5_tc4_digest),
};
/* *INDENT-ON* */
@@ -137,10 +137,10 @@ static u8 md5_tc5_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc5) = {
.name = "RFC2202 HMAC-MD5 TC5",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc5_key),
- .data = TEST_DATA (md5_tc5_data),
- .expected = TEST_DATA (md5_tc5_digest),
+ .plaintext = TEST_DATA (md5_tc5_data),
+ .digest = TEST_DATA (md5_tc5_digest),
};
/* *INDENT-ON* */
@@ -168,10 +168,10 @@ static u8 md5_tc6_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc6) = {
.name = "RFC2202 HMAC-MD5 TC6",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc6_key),
- .data = TEST_DATA (md5_tc6_data),
- .expected = TEST_DATA (md5_tc6_digest),
+ .plaintext = TEST_DATA (md5_tc6_data),
+ .digest = TEST_DATA (md5_tc6_digest),
};
/* *INDENT-ON* */
@@ -186,10 +186,10 @@ static u8 md5_tc7_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_md5_tc7) = {
.name = "RFC2202 HMAC-MD5 TC7",
- .op = VNET_CRYPTO_OP_MD5_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_MD5,
.key = TEST_DATA (md5_tc6_key),
- .data = TEST_DATA (md5_tc7_data),
- .expected = TEST_DATA (md5_tc7_digest),
+ .plaintext = TEST_DATA (md5_tc7_data),
+ .digest = TEST_DATA (md5_tc7_digest),
};
/* *INDENT-ON* */
diff --git a/src/plugins/unittest/crypto/rfc2202_hmac_sha1.c b/src/plugins/unittest/crypto/rfc2202_hmac_sha1.c
index 13505218891..b3942aafa59 100644
--- a/src/plugins/unittest/crypto/rfc2202_hmac_sha1.c
+++ b/src/plugins/unittest/crypto/rfc2202_hmac_sha1.c
@@ -36,10 +36,10 @@ static u8 sha1_tc1_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc1) = {
.name = "RFC2202 HMAC-SHA-1 TC1",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc1_key),
- .data = TEST_DATA (sha1_tc1_data),
- .expected = TEST_DATA (sha1_tc1_digest),
+ .plaintext = TEST_DATA (sha1_tc1_data),
+ .digest = TEST_DATA (sha1_tc1_digest),
};
/* *INDENT-ON* */
@@ -56,10 +56,10 @@ static u8 sha1_tc2_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc2) = {
.name = "RFC2202 HMAC-SHA-1 TC2",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc2_key),
- .data = TEST_DATA (sha1_tc2_data),
- .expected = TEST_DATA (sha1_tc2_digest),
+ .plaintext = TEST_DATA (sha1_tc2_data),
+ .digest = TEST_DATA (sha1_tc2_digest),
};
/* *INDENT-ON* */
@@ -88,10 +88,10 @@ static u8 sha1_tc3_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc3) = {
.name = "RFC2202 HMAC-SHA-1 TC3",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc3_key),
- .data = TEST_DATA (sha1_tc3_data),
- .expected = TEST_DATA (sha1_tc3_digest),
+ .plaintext = TEST_DATA (sha1_tc3_data),
+ .digest = TEST_DATA (sha1_tc3_digest),
};
/* *INDENT-ON* */
@@ -121,10 +121,10 @@ static u8 sha1_tc4_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc4) = {
.name = "RFC2202 HMAC-SHA-1 TC4",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc4_key),
- .data = TEST_DATA (sha1_tc4_data),
- .expected = TEST_DATA (sha1_tc4_digest),
+ .plaintext = TEST_DATA (sha1_tc4_data),
+ .digest = TEST_DATA (sha1_tc4_digest),
};
/* *INDENT-ON* */
@@ -145,10 +145,10 @@ static u8 sha1_tc5_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc5) = {
.name = "RFC2202 HMAC-SHA-1 TC5",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc5_key),
- .data = TEST_DATA (sha1_tc5_data),
- .expected = TEST_DATA (sha1_tc5_digest),
+ .plaintext = TEST_DATA (sha1_tc5_data),
+ .digest = TEST_DATA (sha1_tc5_digest),
};
/* *INDENT-ON* */
@@ -160,11 +160,10 @@ static u8 sha1_tc5_digest_96[12] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc5_trunc) = {
.name = "RFC2202 HMAC-SHA-1-96 TC5-trunc",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc5_key),
- .data = TEST_DATA (sha1_tc5_data),
- .expected = TEST_DATA (sha1_tc5_digest_96),
- .hmac_trunc_len = 12,
+ .plaintext = TEST_DATA (sha1_tc5_data),
+ .digest = TEST_DATA (sha1_tc5_digest_96),
};
/* *INDENT-ON* */
@@ -193,10 +192,10 @@ static u8 sha1_tc6_digest[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc6) = {
.name = "RFC2202 HMAC-SHA-1 TC6",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc6_key),
- .data = TEST_DATA (sha1_tc6_data),
- .expected = TEST_DATA (sha1_tc6_digest),
+ .plaintext = TEST_DATA (sha1_tc6_data),
+ .digest = TEST_DATA (sha1_tc6_digest),
};
/* *INDENT-ON* */
@@ -212,10 +211,10 @@ static u8 sha1_tc7_digest[20] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc_2202_sha1_tc7) = {
.name = "RFC2202 HMAC-SHA-1 TC7",
- .op = VNET_CRYPTO_OP_SHA1_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA1,
.key = TEST_DATA (sha1_tc6_key),
- .data = TEST_DATA (sha1_tc7_data),
- .expected = TEST_DATA (sha1_tc7_digest),
+ .plaintext = TEST_DATA (sha1_tc7_data),
+ .digest = TEST_DATA (sha1_tc7_digest),
};
/* *INDENT-ON* */
diff --git a/src/plugins/unittest/crypto/rfc4231.c b/src/plugins/unittest/crypto/rfc4231.c
index 4943e7d647d..b247d62f2a9 100644
--- a/src/plugins/unittest/crypto/rfc4231.c
+++ b/src/plugins/unittest/crypto/rfc4231.c
@@ -64,34 +64,34 @@ static u8 tc1_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha224) = {
.name = "RFC4231 TC1",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc1_key),
- .data = TEST_DATA (tc1_data),
- .expected = TEST_DATA (tc1_digest_sha224),
+ .plaintext = TEST_DATA (tc1_data),
+ .digest = TEST_DATA (tc1_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha256) = {
.name = "RFC4231 TC1",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc1_key),
- .data = TEST_DATA (tc1_data),
- .expected = TEST_DATA (tc1_digest_sha256),
+ .plaintext = TEST_DATA (tc1_data),
+ .digest = TEST_DATA (tc1_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha384) = {
.name = "RFC4231 TC1",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc1_key),
- .data = TEST_DATA (tc1_data),
- .expected = TEST_DATA (tc1_digest_sha384),
+ .plaintext = TEST_DATA (tc1_data),
+ .digest = TEST_DATA (tc1_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha512) = {
.name = "RFC4231 TC1",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc1_key),
- .data = TEST_DATA (tc1_data),
- .expected = TEST_DATA (tc1_digest_sha512),
+ .plaintext = TEST_DATA (tc1_data),
+ .digest = TEST_DATA (tc1_digest_sha512),
};
/* *INDENT-ON* */
@@ -136,34 +136,34 @@ static u8 tc2_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha224) = {
.name = "RFC4231 TC2",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc2_key),
- .data = TEST_DATA (tc2_data),
- .expected = TEST_DATA (tc2_digest_sha224),
+ .plaintext = TEST_DATA (tc2_data),
+ .digest = TEST_DATA (tc2_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha256) = {
.name = "RFC4231 TC2",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc2_key),
- .data = TEST_DATA (tc2_data),
- .expected = TEST_DATA (tc2_digest_sha256),
+ .plaintext = TEST_DATA (tc2_data),
+ .digest = TEST_DATA (tc2_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha384) = {
.name = "RFC4231 TC2",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc2_key),
- .data = TEST_DATA (tc2_data),
- .expected = TEST_DATA (tc2_digest_sha384),
+ .plaintext = TEST_DATA (tc2_data),
+ .digest = TEST_DATA (tc2_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha512) = {
.name = "RFC4231 TC2",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc2_key),
- .data = TEST_DATA (tc2_data),
- .expected = TEST_DATA (tc2_digest_sha512),
+ .plaintext = TEST_DATA (tc2_data),
+ .digest = TEST_DATA (tc2_digest_sha512),
};
/* *INDENT-ON* */
@@ -220,34 +220,34 @@ static u8 tc3_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha224) = {
.name = "RFC4231 TC3",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc3_key),
- .data = TEST_DATA (tc3_data),
- .expected = TEST_DATA (tc3_digest_sha224),
+ .plaintext = TEST_DATA (tc3_data),
+ .digest = TEST_DATA (tc3_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha256) = {
.name = "RFC4231 TC3",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc3_key),
- .data = TEST_DATA (tc3_data),
- .expected = TEST_DATA (tc3_digest_sha256),
+ .plaintext = TEST_DATA (tc3_data),
+ .digest = TEST_DATA (tc3_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha384) = {
.name = "RFC4231 TC3",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc3_key),
- .data = TEST_DATA (tc3_data),
- .expected = TEST_DATA (tc3_digest_sha384),
+ .plaintext = TEST_DATA (tc3_data),
+ .digest = TEST_DATA (tc3_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha512) = {
.name = "RFC4231 TC3",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc3_key),
- .data = TEST_DATA (tc3_data),
- .expected = TEST_DATA (tc3_digest_sha512),
+ .plaintext = TEST_DATA (tc3_data),
+ .digest = TEST_DATA (tc3_digest_sha512),
};
/* *INDENT-ON* */
@@ -305,34 +305,34 @@ static u8 tc4_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha224) = {
.name = "RFC4231 TC4",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc4_key),
- .data = TEST_DATA (tc4_data),
- .expected = TEST_DATA (tc4_digest_sha224),
+ .plaintext = TEST_DATA (tc4_data),
+ .digest = TEST_DATA (tc4_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha256) = {
.name = "RFC4231 TC4",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc4_key),
- .data = TEST_DATA (tc4_data),
- .expected = TEST_DATA (tc4_digest_sha256),
+ .plaintext = TEST_DATA (tc4_data),
+ .digest = TEST_DATA (tc4_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha384) = {
.name = "RFC4231 TC4",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc4_key),
- .data = TEST_DATA (tc4_data),
- .expected = TEST_DATA (tc4_digest_sha384),
+ .plaintext = TEST_DATA (tc4_data),
+ .digest = TEST_DATA (tc4_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha512) = {
.name = "RFC4231 TC4",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc4_key),
- .data = TEST_DATA (tc4_data),
- .expected = TEST_DATA (tc4_digest_sha512),
+ .plaintext = TEST_DATA (tc4_data),
+ .digest = TEST_DATA (tc4_digest_sha512),
};
/* *INDENT-ON* */
@@ -371,38 +371,34 @@ static u8 tc5_digest_sha512[16] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha224) = {
.name = "RFC4231 TC5",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc5_key),
- .data = TEST_DATA (tc5_data),
- .expected = TEST_DATA (tc5_digest_sha224),
- .hmac_trunc_len = 16,
+ .plaintext = TEST_DATA (tc5_data),
+ .digest = TEST_DATA (tc5_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha256) = {
.name = "RFC4231 TC5",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc5_key),
- .data = TEST_DATA (tc5_data),
- .expected = TEST_DATA (tc5_digest_sha256),
- .hmac_trunc_len = 16,
+ .plaintext = TEST_DATA (tc5_data),
+ .digest = TEST_DATA (tc5_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha384) = {
.name = "RFC4231 TC5",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc5_key),
- .data = TEST_DATA (tc5_data),
- .expected = TEST_DATA (tc5_digest_sha384),
- .hmac_trunc_len = 16,
+ .plaintext = TEST_DATA (tc5_data),
+ .digest = TEST_DATA (tc5_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha512) = {
.name = "RFC4231 TC5",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc5_key),
- .data = TEST_DATA (tc5_data),
- .expected = TEST_DATA (tc5_digest_sha512),
- .hmac_trunc_len = 16,
+ .plaintext = TEST_DATA (tc5_data),
+ .digest = TEST_DATA (tc5_digest_sha512),
};
/* *INDENT-ON* */
@@ -466,34 +462,34 @@ static u8 tc6_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha224) = {
.name = "RFC4231 TC6",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc6_key),
- .data = TEST_DATA (tc6_data),
- .expected = TEST_DATA (tc6_digest_sha224),
+ .plaintext = TEST_DATA (tc6_data),
+ .digest = TEST_DATA (tc6_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha256) = {
.name = "RFC4231 TC6",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc6_key),
- .data = TEST_DATA (tc6_data),
- .expected = TEST_DATA (tc6_digest_sha256),
+ .plaintext = TEST_DATA (tc6_data),
+ .digest = TEST_DATA (tc6_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha384) = {
.name = "RFC4231 TC6",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc6_key),
- .data = TEST_DATA (tc6_data),
- .expected = TEST_DATA (tc6_digest_sha384),
+ .plaintext = TEST_DATA (tc6_data),
+ .digest = TEST_DATA (tc6_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha512) = {
.name = "RFC4231 TC6",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc6_key),
- .data = TEST_DATA (tc6_data),
- .expected = TEST_DATA (tc6_digest_sha512),
+ .plaintext = TEST_DATA (tc6_data),
+ .digest = TEST_DATA (tc6_digest_sha512),
};
/* *INDENT-ON* */
@@ -559,34 +555,34 @@ static u8 tc7_digest_sha512[] = {
/* *INDENT-OFF* */
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha224) = {
.name = "RFC4231 TC7",
- .op = VNET_CRYPTO_OP_SHA224_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
.key = TEST_DATA (tc7_key),
- .data = TEST_DATA (tc7_data),
- .expected = TEST_DATA (tc7_digest_sha224),
+ .plaintext = TEST_DATA (tc7_data),
+ .digest = TEST_DATA (tc7_digest_sha224),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha256) = {
.name = "RFC4231 TC7",
- .op = VNET_CRYPTO_OP_SHA256_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
.key = TEST_DATA (tc7_key),
- .data = TEST_DATA (tc7_data),
- .expected = TEST_DATA (tc7_digest_sha256),
+ .plaintext = TEST_DATA (tc7_data),
+ .digest = TEST_DATA (tc7_digest_sha256),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha384) = {
.name = "RFC4231 TC7",
- .op = VNET_CRYPTO_OP_SHA384_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
.key = TEST_DATA (tc7_key),
- .data = TEST_DATA (tc7_data),
- .expected = TEST_DATA (tc7_digest_sha384),
+ .plaintext = TEST_DATA (tc7_data),
+ .digest = TEST_DATA (tc7_digest_sha384),
};
UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha512) = {
.name = "RFC4231 TC7",
- .op = VNET_CRYPTO_OP_SHA512_HMAC,
+ .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
.key = TEST_DATA (tc7_key),
- .data = TEST_DATA (tc7_data),
- .expected = TEST_DATA (tc7_digest_sha512),
+ .plaintext = TEST_DATA (tc7_data),
+ .digest = TEST_DATA (tc7_digest_sha512),
};
/* *INDENT-ON* */
diff --git a/src/plugins/unittest/crypto_test.c b/src/plugins/unittest/crypto_test.c
index 768221b56ad..eb73e91e186 100644
--- a/src/plugins/unittest/crypto_test.c
+++ b/src/plugins/unittest/crypto_test.c
@@ -27,25 +27,56 @@ sort_registrations (void *a0, void *a1)
unittest_crypto_test_registration_t **r0 = a0;
unittest_crypto_test_registration_t **r1 = a1;
- return (r0[0]->op > r1[0]->op);
+ return (strncmp (r0[0]->name, r1[0]->name, 256));
}
static clib_error_t *
test_crypto (vlib_main_t * vm, crypto_test_main_t * tm)
{
+ vnet_crypto_main_t *cm = &crypto_main;
unittest_crypto_test_registration_t *r = tm->test_registrations;
unittest_crypto_test_registration_t **rv = 0;
+ vnet_crypto_alg_data_t *ad;
vnet_crypto_op_t *ops = 0, *op;
- u8 *computed_data = 0, *s = 0;
- u32 computed_data_total_len = 0, n_tests = 0;
+ u8 *computed_data = 0, *s = 0, *err = 0;
+ u32 computed_data_total_len = 0, n_ops = 0;
u32 i;
/* construct registration vector */
while (r)
{
vec_add1 (rv, r);
- computed_data_total_len += r->data.length;
- n_tests += 1;
+ ad = vec_elt_at_index (cm->algs, r->alg);
+
+ for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
+ {
+ vnet_crypto_op_id_t id = ad->op_by_type[i];
+
+ if (id == 0)
+ continue;
+
+ switch (i)
+ {
+ case VNET_CRYPTO_OP_TYPE_ENCRYPT:
+ case VNET_CRYPTO_OP_TYPE_DECRYPT:
+ case VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT:
+ computed_data_total_len += r->ciphertext.length;
+ n_ops += 1;
+ break;
+ case VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT:
+ computed_data_total_len += r->ciphertext.length;
+ computed_data_total_len += r->tag.length;
+ n_ops += 1;
+ break;
+ case VNET_CRYPTO_OP_TYPE_HMAC:
+ computed_data_total_len += r->digest.length;
+ n_ops += 1;
+ break;
+ default:
+ break;
+ };
+ }
+
/* next */
r = r->next;
}
@@ -54,23 +85,79 @@ test_crypto (vlib_main_t * vm, crypto_test_main_t * tm)
vec_validate_aligned (computed_data, computed_data_total_len - 1,
CLIB_CACHE_LINE_BYTES);
- vec_validate_aligned (ops, n_tests - 1, CLIB_CACHE_LINE_BYTES);
+ vec_validate_aligned (ops, n_ops - 1, CLIB_CACHE_LINE_BYTES);
computed_data_total_len = 0;
+ op = ops;
/* *INDENT-OFF* */
vec_foreach_index (i, rv)
{
r = rv[i];
- op = ops + i;
- vnet_crypto_op_init (op, r->op);
- op->iv = r->iv.data;
- op->key = r->key.data;
- op->src = r->data.data;
- op->dst = computed_data + computed_data_total_len;
- op->len = r->data.length;
- op->key_len = r->key.length;
- op->hmac_trunc_len = r->hmac_trunc_len;
- computed_data_total_len += r->expected.length;
+ int t;
+ ad = vec_elt_at_index (cm->algs, r->alg);
+ for (t = 0; t < VNET_CRYPTO_OP_N_TYPES; t++)
+ {
+ vnet_crypto_op_id_t id = ad->op_by_type[t];
+
+ if (id == 0)
+ continue;
+
+ vnet_crypto_op_init (op, id);
+
+ switch (t)
+ {
+ case VNET_CRYPTO_OP_TYPE_ENCRYPT:
+ case VNET_CRYPTO_OP_TYPE_DECRYPT:
+ op->iv = r->iv.data;
+ op->iv_len = r->iv.length;
+ op->key = r->key.data;
+ op->key_len = r->key.length;
+ op->len = r->plaintext.length;
+ op->src = t == VNET_CRYPTO_OP_TYPE_ENCRYPT ?
+ r->plaintext.data : r->ciphertext.data;
+ op->dst = computed_data + computed_data_total_len;
+ computed_data_total_len += r->ciphertext.length;
+ break;
+ case VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT:
+ case VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT:
+ op->iv = r->iv.data;
+ op->iv_len = r->iv.length;
+ op->key = r->key.data;
+ op->key_len = r->key.length;
+ op->aad = r->aad.data;
+ op->aad_len = r->aad.length;
+ op->len = r->plaintext.length;
+ op->dst = computed_data + computed_data_total_len;
+ computed_data_total_len += r->ciphertext.length;
+ if (t == VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT)
+ {
+ op->src = r->plaintext.data;
+ op->tag = computed_data + computed_data_total_len;
+ computed_data_total_len += r->tag.length;
+ }
+ else
+ {
+ op->src = r->ciphertext.data;
+ op->tag = r->tag.data;
+ }
+ op->tag_len = r->tag.length;
+ break;
+ case VNET_CRYPTO_OP_TYPE_HMAC:
+ op->key = r->key.data;
+ op->key_len = r->key.length;
+ op->src = r->plaintext.data;
+ op->len = r->plaintext.length;
+ op->digest_len = r->digest.length;
+ op->digest = computed_data + computed_data_total_len;
+ computed_data_total_len += r->digest.length;
+ break;
+ default:
+ break;
+ };
+
+ op->user_data = i;
+ op++;
+ }
/* next */
r = r->next;
}
@@ -79,31 +166,92 @@ test_crypto (vlib_main_t * vm, crypto_test_main_t * tm)
vnet_crypto_process_ops (vm, ops, vec_len (ops));
/* *INDENT-OFF* */
- vec_foreach_index (i, rv)
+ vec_foreach (op, ops)
{
int fail = 0;
- r = rv[i];
- op = ops + i;
+ r = rv[op->user_data];
+ unittest_crypto_test_data_t *exp_pt = 0, *exp_ct = 0;
+ unittest_crypto_test_data_t *exp_digest = 0, *exp_tag = 0;
- if (memcmp (op->dst, r->expected.data, r->expected.length) != 0)
- fail = 1;
+ switch (vnet_crypto_get_op_type (op->op))
+ {
+ case VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT:
+ exp_tag = &r->tag;
+ case VNET_CRYPTO_OP_TYPE_ENCRYPT:
+ exp_ct = &r->ciphertext;
+ break;
+ case VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT:
+ case VNET_CRYPTO_OP_TYPE_DECRYPT:
+ exp_pt = &r->plaintext;
+ break;
+ case VNET_CRYPTO_OP_TYPE_HMAC:
+ exp_digest = &r->digest;
+ break;
+ default:
+ break;
+ }
+
+ vec_reset_length (err);
+
+ if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
+ err = format (err, "%sengine error: %U", vec_len (err) ? ", " : "",
+ format_vnet_crypto_op_status, op->status);
+
+ if (exp_ct && memcmp (op->dst, exp_ct->data, exp_ct->length) != 0)
+ err = format (err, "%sciphertext mismatch",
+ vec_len (err) ? ", " : "");
+
+ if (exp_pt && memcmp (op->dst, exp_pt->data, exp_pt->length) != 0)
+ err = format (err, "%splaintext mismatch", vec_len (err) ? ", " : "");
+
+ if (exp_tag && memcmp (op->tag, exp_tag->data, exp_tag->length) != 0)
+ err = format (err, "%stag mismatch", vec_len (err) ? ", " : "");
+
+ if (exp_digest &&
+ memcmp (op->digest, exp_digest->data, exp_digest->length) != 0)
+ err = format (err, "%sdigest mismatch", vec_len (err) ? ", " : "");
vec_reset_length (s);
- s = format (s, "%s (%U)", r->name,
- format_vnet_crypto_op, r->op);
+ s = format (s, "%s (%U)", r->name, format_vnet_crypto_op, op->op);
- vlib_cli_output (vm, "%-60v%s", s, fail ? "FAIL" : "OK");
- if (fail & tm->verbose)
+ if (vec_len (err))
+ fail = 1;
+
+ vlib_cli_output (vm, "%-60v%s%v", s, vec_len (err) ? "FAIL: " : "OK",
+ err);
+ if (tm->verbose)
{
- vlib_cli_output (vm, "Expected:\n%U\nCalculated:\n%U",
- format_hexdump, r->expected.data, r->expected.length,
- format_hexdump, op->dst, r->expected.length);
+ if (tm->verbose == 2)
+ fail = 1;
+
+ if (exp_ct && fail)
+ vlib_cli_output (vm, "Expected ciphertext:\n%U"
+ "\nCalculated ciphertext:\n%U",
+ format_hexdump, exp_ct->data, exp_ct->length,
+ format_hexdump, op->dst, exp_ct->length);
+ if (exp_pt && fail)
+ vlib_cli_output (vm, "Expected plaintext:\n%U"
+ "\nCalculated plaintext:\n%U",
+ format_hexdump, exp_pt->data, exp_pt->length,
+ format_hexdump, op->dst, exp_pt->length);
+ if (r->tag.length && fail)
+ vlib_cli_output (vm, "Expected tag:\n%U"
+ "\nCalculated tag:\n%U",
+ format_hexdump, r->tag.data, r->tag.length,
+ format_hexdump, op->tag, op->tag_len);
+ if (exp_digest && fail)
+ vlib_cli_output (vm, "Expected digest:\n%U"
+ "\nCalculated Digest:\n%U",
+ format_hexdump, exp_digest->data,
+ exp_digest->length, format_hexdump, op->digest,
+ op->digest_len);
}
}
/* *INDENT-ON* */
vec_free (computed_data);
vec_free (ops);
+ vec_free (err);
vec_free (rv);
vec_free (s);
return 0;
@@ -117,8 +265,10 @@ test_crypto_command_fn (vlib_main_t * vm,
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "verbose %d", &tm->verbose))
- ;
+ if (unformat (input, "verbose"))
+ tm->verbose = 1;
+ else if (unformat (input, "detail"))
+ tm->verbose = 2;
else
return clib_error_return (0, "unknown input '%U'",
format_unformat_error, input);
diff --git a/src/vnet/crypto/cli.c b/src/vnet/crypto/cli.c
index 792cc4bf243..4b0e093b02e 100644
--- a/src/vnet/crypto/cli.c
+++ b/src/vnet/crypto/cli.c
@@ -53,33 +53,58 @@ VLIB_CLI_COMMAND (show_crypto_engines_command, static) =
.function = show_crypto_engines_command_fn,
};
-static clib_error_t *
-show_crypto_handlers_command_fn (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd)
+static u8 *
+format_vnet_crypto_handlers (u8 * s, va_list * args)
{
+ vnet_crypto_alg_t alg = va_arg (*args, vnet_crypto_alg_t);
vnet_crypto_main_t *cm = &crypto_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- u8 *s = 0;
-
- if (unformat_user (input, unformat_line_input, line_input))
- unformat_free (line_input);
+ vnet_crypto_alg_data_t *d = vec_elt_at_index (cm->algs, alg);
+ u32 indent = format_get_indent (s);
+ int i, first = 1;
- vlib_cli_output (vm, "%-40s%-20s%s", "Name", "Active", "Candidates");
- for (int i = 1; i < VNET_CRYPTO_N_OP_TYPES; i++)
+ for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
{
- vnet_crypto_op_type_data_t *otd = cm->opt_data + i;
+ vnet_crypto_op_data_t *od;
vnet_crypto_engine_t *e;
+ vnet_crypto_op_id_t id = d->op_by_type[i];
+
+ if (id == 0)
+ continue;
+
+ od = vec_elt_at_index (cm->opt_data, id);
+ if (first == 0)
+ s = format (s, "\n%U", format_white_space, indent);
+ s = format (s, "%-20U%-20U", format_vnet_crypto_op_type, od->type,
+ format_vnet_crypto_engine, od->active_engine_index,s);
- vec_reset_length (s);
vec_foreach (e, cm->engines)
{
- if (e->ops_handlers[i] != 0)
+ if (e->ops_handlers[id] != 0)
s = format (s, "%U ", format_vnet_crypto_engine, e - cm->engines);
}
- vlib_cli_output (vm, "%-40U%-20U%v", format_vnet_crypto_op, i,
- format_vnet_crypto_engine, otd->active_engine_index,s);
+ first = 0;
}
- vec_free (s);
+ return s;
+}
+
+
+static clib_error_t *
+show_crypto_handlers_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ unformat_input_t _line_input, *line_input = &_line_input;
+ int i;
+
+ if (unformat_user (input, unformat_line_input, line_input))
+ unformat_free (line_input);
+
+ vlib_cli_output (vm, "%-20s%-20s%-20s%s", "Algo", "Type", "Active",
+ "Candidates");
+
+ for (i = 0; i < VNET_CRYPTO_N_ALGS; i++)
+ vlib_cli_output (vm, "%-20U%U", format_vnet_crypto_alg, i,
+ format_vnet_crypto_handlers, i);
+
return 0;
}
@@ -135,7 +160,7 @@ set_crypto_handler_command_fn (vlib_main_t * vm,
u8 *value;
/* *INDENT-OFF* */
- hash_foreach_mem (key, value, cm->ops_handler_index_by_name,
+ hash_foreach_mem (key, value, cm->alg_index_by_name,
({
(void) value;
rc += vnet_crypto_set_handler (key, engine);
diff --git a/src/vnet/crypto/crypto.c b/src/vnet/crypto/crypto.c
index 9d0ad8b13ca..58b13638924 100644
--- a/src/vnet/crypto/crypto.c
+++ b/src/vnet/crypto/crypto.c
@@ -22,7 +22,7 @@ vnet_crypto_main_t crypto_main;
static_always_inline u32
vnet_crypto_process_ops_call_handler (vlib_main_t * vm,
vnet_crypto_main_t * cm,
- vnet_crypto_op_type_t opt,
+ vnet_crypto_op_id_t opt,
vnet_crypto_op_t * ops[], u32 n_ops)
{
if (n_ops == 0)
@@ -48,7 +48,7 @@ vnet_crypto_process_ops (vlib_main_t * vm, vnet_crypto_op_t ops[], u32 n_ops)
vnet_crypto_main_t *cm = &crypto_main;
const int op_q_size = VLIB_FRAME_SIZE;
vnet_crypto_op_t *op_queue[op_q_size];
- vnet_crypto_op_type_t opt, current_op_type = ~0;
+ vnet_crypto_op_id_t opt, current_op_type = ~0;
u32 n_op_queue = 0;
u32 rv = 0, i;
@@ -92,41 +92,49 @@ vnet_crypto_register_engine (vlib_main_t * vm, char *name, int prio,
}
int
-vnet_crypto_set_handler (char *ops_handler_name, char *engine)
+vnet_crypto_set_handler (char *alg_name, char *engine)
{
uword *p;
vnet_crypto_main_t *cm = &crypto_main;
- vnet_crypto_op_type_t ot;
- vnet_crypto_op_type_data_t *otd;
+ vnet_crypto_alg_data_t *ad;
vnet_crypto_engine_t *ce;
+ int i;
- p = hash_get_mem (cm->ops_handler_index_by_name, ops_handler_name);
+ p = hash_get_mem (cm->alg_index_by_name, alg_name);
if (!p)
return -1;
- ot = p[0];
- otd = cm->opt_data + ot;
+ ad = vec_elt_at_index (cm->algs, p[0]);
p = hash_get_mem (cm->engine_index_by_name, engine);
if (!p)
return -1;
- ce = cm->engines + p[0];
- otd->active_engine_index = p[0];
- cm->ops_handlers[ot] = ce->ops_handlers[ot];
+ ce = vec_elt_at_index (cm->engines, p[0]);
+
+ for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
+ {
+ vnet_crypto_op_data_t *od;
+ vnet_crypto_op_id_t id = ad->op_by_type[i];
+ if (id == 0)
+ continue;
+ od = vec_elt_at_index (cm->opt_data, id);
+ od->active_engine_index = p[0];
+ cm->ops_handlers[id] = ce->ops_handlers[id];
+ }
return 0;
}
vlib_error_t *
vnet_crypto_register_ops_handler (vlib_main_t * vm, u32 engine_index,
- vnet_crypto_op_type_t opt,
+ vnet_crypto_op_id_t opt,
vnet_crypto_ops_handler_t * fn)
{
vnet_crypto_main_t *cm = &crypto_main;
vnet_crypto_engine_t *ae, *e = vec_elt_at_index (cm->engines, engine_index);
- vnet_crypto_op_type_data_t *otd = cm->opt_data + opt;
- vec_validate_aligned (cm->ops_handlers, VNET_CRYPTO_N_OP_TYPES - 1,
+ vnet_crypto_op_data_t *otd = cm->opt_data + opt;
+ vec_validate_aligned (cm->ops_handlers, VNET_CRYPTO_N_OP_IDS - 1,
CLIB_CACHE_LINE_BYTES);
e->ops_handlers[opt] = fn;
@@ -146,47 +154,73 @@ vnet_crypto_register_ops_handler (vlib_main_t * vm, u32 engine_index,
return 0;
}
+static void
+vnet_crypto_init_cipher_data (vnet_crypto_alg_t alg, vnet_crypto_op_id_t eid,
+ vnet_crypto_op_id_t did, char *name, u8 is_aead)
+{
+ vnet_crypto_op_type_t eopt, dopt;
+ vnet_crypto_main_t *cm = &crypto_main;
+ cm->algs[alg].name = name;
+ cm->opt_data[eid].alg = cm->opt_data[did].alg = alg;
+ cm->opt_data[eid].active_engine_index = ~0;
+ cm->opt_data[did].active_engine_index = ~0;
+ if (is_aead)
+ {
+ eopt = VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT;
+ dopt = VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT;
+ }
+ else
+ {
+ eopt = VNET_CRYPTO_OP_TYPE_ENCRYPT;
+ dopt = VNET_CRYPTO_OP_TYPE_DECRYPT;
+ }
+ cm->opt_data[eid].type = eopt;
+ cm->opt_data[did].type = dopt;
+ cm->algs[alg].op_by_type[eopt] = eid;
+ cm->algs[alg].op_by_type[dopt] = did;
+ hash_set_mem (cm->alg_index_by_name, name, alg);
+}
+
+static void
+vnet_crypto_init_hmac_data (vnet_crypto_alg_t alg,
+ vnet_crypto_op_id_t id, char *name)
+{
+ vnet_crypto_main_t *cm = &crypto_main;
+ cm->algs[alg].name = name;
+ cm->algs[alg].op_by_type[VNET_CRYPTO_OP_TYPE_HMAC] = id;
+ cm->opt_data[id].alg = alg;
+ cm->opt_data[id].active_engine_index = ~0;
+ cm->opt_data[id].type = VNET_CRYPTO_OP_TYPE_HMAC;
+ hash_set_mem (cm->alg_index_by_name, name, alg);
+}
+
clib_error_t *
vnet_crypto_init (vlib_main_t * vm)
{
vnet_crypto_main_t *cm = &crypto_main;
vlib_thread_main_t *tm = vlib_get_thread_main ();
-#define CRYPTO_ENC_STR "encrypt"
-#define CRYPTO_DEC_STR "decrypt"
-#define CRYPTO_HMAC_STR "hmac"
-
cm->engine_index_by_name = hash_create_string ( /* size */ 0,
sizeof (uword));
- cm->ops_handler_index_by_name = hash_create_string (0, sizeof (uword));
-
+ cm->alg_index_by_name = hash_create_string (0, sizeof (uword));
vec_validate_aligned (cm->threads, tm->n_vlib_mains, CLIB_CACHE_LINE_BYTES);
vec_validate (cm->algs, VNET_CRYPTO_N_ALGS);
-
#define _(n, s) \
- cm->algs[VNET_CRYPTO_ALG_##n].name = s; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_ENC].alg = VNET_CRYPTO_ALG_##n; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_DEC].alg = VNET_CRYPTO_ALG_##n; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_ENC].desc = CRYPTO_ENC_STR; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_DEC].desc = CRYPTO_DEC_STR; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_ENC].active_engine_index = ~0; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_DEC].active_engine_index = ~0; \
- hash_set_mem (cm->ops_handler_index_by_name, CRYPTO_ENC_STR "-" s, \
- VNET_CRYPTO_OP_##n##_ENC); \
- hash_set_mem (cm->ops_handler_index_by_name, CRYPTO_DEC_STR "-" s, \
- VNET_CRYPTO_OP_##n##_DEC);
- foreach_crypto_alg;
+ vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
+ VNET_CRYPTO_OP_##n##_ENC, \
+ VNET_CRYPTO_OP_##n##_DEC, s, 0);
+ foreach_crypto_cipher_alg;
#undef _
-
#define _(n, s) \
- cm->algs[VNET_CRYPTO_ALG_##n].name = s; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_HMAC].alg = VNET_CRYPTO_ALG_##n; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_HMAC].desc = CRYPTO_HMAC_STR; \
- cm->opt_data[VNET_CRYPTO_OP_##n##_HMAC].active_engine_index = ~0; \
- hash_set_mem (cm->ops_handler_index_by_name, CRYPTO_HMAC_STR "-" s, \
- VNET_CRYPTO_OP_##n##_HMAC);
- foreach_hmac_alg;
+ vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
+ VNET_CRYPTO_OP_##n##_ENC, \
+ VNET_CRYPTO_OP_##n##_DEC, s, 1);
+ foreach_crypto_aead_alg;
+#undef _
+#define _(n, s) \
+ vnet_crypto_init_hmac_data (VNET_CRYPTO_ALG_HMAC_##n, \
+ VNET_CRYPTO_OP_##n##_HMAC, "hmac-" s);
+ foreach_crypto_hmac_alg;
#undef _
-
return 0;
}
diff --git a/src/vnet/crypto/crypto.h b/src/vnet/crypto/crypto.h
index 2bd40dc9c75..5d03d52756e 100644
--- a/src/vnet/crypto/crypto.h
+++ b/src/vnet/crypto/crypto.h
@@ -20,14 +20,19 @@
#include <vlib/vlib.h>
-#define foreach_crypto_alg \
- _(DES_CBC, "des-cbc") \
- _(3DES_CBC, "3des-cbc") \
+#define foreach_crypto_cipher_alg \
+ _(DES_CBC, "des-cbc") \
+ _(3DES_CBC, "3des-cbc") \
_(AES_128_CBC, "aes-128-cbc") \
_(AES_192_CBC, "aes-192-cbc") \
_(AES_256_CBC, "aes-256-cbc")
-#define foreach_hmac_alg \
+#define foreach_crypto_aead_alg \
+ _(AES_128_GCM, "aes-128-gcm") \
+ _(AES_192_GCM, "aes-192-gcm") \
+ _(AES_256_GCM, "aes-256-gcm")
+
+#define foreach_crypto_hmac_alg \
_(MD5, "md5") \
_(SHA1, "sha-1") \
_(SHA224, "sha-224") \
@@ -35,14 +40,46 @@
_(SHA384, "sha-384") \
_(SHA512, "sha-512")
+
+#define foreach_crypto_op_type \
+ _(ENCRYPT, "encrypt") \
+ _(DECRYPT, "decrypt") \
+ _(AEAD_ENCRYPT, "aead-encrypt") \
+ _(AEAD_DECRYPT, "aead-decrypt") \
+ _(HMAC, "hmac")
+
+typedef enum
+{
+#define _(n, s) VNET_CRYPTO_OP_TYPE_##n,
+ foreach_crypto_op_type
+#undef _
+ VNET_CRYPTO_OP_N_TYPES,
+} vnet_crypto_op_type_t;
+
+#define foreach_crypto_op_status \
+ _(PENDING, "pending") \
+ _(COMPLETED, "completed") \
+ _(FAIL_NO_HANDLER, "no-handler") \
+ _(FAIL_BAD_HMAC, "bad-hmac") \
+ _(FAIL_DECRYPT, "decrypt-fail")
+
+typedef enum
+{
+#define _(n, s) VNET_CRYPTO_OP_STATUS_##n,
+ foreach_crypto_op_status
+#undef _
+ VNET_CRYPTO_OP_N_STATUS,
+} vnet_crypto_op_status_t;
+
/* *INDENT-OFF* */
typedef enum
{
#define _(n, s) VNET_CRYPTO_ALG_##n,
- foreach_crypto_alg
+ foreach_crypto_cipher_alg
+ foreach_crypto_aead_alg
#undef _
-#define _(n, s) VNET_CRYPTO_ALG_##n,
- foreach_hmac_alg
+#define _(n, s) VNET_CRYPTO_ALG_HMAC_##n,
+ foreach_crypto_hmac_alg
#undef _
VNET_CRYPTO_N_ALGS,
} vnet_crypto_alg_t;
@@ -51,68 +88,54 @@ typedef enum
{
VNET_CRYPTO_OP_NONE = 0,
#define _(n, s) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC,
- foreach_crypto_alg
+ foreach_crypto_cipher_alg
+ foreach_crypto_aead_alg
#undef _
#define _(n, s) VNET_CRYPTO_OP_##n##_HMAC,
- foreach_hmac_alg
+ foreach_crypto_hmac_alg
#undef _
- VNET_CRYPTO_N_OP_TYPES,
-} vnet_crypto_op_type_t;
+ VNET_CRYPTO_N_OP_IDS,
+} vnet_crypto_op_id_t;
/* *INDENT-ON* */
typedef struct
{
char *name;
+ vnet_crypto_op_id_t op_by_type[VNET_CRYPTO_OP_N_TYPES];
} vnet_crypto_alg_data_t;
-typedef enum
-{
- VNET_CRYPTO_OP_STATUS_PENDING,
- VNET_CRYPTO_OP_STATUS_COMPLETED,
- VNET_CRYPTO_OP_STATUS_FAIL_NO_HANDLER,
- VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC,
-} vnet_crypto_op_status_t;
-
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- vnet_crypto_op_type_t op:8;
+ vnet_crypto_op_id_t op:16;
vnet_crypto_op_status_t status:8;
- u8 key_len, hmac_trunc_len;
- u16 flags;
+ u8 flags;
#define VNET_CRYPTO_OP_FLAG_INIT_IV (1 << 0)
#define VNET_CRYPTO_OP_FLAG_HMAC_CHECK (1 << 1)
u32 len;
+ u16 aad_len;
+ u8 key_len, iv_len, digest_len, tag_len;
u8 *key;
u8 *iv;
u8 *src;
u8 *dst;
+ u8 *aad;
+ u8 *tag;
+ u8 *digest;
uword user_data;
} vnet_crypto_op_t;
typedef struct
{
+ vnet_crypto_op_type_t type;
vnet_crypto_alg_t alg;
- const char *desc;
u32 active_engine_index;
-} vnet_crypto_op_type_data_t;
-
-typedef struct
-{
- CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- u32 head;
- u32 tail;
- u32 size;
- vnet_crypto_alg_t alg:8;
- vnet_crypto_op_type_t op:8;
- vnet_crypto_op_t *jobs[0];
-} vnet_crypto_queue_t;
+} vnet_crypto_op_data_t;
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
clib_bitmap_t *act_queues;
- vnet_crypto_queue_t *queues[VNET_CRYPTO_N_OP_TYPES];
} vnet_crypto_thread_t;
typedef u32 (vnet_crypto_ops_handler_t) (vlib_main_t * vm,
@@ -123,7 +146,7 @@ u32 vnet_crypto_register_engine (vlib_main_t * vm, char *name, int prio,
vlib_error_t *vnet_crypto_register_ops_handler (vlib_main_t * vm,
u32 provider_index,
- vnet_crypto_op_type_t opt,
+ vnet_crypto_op_id_t opt,
vnet_crypto_ops_handler_t *
f);
@@ -132,7 +155,7 @@ typedef struct
char *name;
char *desc;
int priority;
- vnet_crypto_ops_handler_t *ops_handlers[VNET_CRYPTO_N_OP_TYPES];
+ vnet_crypto_ops_handler_t *ops_handlers[VNET_CRYPTO_N_OP_IDS];
} vnet_crypto_engine_t;
typedef struct
@@ -140,10 +163,10 @@ typedef struct
vnet_crypto_alg_data_t *algs;
vnet_crypto_thread_t *threads;
vnet_crypto_ops_handler_t **ops_handlers;
- vnet_crypto_op_type_data_t opt_data[VNET_CRYPTO_N_OP_TYPES];
+ vnet_crypto_op_data_t opt_data[VNET_CRYPTO_N_OP_IDS];
vnet_crypto_engine_t *engines;
uword *engine_index_by_name;
- uword *ops_handler_index_by_name;
+ uword *alg_index_by_name;
} vnet_crypto_main_t;
extern vnet_crypto_main_t crypto_main;
@@ -160,10 +183,11 @@ int vnet_crypto_set_handler (char *ops_handler_name, char *engine);
format_function_t format_vnet_crypto_alg;
format_function_t format_vnet_crypto_engine;
format_function_t format_vnet_crypto_op;
-
+format_function_t format_vnet_crypto_op_type;
+format_function_t format_vnet_crypto_op_status;
static_always_inline void
-vnet_crypto_op_init (vnet_crypto_op_t * op, vnet_crypto_op_type_t type)
+vnet_crypto_op_init (vnet_crypto_op_t * op, vnet_crypto_op_id_t type)
{
if (CLIB_DEBUG > 0)
clib_memset (op, 0xfe, sizeof (*op));
@@ -171,6 +195,14 @@ vnet_crypto_op_init (vnet_crypto_op_t * op, vnet_crypto_op_type_t type)
op->flags = 0;
}
+static_always_inline vnet_crypto_op_type_t
+vnet_crypto_get_op_type (vnet_crypto_op_id_t id)
+{
+ vnet_crypto_main_t *cm = &crypto_main;
+ vnet_crypto_op_data_t *od = vec_elt_at_index (cm->opt_data, id);
+ return od->type;
+}
+
#endif /* included_vnet_crypto_crypto_h */
/*
diff --git a/src/vnet/crypto/format.c b/src/vnet/crypto/format.c
index c2786ee5afd..df811fe4f2f 100644
--- a/src/vnet/crypto/format.c
+++ b/src/vnet/crypto/format.c
@@ -30,10 +30,43 @@ u8 *
format_vnet_crypto_op (u8 * s, va_list * args)
{
vnet_crypto_main_t *cm = &crypto_main;
- vnet_crypto_op_type_t op = va_arg (*args, int); // vnet_crypto_op_type_t);
- vnet_crypto_op_type_data_t *otd = cm->opt_data + op;
+ vnet_crypto_op_id_t op = va_arg (*args, int); // vnet_crypto_op_id_t);
+ vnet_crypto_op_data_t *otd = cm->opt_data + op;
- return format (s, "%s-%U", otd->desc, format_vnet_crypto_alg, otd->alg);
+ return format (s, "%U-%U", format_vnet_crypto_op_type, otd->type,
+ format_vnet_crypto_alg, otd->alg);
+}
+
+u8 *
+format_vnet_crypto_op_type (u8 * s, va_list * args)
+{
+ vnet_crypto_op_type_t opt = va_arg (*args, vnet_crypto_op_type_t);
+ char *strings[] = {
+#define _(n, s) [VNET_CRYPTO_OP_TYPE_##n] = s,
+ foreach_crypto_op_type
+#undef _
+ };
+
+ if (opt >= VNET_CRYPTO_OP_N_TYPES)
+ return format (s, "unknown");
+
+ return format (s, "%s", strings[opt]);
+}
+
+u8 *
+format_vnet_crypto_op_status (u8 * s, va_list * args)
+{
+ vnet_crypto_op_status_t st = va_arg (*args, vnet_crypto_op_status_t);
+ char *strings[] = {
+#define _(n, s) [VNET_CRYPTO_OP_STATUS_##n] = s,
+ foreach_crypto_op_status
+#undef _
+ };
+
+ if (st >= VNET_CRYPTO_OP_N_STATUS)
+ return format (s, "unknown");
+
+ return format (s, "%s", strings[st]);
}
u8 *
diff --git a/src/vnet/ipsec/esp.h b/src/vnet/ipsec/esp.h
index b6942fadf97..4b67eb2134b 100644
--- a/src/vnet/ipsec/esp.h
+++ b/src/vnet/ipsec/esp.h
@@ -94,16 +94,16 @@ hmac_calc (vlib_main_t * vm, ipsec_sa_t * sa, u8 * data, int data_len,
{
vnet_crypto_op_t _op, *op = &_op;
- if (PREDICT_FALSE (sa->integ_op_type == 0))
+ if (PREDICT_FALSE (sa->integ_op_id == 0))
return 0;
- vnet_crypto_op_init (op, sa->integ_op_type);
+ vnet_crypto_op_init (op, sa->integ_op_id);
op->key = sa->integ_key.data;
op->key_len = sa->integ_key.len;
op->src = data;
op->len = data_len;
- op->dst = signature;
- op->hmac_trunc_len = sa->integ_icv_size;
+ op->digest = signature;
+ op->digest_len = sa->integ_icv_size;
if (ipsec_sa_is_set_USE_ESN (sa))
{
diff --git a/src/vnet/ipsec/esp_decrypt.c b/src/vnet/ipsec/esp_decrypt.c
index 7737d186865..9b24e5aaeaa 100644
--- a/src/vnet/ipsec/esp_decrypt.c
+++ b/src/vnet/ipsec/esp_decrypt.c
@@ -202,14 +202,14 @@ esp_decrypt_inline (vlib_main_t * vm,
vnet_crypto_op_t *op;
vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
- vnet_crypto_op_init (op, sa0->integ_op_type);
+ vnet_crypto_op_init (op, sa0->integ_op_id);
op->key = sa0->integ_key.data;
op->key_len = sa0->integ_key.len;
op->src = payload;
- op->hmac_trunc_len = cpd.icv_sz;
op->flags = VNET_CRYPTO_OP_FLAG_HMAC_CHECK;
op->user_data = b - bufs;
- op->dst = payload + len;
+ op->digest = payload + len;
+ op->digest_len = cpd.icv_sz;
op->len = len;
if (PREDICT_TRUE (sa0->flags & IPSEC_SA_FLAG_USE_ESN))
{
@@ -226,11 +226,11 @@ esp_decrypt_inline (vlib_main_t * vm,
payload += esp_sz;
len -= esp_sz;
- if (sa0->crypto_enc_op_type != VNET_CRYPTO_OP_NONE)
+ if (sa0->crypto_enc_op_id != VNET_CRYPTO_OP_NONE)
{
vnet_crypto_op_t *op;
vec_add2_aligned (ptd->crypto_ops, op, 1, CLIB_CACHE_LINE_BYTES);
- vnet_crypto_op_init (op, sa0->crypto_dec_op_type);
+ vnet_crypto_op_init (op, sa0->crypto_dec_op_id);
op->key = sa0->crypto_key.data;
op->iv = payload;
op->src = op->dst = payload += cpd.iv_sz;
@@ -271,7 +271,6 @@ esp_decrypt_inline (vlib_main_t * vm,
op++;
}
}
-
if ((n = vec_len (ptd->crypto_ops)))
{
vnet_crypto_op_t *op = ptd->crypto_ops;
diff --git a/src/vnet/ipsec/esp_encrypt.c b/src/vnet/ipsec/esp_encrypt.c
index 29e27d4488c..bb1effda68b 100644
--- a/src/vnet/ipsec/esp_encrypt.c
+++ b/src/vnet/ipsec/esp_encrypt.c
@@ -425,11 +425,11 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
esp->spi = spi;
esp->seq = clib_net_to_host_u32 (sa0->seq);
- if (sa0->crypto_enc_op_type)
+ if (sa0->crypto_enc_op_id)
{
vnet_crypto_op_t *op;
vec_add2_aligned (ptd->crypto_ops, op, 1, CLIB_CACHE_LINE_BYTES);
- vnet_crypto_op_init (op, sa0->crypto_enc_op_type);
+ vnet_crypto_op_init (op, sa0->crypto_enc_op_id);
op->iv = payload - iv_sz;
op->src = op->dst = payload;
op->key = sa0->crypto_key.data;
@@ -438,16 +438,16 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
op->user_data = b - bufs;
}
- if (sa0->integ_op_type)
+ if (sa0->integ_op_id)
{
vnet_crypto_op_t *op;
vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
- vnet_crypto_op_init (op, sa0->integ_op_type);
+ vnet_crypto_op_init (op, sa0->integ_op_id);
op->src = payload - iv_sz - sizeof (esp_header_t);
- op->dst = payload + payload_len - icv_sz;
+ op->digest = payload + payload_len - icv_sz;
op->key = sa0->integ_key.data;
op->key_len = sa0->integ_key.len;
- op->hmac_trunc_len = icv_sz;
+ op->digest_len = icv_sz;
op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t);
op->user_data = b - bufs;
if (ipsec_sa_is_set_USE_ESN (sa0))
@@ -484,7 +484,6 @@ esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
current_sa_index, current_sa_packets,
current_sa_bytes);
-
esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts);
esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
diff --git a/src/vnet/ipsec/ipsec.c b/src/vnet/ipsec/ipsec.c
index 9719d3a2d09..dc2f4cdbb60 100644
--- a/src/vnet/ipsec/ipsec.c
+++ b/src/vnet/ipsec/ipsec.c
@@ -269,51 +269,51 @@ ipsec_init (vlib_main_t * vm)
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->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC;
+ a->dec_op_id = 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->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC;
+ a->dec_op_id = 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->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC;
+ a->dec_op_id = 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->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC;
+ a->dec_op_id = 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->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC;
+ a->dec_op_id = 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->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
i->icv_size = 12;
i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
- i->op_type = VNET_CRYPTO_OP_SHA1_HMAC;
+ i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
i->icv_size = 12;
i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
- i->op_type = VNET_CRYPTO_OP_SHA256_HMAC;
+ i->op_id = VNET_CRYPTO_OP_SHA256_HMAC;
i->icv_size = 16;
i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
- i->op_type = VNET_CRYPTO_OP_SHA384_HMAC;
+ i->op_id = VNET_CRYPTO_OP_SHA384_HMAC;
i->icv_size = 24;
i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
- i->op_type = VNET_CRYPTO_OP_SHA512_HMAC;
+ i->op_id = VNET_CRYPTO_OP_SHA512_HMAC;
i->icv_size = 32;
vec_validate_aligned (im->ptd, vlib_num_workers (), CLIB_CACHE_LINE_BYTES);
diff --git a/src/vnet/ipsec/ipsec.h b/src/vnet/ipsec/ipsec.h
index 821b7ed3107..b6332d672fb 100644
--- a/src/vnet/ipsec/ipsec.h
+++ b/src/vnet/ipsec/ipsec.h
@@ -66,15 +66,15 @@ typedef struct
typedef struct
{
- vnet_crypto_op_type_t enc_op_type;
- vnet_crypto_op_type_t dec_op_type;
+ vnet_crypto_op_id_t enc_op_id;
+ vnet_crypto_op_id_t dec_op_id;
u8 iv_size;
u8 block_size;
} ipsec_main_crypto_alg_t;
typedef struct
{
- vnet_crypto_op_type_t op_type;
+ vnet_crypto_op_id_t op_id;
u8 icv_size;
} ipsec_main_integ_alg_t;
diff --git a/src/vnet/ipsec/ipsec_sa.c b/src/vnet/ipsec/ipsec_sa.c
index 4d20566686d..af37b2e49cc 100644
--- a/src/vnet/ipsec/ipsec_sa.c
+++ b/src/vnet/ipsec/ipsec_sa.c
@@ -98,8 +98,8 @@ ipsec_sa_set_crypto_alg (ipsec_sa_t * sa, ipsec_crypto_alg_t crypto_alg)
sa->crypto_alg = crypto_alg;
sa->crypto_iv_size = im->crypto_algs[crypto_alg].iv_size;
sa->crypto_block_size = im->crypto_algs[crypto_alg].block_size;
- sa->crypto_enc_op_type = im->crypto_algs[crypto_alg].enc_op_type;
- sa->crypto_dec_op_type = im->crypto_algs[crypto_alg].dec_op_type;
+ sa->crypto_enc_op_id = im->crypto_algs[crypto_alg].enc_op_id;
+ sa->crypto_dec_op_id = im->crypto_algs[crypto_alg].dec_op_id;
ASSERT (sa->crypto_iv_size <= ESP_MAX_IV_SIZE);
ASSERT (sa->crypto_block_size <= ESP_MAX_BLOCK_SIZE);
}
@@ -110,7 +110,7 @@ ipsec_sa_set_integ_alg (ipsec_sa_t * sa, ipsec_integ_alg_t integ_alg)
ipsec_main_t *im = &ipsec_main;
sa->integ_alg = integ_alg;
sa->integ_icv_size = im->integ_algs[integ_alg].icv_size;
- sa->integ_op_type = im->integ_algs[integ_alg].op_type;
+ sa->integ_op_id = im->integ_algs[integ_alg].op_id;
ASSERT (sa->integ_icv_size <= ESP_MAX_ICV_SIZE);
}
diff --git a/src/vnet/ipsec/ipsec_sa.h b/src/vnet/ipsec/ipsec_sa.h
index 12700ccaa39..72a592984f6 100644
--- a/src/vnet/ipsec/ipsec_sa.h
+++ b/src/vnet/ipsec/ipsec_sa.h
@@ -119,9 +119,9 @@ typedef struct
u32 last_seq_hi;
u64 replay_window;
- vnet_crypto_op_type_t crypto_enc_op_type;
- vnet_crypto_op_type_t crypto_dec_op_type;
- vnet_crypto_op_type_t integ_op_type;
+ vnet_crypto_op_id_t crypto_enc_op_id;
+ vnet_crypto_op_id_t crypto_dec_op_id;
+ vnet_crypto_op_id_t integ_op_id;
dpo_id_t dpo[IPSEC_N_PROTOCOLS];
diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c
index bce44288d08..340217c661e 100644
--- a/src/vnet/lisp-cp/control.c
+++ b/src/vnet/lisp-cp/control.c
@@ -2725,7 +2725,7 @@ build_map_register_record_list (lisp_cp_main_t * lcm)
return recs;
}
-static vnet_crypto_op_type_t
+static vnet_crypto_op_id_t
lisp_key_type_to_crypto_op (lisp_key_type_t key_id)
{
switch (key_id)
@@ -2755,9 +2755,9 @@ update_map_register_auth_data (map_register_hdr_t * map_reg_hdr,
op->key = key;
op->key_len = vec_len (key);
op->len = msg_len;
- op->dst = MREG_DATA (map_reg_hdr);
+ op->digest = MREG_DATA (map_reg_hdr);
op->src = (u8 *) map_reg_hdr;
- op->hmac_trunc_len = 0;
+ op->digest_len = 0;
op->iv = 0;
vnet_crypto_process_ops (lcm->vlib_main, op, 1);
@@ -3946,9 +3946,9 @@ is_auth_data_valid (map_notify_hdr_t * h, u32 msg_len,
op->key = key;
op->key_len = vec_len (key);
op->len = msg_len;
- op->dst = out;
+ op->digest = out;
op->src = (u8 *) h;
- op->hmac_trunc_len = 0;
+ op->digest_len = 0;
op->iv = 0;
vnet_crypto_process_ops (lcm->vlib_main, op, 1);