examples/fips_validation: skip offsetting source for json vectors
PATCH 1/2 examples/fips_validation: skip offsetting source for json vectors
For JSON based test vectors, it is not required to offset further on source address where key value is read.
--- examples/fips_validation/fips_validation.c | 4 ++++ 1 file changed, 4 insertions(+)
examples/fips_validation/fips_validation.c +4 -0
@@ -625,7 +625,11 @@ parse_uint8_hex_str(const char *key, char *src, struct fips_val *val) {uint32_t len, j; +#ifndef USE_JANSSON src +=strlen (key); +#else +RTE_SET_USED (key); +#endif len =strlen (src) /2 ;
Signature · 1 line
2.25.1
PATCH 2/2 examples/fips_validation: add parsing for tdes
Added function to parse algorithm for TDES CBC and ECB tests in json.
--- doc/guides/sample_app_ug/fips_validation.rst | 2 + examples/fips_validation/fips_validation.c | 5 +- examples/fips_validation/fips_validation.h | 4 + .../fips_validation/fips_validation_tdes.c | 333 ++++++++++++++++++ examples/fips_validation/main.c | 94 +++-- 5 files changed, 403 insertions(+), 35 deletions(-)
doc/guides/sample_app_ug/fips_validation.rst +2 -0
@@ -64,6 +64,8 @@ ACVP * AES-XTS (128,256) - AFT * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512) * SHA (1, 256, 384, 512) - AFT, MCT + * TDES-CBC - AFT, MCT + * TDES-ECB - AFT, MCT Application Information
examples/fips_validation/fips_validation.c +4 -1
@@ -468,6 +468,9 @@ fips_test_parse_one_json_vector_set(void) info.algo =FIPS_TEST_ALGO_AES_XTS ; else if (strstr(algo_str, "SHA")) info.algo = FIPS_TEST_ALGO_SHA; + else if (strstr(algo_str, "TDES-CBC") || + strstr(algo_str, "TDES-ECB")) + info.algo = FIPS_TEST_ALGO_TDES; else return -EINVAL;
@@ -529,7 +532,7 @@ fips_test_parse_one_json_case(void)* is not included in the string being parsed. */ ret = info.callbacks[i].cb ( -"" , info.one_line_text, + info.callbacks[i].key, info.one_line_text, info.callbacks[i].val );if (ret <0 )
examples/fips_validation/fips_validation.h +4 -0
@@ -114,6 +114,7 @@ enum fips_tdes_test_types {TDES_VARIABLE_KEY ,TDES_VARIABLE_TEXT ,TDES_KAT , +TDES_AFT ,/* Functional Test */ TDES_MCT ,/* Monte Carlo (Modes) Test */ TDES_MMT /* Multi block Message Test */ };
@@ -290,6 +291,9 @@ parse_test_sha_json_algorithm(void);int parse_test_sha_json_test_type (void ); + +int +parse_test_tdes_json_init (void );#endif /* USE_JANSSON */ int
examples/fips_validation/fips_validation_tdes.c +333 -0
351 lines not on this page · raw message
examples/fips_validation/main.c +60 -34
202 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 1/2 examples/fips_validation: share test callback with multiple keys
Make use of key param in test callbacks so that, test callback can be shared with multiple keys.
--- examples/fips_validation/fips_validation.c | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-)
examples/fips_validation/fips_validation.c +19 -8
@@ -499,11 +499,8 @@ fips_test_parse_one_json_group(void)return -EINVAL ; } -/* First argument is blank because the key -* is not included in the string being parsed. -*/ ret = info.interim_callbacks[i].cb ( -"" , json_value, + info.interim_callbacks[i].key, json_value, info.interim_callbacks[i].val );if (ret <0 )
@@ -525,11 +522,8 @@ fips_test_parse_one_json_case(void) param =json_object_get (json_info.json_test_case, info.callbacks[i].key);if (param) {strcpy (info.one_line_text,json_string_value (param)); -/* First argument is blank because the key -* is not included in the string being parsed. -*/ ret = info.callbacks[i].cb ( -"" , info.one_line_text, + info.callbacks[i].key, info.one_line_text, info.callbacks[i].val );if (ret <0 )
@@ -625,7 +619,14 @@ parse_uint8_hex_str(const char *key, char *src, struct fips_val *val) {uint32_t len, j; +#ifdef USE_JANSSON +/* +* Offset not applicable in case of JSON test vectors. +*/ +RTE_SET_USED (key); +#else src +=strlen (key); +#endif len =strlen (src) /2 ;
@@ -653,6 +654,15 @@ parse_uint8_hex_str(const char *key, char *src, struct fips_val *val)return 0 ; } +#ifdef USE_JANSSON +int +parser_read_uint32_val (const char *key,char *src,struct fips_val *val) +{ +RTE_SET_USED (key); + +return parser_read_uint32 (&val->len, src); +} +#else int parser_read_uint32_val (const char *key,char *src,struct fips_val *val) {
@@ -676,6 +686,7 @@ parser_read_uint32_val(const char *key, char *src, struct fips_val *val) return ret; } +#endif int parser_read_uint32_bit_val (const char *key,char *src,struct fips_val *val)
Signature · 1 line
2.25.1
PATCH v2 2/2 examples/fips_validation: add parsing for TDES
Added function to parse algorithm for TDES CBC and ECB tests in json.
--- doc/guides/sample_app_ug/fips_validation.rst | 2 + examples/fips_validation/fips_validation.c | 3 + examples/fips_validation/fips_validation.h | 4 + .../fips_validation/fips_validation_tdes.c | 335 ++++++++++++++++++ examples/fips_validation/main.c | 94 +++-- 5 files changed, 404 insertions(+), 34 deletions(-)
doc/guides/sample_app_ug/fips_validation.rst +2 -0
@@ -64,6 +64,8 @@ ACVP * AES-XTS (128,256) - AFT * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512) * SHA (1, 256, 384, 512) - AFT, MCT + * TDES-CBC - AFT, MCT + * TDES-ECB - AFT, MCT Application Information
examples/fips_validation/fips_validation.c +3 -0
@@ -468,6 +468,9 @@ fips_test_parse_one_json_vector_set(void) info.algo =FIPS_TEST_ALGO_AES_XTS ; else if (strstr(algo_str, "SHA")) info.algo = FIPS_TEST_ALGO_SHA; + else if (strstr(algo_str, "TDES-CBC") || + strstr(algo_str, "TDES-ECB")) + info.algo = FIPS_TEST_ALGO_TDES; else return -EINVAL;
examples/fips_validation/fips_validation.h +4 -0
@@ -114,6 +114,7 @@ enum fips_tdes_test_types {TDES_VARIABLE_KEY ,TDES_VARIABLE_TEXT ,TDES_KAT , +TDES_AFT ,/* Functional Test */ TDES_MCT ,/* Monte Carlo (Modes) Test */ TDES_MMT /* Multi block Message Test */ };
@@ -290,6 +291,9 @@ parse_test_sha_json_algorithm(void);int parse_test_sha_json_test_type (void ); + +int +parse_test_tdes_json_init (void );#endif /* USE_JANSSON */ int
examples/fips_validation/fips_validation_tdes.c +335 -0
353 lines not on this page · raw message
examples/fips_validation/main.c +60 -34
202 lines not on this page · raw message
Signature · 1 line
2.25.1
RE: [PATCH v2 2/2] examples/fips_validation: add parsing for TDES
Quoted 685 lines
-----Original Message-----
From: Gowrishankar Muthukrishnan <[email protected]>
Sent: Friday, August 12, 2022 12:52 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Zhang, Roy Fan <[email protected]>; Dooley, Brian <[email protected]>; Akhil Goyal <[email protected]>; [email protected]; Gowrishankar Muthukrishnan <[email protected]>
Subject: [PATCH v2 2/2] examples/fips_validation: add parsing for TDESAdded function to parse algorithm for TDES CBC and ECB tests in json.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>--- doc/guides/sample_app_ug/fips_validation.rst | 2 + examples/fips_validation/fips_validation.c | 3 + examples/fips_validation/fips_validation.h | 4 + .../fips_validation/fips_validation_tdes.c | 335 ++++++++++++++++++ examples/fips_validation/main.c | 94 +++-- 5 files changed, 404 insertions(+), 34 deletions(-)doc/guides/sample_app_ug/fips_validation.rst +2
-0@@ -64,6 +64,8 @@ ACVP * AES-XTS (128,256) - AFT * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512) * SHA (1, 256, 384, 512) - AFT, MCT + * TDES-CBC - AFT, MCT + * TDES-ECB - AFT, MCT Application Informationexamples/fips_validation/fips_validation.c +3
-0@@ -468,6 +468,9 @@ fips_test_parse_one_json_vector_set(void) info.algo =FIPS_TEST_ALGO_AES_XTS ; else if (strstr(algo_str, "SHA")) info.algo = FIPS_TEST_ALGO_SHA; + else if (strstr(algo_str, "TDES-CBC") || + strstr(algo_str, "TDES-ECB")) + info.algo = FIPS_TEST_ALGO_TDES; else return -EINVAL;examples/fips_validation/fips_validation.h +1
-0@@ -114,6 +114,7 @@ enum fips_tdes_test_types {TDES_VARIABLE_KEY ,TDES_VARIABLE_TEXT ,TDES_KAT , +TDES_AFT ,/* Functional Test */ TDES_MCT ,/* Monte Carlo (Modes) Test */ TDES_MMT /* Multi block Message Test */ }; @@ -290,6 +291,9 @@parse_test_sha_json_algorithm (void);int
parse_test_sha_json_test_type(void);examples/fips_validation/fips_validation.h +3
-0+ +int +parse_test_tdes_json_init (void );#endif /* USE_JANSSON */ int examples/fips_validation/fips_validation_tdes.c +79
-0@@ -38,6 +38,21 @@#define DEVICE_STR "# Config Info for : " +#define ALGO_JSON_STR "algorithm" +#define TESTTYPE_JSON_STR "testType" +#define DIR_JSON_STR "direction" +#define KEYOPT_JSON_STR "keyingOption" + +#define PT_JSON_STR "pt" +#define CT_JSON_STR "ct" +#define IV_JSON_STR "iv" +#define KEY1_JSON_STR "key1" +#define KEY2_JSON_STR "key2" +#define KEY3_JSON_STR "key3" + +#define OP_ENC_JSON_STR "encrypt" +#define OP_DEC_JSON_STR "decrypt" +struct {uint32_t type;const char *desc;@@ -48,6 +63,7 @@ struct { {TDES_VARIABLE_KEY, "VARIABLE KEY"}, {TDES_VARIABLE_TEXT, "VARIABLEPLAINTEXT /CIPHERTEXT "}, {TDES_VARIABLE_TEXT, "KAT"}, + {TDES_AFT, "Functional Test"}, {TDES_MCT, "Monte Carlo (Modes) Test"}, {TDES_MMT, "Multi block Message Test"}, }; @@ -92,6 +108,325 @@ struct fips_test_callback tdes_writeback_callbacks[] = { {NULL ,NULL ,NULL }/**< end pointer */ }; +#ifdef USE_JANSSON +static struct { +enum fips_tdes_test_types type; +const char *desc; +}const tdes_test_types[] = { + {TDES_AFT ,"AFT" }, + {TDES_MCT ,"MCT" }, +}; + +static struct { +enum fips_tdes_test_mode mode; +const char *desc; +}const tdes_test_modes[] = { + {TDES_MODE_CBC ,"CBC" }, + {TDES_MODE_ECB ,"ECB" }, +}; + +#define TDES_KEYS_TUPLE_LEN 24 + +static int +parser_tdes_read_key (const char *key,char *src,struct fips_val *val) +{ +uint8_t tmp_key[TDES_KEYS_TUPLE_LEN ] = {0 }; +uint32_t len, i; + + len =strlen (src) /2 ; + +if (val->val) { +memcpy (tmp_key, val->val, val->len); +rte_free (val->val); + } + + val->val =rte_zmalloc (NULL ,TDES_KEYS_TUPLE_LEN ,0 ); +if (!val->val) +return -1 ; + +memcpy (val->val, tmp_key,TDES_KEYS_TUPLE_LEN ); + +if (strstr (key,KEY1_JSON_STR )) { +for (i =0 ; i < len; i++) { +char byte[3 ] = {src[i *2 ], src[i *2 +1 ],'\0' }; + +if (parser_read_uint8_hex (&val->val[i], byte) <0 ) + goto error_exit; + } + +if (info.interim_info.tdes_data.nb_keys ==2 ) +memcpy (val->val +16 , val->val,8 ); + + }else if (strstr (key,KEY2_JSON_STR )) { +for (i =0 ; i < len; i++) { +char byte[3 ] = {src[i *2 ], src[i *2 +1 ],'\0' }; + +if (parser_read_uint8_hex (&val->val[i +8 ], byte) <0 ) + goto error_exit; + } + + }else if (strstr (key,KEY3_JSON_STR )) { +for (i =0 ; i < len; i++) { +char byte[3 ] = {src[i *2 ], src[i *2 +1 ],'\0' }; + + if (parser_read_uint8_hex(&val->val[i + 16], byte) <0)
examples/fips_validation/fips_validation_tdes.c +50
-0+ goto error_exit; + } + }else +return -EINVAL ; + + val->len =TDES_KEYS_TUPLE_LEN ; + +return 0 ; + +error_exit: +rte_free (val->val); +memset (val,0 ,sizeof (*val)); +return -EINVAL ; +} + +struct fips_test_callback tdes_dec_json_vectors[] = { + {KEY1_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {KEY2_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {KEY3_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {IV_JSON_STR , parse_uint8_hex_str, &vec.iv}, + {CT_JSON_STR , parse_uint8_hex_str, &vec.ct}, + {NULL ,NULL ,NULL }/**< end pointer */ }; + +struct fips_test_callback tdes_enc_json_vectors[] = { + {KEY1_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {KEY2_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {KEY3_JSON_STR , parser_tdes_read_key, &vec.cipher_auth.key}, + {IV_JSON_STR , parse_uint8_hex_str, &vec.iv}, + {PT_JSON_STR , parse_uint8_hex_str, &vec.pt}, + {NULL ,NULL ,NULL }/**< end pointer */ }; + +static int +parse_test_tdes_json_writeback (struct fips_val *val) { +struct fips_val tmp_val; +json_t *tcId; + + tcId =json_object_get (json_info.json_test_case,"tcId" ); + + json_info.json_write_case =json_object (); +json_object_set (json_info.json_write_case,"tcId" , tcId); + +if (info.op ==FIPS_TEST_ENC_AUTH_GEN ) { +json_t *ct; + + tmp_val.val = val->val; + tmp_val.len = vec.pt.len; + +writeback_hex_str ("" , info.one_line_text, &tmp_val); + ct =json_string (info.one_line_text); + json_object_set_new(json_info.json_write_case,
CT_JSON_STR, ct);examples/fips_validation/fips_validation_tdes.c +11
-0+ + tmp_val.val = val->val + vec.pt.len; + tmp_val.len = val->len - vec.pt.len; + +writeback_hex_str ("" , info.one_line_text, &tmp_val); + }else { +if (vec.status ==RTE_CRYPTO_OP_STATUS_SUCCESS ) { + tmp_val.val = val->val; + tmp_val.len = vec.ct.len; + + writeback_hex_str("", info.one_line_text,
&tmp_val);examples/fips_validation/fips_validation_tdes.c +1
-0+ json_object_set_new(json_info.json_write_case,
PT_JSON_STR,
+json_string(info.one_line_text));examples/fips_validation/fips_validation_tdes.c +2
-0+ }else { + json_object_set_new(json_info.json_write_case,"testPassed",
json_false());examples/fips_validation/fips_validation_tdes.c +19
-0+ } + } + +return 0 ; +} + +static int +parse_test_tdes_mct_json_writeback (struct fips_val *val) { +json_t *tcId, *resArr, *res, *ct, *pt, *key, *iv; +struct fips_val tmp_val; + + tcId =json_object_get (json_info.json_test_case,"tcId" ); +if (json_info.json_write_case) { +json_t *wcId; + + wcId =json_object_get (json_info.json_write_case,"tcId" ); +if (!json_equal (tcId, wcId)) { + json_info.json_write_case =json_object (); + json_object_set(json_info.json_write_case, "tcId",tcId);
examples/fips_validation/fips_validation_tdes.c +1
-0+ json_object_set(json_info.json_write_case,"resultsArray",
json_array());examples/fips_validation/fips_validation_tdes.c +5
-0+ } + }else { + json_info.json_write_case =json_object (); +json_object_set (json_info.json_write_case,"tcId" , tcId); + json_object_set(json_info.json_write_case, "resultsArray",
json_array());examples/fips_validation/fips_validation_tdes.c +3
-0+ } + + resArr = json_object_get(json_info.json_write_case,"resultsArray");
examples/fips_validation/fips_validation_tdes.c +22
-0+if (!json_is_array (resArr)) +return -EINVAL ; + + res =json_object (); +if (info .op ==FIPS_TEST_ENC_AUTH_GEN ) { + tmp_val.len =8 ; + tmp_val.val = vec.cipher_auth.key.val; +writeback_hex_str ("" , info.one_line_text, &tmp_val); + key =json_string (info.one_line_text); +json_object_set_new (res,KEY1_JSON_STR , key); + + tmp_val.val = vec.cipher_auth.key.val +8 ; +writeback_hex_str ("" , info.one_line_text, &tmp_val); + key =json_string (info.one_line_text); +json_object_set_new (res,KEY2_JSON_STR , key); + + tmp_val.val = vec.cipher_auth.key.val +16 ; +writeback_hex_str ("" , info.one_line_text, &tmp_val); + key =json_string (info.one_line_text); +json_object_set_new (res,KEY3_JSON_STR , key); + + if (info.interim_info.tdes_data.test_mode ==
TDES_MODE_CBC) {examples/fips_validation/fips_validation_tdes.c +25
-0+writeback_hex_str ("" , info.one_line_text, &val[2 ]); + iv =json_string (info.one_line_text); +json_object_set_new (res,IV_JSON_STR , iv); + } + +writeback_hex_str ("" , info.one_line_text, &val[1 ]); + pt =json_string (info.one_line_text); +json_object_set_new (res,PT_JSON_STR , pt); + + tmp_val.val = val->val; + tmp_val.len = vec.pt.len; + +writeback_hex_str ("" , info.one_line_text, &tmp_val); + ct =json_string (info.one_line_text); +json_object_set_new (res,CT_JSON_STR , ct); + + tmp_val.val = val->val + vec.pt.len; + tmp_val.len = val->len - vec.pt.len; + +writeback_hex_str ("" , info.one_line_text, &tmp_val); + }else { +if (vec.status ==RTE_CRYPTO_OP_STATUS_SUCCESS ) { + tmp_val.len =8 ; + tmp_val.val = vec.cipher_auth.key.val; + writeback_hex_str("", info.one_line_text,
&tmp_val);examples/fips_validation/fips_validation_tdes.c +5
-0+ key =json_string (info.one_line_text); +json_object_set_new (res,KEY1_JSON_STR , key); + + tmp_val.val = vec.cipher_auth.key.val +8 ; + writeback_hex_str("", info.one_line_text,
&tmp_val);examples/fips_validation/fips_validation_tdes.c +5
-0+ key =json_string (info.one_line_text); +json_object_set_new (res,KEY2_JSON_STR , key); + + tmp_val.val = vec.cipher_auth.key.val +16 ; + writeback_hex_str("", info.one_line_text,
&tmp_val);examples/fips_validation/fips_validation_tdes.c +4
-0+ key =json_string (info.one_line_text); +json_object_set_new (res,KEY3_JSON_STR , key); + + if (info.interim_info.tdes_data.test_mode ==
TDES_MODE_CBC) {examples/fips_validation/fips_validation_tdes.c +1
-0+ writeback_hex_str("", info.one_line_text,&val[2]);
examples/fips_validation/fips_validation_tdes.c +8
-0+ iv =json_string (info.one_line_text); +json_object_set_new (res,IV_JSON_STR , iv); + } + + tmp_val.val = val->val; + tmp_val.len = vec.ct.len; + + writeback_hex_str("", info.one_line_text,
&tmp_val);examples/fips_validation/fips_validation_tdes.c +8
-0+ pt =json_string (info.one_line_text); +json_object_set_new (res,PT_JSON_STR , pt); + +writeback_hex_str ("" , info.one_line_text, &val[1 ]); + ct =json_string (info.one_line_text); +json_object_set_new (res,CT_JSON_STR , ct); + }else { + json_object_set_new(json_info.json_write_case,"testPassed",
json_false());examples/fips_validation/fips_validation_tdes.c +11
-0+ } + } + +json_array_append_new (resArr, res); + +return 0 ; +} + +int parse_test_tdes_json_init (void ) +{ + json_t *type_obj = json_object_get(json_info.json_test_group,
TESTTYPE_JSON_STR);examples/fips_validation/fips_validation_tdes.c +1
-0+ json_t *algo_obj = json_object_get(json_info.json_vector_set,
ALGO_JSON_STR);examples/fips_validation/fips_validation_tdes.c +10
-0+const char *type_str =json_string_value (type_obj); +const char *algo_str =json_string_value (algo_obj); +uint32_t i; + +if (json_info.json_test_group) { +json_t *direction_obj, *opt_obj; +const char *direction_str; +int opt_val; + + direction_obj = json_object_get(json_info.json_test_group,
DIR_JSON_STR);examples/fips_validation/fips_validation_tdes.c +13
-0+ direction_str =json_string_value (direction_obj); + +if (strcmp (direction_str,OP_ENC_JSON_STR ) ==0 ) { + info.op =FIPS_TEST_ENC_AUTH_GEN ; + info.callbacks = tdes_enc_json_vectors; + }else if (strcmp (direction_str,OP_DEC_JSON_STR ) ==0 ) { + info.op =FIPS_TEST_DEC_AUTH_VERIF ; + info.callbacks = tdes_dec_json_vectors; + }else { +return -EINVAL ; + } + + opt_obj = json_object_get(json_info.json_test_group,
KEYOPT_JSON_STR);examples/fips_validation/fips_validation_tdes.c +35
-0+ opt_val =json_integer_value (opt_obj); +if (opt_val ==2 ) + info.interim_info.tdes_data.nb_keys =2 ; +else + info.interim_info.tdes_data.nb_keys =3 ; + + info.interim_callbacks =NULL ; + } + +for (i =0 ; i <RTE_DIM (tdes_test_types); i++) +if (strstr (type_str, tdes_test_types[i].desc)) { + info.interim_info.tdes_data.test_type = + tdes_test_types[i].type; +break ; + } + +if (i >=RTE_DIM (tdes_test_types)) +return -EINVAL ; + +for (i =0 ;RTE_DIM (tdes_test_modes); i++) +if (strstr (algo_str, tdes_test_modes[i].desc)) { + info.interim_info.tdes_data.test_mode = + tdes_test_modes[i].mode; +break ; + } + +if (i >=RTE_DIM (tdes_test_modes)) +return -EINVAL ; + +switch (info.interim_info.tdes_data.test_type) { +case TDES_AFT : + info.parse_writeback = parse_test_tdes_json_writeback; +break ; +case TDES_MCT : + info.parse_writeback =
parse_test_tdes_mct_json_writeback;examples/fips_validation/fips_validation_tdes.c +12
-0+break ; +default : + info.parse_writeback = NULL; + }; + +if (info.parse_writeback ==NULL ) +return -EINVAL ; + +return 0 ; +} +#endif /* USE_JANSSON */ +static int parse_tdes_interim (const char *key,char *text, __rte_unused struct fips_val *val)(quoted diff) +0
-0
b/examples/fips_validation/main.cindex5c3f79a91c..8babbb3298100644examples/fips_validation/main.c +1
-1@@ -1303,7 +1303,7 @@ fips_mct_tdes_test(void)#define TDES_BLOCK_SIZE 8#define TDES_EXTERN_ITER 400#define TDES_INTERN_ITER 10000 -struct fips_val val = {NULL ,0 }, val_key; +struct fips_val val[3 ] = {{NULL ,0 },}, val_key, pt, ct, iv;uint8_t prev_out[TDES_BLOCK_SIZE ] = {0 };uint8_t prev_prev_out[TDES_BLOCK_SIZE ] = {0 }; uint8_t prev_in[TDES_BLOCK_SIZE] = {0}; @@ -1311,16 +1311,25 @@
fips_mct_tdes_test(void)examples/fips_validation/main.c +7
-3int ret;int test_mode = info.interim_info.tdes_data.test_mode; + pt.len = vec.pt.len; + pt.val =calloc (1 , pt.len); + ct.len = vec.ct.len; + ct.val =calloc (1 , ct.len); + iv.len = vec.iv.len; + iv.val =calloc (1 , iv.len); +for (i =0 ; i <TDES_EXTERN_ITER ; i++) { -if ((i ==0 ) && (info.version ==21.4f )) { -if (!(strstr (info.vec[0 ],"COUNT" ))) - fprintf(info.fp_wr, "%s%u\n", "COUNT = ",0);
examples/fips_validation/main.c +4
-1- } +if (info.file_type !=FIPS_TYPE_JSON ) { +if ((i ==0 ) && (info.version ==21.4f )) { +if (!(strstr (info.vec[0 ],"COUNT" ))) + fprintf(info.fp_wr, "%s%u\n","COUNT = ", 0);
examples/fips_validation/main.c +25
-13+ } -if (i !=0 ) -update_info_vec (i); +if (i !=0 ) +update_info_vec (i); -fips_test_write_one_case (); +fips_test_write_one_case (); + }for (j =0 ; j <TDES_INTERN_ITER ; j++) { ret =fips_run_test ();@@ -1335,7 +1344,7 @@ fips_mct_tdes_test(void)return ret; } - ret =get_writeback_data (&val); + ret =get_writeback_data (&val[0 ]);if (ret <0 )return ret;@@ -1343,51 +1352,61 @@ fips_mct_tdes_test(void)memcpy (prev_in, vec.ct.val,TDES_BLOCK_SIZE );if (j ==0 ) { -memcpy (prev_out, val.val, TDES_BLOCK_SIZE); +memcpy (prev_out, val[0 ].val,TDES_BLOCK_SIZE ); +memcpy (pt.val, vec.pt.val, pt.len); +memcpy (ct.val, vec.ct.val, ct.len); +memcpy (iv.val, vec.iv.val, iv.len);if (info.op ==FIPS_TEST_ENC_AUTH_GEN ) {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.pt.val, val.val, +memcpy (vec.pt.val, val[0 ].val,TDES_BLOCK_SIZE ); }else {memcpy (vec.pt.val, vec.iv.val,TDES_BLOCK_SIZE ); -memcpy (vec.iv.val, val.val, +memcpy (vec.iv.val, val[0 ].val,TDES_BLOCK_SIZE ); } - + val[1 ].val = pt.val; + val[1 ].len = pt.len; + val[2 ].val = iv.val; + val[2 ].len = iv.len; }else {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.ct.val, val.val, +memcpy (vec.ct.val, val[0 ].val,TDES_BLOCK_SIZE ); }else {memcpy (vec.iv.val, vec.ct.val,TDES_BLOCK_SIZE ); -memcpy (vec.ct.val, val.val, +memcpy (vec.ct.val, val[0 ].val,TDES_BLOCK_SIZE ); } + val[1 ].val = ct.val; + val[1 ].len = ct.len; + val[2 ].val = iv.val; + val[2 ].len = iv.len; }continue ; }if (info.op ==FIPS_TEST_ENC_AUTH_GEN ) {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.pt.val, val.val, +memcpy (vec.pt.val, val[0 ].val,TDES_BLOCK_SIZE ); }else { -memcpy (vec.iv.val, val.val, +memcpy (vec.iv.val, val[0 ].val,TDES_BLOCK_SIZE );memcpy (vec.pt.val, prev_out,TDES_BLOCK_SIZE ); } }else {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.ct.val, val.val, +memcpy (vec.ct.val, val[0 ].val,TDES_BLOCK_SIZE ); }else { memcpy(vec.iv.val, vec.ct.val,examples/fips_validation/main.c +6
-5TDES_BLOCK_SIZE); -memcpy (vec.ct.val, val.val, +memcpy (vec.ct.val, val[0 ].val,TDES_BLOCK_SIZE ); } }@@ -1395,14 +1414,15 @@ fips_mct_tdes_test(void)if (j ==TDES_INTERN_ITER -1 )continue ; -memcpy (prev_out, val.val,TDES_BLOCK_SIZE ); +memcpy (prev_out, val[0 ].val,TDES_BLOCK_SIZE );if (j ==TDES_INTERN_ITER -3 ) -memcpy (prev_prev_out, val.val, TDES_BLOCK_SIZE); +memcpy (prev_prev_out, val[0 ].val,TDES_BLOCK_SIZE ); } - info.parse_writeback (&val); -fprintf (info.fp_wr,"\n" ); + info.parse_writeback (val); +if (info.file_type !=FIPS_TYPE_JSON ) +fprintf (info.fp_wr,"\n" );examples/fips_validation/main.c +9
-10if (i ==TDES_EXTERN_ITER -1 )continue ;@@ -1424,19 +1444,19 @@ fips_mct_tdes_test(void)switch (info.interim_info.tdes_data.nb_keys) {case 3 : - val_key.val[k] ^= val.val[k]; + val_key.val[k] ^= val[0 ].val[k]; val_key.val[k +8 ] ^= prev_out[k]; val_key.val[k +16 ] ^= prev_prev_out[k];break ;case 2 : - val_key.val[k] ^= val.val[k]; + val_key.val[k] ^= val[0 ].val[k]; val_key.val[k +8 ] ^= prev_out[k]; - val_key.val[k +16 ] ^= val.val[k]; + val_key.val[k +16 ] ^= val[0 ].val[k];break ;default :/* case 1 */ - val_key.val[k] ^= val.val[k]; - val_key.val[k +8 ] ^= val.val[k]; - val_key.val[k +16 ] ^= val.val[k]; + val_key.val[k] ^= val[0 ].val[k]; + val_key.val[k +8 ] ^= val[0 ].val[k]; + val_key.val[k +16 ] ^= val[0 ].val[k];break ; }@@ -1449,22 +1469,25 @@ fips_mct_tdes_test(void)if (info.op ==FIPS_TEST_ENC_AUTH_GEN ) {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.pt.val, val.val, TDES_BLOCK_SIZE); +memcpy (vec.pt.val, val[0 ].val,TDES_BLOCK_SIZE ); }else { -memcpy (vec.iv.val, val.val, TDES_BLOCK_SIZE); +memcpy (vec.iv.val, val[0 ].val,TDES_BLOCK_SIZE );memcpy (vec.pt.val, prev_out,TDES_BLOCK_SIZE ); } }else {if (test_mode ==TDES_MODE_ECB ) { -memcpy (vec.ct.val, val.val, TDES_BLOCK_SIZE); +memcpy (vec.ct.val, val[0 ].val,TDES_BLOCK_SIZE ); }else {memcpy (vec.iv.val, prev_out,TDES_BLOCK_SIZE ); - memcpy(vec.ct.val, val.val,
TDES_BLOCK_SIZE);examples/fips_validation/main.c +1
-0+ memcpy(vec.ct.val, val[0].val,
TDES_BLOCK_SIZE);examples/fips_validation/main.c +7
-2} } } -free (val.val); +free (val[0 ].val); +free (pt.val); +free (ct.val); +free (iv.val);return 0 ; }@@ -2007,6 +2030,9 @@ fips_test_one_test_group(void)case FIPS_TEST_ALGO_SHA : ret =parse_test_sha_json_init ();break ; +case FIPS_TEST_ALGO_TDES : + ret =parse_test_tdes_json_init (); +break ;default :return -EINVAL ; } --
Quoted 1 line
2.25.1
RE: [PATCH v2 2/2] examples/fips_validation: add parsing for TDES
Quoted 8 lines
Quoted 6 lines
Subject: [PATCH v2 2/2] examples/fips_validation: add parsing for TDES
Added function to parse algorithm for TDES CBC and ECB tests in json.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>---
Acked-by Brian Dooley <[email protected]>
Series applied to dpdk-next-crypto
Thanks.
RE: [PATCH v2 1/2] examples/fips_validation: share test callback with multiple keys
In reply to Gowrishankar MuthukrishnanQuoted 89 lines
-----Original Message-----
From: Gowrishankar Muthukrishnan <[email protected]>
Sent: Friday, August 12, 2022 12:52 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Zhang, Roy Fan <[email protected]>; Dooley, Brian <[email protected]>; Akhil Goyal <[email protected]>; [email protected]; Gowrishankar Muthukrishnan <[email protected]>
Subject: [PATCH v2 1/2] examples/fips_validation: share test callback with multiple keysMake use of key param in test callbacks so that, test callback can be shared with multiple keys.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>--- examples/fips_validation/fips_validation.c | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-)examples/fips_validation/fips_validation.c +2
-8@@ -499,11 +499,8 @@ fips_test_parse_one_json_group(void)return -EINVAL ; } -/* First argument is blank because the key -* is not included in the string being parsed. -*/ ret = info.interim_callbacks[i].cb ( -"" , json_value, + info.interim_callbacks[i].key, json_value, info.interim_callbacks[i].val );if (ret <0 )@@ -525,11 +522,8 @@ fips_test_parse_one_json_case(void) param =json_object_get (json_info.json_test_case, info.callbacks[i].key);if (param) {strcpy (info.one_line_text,json_string_value (param)); -/* First argument is blank because the key -* is not included in the string being parsed. -*/ ret = info.callbacks[i].cb ( -"" , info.one_line_text, + info.callbacks[i].key, info.one_line_text, info.callbacks[i].valexamples/fips_validation/fips_validation.c +15
-0);if (ret <0 )@@ -625,7 +619,14 @@ parse_uint8_hex_str(const char *key, char *src, struct fips_val *val) {uint32_t len, j; +#ifdef USE_JANSSON +/* +* Offset not applicable in case of JSON test vectors. +*/ +RTE_SET_USED (key); +#else src +=strlen (key); +#endif len =strlen (src) /2 ;@@ -653,6 +654,15 @@ parse_uint8_hex_str(const char *key, char *src, struct fips_val *val)return 0 ; } +#ifdef USE_JANSSON +int +parser_read_uint32_val (const char *key,char *src,struct fips_val +*val) { +RTE_SET_USED (key); + +return parser_read_uint32 (&val->len, src); }#else int parser_read_uint32_val (const char *key,char *src,struct fips_val *val) {@@ -676,6 +686,7 @@ parser_read_uint32_val(const char *key, char *src, struct fips_val *val) return ret; } +#endif int
Quoted 3 lines
parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val)
--
2.25.1