From patchwork Sat Jan 29 17:03:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106707 X-Patchwork-Delegate: thomas@monjalon.net 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 3DD17A00C4; Sat, 29 Jan 2022 18:03:24 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5DE3540DFD; Sat, 29 Jan 2022 18:03:19 +0100 (CET) Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by mails.dpdk.org (Postfix) with ESMTP id 6185140041 for ; Sat, 29 Jan 2022 18:03:17 +0100 (CET) Received: by mail-qv1-f49.google.com with SMTP id i19so8727845qvx.12 for ; Sat, 29 Jan 2022 09:03:17 -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=XyGL6iWlDMTBm8j5uk9ypFcDfb/rm/zs8bbBjYzmPpfw59pFvKqOQn7O3GHyWYAR/o ELQrilerTTopc28io9WiP2dMEJydxmL/7w6pBKVMggtZWVXig1NTxuz3EgZRiukCfJQW 3tLPMtOYAibtrF9zbMKzimoLtiWop5UAKhkWw= 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=6JISkvLsjwBE7717e1DvPc+gS5W/xGMXafrQ5EOV+G2fSeuwZreAXVctvf6LKw4xzf Tj30/Rwm/xBpstw38ebXVIEI7V+51Gvvrh+aRQqlY2zDkwvpgDwgXsk+xAZYNESR6cAM n4wg94RgWEvQDg0PzwQk83h1uLiQTwZ1OcRFT6STsVpeNrqjGuLgXHfdHj/OA1O32kTP 7S2+LmMTrF25UXM0t8zUbAShdtwyRK9QhvD9WyrXrJ435iJCX2JHCjAmV2csz8484YOK 4ckAgN8nWmhs4P+8OkuOUzJ6ruV78bAkvkXHsFpXSLb6rG/moQOOm+pjqZg9hEFWoY9p sq2A== X-Gm-Message-State: AOAM530/wRDQNC09JXxIlZE4bUrH62JjSrPdK6jvxS9wpVPAA30Oi9Rh NUIGKxqR3MK7wBLqQ5b9sN5RTAVv6QpTkSupR5E= X-Google-Smtp-Source: ABdhPJz5NExB0Vy5IjllSHtCn0a/WitiF4AtTf+KajFIuGsrNcE+xq/55cuAFA772nwTJ6cipIoq9w== X-Received: by 2002:a05:6214:5294:: with SMTP id kj20mr11603239qvb.111.1643475796840; Sat, 29 Jan 2022 09:03:16 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id f9sm5411879qkp.94.2022.01.29.09.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:03:16 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v2 1/5] examples/fips_validation: add jansson dependency Date: Sat, 29 Jan 2022 12:03:09 -0500 Message-Id: <20220129170313.489986-2-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129170313.489986-1-blo@iol.unh.edu> References: <20220127145142.86742-1-blo@iol.unh.edu> <20220129170313.489986-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:03: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: 106708 X-Patchwork-Delegate: thomas@monjalon.net 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 67779A00C4; Sat, 29 Jan 2022 18:03:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 23F99410E3; Sat, 29 Jan 2022 18:03:21 +0100 (CET) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by mails.dpdk.org (Postfix) with ESMTP id 7E39F40041 for ; Sat, 29 Jan 2022 18:03:18 +0100 (CET) Received: by mail-qt1-f177.google.com with SMTP id y8so7846168qtn.8 for ; Sat, 29 Jan 2022 09:03: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=6rkXOfM7b5MpQ/9vS6B3jjlMIKMhW2oqul/I7EKfcSc=; b=JbE9gPHDsZ78iuxH7KEptUZa3v961Zc3SNT1+6tHVwq95yJlnJN7s9QCq4USRQIYrU YDqJQTLAF6znjKu0+yV18qFe3w38OTFeeQEx2cULb5BFz3KgduKDGIi+kXnq+l956R7x ZqpPUtqvJ8C3O0y+sR1mAyST9r3vSwF3dE/wA= 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=6rkXOfM7b5MpQ/9vS6B3jjlMIKMhW2oqul/I7EKfcSc=; b=1nAQb2SZu8qqF5iL7CeQKRA1l9mFRcaLUzFmIha6EJcvv6ak0T+yfaj5b1uJg19kmq vokdzp6e8dZK3W/LrnmMBLzaIiPN8xjxIsNLtSS4Pq8M10RTZucevFt/HDEh1T7az4ha /C5DMaCufeLPpss2HIHr1bg1yJW2jZb8LbqnoPeUTuyn6+K2nQ++8HdExPwXbWOy6nby 9o24Nd5+gnHKpxhHf+gl55fp3m0QpQFQQOiSTzrUPV7kPVqzRFU5ZwiBA2dhOmJDtKuo kqO5MluYU992lLBDMoR8xTdvdfhwrIDtarqCH967gReegP6M9WFdgeapEenW54bQxSIK mn7Q== X-Gm-Message-State: AOAM531xTWQv4qOlrbe954yhS4Ic3ulyLrHe1TqvtfKP2F1SVoS3jgYw wiivDrzTRNVtdEjBiksn7bvSlQ== X-Google-Smtp-Source: ABdhPJwPVXoUhq0as0WqXvzrLEPLb7su4uRpLRlSrNCXoOU/DUOopEoV82cMvH+OIcJRPtwIpuakug== X-Received: by 2002:ac8:5f0e:: with SMTP id x14mr328104qta.612.1643475797934; Sat, 29 Jan 2022 09:03: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 f9sm5411879qkp.94.2022.01.29.09.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:03:17 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v2 2/5] examples/fips_validation: add json info to header Date: Sat, 29 Jan 2022 12:03:10 -0500 Message-Id: <20220129170313.489986-3-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129170313.489986-1-blo@iol.unh.edu> References: <20220127145142.86742-1-blo@iol.unh.edu> <20220129170313.489986-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:03: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: 106709 X-Patchwork-Delegate: thomas@monjalon.net 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 017FDA00C4; Sat, 29 Jan 2022 18:03:36 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20B5A410F3; Sat, 29 Jan 2022 18:03:22 +0100 (CET) Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by mails.dpdk.org (Postfix) with ESMTP id 6571840E0F for ; Sat, 29 Jan 2022 18:03:19 +0100 (CET) Received: by mail-qk1-f181.google.com with SMTP id j24so6039270qkk.10 for ; Sat, 29 Jan 2022 09:03: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=hwcYX4lJA6/XOID/5tWwgZ1VPVelIB/PLcuK90R4zug=; b=LVuMcNmorCdGWPZcr5Jw2iFxjar1432D1C8Ube1+XxNKd9thCfm+I0W4o5u3hjPmNH 2FFedqaxK3zxfHcHRLPnIcV6Ii26MCp1RFtM0ITsuyjLJsbG74GHH8CJYMyy6uoNwn0t 7YUCggp53FH3fQTvpioFg1AB+NUwZjjkPa6VY= 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=hwcYX4lJA6/XOID/5tWwgZ1VPVelIB/PLcuK90R4zug=; b=M+CzV1yylEHJFGoi3m3tYDr07W/nGB01PbkBkg/gLJDmKeeU/R/kIby6TTEM7SHv2v kpKqtaHce6fOx2HfLAJuL1EsGAWYWA9dhZHz6P4KUmrdLfpFhopmJncNi+mA1wEdRpXz vIFV+q/kS8aHxtgwyX2fbQniCWolZBjlHMrmltBWcIbxMGme03sHB9XsnmlrOtjOTzFM 7mE1FiVk1lJBn5+5RXHAbJp0Tw+ELfjaLi9Cd3W0X3RQlCNG8FeFY7qRsWOfKSVr6Hl2 eV03TD/rNnLAXhWLcoiwyFH/R4xNPPNBsFswDZu4+rW28V223YpC9cH72LwM1IKGUJdl U7Uw== X-Gm-Message-State: AOAM532Dc5NDH0t7EkzeaxWnUaCjo1Lb/n9nrJoVmAVaeiCxHLbfHihh qMSA70t3Z/Rw4XfZ4yTRALV7kA== X-Google-Smtp-Source: ABdhPJy23d22EfZdd+gx/ZFDiNwKF3yUih5BJ/tSaUmu9bcVsOJ6xMlwlLr06JsXqAS8gpm+auNo2w== X-Received: by 2002:a05:620a:1511:: with SMTP id i17mr9227979qkk.77.1643475798813; Sat, 29 Jan 2022 09:03: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 f9sm5411879qkp.94.2022.01.29.09.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:03:18 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v2 3/5] examples/fips_validation: add json parsing Date: Sat, 29 Jan 2022 12:03:11 -0500 Message-Id: <20220129170313.489986-4-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129170313.489986-1-blo@iol.unh.edu> References: <20220127145142.86742-1-blo@iol.unh.edu> <20220129170313.489986-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 --- v2: * fix for loop initialization examples/fips_validation/fips_validation.c | 90 +++++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 52a7bf952d..6f83cb7fc4 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,8 @@ 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 +448,71 @@ 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); + sprintf(json_value, "%lld", 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:03: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: 106710 X-Patchwork-Delegate: thomas@monjalon.net 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 24AFCA00C4; Sat, 29 Jan 2022 18:03:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F1824410FB; Sat, 29 Jan 2022 18:03:22 +0100 (CET) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by mails.dpdk.org (Postfix) with ESMTP id 84E9C410E3 for ; Sat, 29 Jan 2022 18:03:20 +0100 (CET) Received: by mail-qk1-f194.google.com with SMTP id w8so8318319qkw.8 for ; Sat, 29 Jan 2022 09:03: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=miDU6fttI/TUAG4yupVdJGmJmq9eD8wG45sMpfV2ur4=; b=OflZrFj0lpsmADhcr1mdc861aWJdw/OBHCllpvapfRdHYh8QLd+WsBHQd/niOagvFE Egr/sHLYfZ1hg+zJiAcFbEIekshO4LONeUZYAivWXYQy6rXUt5ggE2JNKqZgWmgctaEz A+dvBpj9FV1C2RzAkArxIPIPAuJv8wuUYsuz4= 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=miDU6fttI/TUAG4yupVdJGmJmq9eD8wG45sMpfV2ur4=; b=yxIv8SKjfYDkp5G3PpY5iuMqt3zKjDEbn5xinYa5cEHspbJQLlnt4h+gFQX7y4e8ZX pUymTaNFY0YeHeu/uYhmIOF9OCRqKhqHIg/rDVQIisULQSoO7X6C6uHJekKMZ4qUsC2W t/IMWoZSMPfwfWDz8Aj8Qi8XbGpWOyiP0qPKa/DQ6C6ADr/F+J/zRUopJvYx9C8Uuh83 SOryxwGUDCl5I0uMWhUkRA/Ws68yVEquUR4QXjDslukdw74FwwVQEUUr0epfN/6ra09U 8zUB5Snvk9+PoZgSOSs6Wc5s7juu23a+ae4cAyEMg7pn+Ira81EXLxVewD+nRz1Ay2Un vZbg== X-Gm-Message-State: AOAM531wL2ncHhccDbhDGkFaxkpCFdaV9A2gnz4jwU6VL+Uk83MbdBpJ 1vW37YExpSvLYAz+H0KtrkvAOQ== X-Google-Smtp-Source: ABdhPJzNt+8VVeic2Za8BkhsvHDBlNI9hEY+C1cBwYMSfHKJMjkEdJP0MmqskUZAu9gOHWbXndT72Q== X-Received: by 2002:ae9:e850:: with SMTP id a77mr9042318qkg.239.1643475799963; Sat, 29 Jan 2022 09:03:19 -0800 (PST) Received: from blo.hsd1.nh.comcast.net ([2601:187:807e:37c0:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id f9sm5411879qkp.94.2022.01.29.09.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:03:19 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v2 4/5] examples/fips_validation: allow json file as input Date: Sat, 29 Jan 2022 12:03:12 -0500 Message-Id: <20220129170313.489986-5-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129170313.489986-1-blo@iol.unh.edu> References: <20220127145142.86742-1-blo@iol.unh.edu> <20220129170313.489986-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 --- v2: * remove use_json variable examples/fips_validation/main.c | 190 +++++++++++++++++++++++++++++++- 1 file changed, 187 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index dc40bffe7d..2f82c7a541 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,7 @@ 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 +1273,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 +1289,7 @@ 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 +1885,158 @@ 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:03: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: 106711 X-Patchwork-Delegate: thomas@monjalon.net 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 ED847A00C4; Sat, 29 Jan 2022 18:03:47 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 340454114A; Sat, 29 Jan 2022 18:03:24 +0100 (CET) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by mails.dpdk.org (Postfix) with ESMTP id 8248940DDB for ; Sat, 29 Jan 2022 18:03:21 +0100 (CET) Received: by mail-qk1-f195.google.com with SMTP id o10so8387839qkg.0 for ; Sat, 29 Jan 2022 09:03: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=knO9ZofTXTekSQS12//DUOk0MLH+na3txgS57wnEIns=; b=i/czErq8SX9p9QgdW5ZAjLeWNd+4xtJv+Wdv+M0weQoBrdA3eK9PhMuH8hWwt1xGIJ 1FhzlQXHsIZIQCdXuqsH8Sb5xRoj05xmiJhEyaEZoX6XATWIooPFPCOAMgkATJ9RugJM fCLtIDQrhPl5KhmAaTeKFrg92NGlQE0CO5MyY= 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=knO9ZofTXTekSQS12//DUOk0MLH+na3txgS57wnEIns=; b=FUK9MQHSSbz7amm2uwvYkqfCnLueMix7lQTNG3qQ0MJ8owoTNESbTN5k2P9DfprwLa h9ZC9uaJROqk30v4S3l8MSjqcce5xixk05I3nW/eDrgHptNNOPjUqhFLnUji2pnH/pjh CX4L55+gZWH6hrzl9UDh+Pdrd20qCajBYmiUWCl3xFB3jXKjytIMwjRu6ljxu0JFF8uY HHWBKPaArIo1vcy5i9ut9zvRVP+VnYa4dMNBnT7kZpWl6Zsl5U2v//kSj2b/HRvPtTSv 92WoO8jOqCtqcHFVhzc40izbMLnZ24iLHROGqeOE1acFYPm8hMvreEnrgwhi0AydcsP4 18Pw== X-Gm-Message-State: AOAM533rHaQXgNohBvIw10ftcpEqbK0e4RY+qgBBZ/PtBCiHmfaI8/Xo cphHj70jVFwg7P5YszBPbzLl3GgYVUsrXOgP3bk= X-Google-Smtp-Source: ABdhPJxsmS20giRrGcTnMVZvzIe0/d/g6619oIzEkg47DkricRYk1pyktqco9QEy9lJfZeNSCrVKLg== X-Received: by 2002:a05:620a:d42:: with SMTP id o2mr8433257qkl.51.1643475800957; Sat, 29 Jan 2022 09:03: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 f9sm5411879qkp.94.2022.01.29.09.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 09:03:20 -0800 (PST) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v2 5/5] examples/fips_validation: add json to gcm test Date: Sat, 29 Jan 2022 12:03:13 -0500 Message-Id: <20220129170313.489986-6-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220129170313.489986-1-blo@iol.unh.edu> References: <20220127145142.86742-1-blo@iol.unh.edu> <20220129170313.489986-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 --- .../fips_validation/fips_validation_gcm.c | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c index 250d09bf90..4df20370b6 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,102 @@ 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 = 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 */ for (i = 0; i < info.nb_vec_lines; i++) { char *line = info.vec[i];