diff mbox series

[API-NEXT,v5,02/23] validation: crypto: explicitly pass AAD to crypto subsystem

Message ID 20170601090339.9313-3-dmitry.ereminsolenikov@linaro.org
State Accepted
Commit 1ebbb8f882ae6506fc9fa2cb02dadae3d35eaf58
Headers show
Series Major cryptography code rework | expand

Commit Message

Dmitry Eremin-Solenikov June 1, 2017, 9:03 a.m. UTC
Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
 .../validation/api/crypto/odp_crypto_test_inp.c    | 55 +++++++++++++-----
 .../validation/api/crypto/test_vectors.h           | 65 ++++++++--------------
 2 files changed, 64 insertions(+), 56 deletions(-)

-- 
2.11.0
diff mbox series

Patch

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 3d09e3745b4b..c89d04f9c238 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
@@ -74,6 +74,8 @@  static void alg_test(odp_crypto_op_t op,
 		     odp_crypto_key_t auth_key,
 		     odp_packet_data_range_t *cipher_range,
 		     odp_packet_data_range_t *auth_range,
+		     uint8_t *aad,
+		     uint32_t aad_len,
 		     const uint8_t *plaintext,
 		     unsigned int plaintext_len,
 		     const uint8_t *ciphertext,
@@ -240,6 +242,9 @@  static void alg_test(odp_crypto_op_t op,
 	if (op_iv_ptr)
 		op_params.override_iv_ptr = op_iv_ptr;
 
+	op_params.aad.ptr = aad;
+	op_params.aad.length = aad_len;
+
 	op_params.hash_result_offset = plaintext_len;
 	if (0 != digest_len) {
 		memcpy(data_addr + op_params.hash_result_offset,
@@ -472,6 +477,7 @@  void crypto_test_enc_alg_3des_cbc(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 tdes_cbc_reference_plaintext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_ciphertext[i],
@@ -508,6 +514,7 @@  void crypto_test_enc_alg_3des_cbc_ovr_iv(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 tdes_cbc_reference_plaintext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_ciphertext[i],
@@ -548,6 +555,7 @@  void crypto_test_dec_alg_3des_cbc(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 tdes_cbc_reference_ciphertext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_plaintext[i],
@@ -586,6 +594,7 @@  void crypto_test_dec_alg_3des_cbc_ovr_iv(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 tdes_cbc_reference_ciphertext[i],
 			 tdes_cbc_reference_length[i],
 			 tdes_cbc_reference_plaintext[i],
@@ -634,7 +643,9 @@  void crypto_test_enc_alg_aes128_gcm(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_ciphertext[i],
@@ -679,7 +690,9 @@  void crypto_test_enc_alg_aes128_gcm_ovr_iv(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_ciphertext[i],
@@ -730,10 +743,11 @@  void crypto_test_dec_alg_aes128_gcm(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_ciphertext[i],
-			 aes128_gcm_reference_length[i] +
-			 aes128_gcm_reference_tag_length[i],
+			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_ciphertext[i] +
@@ -749,10 +763,11 @@  void crypto_test_dec_alg_aes128_gcm(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_ciphertext[i],
-			 aes128_gcm_reference_length[i] +
-			 aes128_gcm_reference_tag_length[i],
+			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 wrong_digest,
@@ -798,10 +813,11 @@  void crypto_test_dec_alg_aes128_gcm_ovr_iv(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_ciphertext[i],
-			 aes128_gcm_reference_length[i] +
-			 aes128_gcm_reference_tag_length[i],
+			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_ciphertext[i] +
@@ -817,10 +833,11 @@  void crypto_test_dec_alg_aes128_gcm_ovr_iv(void)
 			 ODP_AUTH_ALG_AES_GCM,
 			 auth_key,
 			 &aes128_gcm_cipher_range[i],
-			 &aes128_gcm_auth_range[i],
+			 &aes128_gcm_cipher_range[i],
+			 aes128_gcm_reference_aad[i],
+			 aes128_gcm_reference_aad_length[i],
 			 aes128_gcm_reference_ciphertext[i],
-			 aes128_gcm_reference_length[i] +
-			 aes128_gcm_reference_tag_length[i],
+			 aes128_gcm_reference_length[i],
 			 aes128_gcm_reference_plaintext[i],
 			 aes128_gcm_reference_length[i],
 			 wrong_digest,
@@ -865,6 +882,7 @@  void crypto_test_enc_alg_aes128_cbc(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 aes128_cbc_reference_plaintext[i],
 			 aes128_cbc_reference_length[i],
 			 aes128_cbc_reference_ciphertext[i],
@@ -901,6 +919,7 @@  void crypto_test_enc_alg_aes128_cbc_ovr_iv(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 aes128_cbc_reference_plaintext[i],
 			 aes128_cbc_reference_length[i],
 			 aes128_cbc_reference_ciphertext[i],
@@ -941,6 +960,7 @@  void crypto_test_dec_alg_aes128_cbc(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 aes128_cbc_reference_ciphertext[i],
 			 aes128_cbc_reference_length[i],
 			 aes128_cbc_reference_plaintext[i],
@@ -979,6 +999,7 @@  void crypto_test_dec_alg_aes128_cbc_ovr_iv(void)
 			 ODP_AUTH_ALG_NULL,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 aes128_cbc_reference_ciphertext[i],
 			 aes128_cbc_reference_length[i],
 			 aes128_cbc_reference_plaintext[i],
@@ -1025,6 +1046,7 @@  void crypto_test_gen_alg_hmac_md5(void)
 			 ODP_AUTH_ALG_MD5_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_md5_reference_plaintext[i],
 			 hmac_md5_reference_length[i],
 			 NULL, 0,
@@ -1063,6 +1085,7 @@  void crypto_test_check_alg_hmac_md5(void)
 			 ODP_AUTH_ALG_MD5_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_md5_reference_plaintext[i],
 			 hmac_md5_reference_length[i],
 			 NULL, 0,
@@ -1078,6 +1101,7 @@  void crypto_test_check_alg_hmac_md5(void)
 			 ODP_AUTH_ALG_MD5_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_md5_reference_plaintext[i],
 			 hmac_md5_reference_length[i],
 			 NULL, 0,
@@ -1127,6 +1151,7 @@  void crypto_test_gen_alg_hmac_sha256(void)
 			 ODP_AUTH_ALG_SHA256_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_sha256_reference_plaintext[i],
 			 hmac_sha256_reference_length[i],
 			 NULL, 0,
@@ -1167,6 +1192,7 @@  void crypto_test_check_alg_hmac_sha256(void)
 			 ODP_AUTH_ALG_SHA256_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_sha256_reference_plaintext[i],
 			 hmac_sha256_reference_length[i],
 			 NULL, 0,
@@ -1182,6 +1208,7 @@  void crypto_test_check_alg_hmac_sha256(void)
 			 ODP_AUTH_ALG_SHA256_HMAC,
 			 auth_key,
 			 NULL, NULL,
+			 NULL, 0,
 			 hmac_sha256_reference_plaintext[i],
 			 hmac_sha256_reference_length[i],
 			 NULL, 0,
diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h
index defbda45ad57..0d36c249870f 100644
--- a/test/common_plat/validation/api/crypto/test_vectors.h
+++ b/test/common_plat/validation/api/crypto/test_vectors.h
@@ -137,31 +137,31 @@  static uint8_t aes128_gcm_reference_iv[][AES128_GCM_IV_LEN] = {
 	  0xa2, 0xfc, 0xa1, 0xa3 }
 };
 
-static uint32_t aes128_gcm_reference_length[] = { 84, 72, 72, 40};
+static uint32_t aes128_gcm_reference_length[] = { 72, 64, 64, 28};
 
 static uint32_t aes128_gcm_reference_tag_length[] = { 16, 16, 16, 16};
 
+static uint32_t aes128_gcm_reference_aad_length[] = { 12, 8, 8, 12};
+
 static odp_packet_data_range_t aes128_gcm_cipher_range[] = {
-	{ .offset = 12, .length = 72 },
-	{ .offset = 8, .length = 64 },
-	{ .offset = 8, .length = 64 },
-	{ .offset = 12, .length = 28 },
+	{ .offset = 0, .length = 72 },
+	{ .offset = 0, .length = 64 },
+	{ .offset = 0, .length = 64 },
+	{ .offset = 0, .length = 28 },
 };
 
-static odp_packet_data_range_t aes128_gcm_auth_range[] = {
-	{ .offset = 0, .length = 84 },
-	{ .offset = 0, .length = 72 },
-	{ .offset = 0, .length = 72 },
-	{ .offset = 0, .length = 40 },
+static uint8_t aes128_gcm_reference_aad[][AES128_GCM_MAX_DATA_LEN] = {
+	{ 0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21,
+	  0x00, 0x00, 0x00, 0x00, },
+	{ 0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a, },
+	{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, },
+	{ 0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10,
+	  0x10, 0x10, 0x10, 0x10, },
 };
 
 static uint8_t
 aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
-	{ /* Aad */
-	  0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21,
-	  0x00, 0x00, 0x00, 0x00,
-	  /* Plain */
-	  0x45, 0x00, 0x00, 0x48, 0x69, 0x9a, 0x00, 0x00,
+	{ 0x45, 0x00, 0x00, 0x48, 0x69, 0x9a, 0x00, 0x00,
 	  0x80, 0x11, 0x4d, 0xb7, 0xc0, 0xa8, 0x01, 0x02,
 	  0xc0, 0xa8, 0x01, 0x01, 0x0a, 0x9b, 0xf1, 0x56,
 	  0x38, 0xd3, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
@@ -171,10 +171,7 @@  aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
 	  0x63, 0x69, 0x74, 0x79, 0x02, 0x64, 0x6b, 0x00,
 	  0x00, 0x21, 0x00, 0x01, 0x01, 0x02, 0x02, 0x01 },
 
-	{ /* Aad */
-	  0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a,
-	  /* Plain */
-	  0x45, 0x00, 0x00, 0x3e, 0x69, 0x8f, 0x00, 0x00,
+	{ 0x45, 0x00, 0x00, 0x3e, 0x69, 0x8f, 0x00, 0x00,
 	  0x80, 0x11, 0x4d, 0xcc, 0xc0, 0xa8, 0x01, 0x02,
 	  0xc0, 0xa8, 0x01, 0x01, 0x0a, 0x98, 0x00, 0x35,
 	  0x00, 0x2a, 0x23, 0x43, 0xb2, 0xd0, 0x01, 0x00,
@@ -183,10 +180,7 @@  aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
 	  0x65, 0x72, 0x63, 0x69, 0x74, 0x79, 0x02, 0x64,
 	  0x6b, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 },
 
-	{ /* Aad */
-	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-	  /* Plain */
-	  0x45, 0x00, 0x00, 0x3c, 0x99, 0xc5, 0x00, 0x00,
+	{ 0x45, 0x00, 0x00, 0x3c, 0x99, 0xc5, 0x00, 0x00,
 	  0x80, 0x01, 0xcb, 0x7a, 0x40, 0x67, 0x93, 0x18,
 	  0x01, 0x01, 0x01, 0x01, 0x08, 0x00, 0x07, 0x5c,
 	  0x02, 0x00, 0x44, 0x00, 0x61, 0x62, 0x63, 0x64,
@@ -195,11 +189,7 @@  aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
 	  0x75, 0x76, 0x77, 0x61, 0x62, 0x63, 0x64, 0x65,
 	  0x66, 0x67, 0x68, 0x69, 0x01, 0x02, 0x02, 0x01 },
 
-	{ /* Aad */
-	  0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10,
-	  0x10, 0x10, 0x10, 0x10,
-	  /* Plain */
-	  0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00,
+	{ 0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00,
 	  0x80, 0x01, 0x44, 0x1f, 0x40, 0x67, 0x93, 0xb6,
 	  0xe0, 0x00, 0x00, 0x02, 0x0a, 0x00, 0xf5, 0xff,
 	  0x01, 0x02, 0x02, 0x01 }
@@ -207,10 +197,7 @@  aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
 
 static uint8_t
 aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = {
-	{ /* Aad */
-	  0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21,
-	  0x00, 0x00, 0x00, 0x00,
-	  /* Plain */
+	{ /* Plain */
 	  0xfe, 0xcf, 0x53, 0x7e, 0x72, 0x9d, 0x5b, 0x07,
 	  0xdc, 0x30, 0xdf, 0x52, 0x8d, 0xd2, 0x2b, 0x76,
 	  0x8d, 0x1b, 0x98, 0x73, 0x66, 0x96, 0xa6, 0xfd,
@@ -224,9 +211,7 @@  aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = {
 	  0x45, 0x90, 0x18, 0x14, 0x8f, 0x6c, 0xbe, 0x72,
 	  0x2f, 0xd0, 0x47, 0x96, 0x56, 0x2d, 0xfd, 0xb4  },
 
-	{ /* Aad */
-	  0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a,
-	  /* Plain */
+	{ /* Plain */
 	  0xde, 0xb2, 0x2c, 0xd9, 0xb0, 0x7c, 0x72, 0xc1,
 	  0x6e, 0x3a, 0x65, 0xbe, 0xeb, 0x8d, 0xf3, 0x04,
 	  0xa5, 0xa5, 0x89, 0x7d, 0x33, 0xae, 0x53, 0x0f,
@@ -238,9 +223,8 @@  aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = {
 	  /* Digest */
 	  0x83, 0xb7, 0x0d, 0x3a, 0xa8, 0xbc, 0x6e, 0xe4,
 	  0xc3, 0x09, 0xe9, 0xd8, 0x5a, 0x41, 0xad, 0x4a },
-	{ /* Aad */
-	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-	  /* Plain */
+
+	{ /* Plain */
 	  0x46, 0x88, 0xda, 0xf2, 0xf9, 0x73, 0xa3, 0x92,
 	  0x73, 0x29, 0x09, 0xc3, 0x31, 0xd5, 0x6d, 0x60,
 	  0xf6, 0x94, 0xab, 0xaa, 0x41, 0x4b, 0x5e, 0x7f,
@@ -253,10 +237,7 @@  aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = {
 	  0xf8, 0x21, 0xd4, 0x96, 0xee, 0xb0, 0x96, 0xe9,
 	  0x8a, 0xd2, 0xb6, 0x9e, 0x47, 0x99, 0xc7, 0x1d },
 
-	{ /* Aad */
-	  0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10,
-	  0x10, 0x10, 0x10, 0x10,
-	  /* Plain */
+	{ /* Plain */
 	  0xfb, 0xa2, 0xca, 0x84, 0x5e, 0x5d, 0xf9, 0xf0,
 	  0xf2, 0x2c, 0x3e, 0x6e, 0x86, 0xdd, 0x83, 0x1e,
 	  0x1f, 0xc6, 0x57, 0x92, 0xcd, 0x1a, 0xf9, 0x13,