diff options
author | Fan Zhang <roy.fan.zhang@intel.com> | 2019-11-04 16:01:59 +0000 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2019-11-18 13:30:35 +0000 |
commit | cde7068bbe8d76d84c2e44f79e32c60a1525bcc9 (patch) | |
tree | c5d99c96d543fe15c8d5de7a7ca10ffa024bdcfa /src/plugins | |
parent | e97a054fd38ce1dc252870a78a27ed44fdd42d5a (diff) |
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 <roy.fan.zhang@intel.com>
Change-Id: Ic8a8ca83ca189c879815dc5d065b8c6f7826cd41
(cherry picked from commit bc2e640db7533394a3de7bdffd78fadf2a2ffd9f)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/unittest/crypto_test.c | 34 |
1 files changed, 33 insertions, 1 deletions
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++) { |