diff mbox series

[API-NEXT,v2,9/20] test: crypto: add tests for NULL cipher

Message ID 1495490409-30066-10-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v2,1/20] test: crypto: explicitly pass auth_digest_len to crypto subsystem | expand

Commit Message

Github ODP bot May 22, 2017, 9:59 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 34 (lumag:crypto-update-main-new)
 ** https://github.com/Linaro/odp/pull/34
 ** Patch: https://github.com/Linaro/odp/pull/34.patch
 ** Base sha: 826ee894aa0ebd09d42a17e1de077c46bc5b366a
 ** Merge commit sha: 7c49c61063e2d57f049a5436cf12a3c36710bb34
 **/
 test/common_plat/validation/api/crypto/crypto.h    |  2 +
 .../validation/api/crypto/odp_crypto_test_inp.c    | 71 ++++++++++++++++++++++
 .../validation/api/crypto/test_vectors.h           | 12 ++++
 .../validation/api/crypto/test_vectors_len.h       |  3 +
 4 files changed, 88 insertions(+)
diff mbox series

Patch

diff --git a/test/common_plat/validation/api/crypto/crypto.h b/test/common_plat/validation/api/crypto/crypto.h
index 4d810f62..2a491c3c 100644
--- a/test/common_plat/validation/api/crypto/crypto.h
+++ b/test/common_plat/validation/api/crypto/crypto.h
@@ -10,6 +10,8 @@ 
 #include "odp_cunit_common.h"
 
 /* test functions: */
+void crypto_test_enc_alg_null(void);
+void crypto_test_dec_alg_null(void);
 void crypto_test_enc_alg_3des_cbc(void);
 void crypto_test_enc_alg_3des_cbc_ovr_iv(void);
 void crypto_test_dec_alg_3des_cbc(void);
diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
index a7d8727b..0eb3d5d9 100644
--- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
@@ -430,6 +430,73 @@  static int check_auth_options(odp_auth_alg_t auth, uint32_t key_len,
 	return 1;
 }
 
+static int check_alg_null(void)
+{
+	return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_NULL);
+}
+
+void crypto_test_enc_alg_null(void)
+{
+	odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 },
+			 auth_key   = { .data = NULL, .length = 0 };
+	odp_crypto_iv_t iv;
+	unsigned int test_vec_num = (sizeof(null_reference_length) /
+				     sizeof(null_reference_length[0]));
+	unsigned int i;
+
+	for (i = 0; i < test_vec_num; i++) {
+		if (!check_cipher_options(ODP_CIPHER_ALG_NULL,
+					  cipher_key.length, iv.length))
+			continue;
+
+		alg_test(ODP_CRYPTO_OP_ENCODE,
+			 0,
+			 ODP_CIPHER_ALG_NULL,
+			 iv,
+			 NULL,
+			 cipher_key,
+			 ODP_AUTH_ALG_NULL,
+			 auth_key,
+			 NULL, NULL,
+			 NULL, 0,
+			 null_reference_plaintext[i],
+			 null_reference_length[i],
+			 null_reference_plaintext[i],
+			 null_reference_length[i], NULL, 0);
+	}
+}
+
+void crypto_test_dec_alg_null(void)
+{
+	odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 },
+			 auth_key   = { .data = NULL, .length = 0 };
+	odp_crypto_iv_t iv = { .data = NULL, .length = 0 };
+	unsigned int test_vec_num = (sizeof(null_reference_length) /
+				     sizeof(null_reference_length[0]));
+	unsigned int i;
+
+	for (i = 0; i < test_vec_num; i++) {
+		if (!check_cipher_options(ODP_CIPHER_ALG_NULL,
+					  cipher_key.length, iv.length))
+			continue;
+
+		alg_test(ODP_CRYPTO_OP_DECODE,
+			 0,
+			 ODP_CIPHER_ALG_NULL,
+			 iv,
+			 NULL,
+			 cipher_key,
+			 ODP_AUTH_ALG_NULL,
+			 auth_key,
+			 NULL, NULL,
+			 NULL, 0,
+			 null_reference_plaintext[i],
+			 null_reference_length[i],
+			 null_reference_plaintext[i],
+			 null_reference_length[i], NULL, 0);
+	}
+}
+
 static int check_alg_3des_cbc(void)
 {
 	return check_alg_support(ODP_CIPHER_ALG_3DES_CBC, ODP_AUTH_ALG_NULL);
@@ -1262,6 +1329,10 @@  int crypto_suite_async_init(void)
 }
 
 odp_testinfo_t crypto_suite[] = {
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_null,
+				  check_alg_null),
+	ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_null,
+				  check_alg_null),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_3des_cbc,
 				  check_alg_3des_cbc),
 	ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_cbc,
diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h
index defbda45..b7efe1de 100644
--- a/test/common_plat/validation/api/crypto/test_vectors.h
+++ b/test/common_plat/validation/api/crypto/test_vectors.h
@@ -8,6 +8,18 @@ 
 #define _ODP_TEST_CRYPTO_VECTORS_H_
 
 #include "test_vectors_len.h"
+
+/** length in bytes */
+static uint32_t null_reference_length[] = { 8, 16 };
+
+static uint8_t
+null_reference_plaintext[][NULL_MAX_DATA_LEN] = {
+	{0x32, 0x6a, 0x49, 0x4c, 0xd3, 0x3f, 0xe7, 0x56},
+
+	{0x84, 0x40, 0x1f, 0x78, 0xfe, 0x6c, 0x10, 0x87, 0x6d, 0x8e, 0xa2, 0x30,
+	 0x94, 0xea, 0x53, 0x09}
+};
+
 /* TDES-CBC reference vectors, according to
  * "http://csrc.nist.gov/groups/STM/cavp/documents/des/DESMMT.pdf"
  */
diff --git a/test/common_plat/validation/api/crypto/test_vectors_len.h b/test/common_plat/validation/api/crypto/test_vectors_len.h
index 80fd927b..c1521dd7 100644
--- a/test/common_plat/validation/api/crypto/test_vectors_len.h
+++ b/test/common_plat/validation/api/crypto/test_vectors_len.h
@@ -6,6 +6,9 @@ 
 #ifndef TEST_VECTORS_LEN_
 #define TEST_VECTORS_LEN_
 
+/* NULL */
+#define NULL_MAX_DATA_LEN   16
+
 /* TDES-CBC */
 #define TDES_CBC_KEY_LEN        24
 #define TDES_CBC_IV_LEN         8