From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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) { -- 2.25.1