diff mbox series

[API-NEXT,v8,2/10] validation: crypto: add AES-GMAC testcase

Message ID 1510689611-17861-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v8,1/10] api: crypto: add AES-GMAC declarations | expand

Commit Message

Github ODP bot Nov. 14, 2017, 8 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Add AES-GMAC test vector based on draft-mcgrew-gcm-test-01.

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

---
/** Email created from pull request 288 (lumag:gmac)
 ** https://github.com/Linaro/odp/pull/288
 ** Patch: https://github.com/Linaro/odp/pull/288.patch
 ** Base sha: ba93e355ddf151215aa18b59cbfca08fe175fe65
 ** Merge commit sha: 8363c3a4073075d0f3dd68864b9a33819005aab4
 **/
 test/validation/api/crypto/crypto.h              |  2 ++
 test/validation/api/crypto/odp_crypto_test_inp.c | 46 ++++++++++++++++++++++++
 test/validation/api/crypto/test_vectors.h        | 33 +++++++++++++++++
 3 files changed, 81 insertions(+)
diff mbox series

Patch

diff --git a/test/validation/api/crypto/crypto.h b/test/validation/api/crypto/crypto.h
index ba1058f35..078a1909f 100644
--- a/test/validation/api/crypto/crypto.h
+++ b/test/validation/api/crypto/crypto.h
@@ -36,6 +36,8 @@  void crypto_test_gen_alg_hmac_sha256(void);
 void crypto_test_check_alg_hmac_sha256(void);
 void crypto_test_gen_alg_hmac_sha512(void);
 void crypto_test_check_alg_hmac_sha512(void);
+void crypto_test_gen_alg_aes_gmac(void);
+void crypto_test_check_alg_aes_gmac(void);
 
 /* test arrays: */
 extern odp_testinfo_t crypto_suite[];
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c
index 1f7523de2..fdc0db8e3 100644
--- a/test/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/validation/api/crypto/odp_crypto_test_inp.c
@@ -50,6 +50,8 @@  static const char *auth_alg_name(odp_auth_alg_t auth)
 		return "ODP_AUTH_ALG_SHA512_HMAC";
 	case ODP_AUTH_ALG_AES_GCM:
 		return "ODP_AUTH_ALG_AES_GCM";
+	case ODP_AUTH_ALG_AES_GMAC:
+		return "ODP_AUTH_ALG_AES_GMAC";
 	default:
 		return "Unknown";
 	}
@@ -344,6 +346,9 @@  static void alg_test(odp_crypto_op_t op,
 	if (auth_alg == ODP_AUTH_ALG_AES_GCM &&
 	    !(capa.auths.bit.aes_gcm))
 		rc = -1;
+	if (auth_alg == ODP_AUTH_ALG_AES_GMAC &&
+	    !(capa.auths.bit.aes_gmac))
+		rc = -1;
 	if (auth_alg == ODP_AUTH_ALG_MD5_HMAC &&
 	    !(capa.auths.bit.md5_hmac))
 		rc = -1;
@@ -588,6 +593,10 @@  static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth)
 		if (!capability.auths.bit.aes_gcm)
 			return ODP_TEST_INACTIVE;
 		break;
+	case ODP_AUTH_ALG_AES_GMAC:
+		if (!capability.auths.bit.aes_gmac)
+			return ODP_TEST_INACTIVE;
+		break;
 	default:
 		fprintf(stderr, "Unsupported authentication algorithm\n");
 		return ODP_TEST_INACTIVE;
@@ -1114,6 +1123,39 @@  void crypto_test_check_alg_hmac_sha512(void)
 			 false);
 }
 
+static int check_alg_aes_gmac(void)
+{
+	return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_AES_GMAC);
+}
+
+void crypto_test_gen_alg_aes_gmac(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],
+			 false);
+}
+
+void crypto_test_check_alg_aes_gmac(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],
+			 false);
+}
+
 int crypto_suite_sync_init(void)
 {
 	suite_context.pool = odp_pool_lookup("packet_pool");
@@ -1219,6 +1261,10 @@  odp_testinfo_t crypto_suite[] = {
 				  check_alg_hmac_sha512),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha512,
 				  check_alg_hmac_sha512),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac,
+				  check_alg_aes_gmac),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac,
+				  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 63103227a..f2ce9eb2f 100644
--- a/test/validation/api/crypto/test_vectors.h
+++ b/test/validation/api/crypto/test_vectors.h
@@ -442,6 +442,39 @@  static crypto_test_reference_t aes_gcm_reference[] = {
 	}
 };
 
+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 },
+		.length = 68,
+		.plaintext = { 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07,
+			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			       0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00,
+			       0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05,
+			       0xc0, 0xa8, 0x00, 0x01, 0x08, 0x00, 0xc6, 0xcd,
+			       0x02, 0x00, 0x07, 0x00, 0x61, 0x62, 0x63, 0x64,
+			       0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
+			       0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74,
+			       0x01, 0x02, 0x02, 0x01 },
+		.ciphertext = { 0x00, 0x00, 0x43, 0x21, 0x00, 0x00, 0x00, 0x07,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x45, 0x00, 0x00, 0x30, 0xda, 0x3a, 0x00, 0x00,
+				0x80, 0x01, 0xdf, 0x3b, 0xc0, 0xa8, 0x00, 0x05,
+				0xc0, 0xa8, 0x00, 0x01, 0x08, 0x00, 0xc6, 0xcd,
+				0x02, 0x00, 0x07, 0x00, 0x61, 0x62, 0x63, 0x64,
+				0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
+				0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74,
+				0x01, 0x02, 0x02, 0x01 },
+		.digest_length = AES_GCM_DIGEST_LEN,
+		.digest = { 0xf2, 0xa9, 0xa8, 0x36, 0xe1, 0x55, 0x10, 0x6a,
+			    0xa8, 0xdc, 0xd6, 0x18, 0xe4, 0x09, 0x9a, 0xaa }
+	},
+};
+
 static crypto_test_reference_t hmac_md5_reference[] = {
 	{
 		.auth_key_length = HMAC_MD5_KEY_LEN,