From patchwork Sat Jan 29 17:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106715 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 E8CD2A00C4; Sat, 29 Jan 2022 18:55:22 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C19DD40E5A; Sat, 29 Jan 2022 18:55:19 +0100 (CET) Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by mails.dpdk.org (Postfix) with ESMTP id 6FE9140041 for ; Sat, 29 Jan 2022 18:55:18 +0100 (CET) Received: by mail-qk1-f173.google.com with SMTP id o10so8462172qkg.0 for ; Sat, 29 Jan 2022 09:55:18 -0800 (PST) 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=aURU2OVqLs17RILRMIR2aVO90gUBjRoqkH6qLBAlBw6VHU1OPpb+7gzpcNxWNrP2dy L35C6DxSszVvCh29AHUrD+zFjK46RkW8mBwPuCMPj4JOkCysAF1QLgPb1ercByjYZSeo yDOn5BOJvMaclWiA7IVPER5FOL/RG2BkQQHg4= 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=rMrWqVcLHhiLvB5YS0TNxtFIkc+TLNt2bsuAFaDvvQw/D/jCueaBg1bQ/G5BnH6Ucp T0m1O0gOyLwJzpxXPZ+eTXn13vxXdxJLVxAh9IFez4lzGAIKzby2IkgBd8DppCYZ0+jm X/sr2QJWytYZ9wd2hlVBLeRvCq0vh+YH7RKZ/0BaIpwwKObRUT3v5eMA0MsxOkFQAk20 Lcd2wFddLm/R+WHIYfnR1t7KaQb8pj0JZAFwgeUb24/BR5K4VzNCjx+1xkY3zOkGOaW8 w/aWfFstyd2qoLEpAbGSSq8xAn6dLhTebhq0VkYfhuOfrdLxqUGQ7MJU5y9Hxl86vH6v +MOQ== X-Gm-Message-State: AOAM530+wTsXOLHkTtIpCZKZVLieiEkrPs6VD9CpLcEKWpDnC5NGfkyJ lCJDe1TffUM4vahzj+uWEwGMwjvpoq945DdAyUM= X-Google-Smtp-Source: ABdhPJwUJk87Fswfn2V06ia4ZYQ/lC3ZRSKahdnyO+faRDipEPHwPQe+jV6h/biocicL0jiep8n7/A== X-Received: by 2002:a05:620a:298e:: with SMTP id r14mr714556qkp.634.1643478917929; Sat, 29 Jan 2022 09:55:17 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm5423654qkf.30.2022.01.29.09.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:55:17 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v3 1/5] examples/fips_validation: add jansson dependency Date: Sat, 29 Jan 2022 12:55:10 -0500 Message-Id: <20220129175514.746925-2-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129175514.746925-1-blo@iol.unh.edu> References: <20220129170313.489986-1-blo@iol.unh.edu> <20220129175514.746925-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 --- 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 Sat Jan 29 17:55:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106716 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 B6ED0A00C4; Sat, 29 Jan 2022 18:55:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A748940E2D; Sat, 29 Jan 2022 18:55:22 +0100 (CET) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by mails.dpdk.org (Postfix) with ESMTP id 85D9440E2D for ; Sat, 29 Jan 2022 18:55:19 +0100 (CET) Received: by mail-qk1-f169.google.com with SMTP id j24so6113994qkk.10 for ; Sat, 29 Jan 2022 09:55:19 -0800 (PST) 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=gwlnmQeD/tOhON2UYqK1AATKV/D3dMUkEaJcvvn1dUg=; b=cEjJQ+1rSQyYI6ruqLGzPJ6VI+BCNlQz4+ZcBvc9//aO8d8mwkDiHEtNkKNHf8eAFK S7c9eH/EzyvXi53hJL7LSo3A3Dp6R+tgyIigkY0Z0YxieqRRoDgrCXlkQ+HxEXBxn4Sy LTUnqN7GXwrPAtwwniEYM2pLrC5P/sw8fUxRo= 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=gwlnmQeD/tOhON2UYqK1AATKV/D3dMUkEaJcvvn1dUg=; b=Yel88a825tB2lAjjewNCEeUpVV7hr2W3g+9rZRGRfG0ioKAUiwZzB1wM95RCcMOzs6 lPbJ+spsbcby5/xMDWTo8L/d//1A/ZtfMZ6srt0wqRJ+eaYzR9vdIdximdJfJkz0JitD DhKhPEomzIJfaxUwgV1Z8Udnwu884gXx7MeiZoDHgATstqSMeLMoVKD5my7Qe2SxrM2e L7VcFG4IS+X33f6830A0+zU0ytd4Y7I5qKBo9pLUN6jX2kL2w6skJcFcwyzrsYXIj2SG L33fLvwLex8T1YC8AZgbs7RpPwM/8NC4CaftfIyceUDHHm+n8DKqRmnWSEPwRyNOZhfa mxDQ== X-Gm-Message-State: AOAM530kFG6+bzGA26tehZJFXjoLUbMteoDgURY0+5FqX5KlV2RdWlHR wcn1MN3yIJPfnkTWuW43Z6wzyNFAHtpqbn3/Mws= X-Google-Smtp-Source: ABdhPJzpBudmjzOBbvTo+oEi8bt6x8nR5jpzEefSlt5d0EIVwimRPMCTdX1gjvc/cecgZE62Bzrcrg== X-Received: by 2002:a37:9444:: with SMTP id w65mr8927831qkd.468.1643478918939; Sat, 29 Jan 2022 09:55:18 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm5423654qkf.30.2022.01.29.09.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:55:18 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v3 2/5] examples/fips_validation: add json info to header Date: Sat, 29 Jan 2022 12:55:11 -0500 Message-Id: <20220129175514.746925-3-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129175514.746925-1-blo@iol.unh.edu> References: <20220129170313.489986-1-blo@iol.unh.edu> <20220129175514.746925-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 --- v2: * fix type of prefix to suffix examples/fips_validation/fips_validation.h | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index aaadf01ba8..8e2963faa3 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_SUFFIX "req" +#define RSP_FILE_SUFFIX "rsp" +#define FAX_FILE_SUFFIX "fax" +#define JSON_FILE_SUFFIX "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 Sat Jan 29 17:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106717 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 8E37AA00C4; Sat, 29 Jan 2022 18:55:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 91309410F7; Sat, 29 Jan 2022 18:55:23 +0100 (CET) Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by mails.dpdk.org (Postfix) with ESMTP id EB462410F1 for ; Sat, 29 Jan 2022 18:55:20 +0100 (CET) Received: by mail-qk1-f174.google.com with SMTP id w8so8392458qkw.8 for ; Sat, 29 Jan 2022 09:55:20 -0800 (PST) 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=XSGv7FdmdF/Loly4IgpZ0yQfwKax+bk05xiSvsUPsFg=; b=gTYchceErv8qhTu1yyzl4yQP5LsjuXFhul2SKZfxI7YUrm6BqP/zK5Dcns94FsYC3y JRjy2dxuAldX78r1rczLQMLBBPoDfkHI5PFr87lUYSOCUNX9iEOlZKyI4JN1nzbZ/DO8 PNYOeD+fA8fDb8V8nomlUa22SkZJHmGKXuMas= 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=XSGv7FdmdF/Loly4IgpZ0yQfwKax+bk05xiSvsUPsFg=; b=zHZzCUHgQRuORsp61jv7Glbb4W4876Ke5SnvpzctEN5/el5J7c0JzaDXRQDUPPq9lT LlafZZMsSnPUf34/VrZeqDtXrOLHtGqQlZlRnr991sF+YUg+hlbnrfRtlqDoXhHvmcwz ai0Fkw0pPnmftwTlRpim2NVXGBNoy8cNJm0kj+cCJaFHXj8Or3AI2MsRCJArsjk1LJA5 IM2DJD1+FAnam/venx12YxzXI7CXCbVQV7K3cWZ3T/3vADUFIP2+Q8qMAmMjGuqfTZ7c 5atneFPHoIK0h24cMp8i3Vu/bxatLAU5730zB3ln5azFnRXR0vcdVYUpCQ7Dn/j2Fl5M nCAw== X-Gm-Message-State: AOAM531VoG2YUrLzUcz/pdDQXC0G+l4hK3J3YFG2/ZV+7R3ZSSINuPsY jxiNVZM+djVmO05L/UfEvceMRL7ZfWT1I+fcMSI= X-Google-Smtp-Source: ABdhPJyLiFNLaHgc8A0Jc6J9VxdsRLekFSMdn65j0gNTmTT4tm81PO47RUFXXQV+7rQ3zbHT9n/m9w== X-Received: by 2002:a37:5345:: with SMTP id h66mr8730794qkb.40.1643478920060; Sat, 29 Jan 2022 09:55:20 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm5423654qkf.30.2022.01.29.09.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:55:19 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v3 3/5] examples/fips_validation: add json parsing Date: Sat, 29 Jan 2022 12:55:12 -0500 Message-Id: <20220129175514.746925-4-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129175514.746925-1-blo@iol.unh.edu> References: <20220129170313.489986-1-blo@iol.unh.edu> <20220129175514.746925-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 --- v3: * fix checkpatch warnings v2: * fix for loop initialization examples/fips_validation/fips_validation.c | 96 +++++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 52a7bf952d..198cdb5688 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -270,12 +270,14 @@ parse_file_type(const char *path) { const char *tmp = path + strlen(path) - 3; - if (strstr(tmp, REQ_FILE_PERFIX)) + if (strstr(tmp, REQ_FILE_SUFFIX)) info.file_type = FIPS_TYPE_REQ; - else if (strstr(tmp, RSP_FILE_PERFIX)) + else if (strstr(tmp, RSP_FILE_SUFFIX)) info.file_type = FIPS_TYPE_RSP; - else if (strstr(path, FAX_FILE_PERFIX)) + else if (strstr(path, FAX_FILE_SUFFIX)) info.file_type = FIPS_TYPE_FAX; + else if (strstr(path, JSON_FILE_SUFFIX)) + 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; @@ -429,6 +449,76 @@ 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; + + if (info.interim_callbacks) { + char json_value[256]; + for (i = 0; info.interim_callbacks[i].key != NULL; i++) { + json_t *param = json_object_get(json_info.json_test_group, + info.interim_callbacks[i].key); + json_int_t 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; + + for (i = 0; info.callbacks[i].key != NULL; i++) { + json_t *param = json_object_get(json_info.json_test_case, info.callbacks[i].key); + if (param) { + const char *json_string = json_string_value(param); + strcpy(info.one_line_text, json_string); + /* 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 Sat Jan 29 17:55:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106718 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 ABF59A00C4; Sat, 29 Jan 2022 18:55:37 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8273B41145; Sat, 29 Jan 2022 18:55:24 +0100 (CET) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) by mails.dpdk.org (Postfix) with ESMTP id ACFF840041 for ; Sat, 29 Jan 2022 18:55:21 +0100 (CET) Received: by mail-qv1-f67.google.com with SMTP id e17so148223qvb.8 for ; Sat, 29 Jan 2022 09:55:21 -0800 (PST) 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=/cGbARic2yPKQ0Z0nZpv6ptmu+VAFlWNxutVJ9T/JZo=; b=ABB5Cf7DAB4eYHrGOI2kz0WtqxRckGFIAYS3mky860dmbczXp+WOoHq08i40QT7r6f 5L5Y0xOVF74dJSPw6c/2x9qpk1M9Xa+KNZXpdRCgEaffjmWLJUERnli/07e3cvZD0rbM of9QKEfXpYSzlW/TG6x0RqY6J298gn6bhSmgo= 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=/cGbARic2yPKQ0Z0nZpv6ptmu+VAFlWNxutVJ9T/JZo=; b=PLQQEpH0YD7Ycnu2pb99SFiFST9YCKFfaaHAz06e3Ghcf08o9QqqcdwHOaJgrZPKxY tzwyJOL5lwC5oYLglTYc5DTM9sTGV62qD3AVzZx9a2IFepm8n2Efocp9PNtYnxYaELkK oky27lf8VKPRDEoq2m5jwZiFLa15CXNVZzs7y8xtsvA3LFHCaMAgwd2aT5hk/tUK75sV ExdmF5JGTU82pTkoLC1j7950V8hstD08USzAUvKSD5XfqCnmtyiAshKomDeyo7DSeqZP eTX2GguQBK5T9Q7INM+kCaPuNvYUqTlEkApRGSzDvHANh/4A9pr/1qW70L9MAMMAIrOs OsTQ== X-Gm-Message-State: AOAM530ly1m1eoVaMQPpwmHr6KVncxBQfK8c78TBsfGQXvQmPqKaCXLe TIe4ZVgInGrGU82zJaTg56G+tg== X-Google-Smtp-Source: ABdhPJzoLlF1RnMHFOHxvN80geDh1oMbcnlUOF/dCbmbHwlJtFzQRLB/kxOWSXSygFTeDjWQIZCP0A== X-Received: by 2002:ad4:5ccd:: with SMTP id iu13mr11168864qvb.89.1643478921056; Sat, 29 Jan 2022 09:55:21 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm5423654qkf.30.2022.01.29.09.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:55:20 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v3 4/5] examples/fips_validation: allow json file as input Date: Sat, 29 Jan 2022 12:55:13 -0500 Message-Id: <20220129175514.746925-5-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129175514.746925-1-blo@iol.unh.edu> References: <20220129170313.489986-1-blo@iol.unh.edu> <20220129175514.746925-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 --- v3: * fix checkpatch warnings v2: * remove use_json variable examples/fips_validation/main.c | 195 +++++++++++++++++++++++++++++++- 1 file changed, 192 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index dc40bffe7d..6a6794fab1 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -39,6 +39,10 @@ enum { 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; @@ -169,6 +173,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) { @@ -428,8 +437,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); @@ -484,7 +502,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); @@ -1226,7 +1254,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) { @@ -1245,6 +1274,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); @@ -1260,7 +1290,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; @@ -1856,3 +1887,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 Sat Jan 29 17:55:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106719 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 0C4F6A00C4; Sat, 29 Jan 2022 18:55:44 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C522041157; Sat, 29 Jan 2022 18:55:25 +0100 (CET) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by mails.dpdk.org (Postfix) with ESMTP id 92DB240041 for ; Sat, 29 Jan 2022 18:55:22 +0100 (CET) Received: by mail-qv1-f68.google.com with SMTP id d8so8864033qvv.2 for ; Sat, 29 Jan 2022 09:55:22 -0800 (PST) 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=HhV+nhzoXkgvP3wYCuIKQ9G29915TRTYDyslJAMrpBY=; b=KfMjLWzL5dAzk+W087Gsr3QeAsW5mpVBHEgqPj/k6zIkTtPq255q+H9sGARAOuZaMP T5louN+H0Kn0u3RKVzKcdl9JivFFeYxzv0GXGuice+1JpmC9hO0gmB+SPZmyWsWvP4jA KxZQI4hN3L4aIykuNPOwZaQdQMHZz8190U84Y= 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=HhV+nhzoXkgvP3wYCuIKQ9G29915TRTYDyslJAMrpBY=; b=z9Egjeq27DrYCfrzaa5i8AFJO1wz/ijpoGFNCrCHNsA++yRYJfdwEXV42x003Yt51L 6pAuDGlpywW7Hy2to2kza57hWmTu7VQBie/GzECcU9PtVGb9/3nvbc557xtvxLSUS6r2 pxXQ72KxE74CC1fQFeP1jcC2tFno3xdeURkxYsToUE4PWNX12Ij3EgybTm03y3Imnvq9 lLngf9DtcF2RuQpDgXnrHbGbgY80liCC1fxagvn13v/mjr3NsVWltroC7AtsMejLXH92 HB0N2g4xZKCbn1d8ih0jtTVINu5AXW+wfKNo9y2DuBOQkwEoesBmHmdso4rzqUk6Eu5Q T41w== X-Gm-Message-State: AOAM531Qr2r53BDq71Dl5IgeUwcvzVdbxA1I9vihR4/ASG38DKMtWSBI MuLn5sB33ezek2VgQeP6v30aoA== X-Google-Smtp-Source: ABdhPJytrcWnGpkVxwqRakuXF5EMIMwQbZchjL51PgFHfJB850r3NOGxb/P+ngw7iYW7hR4cOMMyXQ== X-Received: by 2002:ad4:5be9:: with SMTP id k9mr11477874qvc.45.1643478922068; Sat, 29 Jan 2022 09:55:22 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm5423654qkf.30.2022.01.29.09.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:55:21 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v3 5/5] examples/fips_validation: add json to gcm test Date: Sat, 29 Jan 2022 12:55:14 -0500 Message-Id: <20220129175514.746925-6-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129175514.746925-1-blo@iol.unh.edu> References: <20220129170313.489986-1-blo@iol.unh.edu> <20220129175514.746925-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 --- v3: * fix checkpatch warnings .../fips_validation/fips_validation_gcm.c | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c index 250d09bf90..5c72dbf790 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) { @@ -188,12 +247,103 @@ parse_test_gcm_writeback(struct fips_val *val) 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; +} +#endif /* RTE_HAS_JANSSON */ + int parse_test_gcm_init(void) { char *tmp; uint32_t i; +#ifdef RTE_HAS_JANSSON + 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) { + json_t *ivGen_obj; + const char *ivGen_str; + + ivGen_obj = json_object_get(json_info.json_test_group, IVGEN_JSON_STR); + 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 */ for (i = 0; i < info.nb_vec_lines; i++) { char *line = info.vec[i];