From patchwork Wed May 25 17:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111845 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5A6E0A0555; Wed, 25 May 2022 19:14:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4ACF242685; Wed, 25 May 2022 19:14:22 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id E0B4540C35 for ; Wed, 25 May 2022 19:14:20 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24PA074r029110; Wed, 25 May 2022 10:14:19 -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=jrvYqpvchoeSKsfJP9N/4IS70SmdIH/RR3mOdONB0mQ=; b=g3QPbOU074HODJwcXsjoasv3CExoHttYKTyBWNzy56jW4KhVFoKx2DiJu+9MvD4KpawD N19iXJRZZnTDBfKFfA5GEAQkkHu9/ub1A0+AWhEqdFxie11B6pzz0ziVwvnXl7IEp9QN WaPM+EJ+3mCeOmp+9EfZbcXRicGUJtnTKTSX9yWsJAzpvlGPlpf/UkgZWrP/iah+5YSE T5oLc9pRc2jYBnBq82IMzNgrOmqyGEucHHFj5Inpc0jkA1w360JAaCgeQbvm+sR53kPu 2OfedOaprS1mYGGNR++ZVfRKlxPIdpsU5ghgAR321diQqBwOOl8Gyt2+K+2BAGngWezY Og== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:19 -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; Wed, 25 May 2022 10:14:18 -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; Wed, 25 May 2022 10:14:16 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 4BF6B3F7084; Wed, 25 May 2022 10:14:14 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 01/11] examples/fips_validation: add jansson dependency Date: Wed, 25 May 2022 22:43:37 +0530 Message-ID: <6ac0eb4315905ee4aeb3f01174f13ca793d86c08.1653498667.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: asD0FC0JJ2qKTU3i02WfWSz1q3g6Kn1J X-Proofpoint-ORIG-GUID: asD0FC0JJ2qKTU3i02WfWSz1q3g6Kn1J 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-25_04,2022-05-25_02,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 Added a check for RTE_HAS_JANSSON into the meson configuration file for JSON support. Signed-off-by: Brandon Lo --- examples/fips_validation/meson.build | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/fips_validation/meson.build b/examples/fips_validation/meson.build index 7eef456318..8cd63066b5 100644 --- a/examples/fips_validation/meson.build +++ b/examples/fips_validation/meson.build @@ -21,3 +21,7 @@ sources = files( 'fips_dev_self_test.c', 'main.c', ) + +if dpdk_conf.has('RTE_HAS_JANSSON') + ext_deps += jansson_dep +endif From patchwork Wed May 25 17:13:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111846 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95DB4A0555; Wed, 25 May 2022 19:14:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 385A4427FF; Wed, 25 May 2022 19:14:25 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id EA34C427F7 for ; Wed, 25 May 2022 19:14:22 +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 24PGoMs7020530; Wed, 25 May 2022 10:14:22 -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=vjGzwdbXk2tgEY/Emb2cmiyyRZ3h4eo0iyT4Wd3Vxas=; b=ihveS0aP+4o/9cJI7QeqVYzvkvCf0itT0w/yI6GQn+eSagx5R0TGda4ej4Hh3TOswugL eNe7toXTaTqSvHPHBgI1jUFRVY29Rkbux/wi4wRyRC1SbGg0g6ydIJOluOEke44HcNjt lVLQEOsfg0X7PYbJ59o5ZX9SKUfiS/xSgFUOI4562SgvYoy4xb2wkQV7qRVY6hmNtCDM L7rRQS3y5BCnhYttPC5TTmnOxxAP1aOjSmQyRITubiWRxqGUDoHCr8yAgLptho/Bh8dG Rs6dXACUkJKdYmUXrbRUfQm5hr3Uq6+f1vqWY+geJqi569VkyPP0o1nfnwmxPSNtUgdK aQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w4r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:22 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:18 -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; Wed, 25 May 2022 10:14:18 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 3E9583F7092; Wed, 25 May 2022 10:14:17 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v6, 02/11] examples/fips_validation: add json info to header Date: Wed, 25 May 2022 22:43:38 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: yeiu0oBDbC7DAY4tHyik3mcgBrGtlfkg X-Proofpoint-ORIG-GUID: yeiu0oBDbC7DAY4tHyik3mcgBrGtlfkg 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-25_04,2022-05-25_02,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 Added json-specific functions and other information needed to test the new FIPS test vectors. Signed-off-by: Brandon Lo Signed-off-by: Gowrishankar Muthukrishnan --- v5: * fix typo in macro name for prefixes. v2: * fix type of prefix to suffix --- examples/fips_validation/fips_validation.c | 6 +-- examples/fips_validation/fips_validation.h | 48 ++++++++++++++++++++-- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 94253eaee8..38c99b291c 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -270,11 +270,11 @@ parse_file_type(const char *path) { const char *tmp = path + strlen(path) - 3; - if (strstr(tmp, REQ_FILE_PERFIX)) + if (strstr(tmp, REQ_FILE_PREFIX)) info.file_type = FIPS_TYPE_REQ; - else if (strstr(tmp, RSP_FILE_PERFIX)) + else if (strstr(tmp, RSP_FILE_PREFIX)) info.file_type = FIPS_TYPE_RSP; - else if (strstr(path, FAX_FILE_PERFIX)) + else if (strstr(path, FAX_FILE_PREFIX)) info.file_type = FIPS_TYPE_FAX; else return -EINVAL; diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index aaadf01ba8..a1c83a9a6a 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -5,6 +5,10 @@ #ifndef _FIPS_VALIDATION_H_ #define _FIPS_VALIDATION_H_ +#ifdef RTE_HAS_JANSSON +#include +#endif /* RTE_HAS_JANSSON */ + #define FIPS_PARSE_ERR(fmt, args) \ RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args) @@ -21,9 +25,12 @@ #define POSITIVE_TEST 0 #define NEGATIVE_TEST -1 -#define REQ_FILE_PERFIX "req" -#define RSP_FILE_PERFIX "rsp" -#define FAX_FILE_PERFIX "fax" +#define REQ_FILE_PREFIX "req" +#define RSP_FILE_PREFIX "rsp" +#define FAX_FILE_PREFIX "fax" +#define JSON_FILE_PREFIX "json" + +#define ACVVERSION "1.0" enum fips_test_algorithms { FIPS_TEST_ALGO_AES = 0, @@ -40,7 +47,8 @@ enum fips_test_algorithms { enum file_types { FIPS_TYPE_REQ = 1, FIPS_TYPE_FAX, - FIPS_TYPE_RSP + FIPS_TYPE_RSP, + FIPS_TYPE_JSON, }; enum fips_test_op { @@ -161,6 +169,23 @@ struct gcm_interim_data { uint8_t gen_iv; }; +#ifdef RTE_HAS_JANSSON +struct fips_test_json_info { + /* Information used for reading from json */ + json_t *json_root; + json_t *json_vector_set; + json_t *json_test_group; + json_t *json_test_case; + /* Location of json write output */ + json_t *json_write_root; + json_t *json_write_group; + json_t *json_write_set; + json_t *json_write_case; + /* Other info */ + uint8_t is_sample; +}; +#endif /* RTE_HAS_JANSSON */ + struct fips_test_interim_info { FILE *fp_rd; FILE *fp_wr; @@ -196,6 +221,10 @@ struct fips_test_interim_info { extern struct fips_test_vector vec; extern struct fips_test_interim_info info; +#ifdef RTE_HAS_JANSSON +extern struct fips_test_json_info json_info; +#endif /* RTE_HAS_JANSSON */ + int fips_test_init(const char *req_file_path, const char *rsp_file_path, const char *device_name); @@ -212,6 +241,17 @@ fips_test_parse_one_case(void); void fips_test_write_one_case(void); +#ifdef RTE_HAS_JANSSON +int +fips_test_parse_one_json_vector_set(void); + +int +fips_test_parse_one_json_group(void); + +int +fips_test_parse_one_json_case(void); +#endif /* RTE_HAS_JANSSON */ + int parse_test_aes_init(void); From patchwork Wed May 25 17:13:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111847 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6EBE2A0555; Wed, 25 May 2022 19:14:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F8E1427F7; Wed, 25 May 2022 19:14:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 945734280C for ; Wed, 25 May 2022 19:14:25 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24P9xtN7028700; Wed, 25 May 2022 10:14:24 -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=YYeNz8+kV7SrMWkKrNoxAo9NisC1xmktOF1BbrHEOng=; b=Wm/U/cWeRvX9HaSzTM8jMA9Xhz5vTrYEKsEah2MaclJHE29iRGANW95s6tTGAYB0nh9z 5ZKgk9q+UvF0hBZptlWEVSmqgdjgCp3AXoecCV2qDjuicM0/lWKg9yLAueNFakNm76NK fT6ehx0QMkeiT1+47SC4RvPky1Zq92bYFhLIkDEJn+llMM3EmGcIKi9g4BsR+ufeJVlG FCmTNkvGqwVLd5bkSQAPoZMKB2Ofck0GUwlmPBfeNlbhJhjBKTEy66rZfLFx3tkeXuHg G/fh6N6pjE4ojwtxGc+OGDtQh/VM91IYqV7w45pg4dq7x0tXSD1fKohD6dDyl9HAtWe7 8w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:21 -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; Wed, 25 May 2022 10:14:21 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 607353F7075; Wed, 25 May 2022 10:14:20 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 03/11] examples/fips_validation: add json parsing Date: Wed, 25 May 2022 22:43:39 +0530 Message-ID: <122eb87a0034dea2875d8d752812d76a89e6fcd5.1653498667.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: OExWHnx_m-jul8HF6w7Nc6bl3d9Wwv1o X-Proofpoint-ORIG-GUID: OExWHnx_m-jul8HF6w7Nc6bl3d9Wwv1o 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-25_04,2022-05-25_02,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 Added functions to parse the required information from a vector set given in the new json format. Signed-off-by: Brandon Lo --- v3: * fix checkpatch warnings v2: * fix for loop initialization --- examples/fips_validation/fips_validation.c | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 38c99b291c..6594a15579 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -276,6 +276,8 @@ parse_file_type(const char *path) info.file_type = FIPS_TYPE_RSP; else if (strstr(path, FAX_FILE_PREFIX)) info.file_type = FIPS_TYPE_FAX; + else if (strstr(path, JSON_FILE_PREFIX)) + info.file_type = FIPS_TYPE_JSON; else return -EINVAL; @@ -311,6 +313,21 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) { +#ifdef RTE_HAS_JANSSON + json_error_t error; + json_info.json_root = json_loadf(info.fp_rd, 0, &error); + if (!json_info.json_root) { + RTE_LOG(ERR, USER1, "Cannot parse json file %s (line %d, column %d)\n", + req_file_path, error.line, error.column); + return -EINVAL; + } +#else /* RTE_HAS_JANSSON */ + RTE_LOG(ERR, USER1, "No json library configured.\n"); + return -EINVAL; +#endif /* RTE_HAS_JANSSON */ + } + info.fp_wr = fopen(rsp_file_path, "w"); if (!info.fp_wr) { RTE_LOG(ERR, USER1, "Cannot open file %s\n", rsp_file_path); @@ -329,6 +346,9 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) + return 0; + if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); return -1; @@ -428,6 +448,78 @@ fips_test_write_one_case(void) fprintf(info.fp_wr, "%s\n", info.vec[i]); } +#ifdef RTE_HAS_JANSSON +int +fips_test_parse_one_json_vector_set(void) +{ + json_t *algo_obj = json_object_get(json_info.json_vector_set, "algorithm"); + const char *algo_str = json_string_value(algo_obj); + + /* Vector sets contain the algorithm type, and nothing else we need. */ + if (strstr(algo_str, "AES-GCM")) + info.algo = FIPS_TEST_ALGO_AES_GCM; + else + return -EINVAL; + + return 0; +} + +int +fips_test_parse_one_json_group(void) +{ + int ret, i; + json_int_t val; + json_t *param; + + if (info.interim_callbacks) { + char json_value[256]; + for (i = 0; info.interim_callbacks[i].key != NULL; i++) { + param = json_object_get(json_info.json_test_group, + info.interim_callbacks[i].key); + val = json_integer_value(param); + snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT, val); + /* 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].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} + +int +fips_test_parse_one_json_case(void) +{ + uint32_t i; + int ret = 0; + json_t *param; + + for (i = 0; info.callbacks[i].key != NULL; i++) { + 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].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parser_read_uint64_hex(uint64_t *value, const char *p) { From patchwork Wed May 25 17:13:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111848 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ED8D8A0555; Wed, 25 May 2022 19:14:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0E1604280C; Wed, 25 May 2022 19:14:30 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id BD60E42B70 for ; Wed, 25 May 2022 19:14:28 +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 24PH1H42020591; Wed, 25 May 2022 10:14:28 -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=u0BAwXyDFshOid5b0tiuSyBswhiZIZMU9LkdIa11aQA=; b=aqRmlIevgmEdg7PI9k/KxXyWod1eQTfZPN31Kp6Taa7kmHlTMfrqC+EGJKjmTDgzRYbh VtN4muxTpMl+jOEwphSc7UkgmNzlyAftXWMm9ckIWvrjpkRSKMwqk9PTDd05GL9DKZbK ovzCe4USNH4qrDmGT59SrVH9Ha7FwtM52xytLv8qZ/gXXzhVc3G6fChv7hkwZ5t6qjnL mnPC5d7BoQzdFmMBLpMsLdNC/xX1scmq2rjD882U91JWOspnRJsXuIUVEsY2vxWo3sx6 ntpfxJlIGCtbEW8lBowB0g9V5hJpK1VpHK2JNALXi13fFd0bdQvwdtIp6mACpMblfdpj zg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w5k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:28 -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; Wed, 25 May 2022 10:14:26 -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; Wed, 25 May 2022 10:14:24 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 485EB3F7078; Wed, 25 May 2022 10:14:23 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v6, 04/11] examples/fips_validation: allow json file as input Date: Wed, 25 May 2022 22:43:40 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: MyvAUQhVsOmA5ub3McQ2HwzzeHybhF7q X-Proofpoint-ORIG-GUID: MyvAUQhVsOmA5ub3McQ2HwzzeHybhF7q 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-25_04,2022-05-25_02,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 Added the ability to use the json format as the input and output of the example application. Signed-off-by: Brandon Lo Signed-off-by: Gowrishankar Muthukrishnan --- v5: * fix to check info.file_type in json file type as well. v3: * fix checkpatch warnings v2: * remove use_json variable --- examples/fips_validation/main.c | 197 +++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index e06ae37567..3d841e5bfd 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -34,11 +34,17 @@ enum { OPT_CRYPTODEV_BK_ID_NUM, #define OPT_CRYPTODEV_BK_DIR_KEY "broken-test-dir" OPT_CRYPTODEV_BK_DIR_KEY_NUM, +#define OPT_USE_JSON "use-json" + OPT_USE_JSON_NUM, }; struct fips_test_vector vec; struct fips_test_interim_info info; +#ifdef RTE_HAS_JANSSON +struct fips_test_json_info json_info; +#endif /* RTE_HAS_JANSSON */ + struct cryptodev_fips_validate_env { const char *req_path; const char *rsp_path; @@ -166,6 +172,11 @@ cryptodev_fips_validate_app_uninit(void) static int fips_test_one_file(void); +#ifdef RTE_HAS_JANSSON +static int +fips_test_one_json_file(void); +#endif /* RTE_HAS_JANSSON */ + static int parse_cryptodev_arg(char *arg) { @@ -425,8 +436,17 @@ main(int argc, char *argv[]) goto exit; } - +#ifdef RTE_HAS_JANSSON + if (info.file_type == FIPS_TYPE_JSON) { + ret = fips_test_one_json_file(); + json_decref(json_info.json_root); + } else { + ret = fips_test_one_file(); + } +#else /* RTE_HAS_JANSSON */ ret = fips_test_one_file(); +#endif /* RTE_HAS_JANSSON */ + if (ret < 0) { RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n", ret, env.req_path); @@ -481,7 +501,17 @@ main(int argc, char *argv[]) break; } +#ifdef RTE_HAS_JANSSON + if (info.file_type == FIPS_TYPE_JSON) { + ret = fips_test_one_json_file(); + json_decref(json_info.json_root); + } else { + ret = fips_test_one_file(); + } +#else /* RTE_HAS_JANSSON */ ret = fips_test_one_file(); +#endif /* RTE_HAS_JANSSON */ + if (ret < 0) { RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n", ret, req_path); @@ -1219,7 +1249,8 @@ fips_generic_test(void) struct fips_val val = {NULL, 0}; int ret; - fips_test_write_one_case(); + if (info.file_type != FIPS_TYPE_JSON) + fips_test_write_one_case(); ret = fips_run_test(); if (ret < 0) { @@ -1238,6 +1269,7 @@ fips_generic_test(void) switch (info.file_type) { case FIPS_TYPE_REQ: case FIPS_TYPE_RSP: + case FIPS_TYPE_JSON: if (info.parse_writeback == NULL) return -EPERM; ret = info.parse_writeback(&val); @@ -1253,7 +1285,8 @@ fips_generic_test(void) break; } - fprintf(info.fp_wr, "\n"); + if (info.file_type != FIPS_TYPE_JSON) + fprintf(info.fp_wr, "\n"); free(val.val); return 0; @@ -1844,3 +1877,161 @@ fips_test_one_file(void) return ret; } + +#ifdef RTE_HAS_JANSSON +static int +fips_test_json_init_writeback(void) +{ + json_t *session_info, *session_write; + session_info = json_array_get(json_info.json_root, 0); + session_write = json_object(); + json_info.json_write_root = json_array(); + + json_object_set(session_write, "jwt", + json_object_get(session_info, "jwt")); + json_object_set(session_write, "url", + json_object_get(session_info, "url")); + json_object_set(session_write, "isSample", + json_object_get(session_info, "isSample")); + + json_info.is_sample = json_boolean_value( + json_object_get(session_info, "isSample")); + + json_array_append_new(json_info.json_write_root, session_write); + return 0; +} + +static int +fips_test_one_test_case(void) +{ + int ret; + + ret = fips_test_parse_one_json_case(); + + switch (ret) { + case 0: + ret = test_ops.test(); + if (ret == 0) + break; + RTE_LOG(ERR, USER1, "Error %i: test block\n", + ret); + break; + case 1: + break; + default: + RTE_LOG(ERR, USER1, "Error %i: Parse block\n", + ret); + } + return 0; +} + +static int +fips_test_one_test_group(void) +{ + int ret; + json_t *tests, *write_tests; + size_t test_idx, tests_size; + + write_tests = json_array(); + json_info.json_write_group = json_object(); + json_object_set(json_info.json_write_group, "tgId", + json_object_get(json_info.json_test_group, "tgId")); + json_object_set_new(json_info.json_write_group, "tests", write_tests); + + switch (info.algo) { + case FIPS_TEST_ALGO_AES_GCM: + ret = parse_test_gcm_init(); + break; + default: + return -EINVAL; + } + if (ret < 0) + return ret; + + ret = fips_test_parse_one_json_group(); + if (ret < 0) + return ret; + + ret = init_test_ops(); + if (ret < 0) + return ret; + + tests = json_object_get(json_info.json_test_group, "tests"); + tests_size = json_array_size(tests); + for (test_idx = 0; test_idx < tests_size; test_idx++) { + json_info.json_test_case = json_array_get(tests, test_idx); + fips_test_one_test_case(); + json_array_append_new(write_tests, json_info.json_write_case); + } + + return 0; +} + +static int +fips_test_one_vector_set(void) +{ + int ret; + json_t *test_groups, *write_groups, *write_version, *write_set; + size_t group_idx, num_groups; + + test_groups = json_object_get(json_info.json_vector_set, "testGroups"); + num_groups = json_array_size(test_groups); + + json_info.json_write_set = json_array(); + write_version = json_object(); + json_object_set_new(write_version, "acvVersion", json_string(ACVVERSION)); + json_array_append_new(json_info.json_write_set, write_version); + + write_set = json_object(); + json_array_append_new(json_info.json_write_set, write_set); + write_groups = json_array(); + + json_object_set(write_set, "vsId", + json_object_get(json_info.json_vector_set, "vsId")); + json_object_set(write_set, "algorithm", + json_object_get(json_info.json_vector_set, "algorithm")); + json_object_set(write_set, "revision", + json_object_get(json_info.json_vector_set, "revision")); + json_object_set_new(write_set, "isSample", + json_boolean(json_info.is_sample)); + json_object_set_new(write_set, "testGroups", write_groups); + + ret = fips_test_parse_one_json_vector_set(); + if (ret < 0) { + RTE_LOG(ERR, USER1, "Error: Unsupported or invalid vector set algorithm: %s\n", + json_string_value(json_object_get(json_info.json_vector_set, "algorithm"))); + return ret; + } + + for (group_idx = 0; group_idx < num_groups; group_idx++) { + json_info.json_test_group = json_array_get(test_groups, group_idx); + ret = fips_test_one_test_group(); + json_array_append_new(write_groups, json_info.json_write_group); + } + + return 0; +} + +static int +fips_test_one_json_file(void) +{ + size_t vector_set_idx, root_size; + + root_size = json_array_size(json_info.json_root); + fips_test_json_init_writeback(); + + for (vector_set_idx = 1; vector_set_idx < root_size; vector_set_idx++) { + /* Vector set index starts at 1, the 0th index contains test session + * information. + */ + json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx); + fips_test_one_vector_set(); + json_array_append_new(json_info.json_write_root, json_info.json_write_set); + } + + json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4)); + json_decref(json_info.json_write_root); + + return 0; +} +#endif /* RTE_HAS_JANSSON */ From patchwork Wed May 25 17:13:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111849 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C4BDAA0555; Wed, 25 May 2022 19:14:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 47CE242B75; Wed, 25 May 2022 19:14:33 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id ADC5D427F9 for ; Wed, 25 May 2022 19:14:31 +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 24PGWs5G020584; Wed, 25 May 2022 10:14:31 -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=t2ixndRrjF7Mm6Eh5Mjqth5pMWaI6oU+XKHSoAwK3QQ=; b=dWrUhmXOWQ9DUIMwgka4sQSfkK6ieATBJtVE9b4WonoDqtXBoYEgmUpzedddpoY3NRSl igCYa+SFNCEg4Fx1Jb5gIGKrqOI/EVgI153u+WKb8LaPwbuo/GMAnSgg9WvCSor9dZ62 vbuvcZMHxUTG9Aze9a3moA+zvDIeqItfYFB9sXrWD+gZiI9aEwilvO4l0n82+5k+Hpuv jddsX/yQuG838wlUoz4cjlkbA6ueovy1jtAe2uH78RQJBea2kPXJOQMfnDiJw6QsOpex LfG831Ypkye+6Z4GZO9XpNwSCRTnStwe1tEJwH49BlS8XnlbuDffWrHrHPuWUeaW+rFK +Q== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:31 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:27 -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; Wed, 25 May 2022 10:14:29 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 6AB7B3F7075; Wed, 25 May 2022 10:14:26 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 05/11] examples/fips_validation: add json to gcm test Date: Wed, 25 May 2022 22:43:41 +0530 Message-ID: <6a471106e238da3dee5565dc85361ffa60917eac.1653498667.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: 95ZkSRCikrCaHLg7T3uZKKWeLkY8E9m8 X-Proofpoint-ORIG-GUID: 95ZkSRCikrCaHLg7T3uZKKWeLkY8E9m8 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-25_04,2022-05-25_02,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-specific testing and writeback function. Allows the user to test AES-GCM vector sets. Signed-off-by: Brandon Lo --- v3: * fix checkpatch warnings --- examples/fips_validation/fips_validation.h | 3 + .../fips_validation/fips_validation_gcm.c | 151 +++++++++++++++++- examples/fips_validation/main.c | 3 +- 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index a1c83a9a6a..8b9d528c53 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -250,6 +250,9 @@ fips_test_parse_one_json_group(void); int fips_test_parse_one_json_case(void); + +int +parse_test_gcm_json_init(void); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c index 250d09bf90..3604b21f13 100644 --- a/examples/fips_validation/fips_validation_gcm.c +++ b/examples/fips_validation/fips_validation_gcm.c @@ -6,6 +6,10 @@ #include #include +#ifdef RTE_HAS_JANSSON +#include +#endif /* RTE_HAS_JANSSON */ + #include #include @@ -37,6 +41,27 @@ #define OP_ENC_EXT_STR "ExtIV" #define OP_ENC_INT_STR "IntIV" +#define KEYLEN_JSON_STR "keyLen" +#define IVLEN_JSON_STR "ivLen" +#define PAYLOADLEN_JSON_STR "payloadLen" +#define AADLEN_JSON_STR "aadLen" +#define TAGLEN_JSON_STR "tagLen" + +#define KEY_JSON_STR "key" +#define IV_JSON_STR "iv" +#define PT_JSON_STR "pt" +#define CT_JSON_STR "ct" +#define AAD_JSON_STR "aad" +#define TAG_JSON_STR "tag" +#define DIR_JSON_STR "direction" + +#define OP_ENC_JSON_STR "encrypt" +#define OP_DEC_JSON_STR "decrypt" + +#define IVGEN_JSON_STR "ivGen" +#define OP_ENC_EXT_JSON_STR "external" +#define OP_ENC_INT_JSON_STR "internal" + #define NEG_TEST_STR "FAIL" /** @@ -136,6 +161,40 @@ struct fips_test_callback gcm_enc_vectors[] = { {NULL, NULL, NULL} /**< end pointer */ }; +#ifdef RTE_HAS_JANSSON +struct fips_test_callback gcm_dec_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.aead.key}, + {IV_JSON_STR, parse_uint8_known_len_hex_str, &vec.iv}, + {CT_JSON_STR, parse_gcm_pt_ct_str, &vec.ct}, + {AAD_JSON_STR, parse_gcm_aad_str, &vec.aead.aad}, + {TAG_JSON_STR, parse_uint8_known_len_hex_str, + &vec.aead.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback gcm_interim_json_vectors[] = { + {KEYLEN_JSON_STR, parser_read_uint32_bit_val, &vec.aead.key}, + {IVLEN_JSON_STR, parser_read_uint32_bit_val, &vec.iv}, + {PAYLOADLEN_JSON_STR, parser_read_gcm_pt_len, &vec.pt}, + {PAYLOADLEN_JSON_STR, parser_read_uint32_bit_val, &vec.ct}, + /**< The NIST json test vectors use 'payloadLen' to denote input text + * length in case of decrypt & encrypt operations. + */ + {AADLEN_JSON_STR, parser_read_uint32_bit_val, &vec.aead.aad}, + {TAGLEN_JSON_STR, parser_read_uint32_bit_val, + &vec.aead.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback gcm_enc_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.aead.key}, + {IV_JSON_STR, parse_uint8_known_len_hex_str, &vec.iv}, + {PT_JSON_STR, parse_gcm_pt_ct_str, &vec.pt}, + {AAD_JSON_STR, parse_gcm_aad_str, &vec.aead.aad}, + {NULL, NULL, NULL} /**< end pointer */ +}; +#endif /* RTE_HAS_JANSSON */ + static int parse_test_gcm_writeback(struct fips_val *val) { @@ -194,7 +253,6 @@ parse_test_gcm_init(void) char *tmp; uint32_t i; - for (i = 0; i < info.nb_vec_lines; i++) { char *line = info.vec[i]; @@ -218,3 +276,94 @@ parse_test_gcm_init(void) return 0; } + +#ifdef RTE_HAS_JANSSON +static int +parse_test_gcm_json_writeback(struct fips_val *val) +{ + struct fips_val tmp_val; + json_t *tcId, *tag; + + 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); + + if (info.interim_info.gcm_data.gen_iv) { + json_t *iv; + tmp_val.val = vec.iv.val; + tmp_val.len = vec.iv.len; + + writeback_hex_str("", info.one_line_text, &tmp_val); + iv = json_string(info.one_line_text); + json_object_set_new(json_info.json_write_case, IV_JSON_STR, iv); + + rte_free(vec.iv.val); + vec.iv.val = NULL; + } + + 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); + tag = json_string(info.one_line_text); + json_object_set_new(json_info.json_write_case, TAG_JSON_STR, tag); + } else { + if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) { + if (!info.interim_info.gcm_data.is_gmac) { + tmp_val.val = val->val; + tmp_val.len = vec.pt.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_gcm_json_init(void) +{ + json_t *direction_obj; + const char *direction_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) { + json_t *ivGen_obj = json_object_get(json_info.json_test_group, IVGEN_JSON_STR); + const char *ivGen_str = json_string_value(ivGen_obj); + + info.op = FIPS_TEST_ENC_AUTH_GEN; + info.callbacks = gcm_enc_json_vectors; + + if (strcmp(ivGen_str, OP_ENC_INT_JSON_STR) == 0) + info.interim_info.gcm_data.gen_iv = 1; + } else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) { + info.op = FIPS_TEST_DEC_AUTH_VERIF; + info.callbacks = gcm_dec_json_vectors; + } else { + return -EINVAL; + } + info.interim_callbacks = gcm_interim_json_vectors; + info.parse_writeback = parse_test_gcm_json_writeback; + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 3d841e5bfd..6a1b323cc8 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1940,11 +1940,12 @@ fips_test_one_test_group(void) switch (info.algo) { case FIPS_TEST_ALGO_AES_GCM: - ret = parse_test_gcm_init(); + ret = parse_test_gcm_json_init(); break; default: return -EINVAL; } + if (ret < 0) return ret; From patchwork Wed May 25 17:13:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111850 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6AF1BA0555; Wed, 25 May 2022 19:14:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 26C7E42B81; Wed, 25 May 2022 19:14:36 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8586E42B82 for ; Wed, 25 May 2022 19:14:34 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24PA074u029110; Wed, 25 May 2022 10:14:33 -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=6s5UNImbKvfGqPsg08QaTMe24LjGzVldu8OhJYCJf8w=; b=MUs6VOO3dkzZKQWorZFQzKGgBeekxZj9CdlKInIfSnuf3AUD79EhD01V0IZS0tVY7aXI zXmBHqktDEu/65JXgB6OyV79PtLqRpDOAz9LQPVEn+aASSfXfocy8MpFOQR6U0wgh8SO 50pXFMVbMMtvg5QZqbFi7NIwNTsmGmA7G0yYLOJmA08WWm/O6namdK6wgLdegc2uXs9l AcqnLQbr8rBJ6Uwd+awGz5DqlKu7qgQRo8BIwnb/QlFNq3j0alXHnQ/9b6Oc72jEr550 adHzhLBJUu5oVt1aNjLMrfnWjfXlVFnpANUgNnDH1sleN8VBHSq0NVfueqLXpHx0SUCu OQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:33 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:30 -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; Wed, 25 May 2022 10:14:31 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 559163F707D; Wed, 25 May 2022 10:14:29 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 06/11] examples/fips_validation: add json to hmac Date: Wed, 25 May 2022 22:43:42 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: v72wyhgln9hwkvbjK7IUbXyn-o1py1-k X-Proofpoint-ORIG-GUID: v72wyhgln9hwkvbjK7IUbXyn-o1py1-k 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-25_04,2022-05-25_02,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 --- 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 6a1b323cc8..261e2c4c99 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1942,6 +1942,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; } From patchwork Wed May 25 17:13:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111851 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BB937A0555; Wed, 25 May 2022 19:15:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F95C42B85; Wed, 25 May 2022 19:14:39 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 2DB7B42B85 for ; Wed, 25 May 2022 19:14:37 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24P9xwXf028734; Wed, 25 May 2022 10:14:36 -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=OzHb4WrN9JCxJLoz+oE3sMvoWMR94ODWhhXPA0rEJQQ=; b=DQOSp+vvnrtcqxq1vBV5YqXX4fyum5OVUQcNyVX42HyHqX449oCR+qhZEm+0YX3voVn3 Re5qoYQFDshZs+AqhMeO9qGJnEUWCMyjlvMuC4RmPzRGH809zAh/43JSoIVi82yXU2+p 1cume+dm2EizpGr6V+vst5M1CZTzoknq9D8SYvT2hY4mPsCriAhVLYXFYtrdcC8bCQvp HpHO1wZapWGzFdKy7L7SXO0ysO3ZXamtrTC24KyTXRURVH6oz7pZ2YQtrp6ojyBczXp3 ea/6KB9kBRtJhIv7c+i4+L8TgldkWGqVZjZYUmpIua2qp/7SjbE6QTKxqY/tltBPWkuG tA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qxn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:36 -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; Wed, 25 May 2022 10:14:34 -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; Wed, 25 May 2022 10:14:33 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 411123F7075; Wed, 25 May 2022 10:14:32 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo Subject: [v6, 07/11] examples/fips_validation: implement json cmac test Date: Wed, 25 May 2022 22:43:43 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: tdfuDZKn7AsktGu4zoHf8FBZJX-h4tK6 X-Proofpoint-ORIG-GUID: tdfuDZKn7AsktGu4zoHf8FBZJX-h4tK6 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-25_04,2022-05-25_02,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 --- 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) { From patchwork Wed May 25 17:13:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111852 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 04F20A0555; Wed, 25 May 2022 19:15:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EA8C341133; Wed, 25 May 2022 19:14:41 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 7A1E442B89 for ; Wed, 25 May 2022 19:14:40 +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 24PH1H44020591; Wed, 25 May 2022 10:14:39 -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=Z8lFW2AmXT9r692GD1EPxFHFISgdv7NIHXvwHAdhmOY=; b=Y/pFaUz3D3UADgsVpGYWhDkdBdWEn6qqXE+BimPflso2ta8WNJSncV0SbMw1Go97LwpA Vz1HRf69Bt/5MI2+/P71B8iZaJ+x8JIxuuSsjMo24Yuqi6TJLw54ZLA+b3sXCdrArb54 HGOIbgig9sCeKfe/2z92hpTifA8MVW6yeoZE6TtX0zA+6OnRUfdX3qm/+dgNDlrRAY0A mZZmpPEabWB2RlWu7ijB5P56DnR0qUHNLziSTJLXaNGDhcaVaXDBDbTjXQDYRnqrk1CP V3S6R2KckibEyvNGNswig3GQZoUw/4xKtGwoHXRIONc13Uorxr2KIWSTvp5U7tBYrgge tg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w67-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:39 -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; Wed, 25 May 2022 10:14:37 -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; Wed, 25 May 2022 10:14:37 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 279B13F7078; Wed, 25 May 2022 10:14:34 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v6, 08/11] examples/fips_validation: add parsing for cmac Date: Wed, 25 May 2022 22:43:44 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: zDqSuJedfIgFXtVFtN_MiMwYJGPreFIj X-Proofpoint-ORIG-GUID: zDqSuJedfIgFXtVFtN_MiMwYJGPreFIj 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-25_04,2022-05-25_02,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 Added function to parse algorithm for CMAC test. Signed-off-by: Brandon Lo Signed-off-by: Gowrishankar Muthukrishnan --- v5: * parser_read_cmac_direction_str implementation moved to static. --- examples/fips_validation/fips_validation.c | 19 ++++++++++++++++--- examples/fips_validation/main.c | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index e8520f59cf..ab4c0d0eca 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -460,6 +460,8 @@ fips_test_parse_one_json_vector_set(void) info.algo = FIPS_TEST_ALGO_AES_GCM; if (strstr(algo_str, "HMAC")) info.algo = FIPS_TEST_ALGO_HMAC; + if (strstr(algo_str, "CMAC")) + info.algo = FIPS_TEST_ALGO_AES_CMAC; else return -EINVAL; @@ -470,7 +472,6 @@ int fips_test_parse_one_json_group(void) { int ret, i; - json_int_t val; json_t *param; if (info.interim_callbacks) { @@ -478,8 +479,20 @@ fips_test_parse_one_json_group(void) for (i = 0; info.interim_callbacks[i].key != NULL; i++) { param = json_object_get(json_info.json_test_group, info.interim_callbacks[i].key); - val = json_integer_value(param); - snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT, val); + switch (json_typeof(param)) { + case JSON_STRING: + snprintf(json_value, 256, "%s", json_string_value(param)); + break; + + case JSON_INTEGER: + snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT, + json_integer_value(param)); + break; + + default: + return -EINVAL; + } + /* First argument is blank because the key * is not included in the string being parsed. */ diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 261e2c4c99..9df6abf47f 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1945,6 +1945,9 @@ fips_test_one_test_group(void) case FIPS_TEST_ALGO_HMAC: ret = parse_test_hmac_json_init(); break; + case FIPS_TEST_ALGO_AES_CMAC: + ret = parse_test_cmac_json_init(); + break; default: return -EINVAL; } From patchwork Wed May 25 17:13:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111853 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C5ECFA0555; Wed, 25 May 2022 19:15:16 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 23C8842B8B; Wed, 25 May 2022 19:14:45 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id A631242B91 for ; Wed, 25 May 2022 19:14:43 +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 24PGd40P020546; Wed, 25 May 2022 10:14:43 -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=e1lIhUEqfilItYjZU0Q6jcsVeV31lXBFnnZR1L+75l8=; b=HvPZnErVPVk8dCLxpBkoxixkvAWtfLo8CFdnuche2sMg09djQEZcT8uen13PRhTIMVR7 n82LsK3In2R4ttFiNe7EHZRKuLEKaCCcKY+hRXm8rpGebRjvCy+SEyqFRDaonvoUyyTV 1K4UOiDi9vp3p2zq/lvLOMIewRyDbj4KlFtKOy0mtdaBP2rOOEFPath1HT2lB2gKhWYZ InrMlOuWenYs7CDAOp/2xLFzK5at44LGyV+MK2fmtUEcPDPewvU24TClL2/K8BIqQCbC JmGyzIpSp9uiv/lKOLA9RRr5x3PIpWXplwwNjzi/92FRYMPxC+NLNWRjaO3vcJNUXTm/ ZQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w6e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:42 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 25 May 2022 10:14:39 -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; Wed, 25 May 2022 10:14:39 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 48DA73F7075; Wed, 25 May 2022 10:14:38 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Gowrishankar Muthukrishnan Subject: [v6, 09/11] examples/fips_validation: cleanup bypass tests in response file Date: Wed, 25 May 2022 22:43:45 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: B343Kr7msuw3tUQkxLvQVIEHiw7AHmPF X-Proofpoint-ORIG-GUID: B343Kr7msuw3tUQkxLvQVIEHiw7AHmPF 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-25_04,2022-05-25_02,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 Remove garbage entries for bypassed tests in response file. Signed-off-by: Gowrishankar Muthukrishnan --- examples/fips_validation/main.c | 74 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 9df6abf47f..e703a111da 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -804,7 +804,7 @@ prepare_aes_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n", info.device_name, cipher_xform->key.length, cipher_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -852,7 +852,7 @@ prepare_tdes_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n", info.device_name, cipher_xform->key.length, cipher_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -889,7 +889,7 @@ prepare_hmac_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n", info.device_name, auth_xform->key.length, auth_xform->digest_length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -935,7 +935,7 @@ prepare_gcm_xform(struct rte_crypto_sym_xform *xform) aead_xform->digest_length, aead_xform->aad_length, aead_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -980,7 +980,7 @@ prepare_gmac_xform(struct rte_crypto_sym_xform *xform) info.device_name, auth_xform->key.length, auth_xform->digest_length, auth_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -1018,7 +1018,7 @@ prepare_cmac_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n", info.device_name, auth_xform->key.length, auth_xform->digest_length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -1064,7 +1064,7 @@ prepare_ccm_xform(struct rte_crypto_sym_xform *xform) aead_xform->digest_length, aead_xform->aad_length, aead_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -1099,7 +1099,7 @@ prepare_sha_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u digest length %u\n", info.device_name, auth_xform->key.length, auth_xform->digest_length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -1139,7 +1139,7 @@ prepare_xts_xform(struct rte_crypto_sym_xform *xform) RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n", info.device_name, cipher_xform->key.length, cipher_xform->iv.length); - return -EPERM; + return -ENOTSUP; } return 0; @@ -1254,7 +1254,7 @@ fips_generic_test(void) ret = fips_run_test(); if (ret < 0) { - if (ret == -EPERM || ret == -ENOTSUP) { + if (ret == -ENOTSUP) { fprintf(info.fp_wr, "Bypass\n\n"); return 0; } @@ -1289,7 +1289,7 @@ fips_generic_test(void) fprintf(info.fp_wr, "\n"); free(val.val); - return 0; + return 1; } static int @@ -1458,7 +1458,7 @@ fips_mct_tdes_test(void) free(val.val); - return 0; + return 1; } static int @@ -1537,7 +1537,7 @@ fips_mct_aes_ecb_test(void) free(val.val); - return 0; + return 1; } static int fips_mct_aes_test(void) @@ -1645,7 +1645,7 @@ fips_mct_aes_test(void) free(val.val); - return 0; + return 1; } static int @@ -1731,7 +1731,7 @@ fips_mct_sha_test(void) free(val.val); - return 0; + return 1; } @@ -1846,18 +1846,15 @@ fips_test_one_file(void) } ret = fips_test_parse_one_case(); - switch (ret) { - case 0: - ret = test_ops.test(); - if (ret == 0) - break; - RTE_LOG(ERR, USER1, "Error %i: test block\n", + if (ret < 0) { + RTE_LOG(ERR, USER1, "Error %i: Parse block\n", ret); goto error_one_case; - case 1: - break; - default: - RTE_LOG(ERR, USER1, "Error %i: Parse block\n", + } + + ret = test_ops.test(); + if (ret < 0) { + RTE_LOG(ERR, USER1, "Error %i: test block\n", ret); goto error_one_case; } @@ -1907,22 +1904,21 @@ fips_test_one_test_case(void) int ret; ret = fips_test_parse_one_json_case(); + if (ret < 0) { + RTE_LOG(ERR, USER1, "Error %i: Parse block\n", + ret); + goto exit; + } - switch (ret) { - case 0: - ret = test_ops.test(); - if (ret == 0) - break; + ret = test_ops.test(); + if (ret < 0) { RTE_LOG(ERR, USER1, "Error %i: test block\n", ret); - break; - case 1: - break; - default: - RTE_LOG(ERR, USER1, "Error %i: Parse block\n", - ret); + goto exit; } - return 0; + +exit: + return ret; } static int @@ -1967,8 +1963,8 @@ fips_test_one_test_group(void) tests_size = json_array_size(tests); for (test_idx = 0; test_idx < tests_size; test_idx++) { json_info.json_test_case = json_array_get(tests, test_idx); - fips_test_one_test_case(); - json_array_append_new(write_tests, json_info.json_write_case); + if (fips_test_one_test_case() > 0) + json_array_append_new(write_tests, json_info.json_write_case); } return 0; From patchwork Wed May 25 17:13:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111854 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 47C20A0555; Wed, 25 May 2022 19:15:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0828442B94; Wed, 25 May 2022 19:14:48 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 2856E42B92 for ; Wed, 25 May 2022 19:14:46 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24P9xwXi028734; Wed, 25 May 2022 10:14:45 -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=qZJzNMiXF6hju7KaXwYNM0w1KX7yDPhLtudEEAmrK94=; b=i4aEV4wKgFFHDbp+RyEdicAhDmt9it6DoGzSqjdos51uASOB8DsR4tDlCmeJYxXvBajb 4ShfjR+EW0aebuZEb70Uz2voVCQTfV1EOopR3Oo+xm4XlF8vs/VMgn+X32I6jolPIdRw ptvb/gewoHpcSLKWSYmjpn9pJYhj6872ooSN88zw4kohxstyD0TaickeRncyks+Emb1v rR35ldsAehwhCqdCFu/KG+nLkO3iDCjw5jJ9UqEq5riL2/JkDAxFlOZ/ZoQHm8oiPa+C HnLszRXHpCZxZ9r4eTlzSEU6figYkHuNhwFQhhDq4k9Lp1nEBON8KS4aZEW8HpIdWiOl ZQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g9jap1qyr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:45 -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; Wed, 25 May 2022 10:14:43 -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; Wed, 25 May 2022 10:14:43 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 3020E3F707D; Wed, 25 May 2022 10:14:40 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Gowrishankar Muthukrishnan Subject: [v6, 10/11] examples/fips_validation: reset IV generation in every test group Date: Wed, 25 May 2022 22:43:46 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: s1d2o6tSLAGt1ajCxoI9qAc2cQmppVwv X-Proofpoint-ORIG-GUID: s1d2o6tSLAGt1ajCxoI9qAc2cQmppVwv 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-25_04,2022-05-25_02,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 Reset IV generation in every test group. Signed-off-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation_gcm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c index 3604b21f13..7e89f2a6b2 100644 --- a/examples/fips_validation/fips_validation_gcm.c +++ b/examples/fips_validation/fips_validation_gcm.c @@ -344,6 +344,7 @@ parse_test_gcm_json_init(void) direction_obj = json_object_get(json_info.json_test_group, DIR_JSON_STR); direction_str = json_string_value(direction_obj); + info.interim_info.gcm_data.gen_iv = 0; if (strcmp(direction_str, OP_ENC_JSON_STR) == 0) { json_t *ivGen_obj = json_object_get(json_info.json_test_group, IVGEN_JSON_STR); From patchwork Wed May 25 17:13:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 111855 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 46BEAA0555; Wed, 25 May 2022 19:15:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E05AF42B98; Wed, 25 May 2022 19:14:50 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 663EB42B98 for ; Wed, 25 May 2022 19:14:49 +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 24PESAdb020480; Wed, 25 May 2022 10:14:48 -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=Q9+2ZtIC0ewgZfPQR7gXFBv5Bso3vxYr0Vyh3TuvVlQ=; b=IUWctbRdMjqwOU36vD3SSkrQ2Pl2Vb3dPa39H+BwmRFShS8+EOWBXUDjnuts24XzYTpJ YjKZ5vj5+H7z7UsL3xYCx4fKQoBnZX7AwBhOfvEccXtvQKHvHHvaxSGPLZ46IeajXfGs NDXYZAwGAWDasBvK2Kc6qlM3lZdDIrrjGcVSIsizTRurmE66CecQUHlFVdNVDW7KuATN f48U6lva3GrRLxY9uaiQMgVm7ruukCWXUumj42NtlCBHrJArrTnxbRORalKomgVussdT +/xcygqbtm+iBFKlV3+Bt7oTgMbYjZEdRXN6oGQ9Kd64Hzv6AegJGcQsIebm0CpX4JsD qg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g93ty4w71-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 25 May 2022 10:14:48 -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; Wed, 25 May 2022 10:14:46 -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; Wed, 25 May 2022 10:14:46 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 231DE3F7075; Wed, 25 May 2022 10:14:43 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Gowrishankar Muthukrishnan Subject: [v6, 11/11] examples/fips_validation: add parsing for aes_cbc Date: Wed, 25 May 2022 22:43:47 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: HRcIUgiqFfBjdM6PFFZcq-UpMZH-eBR7 X-Proofpoint-ORIG-GUID: HRcIUgiqFfBjdM6PFFZcq-UpMZH-eBR7 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-25_04,2022-05-25_02,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 Added function to parse algorithm for AES_CBC test. Signed-off-by: Gowrishankar Muthukrishnan --- v6: * fixed local variable initialization in fips_mct_aes_test. --- examples/fips_validation/fips_validation.c | 8 +- examples/fips_validation/fips_validation.h | 4 + .../fips_validation/fips_validation_aes.c | 223 ++++++++++++++++++ examples/fips_validation/main.c | 76 ++++-- 4 files changed, 284 insertions(+), 27 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index ab4c0d0eca..8cec172a5f 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -120,7 +120,7 @@ fips_test_parse_header(void) for (i = 0; i < info.nb_vec_lines; i++) { if (!algo_parsed) { - if (strstr(info.vec[i], "AESVS")) { + if (strstr(info.vec[i], "AES")) { algo_parsed = 1; info.algo = FIPS_TEST_ALGO_AES; ret = parse_test_aes_init(); @@ -458,10 +458,12 @@ 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")) + else if (strstr(algo_str, "HMAC")) info.algo = FIPS_TEST_ALGO_HMAC; - if (strstr(algo_str, "CMAC")) + 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; else return -EINVAL; diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 88cbb0303e..6385ec4d8d 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -103,6 +103,7 @@ enum fips_aesavs_test_types { AESAVS_TYPE_VARTXT, AESAVS_TYPE_MMT, AESAVS_TYPE_MCT, + AESAVS_TYPE_AFT, }; enum fips_tdes_test_types { @@ -262,6 +263,9 @@ parse_test_hmac_json_algorithm(void); int parse_test_cmac_json_init(void); + +int +parse_test_aes_json_init(void); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_aes.c b/examples/fips_validation/fips_validation_aes.c index b3c5e31f32..0b7b9c0849 100644 --- a/examples/fips_validation/fips_validation_aes.c +++ b/examples/fips_validation/fips_validation_aes.c @@ -7,6 +7,7 @@ #include #include +#include #include "fips_validation.h" @@ -25,6 +26,19 @@ #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 KEY_JSON_STR "key" +#define IV_JSON_STR "iv" +#define PT_JSON_STR "pt" +#define CT_JSON_STR "ct" + +#define OP_ENC_JSON_STR "encrypt" +#define OP_DEC_JSON_STR "decrypt" + struct { uint32_t type; const char *desc; @@ -37,6 +51,7 @@ struct { {TDES_VARIABLE_TEXT, "KAT"}, {AESAVS_TYPE_MMT, "MMT"}, {AESAVS_TYPE_MCT, "MCT"}, + {AESAVS_TYPE_AFT, "AFT"}, }; struct aes_test_algo { @@ -92,6 +107,214 @@ struct fips_test_callback aes_writeback_callbacks[] = { {NULL, NULL, NULL} /**< end pointer */ }; +#ifdef RTE_HAS_JANSSON +struct fips_test_callback aes_dec_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &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 aes_interim_json_vectors[] = { + {KEYLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback aes_enc_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_known_len_hex_str, &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_aes_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; +} + +static int +parse_test_aes_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); + json_object_set(json_info.json_write_case, "resultsArray", json_array()); + } + } 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()); + } + + resArr = json_object_get(json_info.json_write_case, "resultsArray"); + if (!json_is_array(resArr)) + return -EINVAL; + + res = json_object(); + if (info .op == FIPS_TEST_ENC_AUTH_GEN) { + writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key); + key = json_string(info.one_line_text); + json_object_set_new(res, KEY_JSON_STR, key); + + 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) { + writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key); + key = json_string(info.one_line_text); + json_object_set_new(res, KEY_JSON_STR, key); + + 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); + + tmp_val.val = val->val; + tmp_val.len = vec.ct.len; + + writeback_hex_str("", info.one_line_text, &tmp_val); + 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()); + } + } + + json_array_append(resArr, res); + return 0; +} + +int +parse_test_aes_json_init(void) +{ + json_t *type_obj = json_object_get(json_info.json_test_group, TESTTYPE_JSON_STR); + json_t *algo_obj = json_object_get(json_info.json_vector_set, ALGO_JSON_STR); + 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; + const char *direction_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 = aes_enc_json_vectors; + + } else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) { + info.op = FIPS_TEST_DEC_AUTH_VERIF; + info.callbacks = aes_dec_json_vectors; + } else { + return -EINVAL; + } + info.interim_callbacks = aes_interim_json_vectors; + } + + for (i = 0; i < RTE_DIM(aes_test_types); i++) + if (strstr(type_str, aes_test_types[i].desc)) { + info.interim_info.aes_data.test_type = + aes_test_types[i].type; + break; + } + + if (i >= RTE_DIM(aes_test_types)) + return -EINVAL; + + switch (info.interim_info.aes_data.test_type) { + case AESAVS_TYPE_MCT: + info.parse_writeback = parse_test_aes_mct_json_writeback; + break; + case AESAVS_TYPE_AFT: + info.parse_writeback = parse_test_aes_json_writeback; + break; + default: + info.parse_writeback = NULL; + } + + if (!info.parse_writeback) + return -EINVAL; + + for (i = 0; i < RTE_DIM(algo_con); i++) + if (strstr(algo_str, algo_con[i].name)) { + info.interim_info.aes_data.cipher_algo = + (uint32_t)algo_con[i].algo; + break; + } + + if (i >= RTE_DIM(algo_con)) + return -EINVAL; + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parse_test_aes_writeback(struct fips_val *val) { diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index e703a111da..a74a38e1ae 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1545,7 +1545,7 @@ fips_mct_aes_test(void) #define AES_BLOCK_SIZE 16 #define AES_EXTERN_ITER 100 #define AES_INTERN_ITER 1000 - struct fips_val val = {NULL, 0}, val_key; + struct fips_val val[3] = {{NULL, 0},}, val_key, pt, ct, iv; uint8_t prev_out[AES_BLOCK_SIZE] = {0}; uint8_t prev_in[AES_BLOCK_SIZE] = {0}; uint32_t i, j, k; @@ -1554,11 +1554,16 @@ fips_mct_aes_test(void) if (info.interim_info.aes_data.cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) return fips_mct_aes_ecb_test(); + memset(&pt, 0, sizeof(struct fips_val)); + memset(&ct, 0, sizeof(struct fips_val)); + memset(&iv, 0, sizeof(struct fips_val)); for (i = 0; i < AES_EXTERN_ITER; i++) { - if (i != 0) - update_info_vec(i); + if (info.file_type != FIPS_TYPE_JSON) { + if (i != 0) + update_info_vec(i); - fips_test_write_one_case(); + fips_test_write_one_case(); + } for (j = 0; j < AES_INTERN_ITER; j++) { ret = fips_run_test(); @@ -1571,7 +1576,7 @@ fips_mct_aes_test(void) return ret; } - ret = get_writeback_data(&val); + ret = get_writeback_data(&val[0]); if (ret < 0) return ret; @@ -1579,24 +1584,39 @@ fips_mct_aes_test(void) memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE); if (j == 0) { - memcpy(prev_out, val.val, AES_BLOCK_SIZE); + memcpy(prev_out, val[0].val, AES_BLOCK_SIZE); + pt.len = vec.pt.len; + pt.val = calloc(1, pt.len); + memcpy(pt.val, vec.pt.val, pt.len); + + ct.len = vec.ct.len; + ct.val = calloc(1, ct.len); + memcpy(ct.val, vec.ct.val, ct.len); + + iv.len = vec.iv.len; + iv.val = calloc(1, iv.len); + memcpy(iv.val, vec.iv.val, iv.len); if (info.op == FIPS_TEST_ENC_AUTH_GEN) { - memcpy(vec.pt.val, vec.iv.val, - AES_BLOCK_SIZE); - memcpy(vec.iv.val, val.val, - AES_BLOCK_SIZE); + memcpy(vec.pt.val, vec.iv.val, AES_BLOCK_SIZE); + memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE); + val[1].val = pt.val; + val[1].len = pt.len; + val[2].val = iv.val; + val[2].len = iv.len; } else { - memcpy(vec.ct.val, vec.iv.val, - AES_BLOCK_SIZE); - memcpy(vec.iv.val, prev_in, - AES_BLOCK_SIZE); + memcpy(vec.ct.val, vec.iv.val, AES_BLOCK_SIZE); + memcpy(vec.iv.val, prev_in, AES_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) { - memcpy(vec.iv.val, val.val, AES_BLOCK_SIZE); + memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE); memcpy(vec.pt.val, prev_out, AES_BLOCK_SIZE); } else { memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE); @@ -1606,33 +1626,38 @@ fips_mct_aes_test(void) if (j == AES_INTERN_ITER - 1) continue; - memcpy(prev_out, val.val, AES_BLOCK_SIZE); + memcpy(prev_out, val[0].val, AES_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"); - if (i == AES_EXTERN_ITER - 1) + if (i == AES_EXTERN_ITER - 1) { + free(pt.val); + free(ct.val); + free(iv.val); continue; + } /** update key */ memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key)); for (k = 0; k < vec.cipher_auth.key.len; k++) { switch (vec.cipher_auth.key.len) { case 16: - val_key.val[k] ^= val.val[k]; + val_key.val[k] ^= val[0].val[k]; break; case 24: if (k < 8) val_key.val[k] ^= prev_out[k + 8]; else - val_key.val[k] ^= val.val[k - 8]; + val_key.val[k] ^= val[0].val[k - 8]; break; case 32: if (k < 16) val_key.val[k] ^= prev_out[k]; else - val_key.val[k] ^= val.val[k - 16]; + val_key.val[k] ^= val[0].val[k - 16]; break; default: return -1; @@ -1640,10 +1665,10 @@ fips_mct_aes_test(void) } if (info.op == FIPS_TEST_DEC_AUTH_VERIF) - memcpy(vec.iv.val, val.val, AES_BLOCK_SIZE); + memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE); } - free(val.val); + free(val[0].val); return 1; } @@ -1944,6 +1969,9 @@ fips_test_one_test_group(void) case FIPS_TEST_ALGO_AES_CMAC: ret = parse_test_cmac_json_init(); break; + case FIPS_TEST_ALGO_AES: + ret = parse_test_aes_json_init(); + break; default: return -EINVAL; }