From patchwork Fri Apr 29 16:15:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110518 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 9965CA04FF; Fri, 29 Apr 2022 18:16:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53CA942824; Fri, 29 Apr 2022 18:16:06 +0200 (CEST) Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by mails.dpdk.org (Postfix) with ESMTP id 5FBE3410E3 for ; Fri, 29 Apr 2022 18:16:04 +0200 (CEST) Received: by mail-qt1-f174.google.com with SMTP id p4so5557424qtq.12 for ; Fri, 29 Apr 2022 09:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c0oLues4m3S4z0ui+vk9et+iqABYFEQPpZkF90kW/fo=; b=KW11UrTWRTmXvnE/zxBi/A2dLGDseQIpbWLnyCmYuPviufCZ2kHcnostjE31VeMkKG rOHaSOclD5xXO4Y+OknDfhS4gZkgSTjPiiDIsoDTBRxsWlMknZ5FlWeLedzP+XPO78ko TEEkcTXDwxjwtBoMNcooHatNT5Xbkxo2qrL2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c0oLues4m3S4z0ui+vk9et+iqABYFEQPpZkF90kW/fo=; b=zdPv9JAfLW31OhjSspiUtlODctiT/LLIq4GuZ53MMx8EPaUkd+b6K8G1O/nOdH1pAo 5Gn0Ymh/Qj9fhQuYFuNYgy5LXGDGcOv1w/G3fcwepI3Vx7i+4AVzKdGeD6WOskGSFP1O yOk9rHFTP3IVeGm3NsqGEElgBjWh3lR/0A0KIJe98qe1gPrgnKfhe3DLWJSA7/q+J2Sz z7DJ5RsewF1prS7F+eSz3smSc68vNB5ItZjiQRqYKkrCiDxI3ZDSk26P75Z6kZ3aGaEc +meEH1bx1HSBEf/JJgCZl3aqVN0nPccJrc/TR//otd/0xGTD6QZiCWFnRUpI+Ad2TNbv lPLA== X-Gm-Message-State: AOAM530XbiMiiOEws8MFpTi4+hy4VXu6XCqq0xxsQJDGsBebnFGy/zt8 YM3wuYmKzCvenP1yHGZs8xT12g== X-Google-Smtp-Source: ABdhPJwp1djcRhkko13zYWELGSSbbhpiMD+DWqgQyPBits9r4iU2bqwe4I9tfbpO2Lf1NlOa53MhdA== X-Received: by 2002:a05:622a:1c5:b0:2f1:f99f:b74b with SMTP id t5-20020a05622a01c500b002f1f99fb74bmr147138qtw.602.1651248963316; Fri, 29 Apr 2022 09:16:03 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:02 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 1/8] examples/fips_validation: add jansson dependency Date: Fri, 29 Apr 2022 12:15:52 -0400 Message-Id: <20220429161559.415645-2-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 a check for RTE_HAS_JANSSON into the meson configuration file for JSON support. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- 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 Fri Apr 29 16:15:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110519 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 C7FE0A04FF; Fri, 29 Apr 2022 18:16:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29CB74282B; Fri, 29 Apr 2022 18:16:07 +0200 (CEST) Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by mails.dpdk.org (Postfix) with ESMTP id 5822E4281C for ; Fri, 29 Apr 2022 18:16:05 +0200 (CEST) Received: by mail-qt1-f174.google.com with SMTP id y3so6112033qtn.8 for ; Fri, 29 Apr 2022 09:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KlF/101SYbvdeKOLAIhv/QBa8nErtO/O47h2gUhBxRg=; b=P73MR54waYo1NIbEZyw2RItnBWXK0lkWP2Noq9SYnbwylg4rDh/MfZhY/yia9UQKpw Ow177uTutsatMYbrf67PpYKtKBFDIl9tNaZQq/NlbptbabrFYwHq24UenHikT9k6RIzM r7PpZKXRy9cvVkuxmioh3CwAtnipBTkCL4VoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KlF/101SYbvdeKOLAIhv/QBa8nErtO/O47h2gUhBxRg=; b=6rFsNseFS5ZaGYoyNY8p3+2Rk/g5kvbFGIl/QHIaHYI9SN3Z1CBPkA4I3ojvsf1Li1 YfXy8lndYCdR5WAjm6EqtlqN+JoxHKnKA5YdMl9LI9INYFvLiIUqHJlRNHpZ0MZr1c+0 ItvCkbPqLz9r3hkD8snF/rww9rn5Dz8eeudSvS+2a8Yy9vQJY05xhC6A3k6DBxIH2Uzl wfXt/YaGjW0VAMZLnKWeg2xfDKHR7GtBd9KZcj3QwHZIXS5mowoZAZ9t4mtuhFmKoKIa A/UqAzRyz+3WQuZWZOStyg2MfZld4LhSalKsk6cX9u8/vTmX1gMCa40Js6BcSmJ381NP A27Q== X-Gm-Message-State: AOAM530thtHktrU5meoObXEjJB6RyoH2oW40bzQxGhQ67XfJDwayUK+N lpCTuZyO3Rn9sPfHlewD3mLouA== X-Google-Smtp-Source: ABdhPJzOvJ7iZP7hnIYPJsI99Lm3LVLQ3/sTGSs9bwkSC0L3FD0Zkqo8sAAVXNwY28FLr/90XiFKXQ== X-Received: by 2002:ac8:5902:0:b0:2f3:99cc:d8ca with SMTP id 2-20020ac85902000000b002f399ccd8camr142675qty.83.1651248964414; Fri, 29 Apr 2022 09:16:04 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:03 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 2/8] examples/fips_validation: add json info to header Date: Fri, 29 Apr 2022 12:15:53 -0400 Message-Id: <20220429161559.415645-3-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 json-specific functions and other information needed to test the new FIPS test vectors. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- v2: * fix type of prefix to suffix examples/fips_validation/fips_validation.h | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index aaadf01ba8..e2789df93a 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) @@ -24,6 +28,9 @@ #define REQ_FILE_PERFIX "req" #define RSP_FILE_PERFIX "rsp" #define FAX_FILE_PERFIX "fax" +#define JSON_FILE_PERFIX "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 Fri Apr 29 16:15:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110520 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 D2952A04FF; Fri, 29 Apr 2022 18:16:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D78F4282F; Fri, 29 Apr 2022 18:16:08 +0200 (CEST) Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by mails.dpdk.org (Postfix) with ESMTP id C04014281C for ; Fri, 29 Apr 2022 18:16:05 +0200 (CEST) Received: by mail-qt1-f173.google.com with SMTP id p4so5557484qtq.12 for ; Fri, 29 Apr 2022 09:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vYACZHkBG57qbDzvpGr47m7X+Om0OW6b0K4jZpDxuHQ=; b=b5pjXMbWh3pJYWh3a+pczI6CEgJOZxYHp+iSbRfrIYKtqxI6LiQR47jkmdSwa3n+tk XkEiwDYxlUh9QHZ4+7TY/TODoF5M+vbCbGS+0vb/h9rsmLBEPaztmvDlxewQrA+irGde 6EPUJi+y4+tGRP4Isbyp4NvAIm9vb0PkbGYeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vYACZHkBG57qbDzvpGr47m7X+Om0OW6b0K4jZpDxuHQ=; b=EsWukRdQr8iknRYzdGFIosSyVVJAm79TnQZ+vIXc4vY3uasIPpZ41Yy3vzmpu6v4wZ tCha9EfLrOqH/cES+SMpfGgUzBBsGyxnhq9KwFY8cqWL/skYwYOrMLTUqKmazXb+KXaz ws2tEsmz9xTwcL8lDuhZuvZ/NxjIxU2kD/ltJkf7IuLsWRVlv2o0Xhrv3jVX+vZ4SUFq 08f9nMTHMmMMrmnKtP5sjXYdFI+LdeZz1g4OjsbUEJs9xpYS5SKRNSnKZkMANkCto85E aaagnY0iYsOSudwFMP5GzBUImkwLq0CIEAd39oNw/teS7n6ka8ojFVuuTC1iDMhTFg7U GZGA== X-Gm-Message-State: AOAM530RpeE8T5DkYD/Su3NWjmzi/A1WUTILDnB5jwyt+IZ9VCuRGo1v zO4zQogeZE08wCZq9dHYTDAqVQ== X-Google-Smtp-Source: ABdhPJzjBPNHQi2YRBHnJu6DWmwZ0R3y9GLl8I/VnfhOjzoL875K1OgUhNxI7XGBaGVNxFdxk9niiQ== X-Received: by 2002:ac8:5cc1:0:b0:2f3:86e0:c8b1 with SMTP id s1-20020ac85cc1000000b002f386e0c8b1mr139227qta.99.1651248965219; Fri, 29 Apr 2022 09:16:05 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:04 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 3/8] examples/fips_validation: add json parsing Date: Fri, 29 Apr 2022 12:15:54 -0400 Message-Id: <20220429161559.415645-4-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 functions to parse the required information from a vector set given in the new json format. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- 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 94253eaee8..d220dcab1f 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_PERFIX)) info.file_type = FIPS_TYPE_FAX; + else if (strstr(path, JSON_FILE_PERFIX)) + 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 Fri Apr 29 16:15:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110521 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 D9A37A04FF; Fri, 29 Apr 2022 18:16:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E4DA54282A; Fri, 29 Apr 2022 18:16:09 +0200 (CEST) Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by mails.dpdk.org (Postfix) with ESMTP id 0243D42828 for ; Fri, 29 Apr 2022 18:16:06 +0200 (CEST) Received: by mail-qt1-f169.google.com with SMTP id t11so6094803qto.11 for ; Fri, 29 Apr 2022 09:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8p7LinSrojBS2OxAdx+SVLwhluVL3rzv45cX/GSBZLg=; b=MiaejUy4pYWqAPX9eBPQoT5suc5fCL7GapTq3SEGFmCNVXtaP8AYtm/jiPW9vmxNcf HpUbboZi0mqVpMPX+Bdd17kVQyNP0RrLF9gSQ8bBKiDF0Qp4U6t8ARlHHyFheFDJ6rzW sz/1LXs0LeTOY7SUau47KjMlCkFiRZSc0KZdM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8p7LinSrojBS2OxAdx+SVLwhluVL3rzv45cX/GSBZLg=; b=Uwa/f0SuS4i+/KutZNKMUWLaOECBNK/R5W3uepF0AeTH8taM9d7oDwGtWjiBLOYx3r iUQwJYKFBj4IhEQ6XrFcM7TULHLR8tw1MgLgGJVNCchyI/G+zBtS4qu4Suo8MvBHPIeO kmBqZDnKpPnTuKVyZ+6G06f2QPMyApBD18ENX3XRQE4bLcitGOyVPhz/FUiNZZISLLuB qd5AD+xb5Hbu59fHaD4Ft8BtazgTxesc7Hn9Oc2F2Wp6/fl+4dy3CU9POS6vNHHG0d5H Oq5tRMkP8iAQHBuRv424pD7RmDYcFliEHLADS/yVhI9dBAnAsW++HMvOVaD2rNAq555r WGCg== X-Gm-Message-State: AOAM532xycFcD8IsSYUVijOzJvHe6w7QEz/wAn4CQnkok5zMupDwSBYB OaSrJhfRTjkPqcq3zgOfnDQ+yEYYrNpVAA== X-Google-Smtp-Source: ABdhPJyEwEWsrIx3LApCjeo5sJGw6TnTaC7teQU7EsTFFFh0p9rsVX7OF4oWzeeasg9VJRyGC8o6Iw== X-Received: by 2002:ac8:3d49:0:b0:2eb:cbf8:4140 with SMTP id u9-20020ac83d49000000b002ebcbf84140mr130447qtf.279.1651248966035; Fri, 29 Apr 2022 09:16:06 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:05 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 4/8] examples/fips_validation: allow json file as input Date: Fri, 29 Apr 2022 12:15:55 -0400 Message-Id: <20220429161559.415645-5-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 the ability to use the json format as the input and output of the example application. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- v3: * fix checkpatch warnings v2: * remove use_json variable examples/fips_validation/main.c | 200 +++++++++++++++++++++++++++++++- 1 file changed, 196 insertions(+), 4 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index e06ae37567..65f736f3cb 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) { @@ -389,6 +400,7 @@ int main(int argc, char *argv[]) { int ret; + char use_json; ret = rte_eal_init(argc, argv); if (ret < 0) { @@ -424,9 +436,17 @@ main(int argc, char *argv[]) ret, env.req_path); goto exit; } - - + use_json = info.file_type == FIPS_TYPE_JSON; + +#ifdef RTE_HAS_JANSSON + ret = info.file_type == FIPS_TYPE_JSON ? + fips_test_one_json_file() : fips_test_one_file(); + if (use_json) + json_decref(json_info.json_root); +#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); @@ -480,8 +500,19 @@ main(int argc, char *argv[]) ret, req_path); break; } + use_json = info.file_type == FIPS_TYPE_JSON; +#ifdef RTE_HAS_JANSSON + if (use_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 +1250,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 +1270,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 +1286,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 +1878,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 Fri Apr 29 16:15:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110522 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 3FD32A04FF; Fri, 29 Apr 2022 18:16:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E109742836; Fri, 29 Apr 2022 18:16:10 +0200 (CEST) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by mails.dpdk.org (Postfix) with ESMTP id 8583D4282C for ; Fri, 29 Apr 2022 18:16:07 +0200 (CEST) Received: by mail-qt1-f171.google.com with SMTP id f14so6121302qtq.1 for ; Fri, 29 Apr 2022 09:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wENVn0LZWyicYMNnKLC9Ddl90zKD3W3htvRWFL7r5mU=; b=i6FLe1uTqZHhGiTdPQFv1HcOyZpcD87ypTK25HRSbPYDfk1fi4AmcxDpvuwIIi6Zbo ba1ZxUurxtbIcVBtm4wCzfg8hpb0+TeXodRLzGB0uKtvv/Kx7XT68JTby5fsddmElShT +2zb9rxlj1x/18aVtK0UBc01AzEknGjqpGJC0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wENVn0LZWyicYMNnKLC9Ddl90zKD3W3htvRWFL7r5mU=; b=n/NFvcWVez7LJCtVkVl0swvAyJKfh626ufxo+H/y8Q3luqHeohawJteurA4kv9CGbq BnCmi5s7bVOcEq6hYPei2gBVzKo2mE8PhA9TIITK+XN9mTdxsVqcOazd7fhygSMkZFb0 LvLyD6aaNYp62grC0dDVBaFyvJjS1Nhn4oaFR0ADrlPhEIVnNadBPHbhfLZk/bQ+VFq+ Qm+OFHLIj0Sp/PbNelCUJ2DAM7vzRQ2KAvvJasgQzesWLaqh0xdEeMLwFlj2bqllE4jI aiMuEBwJeSP7gIwdEhaPf0nlq2GiDal5lEGs215XAnrr5voU20xCg3piuSEslZItuNaZ phaA== X-Gm-Message-State: AOAM532IK4iz7zoaUYLUVoeFgcL10q15/RDfUoqmenYavy+ihzZqDtoU NBYUhCEeh+ct6PsnuTPdi8mJGg== X-Google-Smtp-Source: ABdhPJzF8H5q87aoTFqL8SDxJfqDOYNnZmTAHoJ2Kwm/SzlrxQkd4Hzk0AQa/gSBpFpzDlTHODQvcA== X-Received: by 2002:a05:622a:1904:b0:2f3:9101:ac7d with SMTP id w4-20020a05622a190400b002f39101ac7dmr131452qtc.277.1651248966945; Fri, 29 Apr 2022 09:16:06 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:06 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 5/8] examples/fips_validation: add json to gcm test Date: Fri, 29 Apr 2022 12:15:56 -0400 Message-Id: <20220429161559.415645-6-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 Adds json-specific testing and writeback function. Allows the user to test AES-GCM vector sets. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- 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 e2789df93a..8d7af99e04 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 65f736f3cb..a1d8a1d758 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1941,11 +1941,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 Fri Apr 29 16:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110523 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 0C5F9A04FF; Fri, 29 Apr 2022 18:16:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D057B4283B; Fri, 29 Apr 2022 18:16:11 +0200 (CEST) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by mails.dpdk.org (Postfix) with ESMTP id 7260742832 for ; Fri, 29 Apr 2022 18:16:08 +0200 (CEST) Received: by mail-qt1-f182.google.com with SMTP id x9so6114763qts.6 for ; Fri, 29 Apr 2022 09:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EzJ3kxPq37sIG+M3jBZ4BC1iiJ1GgCH/+Bj2xldNKe0=; b=JWcVgv51UoF7Sbeew2Kc4oS/cpM6nVI/JV68RkZ5SnKSOhe/t6qxa/yDD4wvXQ3tY1 AI7w0r4RbzEVMKbT6KB8jtby0esjNqy0iOL32bxG/kmddrbA/NNmakUKgQLHl7hCX7xX GzgpmhD6kWwqrWK5xykFZ8lorNi6FQQhya/pQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EzJ3kxPq37sIG+M3jBZ4BC1iiJ1GgCH/+Bj2xldNKe0=; b=oEIdAqIm8UWNh80ubSfrGr7m74q5jGVPkQpB4MF21aXcefniMwiEbT8qMiq0pulMPk yhgS7v0fF3fxcskJ7MEWtmb7U+MFz0aZvZbHfzJuHIE+Od8QbnYoqT3Cuig36mB68Mfo lOKKOHSt+A/6c1AQbTbE6jdLKcqlxDH1EWu0qgQiaDW2XluT6jMP3cQlnqOtZV6PXi0V g/PAIccBSNPfFsRcK0jlIDQTfVEXw/3aK11ehGEvynkXfPNl7FTIVDvYpblzOxN9qTap xEaKumWpTT0NuIidw+qzz24h8fDPzWRbFyIXYpH4WtERR5A0m0He6Jc0tKs2Hy8jcW+X f9Gw== X-Gm-Message-State: AOAM532fQyGCzojlbPMUtnj7CO7YU2XrPiEKxTWG33f92hYE7v1z/JBx fh+fkLB+B+WwZsmGTpKLYyKaiIUsH3NrAQ== X-Google-Smtp-Source: ABdhPJznNCCrefIWk3NTCgNjwpNsxI4k31EQIz6nf6rVCU388unHVNJsO9v67tkW7NgrdW6oMS/nUw== X-Received: by 2002:ac8:5dd4:0:b0:2f3:8801:856f with SMTP id e20-20020ac85dd4000000b002f38801856fmr138288qtx.107.1651248967870; Fri, 29 Apr 2022 09:16:07 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:07 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 6/8] examples/fips_validation: add json to hmac Date: Fri, 29 Apr 2022 12:15:57 -0400 Message-Id: <20220429161559.415645-7-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 Adds JSON support for the HMAC algorithm. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.c | 2 + examples/fips_validation/fips_validation.h | 6 ++ .../fips_validation/fips_validation_hmac.c | 93 +++++++++++++++++++ examples/fips_validation/main.c | 3 + 4 files changed, 104 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index d220dcab1f..04dfb85262 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 8d7af99e04..2c65d838b0 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 a1d8a1d758..de6dedaf75 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1943,6 +1943,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 Fri Apr 29 16:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110524 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 7CB85A04FF; Fri, 29 Apr 2022 18:16:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D738C42840; Fri, 29 Apr 2022 18:16:12 +0200 (CEST) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by mails.dpdk.org (Postfix) with ESMTP id 4895042833 for ; Fri, 29 Apr 2022 18:16:09 +0200 (CEST) Received: by mail-qt1-f177.google.com with SMTP id p4so5557626qtq.12 for ; Fri, 29 Apr 2022 09:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VUc7jsRduw3fVhSRbhtDqzGMDIQR76TpPoxasjK1OB8=; b=M4qslR2zPlySqyAhx/MlX+TGGqigQlsW7/2sqxQEh2V3AtwaW84n+6jkxeQvuLGH/Q 9vtKfpi43LtfYIc/dmkuMZ6LojQfmPFYCT+WsfbgkBhwBowOyiRBYXWU0f+iZHgp7XAp 7uGElhJ4z56XHE4LTKaI0OvLajP2dOG0t65fY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VUc7jsRduw3fVhSRbhtDqzGMDIQR76TpPoxasjK1OB8=; b=I4Q5YGHY+iNpIJ68UeQ3Pf1kL/19PTIQjNAw2bwSMcdJmOFUghroX8h1wtH/tnSg30 qtgxs6EVAJdnprPpftUKmF0eY2YVXZJAj7EvSd6Xv6kU85N+bYLuglFzT3bh4yFD3G57 cnybYopySpxriHioIVYKRYi6wsegJwRqKNmA1VBujlOJPC9gBnb3pZZYIzLP5ZEiGGNB ClqkEJLjdVZIFlCDLwyqXQKW+NvpgeiZHY9P9ywcA6pekXN2/7YnCWl5tVI4db7jKEPp RgNbB1lkVVv1ymzwCIZwOrvYex+lCD1L4Avk1GWrotM/ScubDFQ4gx/aveQ3GiRZ33YL 8ALQ== X-Gm-Message-State: AOAM530wVtdzl1NLI64qTvY14OCilm8Oz7YHnSrWmJgp5wsmcsgyGddr hNFnbH5ZpvBeTYEUiksbswgGBQ== X-Google-Smtp-Source: ABdhPJzAg4d5DmfnvFmyPh/CxCsyW42GEbrA76ztauwkoD4IHKFShyPOFahBK3aRJRn8K8jUYdxYYg== X-Received: by 2002:ac8:7e94:0:b0:2f3:7e38:ef88 with SMTP id w20-20020ac87e94000000b002f37e38ef88mr165697qtj.280.1651248968720; Fri, 29 Apr 2022 09:16:08 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:08 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 7/8] examples/fips_validation: implement json cmac test Date: Fri, 29 Apr 2022 12:15:58 -0400 Message-Id: <20220429161559.415645-8-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 Implemented JSON support for the CMAC test. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.h | 6 ++ .../fips_validation/fips_validation_cmac.c | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 2c65d838b0..7f68d454f7 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -259,6 +259,12 @@ parse_test_hmac_json_init(void); int parse_test_hmac_json_algorithm(void); + +int +parse_test_cmac_json_init(void); + +int +parser_read_cmac_direction_str(const char *key, char *src, struct fips_val *val); #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..4b5fd2aca7 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,62 @@ struct hash_algo_conversion { {"AES", FIPS_TEST_ALGO_AES_CMAC}, }; +#ifdef RTE_HAS_JANSSON +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 Fri Apr 29 16:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110525 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 65471A04FF; Fri, 29 Apr 2022 18:16:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1596642848; Fri, 29 Apr 2022 18:16:14 +0200 (CEST) Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by mails.dpdk.org (Postfix) with ESMTP id 1D97942834 for ; Fri, 29 Apr 2022 18:16:10 +0200 (CEST) Received: by mail-qt1-f170.google.com with SMTP id p4so5557654qtq.12 for ; Fri, 29 Apr 2022 09:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Iscdf4HUPn4qo1v1LSs0EbMRcDmlYHAsnXH+s2EvAA=; b=MBu2R4iGgRt/k/KX67RknQQKdalZbdmM5eySCsPGSlDGh+e+Gibea890oey7aCwdzD gv+GppKwrvjD7ga+clEskGlVk3uPQZ9vvFhv/jbWZu55R7ZE58n+0G5LBQahNu1++qy9 rLm4493zBjHF4FA6Vv2T9oNkar6lTkCmxbPg8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5Iscdf4HUPn4qo1v1LSs0EbMRcDmlYHAsnXH+s2EvAA=; b=GnxI+wO0FQVeNfPtMIORroSi1NbBH91oYSNLlECJsYEC3NxH6/MznxQ3bydge8mhlJ KCIAK77GWCkPGaMcZOB61SyuvlCdd1Fw9WcqMg22pqH8THKu0HCXLyzYGaXg3Slms3jB gjdalMR78qndAAw/sLb/vhfZYW1BiauOsH8SVOvuf5y7t3wLeOw0Yui5RE79QC1wu/Ie E1NOzrk6XIjg+b0zFN2Unw+zM/mkvw658ogJiIIhRer47nWABHJa8q7tjWOtQdmzxJ7I hBv2uhTFMqrtduKiUL0a41q08YqF4sCMQMFQEhBiF0Uza9R6RRGAptpeUyh5DQWPpUWS mGQA== X-Gm-Message-State: AOAM530NBlc9zHjLF5wrwcsqaP1zdOz6KvPUPR8dFRpx2Cx2ZZoiFPb1 nnREO/sQHbQRqdajqrrCOqVftg== X-Google-Smtp-Source: ABdhPJwLBN0vx/LbNwoT1mDJTyhnV1h0oj55huk9pV+UaUudpzW5MAAO3oAiyU/dc2W1bO7DyotxNg== X-Received: by 2002:a05:622a:1c5:b0:2f1:f99f:b74b with SMTP id t5-20020a05622a01c500b002f1f99fb74bmr147587qtw.602.1651248969516; Fri, 29 Apr 2022 09:16:09 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:09 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 8/8] examples/fips_validation: add parsing for cmac Date: Fri, 29 Apr 2022 12:15:59 -0400 Message-Id: <20220429161559.415645-9-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 CMAC test. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.c | 31 +++++++++++++++++++--- examples/fips_validation/main.c | 3 +++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 04dfb85262..8e0a55c624 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. */ @@ -673,6 +686,18 @@ parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val) return 0; } +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; +} + int writeback_hex_str(const char *key, char *dst, struct fips_val *val) { diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index de6dedaf75..aa8034c29f 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1946,6 +1946,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; }