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 CA79CA0570; Tue, 28 Jun 2022 15:12:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B9C2140691; Tue, 28 Jun 2022 15:12:10 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id E7DCD400D7 for ; Tue, 28 Jun 2022 15:12:08 +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 25SAHhlo010836; Tue, 28 Jun 2022 06:12:08 -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=dQwrePWy0ZNhGbRrG8dWinGBkN3QIdIKHqGFxNh6RFs=; b=kyq9xUl3LcA74wBMvyIG+pSa5mHeleCYpsqB4rIxrsvH3Cj0jGoveUrWBqQ2n0imnU3j ga3pr8Vd4N+bHv7Q9jyNGdsoGJUoBEOZmE3A1nR8VKt/WsYDQ/W+NF2OpMFv+0PyM/hW OhAxzrRI3kCKEW4Ps5q7HhA6TS2F1N3PfxaOK0FafZ5EoY72ukZLrSgDnyc6wPBLKhDB 9v0I2AjNAXFLJVGSlwFUeBW/V/JKKJmWIuvxOzIMlfhC7BgEnHJxCQt9K6V1zv0lMuBG swCD/fl+NJ59AfgPyLkfoIk0WN77PW+HglR70yI68bbp3tanNBB2F0e7ydUWa8y2ofVr oQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3gx1vm3td4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 28 Jun 2022 06:12:08 -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; Tue, 28 Jun 2022 06:12:06 -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; Tue, 28 Jun 2022 06:12:06 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id E69EE3F7092; Tue, 28 Jun 2022 06:12:03 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , Anoob Joseph , "Archana Muniganti" , Jerin Jacob , Gowrishankar Muthukrishnan Subject: [PATCH v2] examples/fips_validation: add parsing for xts Date: Tue, 28 Jun 2022 18:42:01 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <41b2b4d16799a311ea63536b3009052c0cf99d75.1656402995.git.gmuthukrishn@marvell.com> References: <41b2b4d16799a311ea63536b3009052c0cf99d75.1656402995.git.gmuthukrishn@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: JjYclkcokQ3vlywKjdEWawoEuH0QCwB1 X-Proofpoint-GUID: JjYclkcokQ3vlywKjdEWawoEuH0QCwB1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-28_07,2022-06-28_01,2022-06-22_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 Added function to parse algorithm for AES XTS test. Signed-off-by: Gowrishankar Muthukrishnan --- v2: - build failure fixed if no jansson lib available. --- examples/fips_validation/fips_validation.c | 4 +- examples/fips_validation/fips_validation.h | 16 +- .../fips_validation/fips_validation_xts.c | 141 ++++++++++++++++++ examples/fips_validation/main.c | 5 + 4 files changed, 164 insertions(+), 2 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 324abccb14..f181363ef7 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -463,7 +463,9 @@ fips_test_parse_one_json_vector_set(void) else if (strstr(algo_str, "CMAC")) info.algo = FIPS_TEST_ALGO_AES_CMAC; else if (strstr(algo_str, "AES-CBC")) - info.algo = FIPS_TEST_ALGO_AES; + info.algo = FIPS_TEST_ALGO_AES_CBC; + else if (strstr(algo_str, "AES-XTS")) + info.algo = FIPS_TEST_ALGO_AES_XTS; else return -EINVAL; diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 69d738b718..d716b198c6 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -34,13 +34,14 @@ enum fips_test_algorithms { FIPS_TEST_ALGO_AES = 0, + FIPS_TEST_ALGO_AES_CBC, FIPS_TEST_ALGO_AES_GCM, FIPS_TEST_ALGO_AES_CMAC, FIPS_TEST_ALGO_AES_CCM, + FIPS_TEST_ALGO_AES_XTS, FIPS_TEST_ALGO_HMAC, FIPS_TEST_ALGO_TDES, FIPS_TEST_ALGO_SHA, - FIPS_TEST_ALGO_AES_XTS, FIPS_TEST_ALGO_MAX }; @@ -170,6 +171,15 @@ struct gcm_interim_data { uint8_t gen_iv; }; +enum xts_tweak_modes { + XTS_TWEAK_MODE_HEX = 0, + XTS_TWEAK_MODE_NUMBER +}; + +struct xts_interim_data { + enum xts_tweak_modes tweak_mode; +}; + #ifdef USE_JANSSON struct fips_test_json_info { /* Information used for reading from json */ @@ -207,6 +217,7 @@ struct fips_test_interim_info { struct ccm_interim_data ccm_data; struct sha_interim_data sha_data; struct gcm_interim_data gcm_data; + struct xts_interim_data xts_data; } interim_info; enum fips_test_op op; @@ -266,6 +277,9 @@ parse_test_cmac_json_init(void); int parse_test_aes_json_init(void); + +int +parse_test_xts_json_init(void); #endif /* USE_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_xts.c b/examples/fips_validation/fips_validation_xts.c index 5bb1966f6c..531e3c688e 100644 --- a/examples/fips_validation/fips_validation_xts.c +++ b/examples/fips_validation/fips_validation_xts.c @@ -24,6 +24,22 @@ #define OP_ENC_STR "ENCRYPT" #define OP_DEC_STR "DECRYPT" +#define ALGO_JSON_STR "algorithm" +#define TESTTYPE_JSON_STR "testType" +#define DIR_JSON_STR "direction" +#define KEYLEN_JSON_STR "keyLen" +#define TWEAKMODE_JSON_STR "tweakMode" + +#define KEY_JSON_STR "key" +#define DATAUNITLEN_JSON_STR "dataUnitLen" +#define PAYLOADLEN_JSON_STR "payloadLen" +#define TWEAKVALUE_JSON_STR "tweakValue" +#define PT_JSON_STR "pt" +#define CT_JSON_STR "ct" + +#define OP_ENC_JSON_STR "encrypt" +#define OP_DEC_JSON_STR "decrypt" + static int parse_interim_xts_enc_dec(const char *key, __rte_unused char *text, @@ -62,6 +78,131 @@ struct fips_test_callback xts_writeback_callbacks[] = { {NULL, NULL, NULL} /**< end pointer */ }; +#ifdef USE_JANSSON +static int +parser_xts_read_keylen(const char *key, char *src, struct fips_val *val) +{ + int ret; + + ret = parser_read_uint32_bit_val(key, src, val); + if (ret < 0) + return ret; + + val->len *= 2; + return 0; +} + +static int +parser_xts_read_tweakval(const char *key, char *src, struct fips_val *val) +{ + int ret; + + if (info.interim_info.xts_data.tweak_mode == XTS_TWEAK_MODE_HEX) + ret = parse_uint8_hex_str(key, src, val); + else if (info.interim_info.xts_data.tweak_mode == XTS_TWEAK_MODE_NUMBER) + ret = parser_read_uint32_bit_val(key, src, val); + else + ret = -1; + + return ret; +} + +struct fips_test_callback xts_dec_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key}, + {TWEAKVALUE_JSON_STR, parser_xts_read_tweakval, &vec.iv}, + {CT_JSON_STR, parse_uint8_hex_str, &vec.ct}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback xts_interim_json_vectors[] = { + {KEYLEN_JSON_STR, parser_xts_read_keylen, &vec.cipher_auth.key}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback xts_enc_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key}, + {TWEAKVALUE_JSON_STR, parser_xts_read_tweakval, &vec.iv}, + {PT_JSON_STR, parse_uint8_hex_str, &vec.pt}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +static int +parse_test_xts_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); + + 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); + json_object_set_new(json_info.json_write_case, PT_JSON_STR, + json_string(info.one_line_text)); + } else { + json_object_set_new(json_info.json_write_case, "testPassed", json_false()); + } + } + + return 0; +} + +int +parse_test_xts_json_init(void) +{ + if (json_info.json_test_group) { + json_t *direction_obj, *tweakmode_obj; + const char *direction_str, *tweakmode_str; + + direction_obj = json_object_get(json_info.json_test_group, DIR_JSON_STR); + 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 = xts_enc_json_vectors; + + } else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) { + info.op = FIPS_TEST_DEC_AUTH_VERIF; + info.callbacks = xts_dec_json_vectors; + } else { + return -EINVAL; + } + + tweakmode_obj = json_object_get(json_info.json_test_group, TWEAKMODE_JSON_STR); + tweakmode_str = json_string_value(tweakmode_obj); + if (strcmp(tweakmode_str, "hex") == 0) + info.interim_info.xts_data.tweak_mode = XTS_TWEAK_MODE_HEX; + else + info.interim_info.xts_data.tweak_mode = XTS_TWEAK_MODE_NUMBER; + + info.interim_callbacks = xts_interim_json_vectors; + } + + info.parse_writeback = parse_test_xts_json_writeback; + return 0; +} +#endif /* USE_JANSSON */ + static int parse_test_xts_writeback(struct fips_val *val) { diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index ceabea788e..7ccb5f52f4 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1781,6 +1781,7 @@ static int init_test_ops(void) { switch (info.algo) { + case FIPS_TEST_ALGO_AES_CBC: case FIPS_TEST_ALGO_AES: test_ops.prepare_op = prepare_cipher_op; test_ops.prepare_xform = prepare_aes_xform; @@ -1988,6 +1989,10 @@ fips_test_one_test_group(void) case FIPS_TEST_ALGO_AES_CMAC: ret = parse_test_cmac_json_init(); break; + case FIPS_TEST_ALGO_AES_XTS: + ret = parse_test_xts_json_init(); + break; + case FIPS_TEST_ALGO_AES_CBC: case FIPS_TEST_ALGO_AES: ret = parse_test_aes_json_init(); break; -- 2.25.1