]> git.droids-corp.org - dpdk.git/commitdiff
examples/fips_validation: add JSON for HMAC
authorBrandon Lo <blo@iol.unh.edu>
Mon, 30 May 2022 15:52:40 +0000 (21:22 +0530)
committerAkhil Goyal <gakhil@marvell.com>
Wed, 1 Jun 2022 14:26:35 +0000 (16:26 +0200)
Added JSON support for the HMAC algorithm.

Signed-off-by: Brandon Lo <blo@iol.unh.edu>
Acked-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Tested-by: Jakub Poczatek <jakub.poczatek@intel.com>
examples/fips_validation/fips_validation.c
examples/fips_validation/fips_validation.h
examples/fips_validation/fips_validation_hmac.c
examples/fips_validation/main.c

index 6594a155795845a7c8ce91e209c2077cd9f7a7fb..e8520f59cf988610b5de2e18e1af1f0c0a0924fc 100644 (file)
@@ -458,6 +458,8 @@ fips_test_parse_one_json_vector_set(void)
        /* Vector sets contain the algorithm type, and nothing else we need. */
        if (strstr(algo_str, "AES-GCM"))
                info.algo = FIPS_TEST_ALGO_AES_GCM;
+       if (strstr(algo_str, "HMAC"))
+               info.algo = FIPS_TEST_ALGO_HMAC;
        else
                return -EINVAL;
 
index 8b9d528c53b373bfe659a3717ad787d993551b9f..3b3ffb7fa6f7b2c1913b8263aee63df7809e4a83 100644 (file)
@@ -253,6 +253,12 @@ fips_test_parse_one_json_case(void);
 
 int
 parse_test_gcm_json_init(void);
+
+int
+parse_test_hmac_json_init(void);
+
+int
+parse_test_hmac_json_algorithm(void);
 #endif /* RTE_HAS_JANSSON */
 
 int
index 1285c9d28305f0e2bec7c40b5888278a09ae6dbd..4cd1b1ac074b54aac78cdc113eeda3fd08274390 100644 (file)
 #define PT_STR         "Msg = "
 #define TAG_STR                "Mac = "
 
+#define ALGO_JSON_STR  "algorithm"
+
+#define KEYLEN_JSON_STR        "keyLen"
+#define TAGLEN_JSON_STR        "macLen"
+
+#define KEY_JSON_STR   "key"
+#define PT_JSON_STR            "msg"
+#define TAG_JSON_STR   "mac"
+
 struct hash_size_conversion {
        const char *str;
        enum rte_crypto_auth_algorithm algo;
@@ -65,6 +74,29 @@ struct fips_test_callback hmac_tests_interim_vectors[] = {
                {NULL, NULL, NULL} /**< end pointer */
 };
 
+#ifdef RTE_HAS_JANSSON
+struct hash_size_conversion json_algorithms[] = {
+               {"HMAC-SHA-1", RTE_CRYPTO_AUTH_SHA1_HMAC},
+               {"HMAC-SHA2-224", RTE_CRYPTO_AUTH_SHA224_HMAC},
+               {"HMAC-SHA2-256", RTE_CRYPTO_AUTH_SHA256_HMAC},
+               {"HMAC-SHA2-384", RTE_CRYPTO_AUTH_SHA384_HMAC},
+               {"HMAC-SHA2-512", RTE_CRYPTO_AUTH_SHA512_HMAC},
+};
+
+struct fips_test_callback hmac_tests_json_vectors[] = {
+               {KEY_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
+               {PT_JSON_STR, parse_uint8_hex_str, &vec.pt},
+               {TAG_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.digest},
+               {NULL, NULL, NULL} /**< end pointer */
+};
+
+struct fips_test_callback hmac_tests_interim_json_vectors[] = {
+               {KEYLEN_JSON_STR, parser_read_uint32_val, &vec.cipher_auth.key},
+               {TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.digest},
+               {NULL, NULL, NULL} /**< end pointer */
+};
+#endif /* RTE_HAS_JANSSON */
+
 static int
 parse_test_hmac_writeback(struct fips_val *val)
 {
@@ -103,3 +135,64 @@ parse_test_hmac_init(void)
 
        return 0;
 }
+
+#ifdef RTE_HAS_JANSSON
+static int
+parse_test_hmac_json_writeback(struct fips_val *val)
+{
+       struct fips_val val_local;
+       json_t *tcId, *mac;
+
+       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);
+
+
+       val_local.val = val->val + vec.pt.len;
+       val_local.len = vec.cipher_auth.digest.len;
+
+       writeback_hex_str("", info.one_line_text, &val_local);
+
+       mac = json_string(info.one_line_text);
+       json_object_set_new(json_info.json_write_case, TAG_JSON_STR, mac);
+
+       return 0;
+}
+
+int
+parse_test_hmac_json_algorithm(void)
+{
+       json_t *algorithm_object;
+       const char *algorithm_str;
+       uint32_t i;
+
+       algorithm_object = json_object_get(json_info.json_vector_set, "algorithm");
+       algorithm_str = json_string_value(algorithm_object);
+
+       for (i = 0; i < RTE_DIM(json_algorithms); i++) {
+               if (strstr(algorithm_str, json_algorithms[i].str)) {
+                       info.interim_info.hmac_data.algo = json_algorithms[i].algo;
+                       return 0;
+               }
+       }
+
+       return -1;
+}
+
+int
+parse_test_hmac_json_init(void)
+{
+       info.op = FIPS_TEST_ENC_AUTH_GEN;
+       info.parse_writeback = parse_test_hmac_json_writeback;
+       info.callbacks = hmac_tests_json_vectors;
+       info.writeback_callbacks = NULL;
+       info.kat_check = rsp_test_hmac_check;
+       info.interim_callbacks = hmac_tests_interim_json_vectors;
+
+       if (parse_test_hmac_json_algorithm() < 0)
+               return -1;
+
+       return 0;
+}
+#endif /* RTE_HAS_JANSSON */
index e729b01529eaa9ddda42359ede93c6f811337c75..2393559d0d3ae3c87d2af7f65a0007541a783c0f 100644 (file)
@@ -1957,6 +1957,9 @@ fips_test_one_test_group(void)
        case FIPS_TEST_ALGO_AES_GCM:
                ret = parse_test_gcm_json_init();
                break;
+       case FIPS_TEST_ALGO_HMAC:
+               ret = parse_test_hmac_json_init();
+               break;
        default:
                return -EINVAL;
        }