aboutsummaryrefslogtreecommitdiff
path: root/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/common_plat/validation/api/crypto/odp_crypto_test_inp.c')
-rw-r--r--test/common_plat/validation/api/crypto/odp_crypto_test_inp.c599
1 files changed, 556 insertions, 43 deletions
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 43ddb2ffd..ae600e230 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
@@ -28,8 +28,12 @@ static const char *auth_alg_name(odp_auth_alg_t auth)
return "ODP_AUTH_ALG_NULL";
case ODP_AUTH_ALG_MD5_HMAC:
return "ODP_AUTH_ALG_MD5_HMAC";
+ case ODP_AUTH_ALG_SHA1_HMAC:
+ return "ODP_AUTH_ALG_SHA1_HMAC";
case ODP_AUTH_ALG_SHA256_HMAC:
return "ODP_AUTH_ALG_SHA256_HMAC";
+ case ODP_AUTH_ALG_SHA512_HMAC:
+ return "ODP_AUTH_ALG_SHA512_HMAC";
case ODP_AUTH_ALG_AES_GCM:
return "ODP_AUTH_ALG_AES_GCM";
default:
@@ -65,14 +69,17 @@ static const char *cipher_alg_name(odp_cipher_alg_t cipher)
* buffer can be used.
* */
static void alg_test(odp_crypto_op_t op,
+ odp_bool_t should_fail,
odp_cipher_alg_t cipher_alg,
odp_crypto_iv_t ses_iv,
uint8_t *op_iv_ptr,
odp_crypto_key_t cipher_key,
odp_auth_alg_t auth_alg,
odp_crypto_key_t auth_key,
- odp_crypto_data_range_t *cipher_range,
- odp_crypto_data_range_t *auth_range,
+ 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,
@@ -128,9 +135,15 @@ static void alg_test(odp_crypto_op_t op,
if (auth_alg == ODP_AUTH_ALG_NULL &&
!(capa.auths.bit.null))
rc = -1;
+ if (auth_alg == ODP_AUTH_ALG_SHA1_HMAC &&
+ !(capa.auths.bit.sha1_hmac))
+ rc = -1;
if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC &&
!(capa.auths.bit.sha256_hmac))
rc = -1;
+ if (auth_alg == ODP_AUTH_ALG_SHA512_HMAC &&
+ !(capa.auths.bit.sha512_hmac))
+ rc = -1;
CU_ASSERT(!rc);
CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0);
@@ -138,13 +151,8 @@ static void alg_test(odp_crypto_op_t op,
num = odp_crypto_cipher_capability(cipher_alg, cipher_capa,
MAX_ALG_CAPA);
- if (cipher_alg != ODP_CIPHER_ALG_NULL) {
- CU_ASSERT(num > 0);
- found = 0;
- } else {
- CU_ASSERT(num == 0);
- found = 1;
- }
+ CU_ASSERT(num > 0);
+ found = 0;
CU_ASSERT(num <= MAX_ALG_CAPA);
@@ -164,13 +172,8 @@ static void alg_test(odp_crypto_op_t op,
num = odp_crypto_auth_capability(auth_alg, auth_capa, MAX_ALG_CAPA);
- if (auth_alg != ODP_AUTH_ALG_NULL) {
- CU_ASSERT(num > 0);
- found = 0;
- } else {
- CU_ASSERT(num == 0);
- found = 1;
- }
+ CU_ASSERT(num > 0);
+ found = 0;
CU_ASSERT(num <= MAX_ALG_CAPA);
@@ -200,6 +203,7 @@ static void alg_test(odp_crypto_op_t op,
ses_params.cipher_key = cipher_key;
ses_params.iv = ses_iv;
ses_params.auth_key = auth_key;
+ ses_params.auth_digest_len = digest_len;
rc = odp_crypto_session_create(&ses_params, &session, &status);
CU_ASSERT_FATAL(!rc);
@@ -238,7 +242,14 @@ 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,
+ digest, digest_len);
+ }
rc = odp_crypto_operation(&op_params, &posted, &result);
if (rc < 0) {
@@ -259,8 +270,15 @@ static void alg_test(odp_crypto_op_t op,
odp_crypto_compl_free(compl_event);
}
- CU_ASSERT(result.ok);
CU_ASSERT(result.pkt == pkt);
+ CU_ASSERT(result.ctx == (void *)0xdeadbeef);
+
+ if (should_fail) {
+ CU_ASSERT(!result.ok);
+ goto cleanup;
+ }
+
+ CU_ASSERT(result.ok);
if (cipher_alg != ODP_CIPHER_ALG_NULL)
CU_ASSERT(!memcmp(data_addr, ciphertext, ciphertext_len));
@@ -268,8 +286,6 @@ static void alg_test(odp_crypto_op_t op,
if (op == ODP_CRYPTO_OP_ENCODE && auth_alg != ODP_AUTH_ALG_NULL)
CU_ASSERT(!memcmp(data_addr + op_params.hash_result_offset,
digest, digest_len));
-
- CU_ASSERT(result.ctx == (void *)0xdeadbeef);
cleanup:
rc = odp_crypto_session_destroy(session);
CU_ASSERT(!rc);
@@ -330,10 +346,18 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth)
if (!capability.auths.bit.md5_hmac)
return ODP_TEST_INACTIVE;
break;
+ case ODP_AUTH_ALG_SHA1_HMAC:
+ if (!capability.auths.bit.sha1_hmac)
+ return ODP_TEST_INACTIVE;
+ break;
case ODP_AUTH_ALG_SHA256_HMAC:
if (!capability.auths.bit.sha256_hmac)
return ODP_TEST_INACTIVE;
break;
+ case ODP_AUTH_ALG_SHA512_HMAC:
+ if (!capability.auths.bit.sha512_hmac)
+ return ODP_TEST_INACTIVE;
+ break;
case ODP_AUTH_ALG_AES_GCM:
if (!capability.auths.bit.aes_gcm)
return ODP_TEST_INACTIVE;
@@ -416,6 +440,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 = { .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_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);
@@ -445,6 +536,7 @@ void crypto_test_enc_alg_3des_cbc(void)
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_3DES_CBC,
iv,
NULL,
@@ -452,6 +544,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],
@@ -480,6 +573,7 @@ void crypto_test_enc_alg_3des_cbc_ovr_iv(void)
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_3DES_CBC,
iv,
tdes_cbc_reference_iv[i],
@@ -487,6 +581,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],
@@ -519,6 +614,7 @@ void crypto_test_dec_alg_3des_cbc(void)
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_3DES_CBC,
iv,
NULL,
@@ -526,6 +622,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],
@@ -556,6 +653,7 @@ void crypto_test_dec_alg_3des_cbc_ovr_iv(void)
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_3DES_CBC,
iv,
tdes_cbc_reference_iv[i],
@@ -563,6 +661,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],
@@ -598,10 +697,12 @@ void crypto_test_enc_alg_aes128_gcm(void)
cipher_key.length, iv.length))
continue;
if (!check_auth_options(ODP_AUTH_ALG_AES_GCM,
- auth_key.length, AES128_GCM_CHECK_LEN))
+ auth_key.length,
+ aes128_gcm_reference_tag_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_AES_GCM,
iv,
NULL,
@@ -609,14 +710,16 @@ 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],
aes128_gcm_reference_length[i],
aes128_gcm_reference_ciphertext[i] +
aes128_gcm_reference_length[i],
- AES128_GCM_CHECK_LEN);
+ aes128_gcm_reference_tag_length[i]);
}
}
@@ -641,10 +744,12 @@ void crypto_test_enc_alg_aes128_gcm_ovr_iv(void)
cipher_key.length, iv.length))
continue;
if (!check_auth_options(ODP_AUTH_ALG_AES_GCM,
- auth_key.length, AES128_GCM_CHECK_LEN))
+ auth_key.length,
+ aes128_gcm_reference_tag_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_AES_GCM,
iv,
aes128_gcm_reference_iv[i],
@@ -652,14 +757,16 @@ 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],
aes128_gcm_reference_length[i],
aes128_gcm_reference_ciphertext[i] +
aes128_gcm_reference_length[i],
- AES128_GCM_CHECK_LEN);
+ aes128_gcm_reference_tag_length[i]);
}
}
@@ -673,10 +780,13 @@ void crypto_test_dec_alg_aes128_gcm(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 = AES128_GCM_IV_LEN };
+ uint8_t wrong_digest[AES128_GCM_DIGEST_LEN];
unsigned int test_vec_num = (sizeof(aes128_gcm_reference_length) /
sizeof(aes128_gcm_reference_length[0]));
unsigned int i;
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
for (i = 0; i < test_vec_num; i++) {
cipher_key.data = aes128_gcm_reference_key[i];
cipher_key.length = sizeof(aes128_gcm_reference_key[i]);
@@ -687,10 +797,12 @@ void crypto_test_dec_alg_aes128_gcm(void)
cipher_key.length, iv.length))
continue;
if (!check_auth_options(ODP_AUTH_ALG_AES_GCM,
- auth_key.length, AES128_GCM_CHECK_LEN))
+ auth_key.length,
+ aes128_gcm_reference_tag_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_AES_GCM,
iv,
NULL,
@@ -698,14 +810,35 @@ 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_CHECK_LEN,
+ aes128_gcm_reference_length[i],
aes128_gcm_reference_plaintext[i],
aes128_gcm_reference_length[i],
aes128_gcm_reference_ciphertext[i] +
aes128_gcm_reference_length[i],
- AES128_GCM_CHECK_LEN);
+ aes128_gcm_reference_tag_length[i]);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_AES_GCM,
+ iv,
+ NULL,
+ cipher_key,
+ ODP_AUTH_ALG_AES_GCM,
+ auth_key,
+ &aes128_gcm_cipher_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_plaintext[i],
+ aes128_gcm_reference_length[i],
+ wrong_digest,
+ aes128_gcm_reference_tag_length[i]);
}
}
@@ -719,10 +852,13 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(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 = AES128_GCM_IV_LEN };
+ uint8_t wrong_digest[AES128_GCM_DIGEST_LEN];
unsigned int test_vec_num = (sizeof(aes128_gcm_reference_length) /
sizeof(aes128_gcm_reference_length[0]));
unsigned int i;
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
for (i = 0; i < test_vec_num; i++) {
cipher_key.data = aes128_gcm_reference_key[i];
cipher_key.length = sizeof(aes128_gcm_reference_key[i]);
@@ -731,10 +867,12 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void)
cipher_key.length, iv.length))
continue;
if (!check_auth_options(ODP_AUTH_ALG_AES_GCM,
- auth_key.length, AES128_GCM_CHECK_LEN))
+ auth_key.length,
+ aes128_gcm_reference_tag_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_AES_GCM,
iv,
aes128_gcm_reference_iv[i],
@@ -742,14 +880,35 @@ 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_CHECK_LEN,
+ aes128_gcm_reference_length[i],
aes128_gcm_reference_plaintext[i],
aes128_gcm_reference_length[i],
aes128_gcm_reference_ciphertext[i] +
aes128_gcm_reference_length[i],
- AES128_GCM_CHECK_LEN);
+ aes128_gcm_reference_tag_length[i]);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_AES_GCM,
+ iv,
+ aes128_gcm_reference_iv[i],
+ cipher_key,
+ ODP_AUTH_ALG_AES_GCM,
+ auth_key,
+ &aes128_gcm_cipher_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_plaintext[i],
+ aes128_gcm_reference_length[i],
+ wrong_digest,
+ aes128_gcm_reference_tag_length[i]);
}
}
@@ -782,6 +941,7 @@ void crypto_test_enc_alg_aes128_cbc(void)
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_AES_CBC,
iv,
NULL,
@@ -789,6 +949,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],
@@ -817,6 +978,7 @@ void crypto_test_enc_alg_aes128_cbc_ovr_iv(void)
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_AES_CBC,
iv,
aes128_cbc_reference_iv[i],
@@ -824,6 +986,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],
@@ -856,6 +1019,7 @@ void crypto_test_dec_alg_aes128_cbc(void)
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_AES_CBC,
iv,
NULL,
@@ -863,6 +1027,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],
@@ -893,6 +1058,7 @@ void crypto_test_dec_alg_aes128_cbc_ovr_iv(void)
continue;
alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_AES_CBC,
iv,
aes128_cbc_reference_iv[i],
@@ -900,6 +1066,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],
@@ -919,7 +1086,7 @@ static int check_alg_hmac_md5(void)
* In addition the test verifies if the implementation can use the
* packet buffer as completion event buffer.
* */
-void crypto_test_alg_hmac_md5(void)
+void crypto_test_gen_alg_hmac_md5(void)
{
odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 },
auth_key = { .data = NULL, .length = 0 };
@@ -934,10 +1101,50 @@ void crypto_test_alg_hmac_md5(void)
auth_key.length = sizeof(hmac_md5_reference_key[i]);
if (!check_auth_options(ODP_AUTH_ALG_MD5_HMAC, auth_key.length,
- HMAC_MD5_96_CHECK_LEN))
+ hmac_md5_reference_digest_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_MD5_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_md5_reference_plaintext[i],
+ hmac_md5_reference_length[i],
+ NULL, 0,
+ hmac_md5_reference_digest[i],
+ hmac_md5_reference_digest_length[i]);
+ }
+}
+
+void crypto_test_check_alg_hmac_md5(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 };
+ uint8_t wrong_digest[HMAC_MD5_DIGEST_LEN];
+
+ unsigned int test_vec_num = (sizeof(hmac_md5_reference_length) /
+ sizeof(hmac_md5_reference_length[0]));
+ unsigned int i;
+
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_md5_reference_key[i];
+ auth_key.length = sizeof(hmac_md5_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_MD5_HMAC, auth_key.length,
+ hmac_md5_reference_digest_length[i]))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
ODP_CIPHER_ALG_NULL,
iv,
iv.data,
@@ -945,11 +1152,135 @@ void crypto_test_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,
hmac_md5_reference_digest[i],
- HMAC_MD5_96_CHECK_LEN);
+ hmac_md5_reference_digest_length[i]);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_MD5_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_md5_reference_plaintext[i],
+ hmac_md5_reference_length[i],
+ NULL, 0,
+ wrong_digest,
+ hmac_md5_reference_digest_length[i]);
+ }
+}
+
+static int check_alg_hmac_sha1(void)
+{
+ return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA1_HMAC);
+}
+
+/* This test verifies the correctness of HMAC_SHA1 digest operation.
+ * The output check length is truncated to 12 bytes (96 bits) as
+ * returned by the crypto operation API call.
+ * Note that hash digest is a one-way operation.
+ * In addition the test verifies if the implementation can use the
+ * packet buffer as completion event buffer.
+ * */
+void crypto_test_gen_alg_hmac_sha1(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(hmac_sha1_reference_length) /
+ sizeof(hmac_sha1_reference_length[0]));
+
+ unsigned int i;
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_sha1_reference_key[i];
+ auth_key.length = sizeof(hmac_sha1_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_SHA1_HMAC,
+ auth_key.length,
+ HMAC_SHA1_96_CHECK_LEN))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA1_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha1_reference_plaintext[i],
+ hmac_sha1_reference_length[i],
+ NULL, 0,
+ hmac_sha1_reference_digest[i],
+ HMAC_SHA1_96_CHECK_LEN);
+ }
+}
+
+void crypto_test_check_alg_hmac_sha1(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 };
+ uint8_t wrong_digest[HMAC_SHA1_DIGEST_LEN];
+
+ unsigned int test_vec_num = (sizeof(hmac_sha1_reference_length) /
+ sizeof(hmac_sha1_reference_length[0]));
+
+ unsigned int i;
+
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_sha1_reference_key[i];
+ auth_key.length = sizeof(hmac_sha1_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_SHA1_HMAC,
+ auth_key.length,
+ HMAC_SHA1_96_CHECK_LEN))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA1_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha1_reference_plaintext[i],
+ hmac_sha1_reference_length[i],
+ NULL, 0,
+ hmac_sha1_reference_digest[i],
+ HMAC_SHA1_96_CHECK_LEN);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA1_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha1_reference_plaintext[i],
+ hmac_sha1_reference_length[i],
+ NULL, 0,
+ wrong_digest,
+ HMAC_SHA1_96_CHECK_LEN);
}
}
@@ -958,14 +1289,14 @@ static int check_alg_hmac_sha256(void)
return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA256_HMAC);
}
-/* This test verifies the correctness of HMAC_MD5 digest operation.
- * The output check length is truncated to 12 bytes (96 bits) as
+/* This test verifies the correctness of HMAC_SHA256 digest operation.
+ * The output check length is truncated to 16 bytes (128 bits) as
* returned by the crypto operation API call.
* Note that hash digest is a one-way operation.
* In addition the test verifies if the implementation can use the
* packet buffer as completion event buffer.
* */
-void crypto_test_alg_hmac_sha256(void)
+void crypto_test_gen_alg_hmac_sha256(void)
{
odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 },
auth_key = { .data = NULL, .length = 0 };
@@ -982,10 +1313,11 @@ void crypto_test_alg_hmac_sha256(void)
if (!check_auth_options(ODP_AUTH_ALG_SHA256_HMAC,
auth_key.length,
- HMAC_SHA256_128_CHECK_LEN))
+ hmac_sha256_reference_digest_length[i]))
continue;
alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
ODP_CIPHER_ALG_NULL,
iv,
iv.data,
@@ -993,11 +1325,176 @@ void crypto_test_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,
hmac_sha256_reference_digest[i],
- HMAC_SHA256_128_CHECK_LEN);
+ hmac_sha256_reference_digest_length[i]);
+ }
+}
+
+void crypto_test_check_alg_hmac_sha256(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 };
+ uint8_t wrong_digest[HMAC_SHA256_DIGEST_LEN];
+
+ unsigned int test_vec_num = (sizeof(hmac_sha256_reference_length) /
+ sizeof(hmac_sha256_reference_length[0]));
+
+ unsigned int i;
+
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_sha256_reference_key[i];
+ auth_key.length = sizeof(hmac_sha256_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_SHA256_HMAC,
+ auth_key.length,
+ hmac_sha256_reference_digest_length[i]))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA256_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha256_reference_plaintext[i],
+ hmac_sha256_reference_length[i],
+ NULL, 0,
+ hmac_sha256_reference_digest[i],
+ hmac_sha256_reference_digest_length[i]);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA256_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha256_reference_plaintext[i],
+ hmac_sha256_reference_length[i],
+ NULL, 0,
+ wrong_digest,
+ hmac_sha256_reference_digest_length[i]);
+ }
+}
+
+static int check_alg_hmac_sha512(void)
+{
+ return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512_HMAC);
+}
+
+/* This test verifies the correctness of HMAC_SHA512 digest operation.
+ * The output check length is truncated to 32 bytes (256 bits) as
+ * returned by the crypto operation API call.
+ * Note that hash digest is a one-way operation.
+ * In addition the test verifies if the implementation can use the
+ * packet buffer as completion event buffer.
+ * */
+void crypto_test_gen_alg_hmac_sha512(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(hmac_sha512_reference_length) /
+ sizeof(hmac_sha512_reference_length[0]));
+
+ unsigned int i;
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_sha512_reference_key[i];
+ auth_key.length = sizeof(hmac_sha512_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_SHA512_HMAC,
+ auth_key.length,
+ HMAC_SHA512_256_CHECK_LEN))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_ENCODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA512_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha512_reference_plaintext[i],
+ hmac_sha512_reference_length[i],
+ NULL, 0,
+ hmac_sha512_reference_digest[i],
+ HMAC_SHA512_256_CHECK_LEN);
+ }
+}
+
+void crypto_test_check_alg_hmac_sha512(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 };
+ uint8_t wrong_digest[HMAC_SHA512_DIGEST_LEN];
+
+ unsigned int test_vec_num = (sizeof(hmac_sha512_reference_length) /
+ sizeof(hmac_sha512_reference_length[0]));
+
+ unsigned int i;
+
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest));
+
+ for (i = 0; i < test_vec_num; i++) {
+ auth_key.data = hmac_sha512_reference_key[i];
+ auth_key.length = sizeof(hmac_sha512_reference_key[i]);
+
+ if (!check_auth_options(ODP_AUTH_ALG_SHA512_HMAC,
+ auth_key.length,
+ HMAC_SHA512_256_CHECK_LEN))
+ continue;
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 0,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA512_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha512_reference_plaintext[i],
+ hmac_sha512_reference_length[i],
+ NULL, 0,
+ hmac_sha512_reference_digest[i],
+ HMAC_SHA512_256_CHECK_LEN);
+
+ alg_test(ODP_CRYPTO_OP_DECODE,
+ 1,
+ ODP_CIPHER_ALG_NULL,
+ iv,
+ iv.data,
+ cipher_key,
+ ODP_AUTH_ALG_SHA512_HMAC,
+ auth_key,
+ NULL, NULL,
+ NULL, 0,
+ hmac_sha512_reference_plaintext[i],
+ hmac_sha512_reference_length[i],
+ NULL, 0,
+ wrong_digest,
+ HMAC_SHA512_256_CHECK_LEN);
}
}
@@ -1026,6 +1523,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,
@@ -1050,10 +1551,22 @@ odp_testinfo_t crypto_suite[] = {
check_alg_aes_gcm),
ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes128_gcm_ovr_iv,
check_alg_aes_gcm),
- ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_md5,
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_md5,
check_alg_hmac_md5),
- ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_sha256,
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_md5,
+ check_alg_hmac_md5),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha1,
+ check_alg_hmac_sha1),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha1,
+ check_alg_hmac_sha1),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha256,
+ check_alg_hmac_sha256),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha256,
check_alg_hmac_sha256),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha512,
+ check_alg_hmac_sha512),
+ ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha512,
+ check_alg_hmac_sha512),
ODP_TEST_INFO_NULL,
};