From bc2e640db7533394a3de7bdffd78fadf2a2ffd9f Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Mon, 4 Nov 2019 16:01:59 +0000 Subject: crypto: fix crypto perf unittest crash Type: fix crypto perf test crashes for key size different than 16 bytes. This patch fixes the issue Signed-off-by: Fan Zhang Change-Id: Ic8a8ca83ca189c879815dc5d065b8c6f7826cd41 --- src/plugins/unittest/crypto_test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/plugins/unittest') diff --git a/src/plugins/unittest/crypto_test.c b/src/plugins/unittest/crypto_test.c index 44c435964fd..9030415aec8 100644 --- a/src/plugins/unittest/crypto_test.c +++ b/src/plugins/unittest/crypto_test.c @@ -268,6 +268,37 @@ test_crypto (vlib_main_t * vm, crypto_test_main_t * tm) return 0; } +static u32 +test_crypto_get_key_sz (vnet_crypto_alg_t alg) +{ + switch (alg) + { +#define _(n, s, l) \ + case VNET_CRYPTO_ALG_##n: \ + return l; + /* *INDENT-OFF* */ + foreach_crypto_cipher_alg + foreach_crypto_aead_alg + /* *INDENT-ON* */ +#undef _ + case VNET_CRYPTO_ALG_HMAC_MD5: + case VNET_CRYPTO_ALG_HMAC_SHA1: + return 20; + case VNET_CRYPTO_ALG_HMAC_SHA224: + return 28; + case VNET_CRYPTO_ALG_HMAC_SHA256: + return 32; + case VNET_CRYPTO_ALG_HMAC_SHA384: + return 48; + case VNET_CRYPTO_ALG_HMAC_SHA512: + return 64; + default: + return 0; + } + + return 0; +} + static clib_error_t * test_crypto_perf (vlib_main_t * vm, crypto_test_main_t * tm) { @@ -320,7 +351,8 @@ test_crypto_perf (vlib_main_t * vm, crypto_test_main_t * tm) for (i = 0; i < sizeof (key); i++) key[i] = i; - key_index = vnet_crypto_key_add (vm, tm->alg, key, sizeof (key)); + key_index = vnet_crypto_key_add (vm, tm->alg, key, + test_crypto_get_key_sz (tm->alg)); for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++) { -- cgit 1.2.3-korg