[API-NEXT,v5,5/6] validation: crypto: use auth IV for GMAC test case

Message ID 1515024013-30222-6-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series
  • Add separate auth IV
Related show

Commit Message

Github ODP bot Jan. 4, 2018, midnight
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>

---
/** Email created from pull request 352 (lumag:crypto_gmac_iv)
 ** https://github.com/Linaro/odp/pull/352
 ** Patch: https://github.com/Linaro/odp/pull/352.patch
 ** Base sha: 6303c7d0e98fafe0f14c8c4dd9989b3b7633ebf4
 ** Merge commit sha: 5a1e35f8e8d8df2bc17b098f7c9c92611ea98e23
 **/
 test/validation/api/crypto/odp_crypto_test_inp.c | 61 ++++++++++++++++++++++--
 test/validation/api/crypto/test_vectors.h        |  8 ++--
 2 files changed, 61 insertions(+), 8 deletions(-)

Patch

diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c
index b49cffb5a..0f10c4f49 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 *op_iv_ptr,
+		  uint8_t *op_auth_iv_ptr,
 		  odp_packet_data_range_t *cipher_range,
 		  odp_packet_data_range_t *auth_range,
 		  uint8_t *aad,
@@ -99,8 +100,10 @@  static int alg_op(odp_packet_t pkt,
 
 	op_params.cipher_range = *cipher_range;
 	op_params.auth_range = *auth_range;
-	if (op_iv_ptr)
+	if (op_iv_ptr) {
 		op_params.override_iv_ptr = op_iv_ptr;
+		op_params.override_auth_iv_ptr = op_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 *op_iv_ptr,
+			 uint8_t *op_auth_iv_ptr,
 			 odp_packet_data_range_t *cipher_range,
 			 odp_packet_data_range_t *auth_range,
 			 uint8_t *aad,
@@ -171,8 +175,10 @@  static int alg_packet_op(odp_packet_t pkt,
 
 	op_params.cipher_range = *cipher_range;
 	op_params.auth_range = *auth_range;
-	if (op_iv_ptr)
+	if (op_iv_ptr) {
 		op_params.override_iv_ptr = op_iv_ptr;
+		op_params.override_auth_iv_ptr = op_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 *op_iv_ptr,
+			     uint8_t *op_auth_iv_ptr,
 			     odp_packet_data_range_t *cipher_range,
 			     odp_packet_data_range_t *auth_range,
 			     uint8_t *aad,
@@ -229,8 +236,10 @@  static int alg_packet_op_enq(odp_packet_t pkt,
 
 	op_params.cipher_range = *cipher_range;
 	op_params.auth_range = *auth_range;
-	if (op_iv_ptr)
+	if (op_iv_ptr) {
 		op_params.override_iv_ptr = op_iv_ptr;
+		op_params.override_auth_iv_ptr = op_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->iv,
 		.length = ref->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 = 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->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->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->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 f2ce9eb2f..90b020356 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 iv_length;
 	uint8_t 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},
-		.iv_length = AES_GCM_IV_LEN,
-		.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,