diff mbox series

[API-NEXT,v4,3/6] validation: crypto: add ChaCha20-Poly1305 test vectors

Message ID 1516820410-23442-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v4,1/6] api: crypto: add ChaCha20-Poly1305 support | expand

Commit Message

Github ODP bot Jan. 24, 2018, 7 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


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

---
/** Email created from pull request 428 (lumag:chacha-poly1305)
 ** https://github.com/Linaro/odp/pull/428
 ** Patch: https://github.com/Linaro/odp/pull/428.patch
 ** Base sha: 44974a09b01c79adb9637a5dff38539598a76737
 ** Merge commit sha: 516808773882a012c221502d190787c1cdddd1b9
 **/
 test/validation/api/crypto/odp_crypto_test_inp.c | 72 +++++++++++++++++++
 test/validation/api/crypto/test_vectors.h        | 88 ++++++++++++++++++++++++
 test/validation/api/crypto/test_vectors_len.h    |  7 +-
 3 files changed, 166 insertions(+), 1 deletion(-)
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 2b0ba1cd9..dfcd4793b 100644
--- a/test/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/validation/api/crypto/odp_crypto_test_inp.c
@@ -52,6 +52,8 @@  static const char *auth_alg_name(odp_auth_alg_t auth)
 		return "ODP_AUTH_ALG_AES_GCM";
 	case ODP_AUTH_ALG_AES_GMAC:
 		return "ODP_AUTH_ALG_AES_GMAC";
+	case ODP_AUTH_ALG_CHACHA20_POLY1305:
+		return "ODP_AUTH_ALG_CHACHA20_POLY1305";
 	default:
 		return "Unknown";
 	}
@@ -70,6 +72,8 @@  static const char *cipher_alg_name(odp_cipher_alg_t cipher)
 		return "ODP_CIPHER_ALG_AES_CBC";
 	case ODP_CIPHER_ALG_AES_GCM:
 		return "ODP_CIPHER_ALG_AES_GCM";
+	case ODP_CIPHER_ALG_CHACHA20_POLY1305:
+		return "ODP_CIPHER_ALG_CHACHA20_POLY1305";
 	default:
 		return "Unknown";
 	}
@@ -473,6 +477,9 @@  static void check_alg(odp_crypto_op_t op,
 	if (cipher_alg == ODP_CIPHER_ALG_AES_GCM &&
 	    !(capa.ciphers.bit.aes_gcm))
 		rc = -1;
+	if (cipher_alg == ODP_CIPHER_ALG_CHACHA20_POLY1305 &&
+	    !(capa.ciphers.bit.chacha20_poly1305))
+		rc = -1;
 	if (cipher_alg == ODP_CIPHER_ALG_DES &&
 	    !(capa.ciphers.bit.des))
 		rc = -1;
@@ -489,6 +496,9 @@  static void check_alg(odp_crypto_op_t op,
 	if (auth_alg == ODP_AUTH_ALG_AES_GMAC &&
 	    !(capa.auths.bit.aes_gmac))
 		rc = -1;
+	if (auth_alg == ODP_AUTH_ALG_CHACHA20_POLY1305 &&
+	    !(capa.auths.bit.chacha20_poly1305))
+		rc = -1;
 	if (auth_alg == ODP_AUTH_ALG_MD5_HMAC &&
 	    !(capa.auths.bit.md5_hmac))
 		rc = -1;
@@ -657,6 +667,10 @@  static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth)
 		if (!capability.ciphers.bit.aes_gcm)
 			return ODP_TEST_INACTIVE;
 		break;
+	case ODP_CIPHER_ALG_CHACHA20_POLY1305:
+		if (!capability.ciphers.bit.chacha20_poly1305)
+			return ODP_TEST_INACTIVE;
+		break;
 	default:
 		fprintf(stderr, "Unsupported cipher algorithm\n");
 		return ODP_TEST_INACTIVE;
@@ -692,6 +706,10 @@  static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth)
 		if (!capability.auths.bit.aes_gmac)
 			return ODP_TEST_INACTIVE;
 		break;
+	case ODP_AUTH_ALG_CHACHA20_POLY1305:
+		if (!capability.auths.bit.chacha20_poly1305)
+			return ODP_TEST_INACTIVE;
+		break;
 	default:
 		fprintf(stderr, "Unsupported authentication algorithm\n");
 		return ODP_TEST_INACTIVE;
@@ -788,6 +806,52 @@  static void crypto_test_dec_alg_3des_cbc_ovr_iv(void)
 		  true);
 }
 
