diff options
author | Fan Zhang <roy.fan.zhang@intel.com> | 2019-11-04 16:01:59 +0000 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2019-11-07 21:34:30 +0100 |
commit | bc2e640db7533394a3de7bdffd78fadf2a2ffd9f (patch) | |
tree | 3cde701eba711a9dc32ad14432221b762e4ba43a /src/plugins | |
parent | bf1f8b7f288c29bfcc128b1d09eae1c1eac2b7cc (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
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++) { |