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 0571DA0542; Mon, 30 May 2022 17:53:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F4224282A; Mon, 30 May 2022 17:53:15 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id AFF1642B8B for ; Mon, 30 May 2022 17:53:13 +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 24UC1RlO018928; Mon, 30 May 2022 08:53:13 -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=EU9r0jwuglVZnLGDP+lBKgSBYt5AuXcoemc4kCDSjJ8=; b=JWQ2w2sp2vH6COMPYMSn3+1OKV4xk736NG5MnNfwXtzfZMH8nYrk1O3ZMguyitNPnYaj cPewj/C+ewgNLKQkn34YsbPjNFcYW76RwUF5LuujwUnNQjA/s6xt+FJr5IH/S/NgiZhf yQXlRQoNKPekUaEQr710xuZGkIXGZwtG0zX41ifCZyXXazhtjwVMaOMjcsCPgyxlgm5H PeGWAxfs0iOqUlBhqk6fFZMYa0y7O5/cT4aHDG6YrnSs/Dd+y3JLa/rWx+BH4U+p8HUG Ka/abHRW8BkbBD39Vcp/BFyFhmDYP5F162mEn+btD5S7ZTgS60OiwDrwWSWAigPHm60R JA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3gbk8n61pu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 08:53:13 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 30 May 2022 08:53:11 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 30 May 2022 08:53:10 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 6E8053F7048; Mon, 30 May 2022 08:53:08 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v9, 07/10] examples/fips_validation: implement json cmac test Date: Mon, 30 May 2022 21:22:41 +0530 Message-ID: <15e03aa4e9742b7428199dca46a225034bfff392.1653925803.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: hX6QJn04RNGqzaVSGzT0uwam37swq63j X-Proofpoint-GUID: hX6QJn04RNGqzaVSGzT0uwam37swq63j 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_07,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 Implemented JSON support for the CMAC test. Signed-off-by: Brandon Lo Signed-off-by: Gowrishankar Muthukrishnan --- v5: * parser_read_cmac_direction_str is static. --- examples/fips_validation/fips_validation.h | 3 + .../fips_validation/fips_validation_cmac.c | 80 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 3b3ffb7fa6..88cbb0303e 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -259,6 +259,9 @@ parse_test_hmac_json_init(void); int parse_test_hmac_json_algorithm(void); + +int +parse_test_cmac_json_init(void); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_cmac.c b/examples/fips_validation/fips_validation_cmac.c index 54c951ef83..094e3922a4 100644 --- a/examples/fips_validation/fips_validation_cmac.c +++ b/examples/fips_validation/fips_validation_cmac.c @@ -32,6 +32,18 @@ #define PASS_STR "P" #define FAIL_STR "F" +#define KLEN_JSON_STR "keyLen" +#define PTLEN_JSON_STR "msgLen" +#define TAGLEN_JSON_STR "macLen" +#define KEY_JSON_STR "key" +#define PT_JSON_STR "message" +#define TAG_JSON_STR "mac" +#define DIRECTION_JSON_STR "direction" +#define POS_NEG_JSON_STR "testPassed" + +#define GEN_JSON_STR "gen" +#define VERIF_JSON_STR "ver" + struct hash_algo_conversion { const char *str; enum fips_test_algorithms algo; @@ -39,6 +51,74 @@ struct hash_algo_conversion { {"AES", FIPS_TEST_ALGO_AES_CMAC}, }; +#ifdef RTE_HAS_JANSSON +static int +parser_read_cmac_direction_str(__rte_unused const char *key, char *src, + __rte_unused struct fips_val *val) +{ + if (strcmp(src, "gen") == 0) + info.op = FIPS_TEST_ENC_AUTH_GEN; + else if (strcmp(src, "ver") == 0) + info.op = FIPS_TEST_DEC_AUTH_VERIF; + + return 0; +} + +struct fips_test_callback cmac_tests_interim_json_vectors[] = { + {KLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key}, + {PTLEN_JSON_STR, parser_read_uint32_bit_val, &vec.pt}, + {TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.digest}, + {DIRECTION_JSON_STR, parser_read_cmac_direction_str, NULL}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback cmac_tests_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.key}, + {PT_JSON_STR, parse_uint8_known_len_hex_str, &vec.pt}, + {TAG_JSON_STR, parse_uint8_known_len_hex_str, + &vec.cipher_auth.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +static int +parse_test_cmac_json_writeback(struct fips_val *val) +{ + json_info.json_write_case = json_object(); + json_object_set(json_info.json_write_case, "tcId", + json_object_get(json_info.json_test_case, "tcId")); + + if (info.op == FIPS_TEST_ENC_AUTH_GEN) { + struct fips_val tmp_val = {val->val + vec.pt.len, + vec.cipher_auth.digest.len}; + + writeback_hex_str("", info.one_line_text, &tmp_val); + json_object_set_new(json_info.json_write_case, TAG_JSON_STR, + json_string(info.one_line_text)); + } else { + if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) + json_object_set_new(json_info.json_write_case, POS_NEG_JSON_STR, + json_boolean(true)); + else if (vec.status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED) + json_object_set_new(json_info.json_write_case, POS_NEG_JSON_STR, + json_boolean(false)); + } + + return 0; +} + +int +parse_test_cmac_json_init(void) +{ + info.algo = FIPS_TEST_ALGO_AES_CMAC; + + info.parse_writeback = parse_test_cmac_json_writeback; + info.callbacks = cmac_tests_json_vectors; + info.interim_callbacks = cmac_tests_interim_json_vectors; + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parse_test_cmac_writeback(struct fips_val *val) { -- 2.25.1