From patchwork Fri Apr 29 16:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110524 X-Patchwork-Delegate: gakhil@marvell.com 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 7CB85A04FF; Fri, 29 Apr 2022 18:16:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D738C42840; Fri, 29 Apr 2022 18:16:12 +0200 (CEST) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by mails.dpdk.org (Postfix) with ESMTP id 4895042833 for ; Fri, 29 Apr 2022 18:16:09 +0200 (CEST) Received: by mail-qt1-f177.google.com with SMTP id p4so5557626qtq.12 for ; Fri, 29 Apr 2022 09:16:09 -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=VUc7jsRduw3fVhSRbhtDqzGMDIQR76TpPoxasjK1OB8=; b=M4qslR2zPlySqyAhx/MlX+TGGqigQlsW7/2sqxQEh2V3AtwaW84n+6jkxeQvuLGH/Q 9vtKfpi43LtfYIc/dmkuMZ6LojQfmPFYCT+WsfbgkBhwBowOyiRBYXWU0f+iZHgp7XAp 7uGElhJ4z56XHE4LTKaI0OvLajP2dOG0t65fY= 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=VUc7jsRduw3fVhSRbhtDqzGMDIQR76TpPoxasjK1OB8=; b=I4Q5YGHY+iNpIJ68UeQ3Pf1kL/19PTIQjNAw2bwSMcdJmOFUghroX8h1wtH/tnSg30 qtgxs6EVAJdnprPpftUKmF0eY2YVXZJAj7EvSd6Xv6kU85N+bYLuglFzT3bh4yFD3G57 cnybYopySpxriHioIVYKRYi6wsegJwRqKNmA1VBujlOJPC9gBnb3pZZYIzLP5ZEiGGNB ClqkEJLjdVZIFlCDLwyqXQKW+NvpgeiZHY9P9ywcA6pekXN2/7YnCWl5tVI4db7jKEPp RgNbB1lkVVv1ymzwCIZwOrvYex+lCD1L4Avk1GWrotM/ScubDFQ4gx/aveQ3GiRZ33YL 8ALQ== X-Gm-Message-State: AOAM530wVtdzl1NLI64qTvY14OCilm8Oz7YHnSrWmJgp5wsmcsgyGddr hNFnbH5ZpvBeTYEUiksbswgGBQ== X-Google-Smtp-Source: ABdhPJzAg4d5DmfnvFmyPh/CxCsyW42GEbrA76ztauwkoD4IHKFShyPOFahBK3aRJRn8K8jUYdxYYg== X-Received: by 2002:ac8:7e94:0:b0:2f3:7e38:ef88 with SMTP id w20-20020ac87e94000000b002f37e38ef88mr165697qtj.280.1651248968720; Fri, 29 Apr 2022 09:16:08 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:08 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 7/8] examples/fips_validation: implement json cmac test Date: Fri, 29 Apr 2022 12:15:58 -0400 Message-Id: <20220429161559.415645-8-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 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 Implemented JSON support for the CMAC test. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.h | 6 ++ .../fips_validation/fips_validation_cmac.c | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 2c65d838b0..7f68d454f7 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -259,6 +259,12 @@ parse_test_hmac_json_init(void); int parse_test_hmac_json_algorithm(void); + +int +parse_test_cmac_json_init(void); + +int +parser_read_cmac_direction_str(const char *key, char *src, struct fips_val *val); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_cmac.c b/examples/fips_validation/fips_validation_cmac.c index 54c951ef83..4b5fd2aca7 100644 --- a/examples/fips_validation/fips_validation_cmac.c +++ b/examples/fips_validation/fips_validation_cmac.c @@ -32,6 +32,18 @@ #define PASS_STR "P" #define FAIL_STR "F" +#define KLEN_JSON_STR "keyLen" +#define PTLEN_JSON_STR "msgLen" +#define TAGLEN_JSON_STR "macLen" +#define KEY_JSON_STR "key" +#define PT_JSON_STR "message" +#define TAG_JSON_STR "mac" +#define DIRECTION_JSON_STR "direction" +#define POS_NEG_JSON_STR "testPassed" + +#define GEN_JSON_STR "gen" +#define VERIF_JSON_STR "ver" + struct hash_algo_conversion { const char *str; enum fips_test_algorithms algo; @@ -39,6 +51,62 @@ struct hash_algo_conversion { {"AES", FIPS_TEST_ALGO_AES_CMAC}, }; +#ifdef RTE_HAS_JANSSON +struct fips_test_callback cmac_tests_interim_json_vectors[] = { + {KLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key}, + {PTLEN_JSON_STR, parser_read_uint32_bit_val, &vec.pt}, + {TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.digest}, + {DIRECTION_JSON_STR, parser_read_cmac_direction_str, NULL}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback cmac_tests_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.key}, + {PT_JSON_STR, parse_uint8_known_len_hex_str, &vec.pt}, + {TAG_JSON_STR, parse_uint8_known_len_hex_str, + &vec.cipher_auth.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +static int +parse_test_cmac_json_writeback(struct fips_val *val) +{ + json_info.json_write_case = json_object(); + json_object_set(json_info.json_write_case, "tcId", + json_object_get(json_info.json_test_case, "tcId")); + + if (info.op == FIPS_TEST_ENC_AUTH_GEN) { + struct fips_val tmp_val = {val->val + vec.pt.len, + vec.cipher_auth.digest.len}; + + writeback_hex_str("", info.one_line_text, &tmp_val); + json_object_set_new(json_info.json_write_case, TAG_JSON_STR, + json_string(info.one_line_text)); + } else { + if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) + json_object_set_new(json_info.json_write_case, POS_NEG_JSON_STR, + json_boolean(true)); + else if (vec.status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED) + json_object_set_new(json_info.json_write_case, POS_NEG_JSON_STR, + json_boolean(false)); + } + + return 0; +} + +int +parse_test_cmac_json_init(void) +{ + info.algo = FIPS_TEST_ALGO_AES_CMAC; + + info.parse_writeback = parse_test_cmac_json_writeback; + info.callbacks = cmac_tests_json_vectors; + info.interim_callbacks = cmac_tests_interim_json_vectors; + + return 0; +} +#endif /* RTE_HAS_JANSSON */ + static int parse_test_cmac_writeback(struct fips_val *val) {