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 D2952A04FF; Fri, 29 Apr 2022 18:16:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D78F4282F; Fri, 29 Apr 2022 18:16:08 +0200 (CEST) Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by mails.dpdk.org (Postfix) with ESMTP id C04014281C for ; Fri, 29 Apr 2022 18:16:05 +0200 (CEST) Received: by mail-qt1-f173.google.com with SMTP id p4so5557484qtq.12 for ; Fri, 29 Apr 2022 09:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vYACZHkBG57qbDzvpGr47m7X+Om0OW6b0K4jZpDxuHQ=; b=b5pjXMbWh3pJYWh3a+pczI6CEgJOZxYHp+iSbRfrIYKtqxI6LiQR47jkmdSwa3n+tk XkEiwDYxlUh9QHZ4+7TY/TODoF5M+vbCbGS+0vb/h9rsmLBEPaztmvDlxewQrA+irGde 6EPUJi+y4+tGRP4Isbyp4NvAIm9vb0PkbGYeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vYACZHkBG57qbDzvpGr47m7X+Om0OW6b0K4jZpDxuHQ=; b=EsWukRdQr8iknRYzdGFIosSyVVJAm79TnQZ+vIXc4vY3uasIPpZ41Yy3vzmpu6v4wZ tCha9EfLrOqH/cES+SMpfGgUzBBsGyxnhq9KwFY8cqWL/skYwYOrMLTUqKmazXb+KXaz ws2tEsmz9xTwcL8lDuhZuvZ/NxjIxU2kD/ltJkf7IuLsWRVlv2o0Xhrv3jVX+vZ4SUFq 08f9nMTHMmMMrmnKtP5sjXYdFI+LdeZz1g4OjsbUEJs9xpYS5SKRNSnKZkMANkCto85E aaagnY0iYsOSudwFMP5GzBUImkwLq0CIEAd39oNw/teS7n6ka8ojFVuuTC1iDMhTFg7U GZGA== X-Gm-Message-State: AOAM530RpeE8T5DkYD/Su3NWjmzi/A1WUTILDnB5jwyt+IZ9VCuRGo1v zO4zQogeZE08wCZq9dHYTDAqVQ== X-Google-Smtp-Source: ABdhPJzjBPNHQi2YRBHnJu6DWmwZ0R3y9GLl8I/VnfhOjzoL875K1OgUhNxI7XGBaGVNxFdxk9niiQ== X-Received: by 2002:ac8:5cc1:0:b0:2f3:86e0:c8b1 with SMTP id s1-20020ac85cc1000000b002f386e0c8b1mr139227qta.99.1651248965219; Fri, 29 Apr 2022 09:16:05 -0700 (PDT) Received: from blo.iol.unh.edu ([2606:4100:3880:1270:ec49:26fa:daa6:229d]) by smtp.gmail.com with ESMTPSA id k20-20020a05622a03d400b002ec16d2694fsm2081188qtx.39.2022.04.29.09.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:04 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 3/8] examples/fips_validation: add json parsing Date: Fri, 29 Apr 2022 12:15:54 -0400 Message-Id: <20220429161559.415645-4-blo@iol.unh.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429161559.415645-1-blo@iol.unh.edu> References: <20220129175514.746925-1-blo@iol.unh.edu> <20220429161559.415645-1-blo@iol.unh.edu> MIME-Version: 1.0 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 | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 94253eaee8..d220dcab1f 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -276,6 +276,8 @@ parse_file_type(const char *path) info.file_type = FIPS_TYPE_RSP; else if (strstr(path, FAX_FILE_PERFIX)) info.file_type = FIPS_TYPE_FAX; + else if (strstr(path, JSON_FILE_PERFIX)) + info.file_type = FIPS_TYPE_JSON; else return -EINVAL; @@ -311,6 +313,21 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) { +#ifdef RTE_HAS_JANSSON + json_error_t error; + json_info.json_root = json_loadf(info.fp_rd, 0, &error); + if (!json_info.json_root) { + RTE_LOG(ERR, USER1, "Cannot parse json file %s (line %d, column %d)\n", + req_file_path, error.line, error.column); + return -EINVAL; + } +#else /* RTE_HAS_JANSSON */ + RTE_LOG(ERR, USER1, "No json library configured.\n"); + return -EINVAL; +#endif /* RTE_HAS_JANSSON */ + } + info.fp_wr = fopen(rsp_file_path, "w"); if (!info.fp_wr) { RTE_LOG(ERR, USER1, "Cannot open file %s\n", rsp_file_path); @@ -329,6 +346,9 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -EINVAL; } + if (info.file_type == FIPS_TYPE_JSON) + return 0; + if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); return -1; @@ -428,6 +448,78 @@ fips_test_write_one_case(void) fprintf(info.fp_wr, "%s\n", info.vec[i]); } +#ifdef RTE_HAS_JANSSON +int +fips_test_parse_one_json_vector_set(void) +{ + json_t *algo_obj = json_object_get(json_info.json_vector_set, "algorithm"); + const char *algo_str = json_string_value(algo_obj); + + /* Vector sets contain the algorithm type, and nothing else we need. */ + if (strstr(algo_str, "AES-GCM")) + info.algo = FIPS_TEST_ALGO_AES_GCM; + else + return -EINVAL; + + return 0; +} + +int +fips_test_parse_one_json_group(void) +{ + int ret, i; + json_int_t val; + json_t *param; + + if (info.interim_callbacks) { + char json_value[256]; + for (i = 0; info.interim_callbacks[i].key != NULL; i++) { + param = json_object_get(json_info.json_test_group, + info.interim_callbacks[i].key); + val = json_integer_value(param); + snprintf(json_value, 255, "%"JSON_INTEGER_FORMAT, val); + /* First argument is blank because the key + * is not included in the string being parsed. + */ + ret = info.interim_callbacks[i].cb( + "", json_value, + info.interim_callbacks[i].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} + +int +fips_test_parse_one_json_case(void) +{ + uint32_t i; + int ret = 0; + json_t *param; + + for (i = 0; info.callbacks[i].key != NULL; i++) { + param = json_object_get(json_info.json_test_case, info.callbacks[i].key); + if (param) { + strcpy(info.one_line_text, json_string_value(param)); + /* First argument is blank because the key + * is not included in the string being parsed. + */ + ret = info.callbacks[i].cb( + "", info.one_line_text, + info.callbacks[i].val + ); + if (ret < 0) + return ret; + } + } + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parser_read_uint64_hex(uint64_t *value, const char *p) { -- 2.25.1