aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2021-05-03 15:29:56 +0000
committerDamjan Marion <dmarion@me.com>2021-05-05 07:34:00 +0000
commit06111a837d77323d253ecfd26557775fa0b03ca8 (patch)
treed41200c0d91d01894b6caaa82e03c2f86c5800b2 /src/vnet
parent9592909ecc1522cf36d4701f998b6f03c738e319 (diff)
crypto crypto-openssl: support hashing operations
Type: feature Change-Id: I36041fe5c5f0ff129aee42516189807e96f62123 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/crypto/crypto.c27
-rw-r--r--src/vnet/crypto/crypto.h40
2 files changed, 52 insertions, 15 deletions
diff --git a/src/vnet/crypto/crypto.c b/src/vnet/crypto/crypto.c
index 74f945e8382..3b1505ad448 100644
--- a/src/vnet/crypto/crypto.c
+++ b/src/vnet/crypto/crypto.c
@@ -343,7 +343,13 @@ vnet_crypto_key_len_check (vnet_crypto_alg_t alg, u16 length)
#define _(n, s) \
case VNET_CRYPTO_ALG_HMAC_##n: \
return 1;
- foreach_crypto_hmac_alg
+ foreach_crypto_hmac_alg
+#undef _
+
+#define _(n, s) \
+ case VNET_CRYPTO_ALG_HASH_##n: \
+ return 1;
+ foreach_crypto_hash_alg
#undef _
}
@@ -669,6 +675,20 @@ vnet_crypto_init_cipher_data (vnet_crypto_alg_t alg, vnet_crypto_op_id_t eid,
}
static void
+vnet_crypto_init_hash_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_HASH] = id;
+ cm->opt_data[id].alg = alg;
+ cm->opt_data[id].active_engine_index_simple = ~0;
+ cm->opt_data[id].active_engine_index_chained = ~0;
+ cm->opt_data[id].type = VNET_CRYPTO_OP_TYPE_HASH;
+ 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)
{
@@ -740,6 +760,11 @@ vnet_crypto_init (vlib_main_t * vm)
VNET_CRYPTO_OP_##n##_HMAC, "hmac-" s);
foreach_crypto_hmac_alg;
#undef _
+#define _(n, s) \
+ vnet_crypto_init_hash_data (VNET_CRYPTO_ALG_HASH_##n, \
+ VNET_CRYPTO_OP_##n##_HASH, s);
+ foreach_crypto_hash_alg;
+#undef _
#define _(n, s, k, t, a) \
vnet_crypto_init_async_data (VNET_CRYPTO_ALG_##n##_TAG##t##_AAD##a, \
VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_ENC, \
diff --git a/src/vnet/crypto/crypto.h b/src/vnet/crypto/crypto.h
index a44c8910555..71978b64835 100644
--- a/src/vnet/crypto/crypto.h
+++ b/src/vnet/crypto/crypto.h
@@ -39,6 +39,13 @@
_(AES_256_GCM, "aes-256-gcm", 32) \
_(CHACHA20_POLY1305, "chacha20-poly1305", 32)
+#define foreach_crypto_hash_alg \
+ _ (SHA1, "sha-1") \
+ _ (SHA224, "sha-224") \
+ _ (SHA256, "sha-256") \
+ _ (SHA384, "sha-384") \
+ _ (SHA512, "sha-512")
+
#define foreach_crypto_hmac_alg \
_(MD5, "md5") \
_(SHA1, "sha-1") \
@@ -47,12 +54,13 @@
_(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")
+#define foreach_crypto_op_type \
+ _ (ENCRYPT, "encrypt") \
+ _ (DECRYPT, "decrypt") \
+ _ (AEAD_ENCRYPT, "aead-encrypt") \
+ _ (AEAD_DECRYPT, "aead-decrypt") \
+ _ (HMAC, "hmac") \
+ _ (HASH, "hash")
typedef enum
{
@@ -138,13 +146,15 @@ typedef enum
{
VNET_CRYPTO_ALG_NONE = 0,
#define _(n, s, l) VNET_CRYPTO_ALG_##n,
- foreach_crypto_cipher_alg
- foreach_crypto_aead_alg
+ foreach_crypto_cipher_alg foreach_crypto_aead_alg
#undef _
#define _(n, s) VNET_CRYPTO_ALG_HMAC_##n,
- foreach_crypto_hmac_alg
+ foreach_crypto_hmac_alg
+#undef _
+#define _(n, s) VNET_CRYPTO_ALG_HASH_##n,
+ foreach_crypto_hash_alg
#undef _
- VNET_CRYPTO_N_ALGS,
+ VNET_CRYPTO_N_ALGS,
} vnet_crypto_alg_t;
typedef enum
@@ -210,13 +220,15 @@ typedef enum
{
VNET_CRYPTO_OP_NONE = 0,
#define _(n, s, l) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC,
- foreach_crypto_cipher_alg
- foreach_crypto_aead_alg
+ foreach_crypto_cipher_alg foreach_crypto_aead_alg
#undef _
#define _(n, s) VNET_CRYPTO_OP_##n##_HMAC,
- foreach_crypto_hmac_alg
+ foreach_crypto_hmac_alg
+#undef _
+#define _(n, s) VNET_CRYPTO_OP_##n##_HASH,
+ foreach_crypto_hash_alg
#undef _
- VNET_CRYPTO_N_OP_IDS,
+ VNET_CRYPTO_N_OP_IDS,
} vnet_crypto_op_id_t;
/* *INDENT-ON* */