From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2AA2AA00C4; Mon, 30 May 2022 14:24:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A7A5142BA5; Mon, 30 May 2022 14:24:06 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 0219D42B93 for ; Mon, 30 May 2022 14:24:04 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24UCDgwr004646; Mon, 30 May 2022 05:24:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=C8RbUJ5gLhVbKErQxEAQfZKDPJUIm32JjsdtPUcqYCY=; b=CzhkGMilMWj9/BZ9A5lh7kV2jJC2vzSJlbp9BLwK1mGuNk7Jgs9UUqz3RVdIjnxFZ5oH LTH+aedWsf6QmMMzVfNNxqDtnYwyrKmC/6Lt8cLvyLPuNmEb6f/LJAaTrMHKYc7on0/3 UO04W4VvCGjP9e/MbW2xiu5oBLUmiVCzk/vvp3geCbEFgdEdTxdk9kJUicRvPevj5UNZ NJBm9XUa3BNc/Uhk1NMOyk+53Cm2cWhMRSHZOxYRmOErPILWgqNmo8KECGrZlokW+gIf IXGMWvsFLgmkmbLVJ21MqWB7x+G4rBoRe5tWBaAKl6BIhVhYBDYvfk78g1gbOse888zC 7w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3gbk8n5c8g-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 05:24:04 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 30 May 2022 05:24:02 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 30 May 2022 05:24:02 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 1440D3F7081; Mon, 30 May 2022 05:23:59 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v8, 06/10] examples/fips_validation: add json to hmac Date: Mon, 30 May 2022 17:53:26 +0530 Message-ID: <498d847636038e5512a6b4632df4c8de22f1f9a1.1653913201.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: lXN6hmRd5Q_kj2hltyjjnIibpbHaJYic X-Proofpoint-GUID: lXN6hmRd5Q_kj2hltyjjnIibpbHaJYic X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-30_04,2022-05-30_01,2022-02-23_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Brandon Lo Adds JSON support for the HMAC algorithm. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.c | 2 + examples/fips_validation/fips_validation.h | 6 ++ .../fips_validation/fips_validation_hmac.c | 93 +++++++++++++++++++ examples/fips_validation/main.c | 3 + 4 files changed, 104 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 6594a15579..e8520f59cf 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -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; diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 8b9d528c53..3b3ffb7fa6 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -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 diff --git a/examples/fips_validation/fips_validation_hmac.c b/examples/fips_validation/fips_validation_hmac.c index 1285c9d283..4cd1b1ac07 100644 --- a/examples/fips_validation/fips_validation_hmac.c +++ b/examples/fips_validation/fips_validation_hmac.c @@ -19,6 +19,15 @@ #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 */ diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index e729b01529..2393559d0d 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -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; } -- 2.25.1