[v2,3/7] examples/fips_validation: add function to calculate SHA hash size
Checks
Commit Message
Add function to calculate hash size for a given SHA hash algorithm.
Fixes: d5c247145c2 ("examples/fips_validation: add parsing for SHA")
Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Acked-by: Brian Dooley <brian.dooley@intel.com>
---
v2:
- fixed include file
---
examples/fips_validation/fips_validation.h | 1 +
.../fips_validation/fips_validation_sha.c | 39 ++++++++++++-------
2 files changed, 25 insertions(+), 15 deletions(-)
Comments
> Subject: [v2 3/7] examples/fips_validation: add function to calculate SHA hash
> size
>
> Add function to calculate hash size for a given SHA hash algorithm.
>
> Fixes: d5c247145c2 ("examples/fips_validation: add parsing for SHA")
>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Acked-by: Brian Dooley <brian.dooley@intel.com>
>
> ---
This patch caused a build failure for cross compile.
[713/820] Compiling C object 'examples/c590b3c@@dpdk-fips_validation@exe/fips_validation_fips_validation_sha.c.o'.
../examples/fips_validation/fips_validation_sha.c: In function 'parse_test_sha_hash_size':
../examples/fips_validation/fips_validation_sha.c:44:10: error: implicit declaration of function 'atoi' [-Wimplicit-function-declaration]
44 | ret = atoi(phsc[i].str);
| ^~~~
../examples/fips_validation/fips_validation_sha.c:44:10: error: nested extern declaration of 'atoi' [-Wnested-externs]
Added include file in fips_validation_sha.c
#include <stdlib.h>
> v2:
> - fixed include file
> ---
> examples/fips_validation/fips_validation.h | 1 +
> .../fips_validation/fips_validation_sha.c | 39 ++++++++++++-------
> 2 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/examples/fips_validation/fips_validation.h
> b/examples/fips_validation/fips_validation.h
> index a6288e17e5..6e5f2fce75 100644
> --- a/examples/fips_validation/fips_validation.h
> +++ b/examples/fips_validation/fips_validation.h
> @@ -374,4 +374,5 @@ int prepare_gcm_xform(struct rte_crypto_sym_xform
> *xform);
>
> int prepare_gmac_xform(struct rte_crypto_sym_xform *xform);
>
> +int parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo);
> #endif
> diff --git a/examples/fips_validation/fips_validation_sha.c
> b/examples/fips_validation/fips_validation_sha.c
> index 75b073c15d..cac2a25e6c 100644
> --- a/examples/fips_validation/fips_validation_sha.c
> +++ b/examples/fips_validation/fips_validation_sha.c
> @@ -33,6 +33,22 @@ struct plain_hash_size_conversion {
> {"64", RTE_CRYPTO_AUTH_SHA512},
> };
>
> +int
> +parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo)
> +{
> + int ret = -EINVAL;
> + uint8_t i;
> +
> + for (i = 0; i < RTE_DIM(phsc); i++) {
> + if (phsc[i].algo == algo) {
> + ret = atoi(phsc[i].str);
> + break;
> + }
> + }
> +
> + return ret;
> +}
> +
> static int
> parse_interim_algo(__rte_unused const char *key,
> char *text,
> @@ -212,6 +228,7 @@ parse_test_sha_json_algorithm(void)
> json_t *algorithm_object;
> const char *algorithm_str;
> uint32_t i;
> + int sz;
>
> algorithm_object = json_object_get(json_info.json_vector_set,
> "algorithm");
> algorithm_str = json_string_value(algorithm_object);
> @@ -226,23 +243,15 @@ parse_test_sha_json_algorithm(void)
> if (i == RTE_DIM(json_algorithms))
> return -1;
>
> - for (i = 0; i < RTE_DIM(phsc); i++) {
> - if (info.interim_info.sha_data.algo == phsc[i].algo) {
> - vec.cipher_auth.digest.len = atoi(phsc[i].str);
> - free(vec.cipher_auth.digest.val);
> - vec.cipher_auth.digest.val = calloc(1,
> vec.cipher_auth.digest.len);
> - if (vec.cipher_auth.digest.val == NULL)
> - return -1;
> -
> - break;
> - }
> - }
> + sz = parse_test_sha_hash_size(info.interim_info.sha_data.algo);
> + if (sz < 0)
> + return -1;
>
> - if (i == RTE_DIM(phsc)) {
> - free(vec.cipher_auth.digest.val);
> - vec.cipher_auth.digest.val = NULL;
> + free(vec.cipher_auth.digest.val);
> + vec.cipher_auth.digest.len = sz;
> + vec.cipher_auth.digest.val = calloc(1, sz);
> + if (vec.cipher_auth.digest.val == NULL)
> return -1;
> - }
>
> return 0;
> }
> --
> 2.25.1
@@ -374,4 +374,5 @@ int prepare_gcm_xform(struct rte_crypto_sym_xform *xform);
int prepare_gmac_xform(struct rte_crypto_sym_xform *xform);
+int parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo);
#endif
@@ -33,6 +33,22 @@ struct plain_hash_size_conversion {
{"64", RTE_CRYPTO_AUTH_SHA512},
};
+int
+parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo)
+{
+ int ret = -EINVAL;
+ uint8_t i;
+
+ for (i = 0; i < RTE_DIM(phsc); i++) {
+ if (phsc[i].algo == algo) {
+ ret = atoi(phsc[i].str);
+ break;
+ }
+ }
+
+ return ret;
+}
+
static int
parse_interim_algo(__rte_unused const char *key,
char *text,
@@ -212,6 +228,7 @@ parse_test_sha_json_algorithm(void)
json_t *algorithm_object;
const char *algorithm_str;
uint32_t i;
+ int sz;
algorithm_object = json_object_get(json_info.json_vector_set, "algorithm");
algorithm_str = json_string_value(algorithm_object);
@@ -226,23 +243,15 @@ parse_test_sha_json_algorithm(void)
if (i == RTE_DIM(json_algorithms))
return -1;
- for (i = 0; i < RTE_DIM(phsc); i++) {
- if (info.interim_info.sha_data.algo == phsc[i].algo) {
- vec.cipher_auth.digest.len = atoi(phsc[i].str);
- free(vec.cipher_auth.digest.val);
- vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len);
- if (vec.cipher_auth.digest.val == NULL)
- return -1;
-
- break;
- }
- }
+ sz = parse_test_sha_hash_size(info.interim_info.sha_data.algo);
+ if (sz < 0)
+ return -1;
- if (i == RTE_DIM(phsc)) {
- free(vec.cipher_auth.digest.val);
- vec.cipher_auth.digest.val = NULL;
+ free(vec.cipher_auth.digest.val);
+ vec.cipher_auth.digest.len = sz;
+ vec.cipher_auth.digest.val = calloc(1, sz);
+ if (vec.cipher_auth.digest.val == NULL)
return -1;
- }
return 0;
}