From patchwork Thu Jan 27 14:51:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106608 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 99563A04A6; Thu, 27 Jan 2022 15:51:55 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0C538427E5; Thu, 27 Jan 2022 15:51:49 +0100 (CET) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by mails.dpdk.org (Postfix) with ESMTP id 425BE4067C for ; Thu, 27 Jan 2022 15:51:47 +0100 (CET) Received: by mail-qk1-f179.google.com with SMTP id o10so2833253qkg.0 for ; Thu, 27 Jan 2022 06:51:47 -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=hL228ueAs4fVSu28FfgiM5PO8iVj04hXVtisv3j1uj2mm88F5IGUDd1TQGPQQaa4hJ X3wZywzkFOp5nuYlu3G8v3Yt3GSUM/1nrVQvtLTJjGczXaCf79FyKmQTzA5ujnkZNIS3 2sWnua/5QVso4p5Ea2blwjoZmHtUkN7ZLYe8s= 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=RhE0e9CupGtBtGUvFNFzQpUbGXIzyUM49PJOt716mYLyI4aGHh5rgifehCFX2YRHzv 3PuAw1Rd6W0IT4T2szxwDQXgfUVePTKNS3vD9/Zo/uSEZ765O6BNh91lMcv81WPCu+D7 pifvlfvOJYbwaTVU8cODb3BM7RzKegEJMSt6CsPniWLfVfbUqf3hXY0+XtqCj9W3b5I+ WGibLQZIgDMZeCT894b0bAqI821adNBGH76y79XUhlKMC0qKmAMJsW1NvimO5WaDkszL nnVvEP6lfyj8fxpRPNjyygOiJeAc08aRc6lzNpZeBCuR3Wk0gkZ7zT8NUhrmlamucF/z Kdaw== X-Gm-Message-State: AOAM530ovOYivZigtPmc73vPcj2moJOlCDveC+VvdJlzRcGeIDHl+TQY B3c/v5W/d/SQp4IMbovgNcyhFyEGHEhYgjKR/qG789573bePLsLcUm8oOwkH5VH1V9MXLNc7rSZ 50cyZfcW+b7GOlY8Ivcxu4hzKoZMEB4riPgIjcFS2I3paPnRdvQA= X-Google-Smtp-Source: ABdhPJy9yJbcaTMj2LrbM3rFOhn1Jnq/TTqQOmn7r0YO1Bm/lZ3+PBizf8ApdIaDXKCP8CraLGH+DA== X-Received: by 2002:a05:620a:16a7:: with SMTP id s7mr2796973qkj.700.1643295106302; Thu, 27 Jan 2022 06:51:46 -0800 (PST) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm1507324qkf.30.2022.01.27.06.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 06:51:45 -0800 (PST) From: Brandon Lo To: dev@dpdk.org Cc: ciara.power@intel.com, roy.fan.zhang@intel.com, Brandon Lo Subject: [PATCH 1/5] examples/fips_validation: add jansson dependency Date: Thu, 27 Jan 2022 09:51:38 -0500 Message-Id: <20220127145142.86742-2-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127145142.86742-1-blo@iol.unh.edu> References: <20220127145142.86742-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 Thu Jan 27 14:51:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106609 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 34D69A04A6; Thu, 27 Jan 2022 15:52:01 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DA19C427FC; Thu, 27 Jan 2022 15:51:49 +0100 (CET) Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by mails.dpdk.org (Postfix) with ESMTP id AE8BB427E5 for ; Thu, 27 Jan 2022 15:51:48 +0100 (CET) Received: by mail-qt1-f169.google.com with SMTP id i4so2702714qtr.0 for ; Thu, 27 Jan 2022 06:51:48 -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=Ga2+F2WdhQPGQa6+n0WhdVmssIAHFiGxO5U5ZDENIFw=; b=LaF38sIZvKHeA9wyDqtibenOyz1qZ6Amg6bkBPXR7aICubJD0lpiHzxpM8sphsZkKR tkxkNtwgFCiDFp9oVzGZ6KkKqH2UroVll5gnj1QgP1zw9+h3mk7S5c0eeGrT7zC6gzWR iV2EJ7m6mVPXkrEYkW+eLOMgqNDANuyazn8BI= 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=Ga2+F2WdhQPGQa6+n0WhdVmssIAHFiGxO5U5ZDENIFw=; b=jwY/k6/427cCNUBhfz/qNEGEj3mtZ0IYXbiiLEY6vpWb7EKmlDlm5JjCnM7lcyGud3 2LJZFZaR6mimggNMOsJvoaocUQBsy1w9bpTspwdrWT0bQq+AFRz83kQOqiofG5rOaiNd YM//a4xX5Gkz5m0aQY9yhtG6QfHXyaER2G97bQweVL4LLancD5UyHQFpFELMVNgTFCij BZT+lEfgyjPrRl2Lx0BgJZZtuOgYM5L595NLbgzh2msxZyOtTqCF1cUwA1xPk2dGsLgn QESpWviNrTx6wGEpH6UNcpNltnUgBVQ0onvjdhyrRDrFqLTQ6mwNGe2CC7JkN5XO4tSE EjUA== X-Gm-Message-State: AOAM53057ce/aNi55QqwLEY4w57lGJEwC4RdLbI/aQMfkO32XH3Fsyc3 l3MxJa7VP8HwVpn60FDsxHxHM8rr6BAdIJEqKlxQqPyE69Vm75GFSKJI8ZN5V7zn3OUSHomASwj IPqrv31RR3pEzB5zN5Yr4TvVdIXU4lXN1RopU0T5mkkaI18psCQI= X-Google-Smtp-Source: ABdhPJxztAoiVKIrSreH6sAhGejBuu/azd0ZiT4fkLzdcPrfizn9ND5cjxKaDXD9tSeDpPj34ZSCvw== X-Received: by 2002:ac8:580b:: with SMTP id g11mr2953817qtg.457.1643295107540; Thu, 27 Jan 2022 06:51:47 -0800 (PST) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm1507324qkf.30.2022.01.27.06.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 06:51:47 -0800 (PST) From: Brandon Lo To: dev@dpdk.org Cc: ciara.power@intel.com, roy.fan.zhang@intel.com, Brandon Lo Subject: [PATCH 2/5] examples/fips_validation: add json info to header Date: Thu, 27 Jan 2022 09:51:39 -0500 Message-Id: <20220127145142.86742-3-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127145142.86742-1-blo@iol.unh.edu> References: <20220127145142.86742-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 --- 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 Thu Jan 27 14:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106610 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 6BA22A04A6; Thu, 27 Jan 2022 15:52:08 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C012F4280E; Thu, 27 Jan 2022 15:51:50 +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 30153427F1 for ; Thu, 27 Jan 2022 15:51:49 +0100 (CET) Received: by mail-qk1-f174.google.com with SMTP id j24so479996qkk.10 for ; Thu, 27 Jan 2022 06:51:49 -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=5URAumc2UC6Pu6qU7j82NQmtqD3G6iW/jCuZjpr8cdE=; b=VYx/f3c58vaa4a4BqkZ1X87suUCjInCt3CW6m1NYipyXAsyHJlptxQNR8JMr3DWLeP siDaZw8JT5+kMELgb+vA/IpOFMVCsKUzVb+kKL7T+k5R8HHLC26QExnV/hDgobc712Ne XCSZrxKIZfGmkM5uMk3bDd7gG6nei7Kww5keg= 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=5URAumc2UC6Pu6qU7j82NQmtqD3G6iW/jCuZjpr8cdE=; b=qYyGNQVAM83uQUlIVSRTHyAnMZKTCmE1oa1qksdM/D1ojN1oTopP99BTV+vsdgnoFA 7YtYHxKyNgqtjCEV1Ih4Whz4X0RK4rqnvfxfrH+/R3aDyz+DWwugM6Qm1MCxBMj5j+Gy 3hNsRNRzcEJpGFaDGOdxvCx/wUQcmYyVtFGYV/rusnX2Q37A3gvytsetFSTmKT/XdJg1 azHMa9n2+06NzbltkoHdPvgXQMVK7vgoAAkYAK/xCC5EPOzzCVlXoI6GVhOKsxNzUcpu /oXyB8ol9KvOuiBsKUS9sE8SJ6KA3qnZ0qz77Bc91vZ/aB+7OQ5LEkamM5xSj6qr0PpA HR7g== X-Gm-Message-State: AOAM532+sC0UIqFTfdl3qH5UGCTMifeXwO5en77/uTBHrN0IG7Yxyeu0 Ag9Wo3Vk7l+A75DREXgWaBgbIFjbwp8yU+ZKcCVjB6uuSqkhpkJD7c/ClZFnD6RwumSyjuBNjr5 dR9BwrZtNhu7YrNjWjDnBpkx9jbudbtguDFxZJYPefChnqu+qb+w= X-Google-Smtp-Source: ABdhPJx2Boennx/0fMsyu9BP7eV8fV54/2g0ElMUCiappUgK+2FAXnJQeloAPRkFA/0sVIFiswaOgw== X-Received: by 2002:a37:b201:: with SMTP id b1mr2829221qkf.370.1643295108330; Thu, 27 Jan 2022 06:51:48 -0800 (PST) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm1507324qkf.30.2022.01.27.06.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 06:51:47 -0800 (PST) From: Brandon Lo To: dev@dpdk.org Cc: ciara.power@intel.com, roy.fan.zhang@intel.com, Brandon Lo Subject: [PATCH 3/5] examples/fips_validation: add json parsing Date: Thu, 27 Jan 2022 09:51:40 -0500 Message-Id: <20220127145142.86742-4-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127145142.86742-1-blo@iol.unh.edu> References: <20220127145142.86742-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 --- examples/fips_validation/fips_validation.c | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 52a7bf952d..40254a9181 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,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; + + if (info.interim_callbacks) { + char json_value[256]; + for (int 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 Thu Jan 27 14:51:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106611 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 E154DA04A6; Thu, 27 Jan 2022 15:52:16 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB84942824; Thu, 27 Jan 2022 15:51:52 +0100 (CET) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by mails.dpdk.org (Postfix) with ESMTP id 09C4D42807 for ; Thu, 27 Jan 2022 15:51:50 +0100 (CET) Received: by mail-qt1-f176.google.com with SMTP id g12so2610219qto.13 for ; Thu, 27 Jan 2022 06:51:49 -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=5dPqdn2ivva1M8IJ8Ne8TykR021/m3X5V6a50Esek/s=; b=O7R5yLYT2I4f/o2e1AGqyASHSRWGuRkJLmHbuKcOJ9W0VFeCyjkWGRAcaPQ1vAOUWC BP0jZM8aiYuuty2jdLxWCf99spjgCZP1OIFPF0XcOBeBOZ9QzRCIUlfQ4USbxPOBcyJw w0yb5cI9Pti6onGODvm+/XoRSO9V7eTIhQFpI= 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=5dPqdn2ivva1M8IJ8Ne8TykR021/m3X5V6a50Esek/s=; b=1lkHgg4jf2rPODbiOg7vyrRYy34NvnoOK32aBq+zJHDon61FiU3QohxSbfukISlPNw EbtUTgVUi/TPAc1qzLhanNxLgQpA9jSpV9oc4sDvcGSxqrGEJ7w157rwQ7vdg/gd2McI 5Cd+AtqM76nFKXVX3cUzo1zfIf2Cae+l6qn23ZsDqP2JyAQmLXS7w1SqjPKFeEV3KIot 9rA+Npix3NxcCENbueWrNm+FZRx6BYrjAqC7A1stvnAJtrnOUR1Eb3HTLK73MUbMXAhI BKVipvx1OEsFnmXpH6j9wN/yx6I1d/czObRQ20iIr4vZUd/T3GDdVjIlmhY6OSx76cA+ mAaA== X-Gm-Message-State: AOAM530t7ge08rTxdqA97pBCnQIXk1PVIwcUS0Pzf4qwoHlQFJgZK/Aw 3eleZiItNom3djjB2msmM8WiPUtm+/vyCuBPM28P6keV2c4ObpWUGOXVZ63jFoMxskKVuRG3pQ1 7MF/D0MTh4J5+3lOho53Fz4j5EUaMctAHeZO7ZTt0J9XvnAxiBVY= X-Google-Smtp-Source: ABdhPJwen9++2lWJp3m3m+dOtJVW97XJqL081q64TXcKYZMWkAuUx7LSOgsJqVALS2qDZvizd99JNg== X-Received: by 2002:a05:622a:1788:: with SMTP id s8mr2947862qtk.344.1643295109144; Thu, 27 Jan 2022 06:51:49 -0800 (PST) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm1507324qkf.30.2022.01.27.06.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 06:51:48 -0800 (PST) From: Brandon Lo To: dev@dpdk.org Cc: ciara.power@intel.com, roy.fan.zhang@intel.com, Brandon Lo Subject: [PATCH 4/5] examples/fips_validation: allow json file as input Date: Thu, 27 Jan 2022 09:51:41 -0500 Message-Id: <20220127145142.86742-5-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127145142.86742-1-blo@iol.unh.edu> References: <20220127145142.86742-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 --- examples/fips_validation/main.c | 192 +++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 3 deletions(-) diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index dc40bffe7d..40d0d10ec7 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; @@ -169,6 +175,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) { @@ -392,6 +403,7 @@ int main(int argc, char *argv[]) { int ret; + char use_json; ret = rte_eal_init(argc, argv); if (ret < 0) { @@ -427,9 +439,16 @@ 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); @@ -483,8 +502,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); @@ -1226,7 +1256,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 +1275,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 +1291,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 +1887,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 Thu Jan 27 14:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 106612 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 EE5BFA04A6; Thu, 27 Jan 2022 15:52:22 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DABD742830; Thu, 27 Jan 2022 15:51:53 +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 DF8C742813 for ; Thu, 27 Jan 2022 15:51:50 +0100 (CET) Received: by mail-qk1-f181.google.com with SMTP id o10so2833437qkg.0 for ; Thu, 27 Jan 2022 06:51:50 -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=U74Tcgn4U1FdNQpFcewrA2TMkqjNrv9jKKRM5ww9HTv6ov//dUSzD2LpAqWyUsRQ9Z uhl5nkQ5LHNYGi17nTN7OxFblzf/TfexcwD9VZ+vDf5Fca66lqq8Vbys7lgq9jHTyaWx l2Hsc8nwslQWjqBbWj82CR6MCR0Sd2tEmP5/o= 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=nd+ZCH26CoaiTh208+O9ok1MNulijGljUscri+TSn6ngaoLclHGkMxphKBRJ1eXNra nbmi98HUK9dP0NnR+7O2Qa1IPfnD9pI42FzPiRn2DyGzpAwF+fVr0VjjisZl8w7Lx+e1 r+xsjhm1d16lLrNodqVsciBfnYJWPPClEf3F5beA3fMakw6au5B8u6meofWdF5URwoRn wBTECzK6BkjgoqcnupBugPd5iQ6xCd8yQH6Wc/vAm5gxM3xPl5fE7ZXJKD9Lf/ky1kCp QPtZ4jpd0O20rWpNm50rJagiUjVzwqIcNWNcTBbKJQr3sA4EER6hpeqHEqLIjzf1jqju iVIQ== X-Gm-Message-State: AOAM530a0pLz2RGEEdk7SGjnMLPtrnOPm54Y/8V+N0bNbMWkJO2+kEv1 XueLVZTndKgs3ZqPBwaFrEDk4Nwp7CvisDIcuXiMG4EPHXFwZ3CIz+NPbvJEsQl+m4fIeGP5n57 sGgh9AV6m1R54q36ji+OnIAqEuLTPN8/MQ7CGhpQLdMvlEFvI4zU= X-Google-Smtp-Source: ABdhPJyWuOZ+OPwholoS3pOTQ37VlH+jyEIiikt6Rvm76y+gzH6tRkKNYfPuq3/1jHvVye+7Wl2nSA== X-Received: by 2002:ae9:e50d:: with SMTP id w13mr2762412qkf.404.1643295110063; Thu, 27 Jan 2022 06:51:50 -0800 (PST) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:8f3:b5b9:6ccc:8a5c]) by smtp.gmail.com with ESMTPSA id 195sm1507324qkf.30.2022.01.27.06.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 06:51:49 -0800 (PST) From: Brandon Lo To: dev@dpdk.org Cc: ciara.power@intel.com, roy.fan.zhang@intel.com, Brandon Lo Subject: [PATCH 5/5] examples/fips_validation: add json to gcm test Date: Thu, 27 Jan 2022 09:51:42 -0500 Message-Id: <20220127145142.86742-6-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220127145142.86742-1-blo@iol.unh.edu> References: <20220127145142.86742-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];