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 0C901A0542; Mon, 30 May 2022 17:53:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 06F8642B72; Mon, 30 May 2022 17:53:09 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id A8CD442B72 for ; Mon, 30 May 2022 17:53:07 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24UBWl1g007791; Mon, 30 May 2022 08:53:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=3kzrrk4C+cbK/Hgf9ZYgwT1FMipfq69IQlftYCc27KY=; b=Aib4/d78W8KCZuvb0jnyJJhO/aKcaFjJqZyHvqEO/mHQD1r0hdsTrWC5eVl+PjeTYVLE XiSIqu2qrX/Qch55xCoJ6asMJm4523cOQfXH2G93evnYEmrCjmZvXRAEV29MYhkQ5Bta N44N9XtnQMy+GERtmf5+jccFwG5rwtL5yT03ME0GpS7odAW8V2S8SlKSsxLh9wzrVGAm aWawGXuSeYq9D2QSNxQaCrnrjhnktv5rkmiJ7p8ZFHEVg6kE7c5ZyLeP0HM2BPuHkSXa jLdKov1t67pVUniJJik+Er1+XbcK6+CQfc3E3uG7zsGELOTr6xVxlu41OP6rRPiGBulq Cg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3gbk8n61pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 08:53:06 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 30 May 2022 08:53:04 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 30 May 2022 08:53:04 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 48A913F70CB; Mon, 30 May 2022 08:53:02 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Fan Zhang , Brian Dooley , , Anoob Joseph , Archana Muniganti , Jerin Jacob , Brandon Lo , "Gowrishankar Muthukrishnan" Subject: [v9, 05/10] examples/fips_validation: add json to gcm test Date: Mon, 30 May 2022 21:22:39 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: FbWtyBw68tyS7tErxwm1324ANSKppJDp X-Proofpoint-GUID: FbWtyBw68tyS7tErxwm1324ANSKppJDp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-30_07,2022-05-30_01,2022-02-23_01 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 From: Brandon Lo Adds json-specific testing and writeback function. Allows the user to test AES-GCM vector sets. Signed-off-by: Brandon Lo Acked-by: Gowrishankar Muthukrishnan --- v8: * reset IV generation var in every test group as initialization. v3: * fix checkpatch warnings --- examples/fips_validation/fips_validation.h | 3 + .../fips_validation/fips_validation_gcm.c | 152 +++++++++++++++++- examples/fips_validation/main.c | 3 +- 3 files changed, 156 insertions(+), 2 deletions(-) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index a1c83a9a6a..8b9d528c53 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -250,6 +250,9 @@ fips_test_parse_one_json_group(void); int fips_test_parse_one_json_case(void); + +int +parse_test_gcm_json_init(void); #endif /* RTE_HAS_JANSSON */ int diff --git a/examples/fips_validation/fips_validation_gcm.c b/examples/fips_validation/fips_validation_gcm.c index 250d09bf90..7e89f2a6b2 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) { @@ -194,7 +253,6 @@ parse_test_gcm_init(void) char *tmp; uint32_t i; - for (i = 0; i < info.nb_vec_lines; i++) { char *line = info.vec[i]; @@ -218,3 +276,95 @@ parse_test_gcm_init(void) 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; +} + +int +parse_test_gcm_json_init(void) +{ + 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); + info.interim_info.gcm_data.gen_iv = 0; + + 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 */ + diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 5bebff853e..e729b01529 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1955,11 +1955,12 @@ fips_test_one_test_group(void) switch (info.algo) { case FIPS_TEST_ALGO_AES_GCM: - ret = parse_test_gcm_init(); + ret = parse_test_gcm_json_init(); break; default: return -EINVAL; } + if (ret < 0) return ret; -- 2.25.1