diff mbox series

[v1,6/12] validation: crypto: use auth IV for GMAC test case

Message ID 1516608010-2535-7-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/12] validation: crypto: stop declaring test functions as public | expand

Commit Message

Github ODP bot Jan. 22, 2018, 8 a.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Change GMAC testing code to use new auth IV fields.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>

Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org>

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
/** Email created from pull request 413 (SonicwallYhe:api-next)
 ** https://github.com/Linaro/odp/pull/413
 ** Patch: https://github.com/Linaro/odp/pull/413.patch
 ** Base sha: 5a4502fc6bc53e6503169da3028f456b64811a0b
 ** Merge commit sha: 6669be7b55ab094f9e27d2101a6bb005ca87e405
 **/
 test/validation/api/crypto/odp_crypto_test_inp.c | 55 +++++++++++++++++++++++-
 test/validation/api/crypto/test_vectors.h        |  8 ++--
 2 files changed, 58 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c
index 7309b5d52..976c88821 100644
--- a/test/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/validation/api/crypto/odp_crypto_test_inp.c
@@ -79,6 +79,7 @@  static int alg_op(odp_packet_t pkt,
 		  odp_bool_t *ok,
 		  odp_crypto_session_t session,
 		  uint8_t *cipher_iv_ptr,
+		  uint8_t *auth_iv_ptr,
 		  odp_packet_data_range_t *cipher_range,
 		  odp_packet_data_range_t *auth_range,
 		  uint8_t *aad,
@@ -101,6 +102,8 @@  static int alg_op(odp_packet_t pkt,
 	op_params.auth_range = *auth_range;
 	if (cipher_iv_ptr)
 		op_params.cipher_iv_ptr = cipher_iv_ptr;
+	if (auth_iv_ptr)
+		op_params.auth_iv_ptr = auth_iv_ptr;
 
 	op_params.aad_ptr = aad;
 
@@ -154,6 +157,7 @@  static int alg_packet_op(odp_packet_t pkt,
 			 odp_bool_t *ok,
 			 odp_crypto_session_t session,
 			 uint8_t *cipher_iv_ptr,
+			 uint8_t *auth_iv_ptr,
 			 odp_packet_data_range_t *cipher_range,
 			 odp_packet_data_range_t *auth_range,
 			 uint8_t *aad,
@@ -173,6 +177,8 @@  static int alg_packet_op(odp_packet_t pkt,
 	op_params.auth_range = *auth_range;
 	if (cipher_iv_ptr)
 		op_params.cipher_iv_ptr = cipher_iv_ptr;
+	if (auth_iv_ptr)
+		op_params.auth_iv_ptr = auth_iv_ptr;
 
 	op_params.aad_ptr = aad;
 
@@ -211,6 +217,7 @@  static int alg_packet_op_enq(odp_packet_t pkt,
 			     odp_bool_t *ok,
 			     odp_crypto_session_t session,
 			     uint8_t *cipher_iv_ptr,
+			     uint8_t *auth_iv_ptr,
 			     odp_packet_data_range_t *cipher_range,
 			     odp_packet_data_range_t *auth_range,
 			     uint8_t *aad,
@@ -231,6 +238,8 @@  static int alg_packet_op_enq(odp_packet_t pkt,
 	op_params.auth_range = *auth_range;
 	if (cipher_iv_ptr)
 		op_params.cipher_iv_ptr = cipher_iv_ptr;
+	if (auth_iv_ptr)
+		op_params.auth_iv_ptr = auth_iv_ptr;
 
 	op_params.aad_ptr = aad;
 
@@ -321,6 +330,10 @@  static void alg_test(odp_crypto_op_t op,
 		.data = ovr_iv ? NULL : ref->cipher_iv,
 		.length = ref->cipher_iv_length
 	};
+	odp_crypto_iv_t auth_iv = {
+		.data = ovr_iv ? NULL : ref->auth_iv,
+		.length = ref->auth_iv_length
+	};
 	int num, i;
 	int found;
 
@@ -414,6 +427,7 @@  static void alg_test(odp_crypto_op_t op,
 	/* Search for the test case */
 	for (i = 0; i < num; i++) {
 		if (auth_capa[i].digest_len == ref->digest_length &&
+		    auth_capa[i].iv_len     == auth_iv.length &&
 		    auth_capa[i].key_len    == auth_key.length) {
 			found = 1;
 			break;
@@ -422,8 +436,9 @@  static void alg_test(odp_crypto_op_t op,
 
 	if (!found) {
 		printf("\n    Unsupported: alg=%s, key_len=%" PRIu32 ", "
-		       "digest_len=%" PRIu32 "\n", auth_alg_name(auth_alg),
-		       auth_key.length, ref->digest_length);
+		       "digest_len=%" PRIu32 ", iv_len=%" PRIu32 "\n",
+		       auth_alg_name(auth_alg), auth_key.length,
+		       ref->digest_length, auth_iv.length);
 		return;
 	}
 
@@ -439,6 +454,7 @@  static void alg_test(odp_crypto_op_t op,
 	ses_params.output_pool = suite_context.pool;
 	ses_params.cipher_key = cipher_key;
 	ses_params.cipher_iv = cipher_iv;
+	ses_params.auth_iv = auth_iv;
 	ses_params.auth_key = auth_key;
 	ses_params.auth_digest_len = ref->digest_length;
 	ses_params.auth_aad_len = ref->aad_length;
@@ -489,16 +505,19 @@  static void alg_test(odp_crypto_op_t op,
 		if (!suite_context.packet)
 			rc = alg_op(pkt, &ok, session,
 				    ovr_iv ? ref->cipher_iv : NULL,
+				    ovr_iv ? ref->auth_iv : NULL,
 				    &cipher_range, &auth_range,
 				    ref->aad, ref->length);
 		else if (ODP_CRYPTO_ASYNC == suite_context.op_mode)
 			rc = alg_packet_op_enq(pkt, &ok, session,
 					       ovr_iv ? ref->cipher_iv : NULL,
+					       ovr_iv ? ref->auth_iv : NULL,
 					       &cipher_range, &auth_range,
 					       ref->aad, ref->length);
 		else
 			rc = alg_packet_op(pkt, &ok, session,
 					   ovr_iv ? ref->cipher_iv : NULL,
+					   ovr_iv ? ref->auth_iv : NULL,
 					   &cipher_range, &auth_range,
 					   ref->aad, ref->length);
 		if (rc < 0)
@@ -1163,6 +1182,20 @@  static void crypto_test_gen_alg_aes_gmac(void)
 			 false);
 }
 
+static void crypto_test_gen_alg_aes_gmac_ovr_iv(void)
+{
+	unsigned int test_vec_num = (sizeof(aes_gmac_reference) /
+				     sizeof(aes_gmac_reference[0]));
+	unsigned int i;
+
+	for (i = 0; i < test_vec_num; i++)
+		alg_test(ODP_CRYPTO_OP_ENCODE,
+			 ODP_CIPHER_ALG_NULL,
+			 ODP_AUTH_ALG_AES_GMAC,
+			 &aes_gmac_reference[i],
+			 true);
+}
+
 static void crypto_test_check_alg_aes_gmac(void)
 {
 	unsigned int test_vec_num = (sizeof(aes_gmac_reference) /
@@ -1177,6 +1210,20 @@  static void crypto_test_check_alg_aes_gmac(void)
 			 false);
 }
 
+static void crypto_test_check_alg_aes_gmac_ovr_iv(void)
+{
+	unsigned int test_vec_num = (sizeof(aes_gmac_reference) /
+				     sizeof(aes_gmac_reference[0]));
+	unsigned int i;
+
+	for (i = 0; i < test_vec_num; i++)
+		alg_test(ODP_CRYPTO_OP_DECODE,
+			 ODP_CIPHER_ALG_NULL,
+			 ODP_AUTH_ALG_AES_GMAC,
+			 &aes_gmac_reference[i],
+			 true);
+}
+
 int crypto_suite_sync_init(void)
 {
 	suite_context.pool = odp_pool_lookup("packet_pool");
@@ -1284,8 +1331,12 @@  odp_testinfo_t crypto_suite[] = {
 				  check_alg_hmac_sha512),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac,
 				  check_alg_aes_gmac),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac_ovr_iv,
+				  check_alg_aes_gmac),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac,
 				  check_alg_aes_gmac),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac_ovr_iv,
+				  check_alg_aes_gmac),
 	ODP_TEST_INFO_NULL,
 };
 
diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h
index 6673ba4b6..d08bf1500 100644
--- a/test/validation/api/crypto/test_vectors.h
+++ b/test/validation/api/crypto/test_vectors.h
@@ -16,6 +16,8 @@  typedef struct crypto_test_reference_s {
 	uint8_t auth_key[MAX_KEY_LEN];
 	uint32_t cipher_iv_length;
 	uint8_t cipher_iv[MAX_IV_LEN];
+	uint32_t auth_iv_length;
+	uint8_t auth_iv[MAX_IV_LEN];
 	uint32_t length;
 	uint8_t plaintext[MAX_DATA_LEN];
 	uint8_t ciphertext[MAX_DATA_LEN];
@@ -447,9 +449,9 @@  static crypto_test_reference_t aes_gmac_reference[] = {
 		.auth_key_length = AES128_GCM_KEY_LEN,
 		.auth_key = { 0x4c, 0x80, 0xcd, 0xef, 0xbb, 0x5d, 0x10, 0xda,
 			      0x90, 0x6a, 0xc7, 0x3c, 0x36, 0x13, 0xa6, 0x34},
-		.cipher_iv_length = AES_GCM_IV_LEN,
-		.cipher_iv = { 0x22, 0x43, 0x3c, 0x64, 0x00, 0x00, 0x00, 0x00,
-			       0x00, 0x00, 0x00, 0x00 },
+		.auth_iv_length = AES_GCM_IV_LEN,
+		.auth_iv = { 0x22, 0x43, 0x3c, 0x64, 0x00, 0x00, 0x00, 0x00,
+			     0x00, 0x00, 0x00, 0x00 },
 		.length = 68,
 		.plaintext = { 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07,
 			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,