+static int check_alg_chacha20_poly1305(void)
+{
+	return check_alg_support(ODP_CIPHER_ALG_CHACHA20_POLY1305,
+				 ODP_AUTH_ALG_CHACHA20_POLY1305);
+}
+
+static void crypto_test_enc_alg_chacha20_poly1305(void)
+{
+	check_alg(ODP_CRYPTO_OP_ENCODE,
+		  ODP_CIPHER_ALG_CHACHA20_POLY1305,
+		  ODP_AUTH_ALG_CHACHA20_POLY1305,
+		  chacha20_poly1305_reference,
+		  ARRAY_SIZE(chacha20_poly1305_reference),
+		  false);
+}
+
+static void crypto_test_enc_alg_chacha20_poly1305_ovr_iv(void)
+{
+	check_alg(ODP_CRYPTO_OP_ENCODE,
+		  ODP_CIPHER_ALG_CHACHA20_POLY1305,
+		  ODP_AUTH_ALG_CHACHA20_POLY1305,
+		  chacha20_poly1305_reference,
+		  ARRAY_SIZE(chacha20_poly1305_reference),
+		  true);
+}
+
+static void crypto_test_dec_alg_chacha20_poly1305(void)
+{
+	check_alg(ODP_CRYPTO_OP_DECODE,
+		  ODP_CIPHER_ALG_CHACHA20_POLY1305,
+		  ODP_AUTH_ALG_CHACHA20_POLY1305,
+		  chacha20_poly1305_reference,
+		  ARRAY_SIZE(chacha20_poly1305_reference),
+		  false);
+}
+
+static void crypto_test_dec_alg_chacha20_poly1305_ovr_iv(void)
+{
+	check_alg(ODP_CRYPTO_OP_DECODE,
+		  ODP_CIPHER_ALG_CHACHA20_POLY1305,
+		  ODP_AUTH_ALG_CHACHA20_POLY1305,
+		  chacha20_poly1305_reference,
+		  ARRAY_SIZE(chacha20_poly1305_reference),
+		  true);
+}
+
 static int check_alg_aes_gcm(void)
 {
 	return check_alg_support(ODP_CIPHER_ALG_AES_GCM, ODP_AUTH_ALG_AES_GCM);
@@ -1250,6 +1314,14 @@  odp_testinfo_t crypto_suite[] = {
 				  check_alg_aes_gcm),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_gcm_ovr_iv,
 				  check_alg_aes_gcm),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_chacha20_poly1305,
+				  check_alg_chacha20_poly1305),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_chacha20_poly1305_ovr_iv,
+				  check_alg_chacha20_poly1305),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_chacha20_poly1305,
+				  check_alg_chacha20_poly1305),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_chacha20_poly1305_ovr_iv,
+				  check_alg_chacha20_poly1305),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_md5,
 				  check_alg_hmac_md5),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_md5,
diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h
index 9c0b844d1..a3970bb28 100644
--- a/test/validation/api/crypto/test_vectors.h
+++ b/test/validation/api/crypto/test_vectors.h
@@ -477,6 +477,94 @@  static crypto_test_reference_t aes_gmac_reference[] = {
 	},
 };
 
+static crypto_test_reference_t chacha20_poly1305_reference[] = {
+	{
+		.cipher_key_length = CHACHA20_POLY1305_KEY_LEN,
+		.cipher_key = { 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
+				0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
+				0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
+				0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0},
+		.cipher_iv_length = CHACHA20_POLY1305_IV_LEN,
+		.cipher_iv = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
+			       0x05, 0x06, 0x07, 0x08 },
+		.length = 265,
+		.plaintext = { 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
+			       0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
+			       0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
+			       0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
+			       0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
+			       0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
+			       0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
+			       0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
+			       0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
+			       0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
+			       0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
+			       0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
+			       0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
+			       0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
+			       0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
+			       0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
+			       0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
+			       0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
+			       0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
+			       0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
+			       0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
+			       0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
+			       0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
+			       0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
+			       0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
+			       0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
+			       0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
+			       0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
+			       0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
+			       0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
+			       0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
+			       0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
+			       0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
+			       0x9d },
+		.ciphertext = { 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
+				0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
+				0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
+				0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
+				0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
+				0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
+				0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
+				0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
+				0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
+				0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
+				0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
+				0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
+				0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
+				0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
+				0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
+				0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
+				0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
+				0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
+				0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
+				0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
+				0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
+				0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
+				0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
+				0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
+				0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
+				0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
+				0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
+				0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
+				0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
+				0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
+				0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
+				0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
+				0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
+				0x9b },
+		.aad_length = 12,
+		.aad = { 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00,
+			 0x00, 0x4e, 0x91 },
+		.digest_length = CHACHA20_POLY1305_CHECK_LEN,
+		.digest = { 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
+			    0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38 }
+	},
+};
+
 static crypto_test_reference_t hmac_md5_reference[] = {
 	{
 		.auth_key_length = HMAC_MD5_KEY_LEN,
diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h
index 2551b054c..d41c7b286 100644
--- a/test/validation/api/crypto/test_vectors_len.h
+++ b/test/validation/api/crypto/test_vectors_len.h
@@ -9,7 +9,7 @@ 
 /* Maximum */
 #define MAX_KEY_LEN         64
 #define MAX_IV_LEN          16
-#define MAX_DATA_LEN        128
+#define MAX_DATA_LEN        270
 #define MAX_AAD_LEN         12
 #define MAX_DIGEST_LEN      64
 
@@ -74,4 +74,9 @@ 
 #define HMAC_SHA512_256_CHECK_LEN  32
 #define HMAC_SHA512_CHECK_LEN      64
 
+/* ChaCha20-Poly1305 */
+#define CHACHA20_POLY1305_KEY_LEN  32
+#define CHACHA20_POLY1305_IV_LEN   12
+#define CHACHA20_POLY1305_CHECK_LEN 16
+
 #endif