From patchwork Fri Apr 29 16:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Lo X-Patchwork-Id: 110523 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 0C5F9A04FF; Fri, 29 Apr 2022 18:16:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D057B4283B; Fri, 29 Apr 2022 18:16:11 +0200 (CEST) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by mails.dpdk.org (Postfix) with ESMTP id 7260742832 for ; Fri, 29 Apr 2022 18:16:08 +0200 (CEST) Received: by mail-qt1-f182.google.com with SMTP id x9so6114763qts.6 for ; Fri, 29 Apr 2022 09:16:08 -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=EzJ3kxPq37sIG+M3jBZ4BC1iiJ1GgCH/+Bj2xldNKe0=; b=JWcVgv51UoF7Sbeew2Kc4oS/cpM6nVI/JV68RkZ5SnKSOhe/t6qxa/yDD4wvXQ3tY1 AI7w0r4RbzEVMKbT6KB8jtby0esjNqy0iOL32bxG/kmddrbA/NNmakUKgQLHl7hCX7xX GzgpmhD6kWwqrWK5xykFZ8lorNi6FQQhya/pQ= 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=EzJ3kxPq37sIG+M3jBZ4BC1iiJ1GgCH/+Bj2xldNKe0=; b=oEIdAqIm8UWNh80ubSfrGr7m74q5jGVPkQpB4MF21aXcefniMwiEbT8qMiq0pulMPk yhgS7v0fF3fxcskJ7MEWtmb7U+MFz0aZvZbHfzJuHIE+Od8QbnYoqT3Cuig36mB68Mfo lOKKOHSt+A/6c1AQbTbE6jdLKcqlxDH1EWu0qgQiaDW2XluT6jMP3cQlnqOtZV6PXi0V g/PAIccBSNPfFsRcK0jlIDQTfVEXw/3aK11ehGEvynkXfPNl7FTIVDvYpblzOxN9qTap xEaKumWpTT0NuIidw+qzz24h8fDPzWRbFyIXYpH4WtERR5A0m0He6Jc0tKs2Hy8jcW+X f9Gw== X-Gm-Message-State: AOAM532fQyGCzojlbPMUtnj7CO7YU2XrPiEKxTWG33f92hYE7v1z/JBx fh+fkLB+B+WwZsmGTpKLYyKaiIUsH3NrAQ== X-Google-Smtp-Source: ABdhPJznNCCrefIWk3NTCgNjwpNsxI4k31EQIz6nf6rVCU388unHVNJsO9v67tkW7NgrdW6oMS/nUw== X-Received: by 2002:ac8:5dd4:0:b0:2f3:8801:856f with SMTP id e20-20020ac85dd4000000b002f38801856fmr138288qtx.107.1651248967870; Fri, 29 Apr 2022 09:16:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 09:16:07 -0700 (PDT) From: Brandon Lo To: roy.fan.zhang@intel.com, ciara.power@intel.com Cc: dev@dpdk.org, Brandon Lo Subject: [PATCH v4 6/8] examples/fips_validation: add json to hmac Date: Fri, 29 Apr 2022 12:15:57 -0400 Message-Id: <20220429161559.415645-7-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 Adds JSON support for the HMAC algorithm. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- examples/fips_validation/fips_validation.c | 2 + examples/fips_validation/fips_validation.h | 6 ++ .../fips_validation/fips_validation_hmac.c | 93 +++++++++++++++++++ examples/fips_validation/main.c | 3 + 4 files changed, 104 insertions(+) diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index d220dcab1f..04dfb85262 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -458,6 +458,8 @@ fips_test_parse_one_json_vector_set(void) /* Vector sets contain the algorithm type, and nothing else we need. */ if (strstr(algo_str, "AES-GCM")) info.algo = FIPS_TEST_ALGO_AES_GCM; + if (strstr(algo_str, "HMAC")) + info.algo = FIPS_TEST_ALGO_HMAC; else return -EINVAL; diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index 8d7af99e04..2c65d838b0 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -253,6 +253,12 @@ fips_test_parse_one_json_case(void); int parse_test_gcm_json_init(void); + +int +parse_test_hmac_json_init(void); + +int +parse_test_hmac_json_algorithm(void); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_hmac.c b/examples/fips_validation/fips_validation_hmac.c index 1285c9d283..4cd1b1ac07 100644 --- a/examples/fips_validation/fips_validation_hmac.c +++ b/examples/fips_validation/fips_validation_hmac.c @@ -19,6 +19,15 @@ #define PT_STR "Msg = " #define TAG_STR "Mac = " +#define ALGO_JSON_STR "algorithm" + +#define KEYLEN_JSON_STR "keyLen" +#define TAGLEN_JSON_STR "macLen" + +#define KEY_JSON_STR "key" +#define PT_JSON_STR "msg" +#define TAG_JSON_STR "mac" + struct hash_size_conversion { const char *str; enum rte_crypto_auth_algorithm algo; @@ -65,6 +74,29 @@ struct fips_test_callback hmac_tests_interim_vectors[] = { {NULL, NULL, NULL} /**< end pointer */ }; +#ifdef RTE_HAS_JANSSON +struct hash_size_conversion json_algorithms[] = { + {"HMAC-SHA-1", RTE_CRYPTO_AUTH_SHA1_HMAC}, + {"HMAC-SHA2-224", RTE_CRYPTO_AUTH_SHA224_HMAC}, + {"HMAC-SHA2-256", RTE_CRYPTO_AUTH_SHA256_HMAC}, + {"HMAC-SHA2-384", RTE_CRYPTO_AUTH_SHA384_HMAC}, + {"HMAC-SHA2-512", RTE_CRYPTO_AUTH_SHA512_HMAC}, +}; + +struct fips_test_callback hmac_tests_json_vectors[] = { + {KEY_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.key}, + {PT_JSON_STR, parse_uint8_hex_str, &vec.pt}, + {TAG_JSON_STR, parse_uint8_hex_str, &vec.cipher_auth.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; + +struct fips_test_callback hmac_tests_interim_json_vectors[] = { + {KEYLEN_JSON_STR, parser_read_uint32_val, &vec.cipher_auth.key}, + {TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.digest}, + {NULL, NULL, NULL} /**< end pointer */ +}; +#endif /* RTE_HAS_JANSSON */ + static int parse_test_hmac_writeback(struct fips_val *val) { @@ -103,3 +135,64 @@ parse_test_hmac_init(void) return 0; } + +#ifdef RTE_HAS_JANSSON +static int +parse_test_hmac_json_writeback(struct fips_val *val) +{ + struct fips_val val_local; + json_t *tcId, *mac; + + 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); + + + val_local.val = val->val + vec.pt.len; + val_local.len = vec.cipher_auth.digest.len; + + writeback_hex_str("", info.one_line_text, &val_local); + + mac = json_string(info.one_line_text); + json_object_set_new(json_info.json_write_case, TAG_JSON_STR, mac); + + return 0; +} + +int +parse_test_hmac_json_algorithm(void) +{ + json_t *algorithm_object; + const char *algorithm_str; + uint32_t i; + + algorithm_object = json_object_get(json_info.json_vector_set, "algorithm"); + algorithm_str = json_string_value(algorithm_object); + + for (i = 0; i < RTE_DIM(json_algorithms); i++) { + if (strstr(algorithm_str, json_algorithms[i].str)) { + info.interim_info.hmac_data.algo = json_algorithms[i].algo; + return 0; + } + } + + return -1; +} + +int +parse_test_hmac_json_init(void) +{ + info.op = FIPS_TEST_ENC_AUTH_GEN; + info.parse_writeback = parse_test_hmac_json_writeback; + info.callbacks = hmac_tests_json_vectors; + info.writeback_callbacks = NULL; + info.kat_check = rsp_test_hmac_check; + info.interim_callbacks = hmac_tests_interim_json_vectors; + + if (parse_test_hmac_json_algorithm() < 0) + return -1; + + return 0; +} +#endif /* RTE_HAS_JANSSON */ diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index a1d8a1d758..de6dedaf75 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1943,6 +1943,9 @@ fips_test_one_test_group(void) case FIPS_TEST_ALGO_AES_GCM: ret = parse_test_gcm_json_init(); break; + case FIPS_TEST_ALGO_HMAC: + ret = parse_test_hmac_json_init(); + break; default: return -EINVAL; }