aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2018-07-16 15:34:54 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-07-23 17:50:15 +0300
commit8df494a3b0bc4818a63a4780aa71181a5d16dcc4 (patch)
tree66f4c9d08b4e6ced331cadacbe52bfd55a0c6199
parent1dc3772b965dd9285d8f006fb7d6600ed7c1bc33 (diff)
validation: crypto: add support for bit mode algorithm testing
Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r--test/validation/api/crypto/odp_crypto_test_inp.c140
1 files changed, 100 insertions, 40 deletions
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c
index 1e06761c6..a551be558 100644
--- a/test/validation/api/crypto/odp_crypto_test_inp.c
+++ b/test/validation/api/crypto/odp_crypto_test_inp.c
@@ -320,13 +320,15 @@ static void alg_test(odp_crypto_op_t op,
odp_cipher_alg_t cipher_alg,
odp_auth_alg_t auth_alg,
crypto_test_reference_t *ref,
- odp_bool_t ovr_iv)
+ odp_bool_t ovr_iv,
+ odp_bool_t bit_mode)
{
odp_crypto_session_t session;
int rc;
odp_crypto_ses_create_err_t status;
odp_bool_t ok = false;
int iteration;
+ uint32_t reflength;
odp_crypto_session_param_t ses_params;
odp_packet_data_range_t cipher_range;
odp_packet_data_range_t auth_range;
@@ -375,9 +377,14 @@ static void alg_test(odp_crypto_op_t op,
auth_range.offset = 0;
auth_range.length = ref->length;
+ if (bit_mode)
+ reflength = (ref->length + 7) / 8;
+ else
+ reflength = ref->length;
+
/* Prepare input data */
odp_packet_t pkt = odp_packet_alloc(suite_context.pool,
- ref->length + ref->digest_length);
+ reflength + ref->digest_length);
CU_ASSERT(pkt != ODP_PACKET_INVALID);
if (pkt == ODP_PACKET_INVALID)
goto cleanup;
@@ -391,18 +398,18 @@ static void alg_test(odp_crypto_op_t op,
continue;
if (op == ODP_CRYPTO_OP_ENCODE) {
- odp_packet_copy_from_mem(pkt, 0, ref->length,
+ odp_packet_copy_from_mem(pkt, 0, reflength,
ref->plaintext);
} else {
- odp_packet_copy_from_mem(pkt, 0, ref->length,
+ odp_packet_copy_from_mem(pkt, 0, reflength,
ref->ciphertext);
- odp_packet_copy_from_mem(pkt, ref->length,
+ odp_packet_copy_from_mem(pkt, reflength,
ref->digest_length,
ref->digest);
if (iteration == WRONG_DIGEST_TEST) {
uint8_t byte = ~ref->digest[0];
- odp_packet_copy_from_mem(pkt, ref->length,
+ odp_packet_copy_from_mem(pkt, reflength,
1, &byte);
}
}
@@ -412,19 +419,19 @@ static void alg_test(odp_crypto_op_t op,
ovr_iv ? ref->cipher_iv : NULL,
ovr_iv ? ref->auth_iv : NULL,
&cipher_range, &auth_range,
- ref->aad, ref->length);
+ ref->aad, reflength);
else if (ODP_CRYPTO_ASYNC == suite_context.op_mode)
rc = alg_packet_op_enq(pkt, &ok, session,
ovr_iv ? ref->cipher_iv : NULL,
ovr_iv ? ref->auth_iv : NULL,
&cipher_range, &auth_range,
- ref->aad, ref->length);
+ ref->aad, reflength);
else
rc = alg_packet_op(pkt, &ok, session,
ovr_iv ? ref->cipher_iv : NULL,
ovr_iv ? ref->auth_iv : NULL,
&cipher_range, &auth_range,
- ref->aad, ref->length);
+ ref->aad, reflength);
if (rc < 0)
break;
@@ -438,14 +445,14 @@ static void alg_test(odp_crypto_op_t op,
if (op == ODP_CRYPTO_OP_ENCODE) {
CU_ASSERT(!packet_cmp_mem(pkt, 0,
ref->ciphertext,
- ref->length));
- CU_ASSERT(!packet_cmp_mem(pkt, ref->length,
+ reflength));
+ CU_ASSERT(!packet_cmp_mem(pkt, reflength,
ref->digest,
ref->digest_length));
} else {
CU_ASSERT(!packet_cmp_mem(pkt, 0,
ref->plaintext,
- ref->length));
+ reflength));
}
}
@@ -461,7 +468,8 @@ static void check_alg(odp_crypto_op_t op,
odp_auth_alg_t auth_alg,
crypto_test_reference_t *ref,
size_t count,
- odp_bool_t ovr_iv)
+ odp_bool_t ovr_iv,
+ odp_bool_t bit_mode)
{
odp_crypto_capability_t capa;
int rc, i;
@@ -565,7 +573,9 @@ static void check_alg(odp_crypto_op_t op,
if (cipher_capa[i].key_len ==
ref[idx].cipher_key_length &&
cipher_capa[i].iv_len ==
- ref[idx].cipher_iv_length) {
+ ref[idx].cipher_iv_length &&
+ cipher_capa[i].bit_mode ==
+ bit_mode) {
cipher_idx = i;
break;
}
@@ -573,10 +583,11 @@ static void check_alg(odp_crypto_op_t op,
if (cipher_idx < 0) {
printf("\n Unsupported: alg=%s, key_len=%" PRIu32
- ", iv_len=%" PRIu32 "\n",
+ ", iv_len=%" PRIu32 "%s\n",
cipher_alg_name(cipher_alg),
ref[idx].cipher_key_length,
- ref[idx].cipher_iv_length);
+ ref[idx].cipher_iv_length,
+ bit_mode ? " using bits" : "");
continue;
}
@@ -586,7 +597,9 @@ static void check_alg(odp_crypto_op_t op,
auth_capa[i].iv_len ==
ref[idx].auth_iv_length &&
auth_capa[i].key_len ==
- ref[idx].auth_key_length) {
+ ref[idx].auth_key_length &&
+ auth_capa[i].bit_mode ==
+ bit_mode) {
auth_idx = i;
break;
}
@@ -594,15 +607,17 @@ static void check_alg(odp_crypto_op_t op,
if (auth_idx < 0) {
printf("\n Unsupported: alg=%s, key_len=%" PRIu32
- ", iv_len=%" PRIu32 ", digest_len=%" PRIu32 "\n",
+ ", iv_len=%" PRIu32 ", digest_len=%" PRIu32
+ "%s\n",
auth_alg_name(auth_alg),
ref[idx].auth_key_length,
ref[idx].auth_iv_length,
- ref[idx].digest_length);
+ ref[idx].digest_length,
+ bit_mode ? " using bits" : "");
continue;
}
- alg_test(op, cipher_alg, auth_alg, &ref[idx], ovr_iv);
+ alg_test(op, cipher_alg, auth_alg, &ref[idx], ovr_iv, bit_mode);
cipher_tested[cipher_idx] = true;
auth_tested[auth_idx] = true;
@@ -610,23 +625,24 @@ static void check_alg(odp_crypto_op_t op,
for (i = 0; i < cipher_num; i++) {
cipher_ok |= cipher_tested[i];
- if (!cipher_tested[i]) {
+ if (!cipher_tested[i] && cipher_capa[i].bit_mode == bit_mode)
printf("\n Untested: alg=%s, key_len=%" PRIu32 ", "
- "iv_len=%" PRIu32 "\n",
+ "iv_len=%" PRIu32 "%s\n",
cipher_alg_name(cipher_alg),
cipher_capa[i].key_len,
- cipher_capa[i].iv_len);
- }
+ cipher_capa[i].iv_len,
+ cipher_capa[i].bit_mode ? " using bits" : "");
}
for (i = 0; i < auth_num; i++) {
auth_ok |= auth_tested[i];
- if (!auth_tested[i])
+ if (!auth_tested[i] && auth_capa[i].bit_mode == bit_mode)
printf("\n Untested: alg=%s, key_len=%" PRIu32 ", "
- "digest_len=%" PRIu32 "\n",
+ "digest_len=%" PRIu32 "%s\n",
auth_alg_name(auth_alg),
auth_capa[i].key_len,
- auth_capa[i].digest_len);
+ auth_capa[i].digest_len,
+ auth_capa[i].bit_mode ? " using bits" : "");
}
/* Verify that we were able to run at least several tests */
@@ -769,6 +785,7 @@ static void crypto_test_enc_alg_null(void)
ODP_AUTH_ALG_NULL,
null_reference,
ARRAY_SIZE(null_reference),
+ false,
false);
}
@@ -779,6 +796,7 @@ static void crypto_test_dec_alg_null(void)
ODP_AUTH_ALG_NULL,
null_reference,
ARRAY_SIZE(null_reference),
+ false,
false);
}
@@ -798,6 +816,7 @@ static void crypto_test_enc_alg_3des_cbc(void)
ODP_AUTH_ALG_NULL,
tdes_cbc_reference,
ARRAY_SIZE(tdes_cbc_reference),
+ false,
false);
}
@@ -811,7 +830,8 @@ static void crypto_test_enc_alg_3des_cbc_ovr_iv(void)
ODP_AUTH_ALG_NULL,
tdes_cbc_reference,
ARRAY_SIZE(tdes_cbc_reference),
- true);
+ true,
+ false);
}
/* This test verifies the correctness of decode (ciphertext -> plaintext)
@@ -826,6 +846,7 @@ static void crypto_test_dec_alg_3des_cbc(void)
ODP_AUTH_ALG_NULL,
tdes_cbc_reference,
ARRAY_SIZE(tdes_cbc_reference),
+ false,
false);
}
@@ -841,7 +862,8 @@ static void crypto_test_dec_alg_3des_cbc_ovr_iv(void)
ODP_AUTH_ALG_NULL,
tdes_cbc_reference,
ARRAY_SIZE(tdes_cbc_reference),
- true);
+ true,
+ false);
}
static int check_alg_chacha20_poly1305(void)
@@ -857,6 +879,7 @@ static void crypto_test_enc_alg_chacha20_poly1305(void)
ODP_AUTH_ALG_CHACHA20_POLY1305,
chacha20_poly1305_reference,
ARRAY_SIZE(chacha20_poly1305_reference),
+ false,
false);
}
@@ -867,7 +890,8 @@ static void crypto_test_enc_alg_chacha20_poly1305_ovr_iv(void)
ODP_AUTH_ALG_CHACHA20_POLY1305,
chacha20_poly1305_reference,
ARRAY_SIZE(chacha20_poly1305_reference),
- true);
+ true,
+ false);
}
static void crypto_test_dec_alg_chacha20_poly1305(void)
@@ -877,6 +901,7 @@ static void crypto_test_dec_alg_chacha20_poly1305(void)
ODP_AUTH_ALG_CHACHA20_POLY1305,
chacha20_poly1305_reference,
ARRAY_SIZE(chacha20_poly1305_reference),
+ false,
false);
}
@@ -887,7 +912,8 @@ static void crypto_test_dec_alg_chacha20_poly1305_ovr_iv(void)
ODP_AUTH_ALG_CHACHA20_POLY1305,
chacha20_poly1305_reference,
ARRAY_SIZE(chacha20_poly1305_reference),
- true);
+ true,
+ false);
}
static int check_alg_aes_gcm(void)
@@ -906,6 +932,7 @@ static void crypto_test_enc_alg_aes_gcm(void)
ODP_AUTH_ALG_AES_GCM,
aes_gcm_reference,
ARRAY_SIZE(aes_gcm_reference),
+ false,
false);
}
@@ -920,7 +947,8 @@ static void crypto_test_enc_alg_aes_gcm_ovr_iv(void)
ODP_AUTH_ALG_AES_GCM,
aes_gcm_reference,
ARRAY_SIZE(aes_gcm_reference),
- true);
+ true,
+ false);
}
/* This test verifies the correctness of decode (ciphertext -> plaintext)
@@ -935,6 +963,7 @@ static void crypto_test_dec_alg_aes_gcm(void)
ODP_AUTH_ALG_AES_GCM,
aes_gcm_reference,
ARRAY_SIZE(aes_gcm_reference),
+ false,
false);
}
@@ -950,7 +979,8 @@ static void crypto_test_dec_alg_aes_gcm_ovr_iv(void)
ODP_AUTH_ALG_AES_GCM,
aes_gcm_reference,
ARRAY_SIZE(aes_gcm_reference),
- true);
+ true,
+ false);
}
static int check_alg_aes_ccm(void)
@@ -965,6 +995,7 @@ static void crypto_test_enc_alg_aes_ccm(void)
ODP_AUTH_ALG_AES_CCM,
aes_ccm_reference,
ARRAY_SIZE(aes_ccm_reference),
+ false,
false);
}
@@ -975,7 +1006,8 @@ static void crypto_test_enc_alg_aes_ccm_ovr_iv(void)
ODP_AUTH_ALG_AES_CCM,
aes_ccm_reference,
ARRAY_SIZE(aes_ccm_reference),
- true);
+ true,
+ false);
}
static void crypto_test_dec_alg_aes_ccm(void)
@@ -985,6 +1017,7 @@ static void crypto_test_dec_alg_aes_ccm(void)
ODP_AUTH_ALG_AES_CCM,
aes_ccm_reference,
ARRAY_SIZE(aes_ccm_reference),
+ false,
false);
}
@@ -995,7 +1028,8 @@ static void crypto_test_dec_alg_aes_ccm_ovr_iv(void)
ODP_AUTH_ALG_AES_CCM,
aes_ccm_reference,
ARRAY_SIZE(aes_ccm_reference),
- true);
+ true,
+ false);
}
static int check_alg_aes_cbc(void)
@@ -1014,6 +1048,7 @@ static void crypto_test_enc_alg_aes_cbc(void)
ODP_AUTH_ALG_NULL,
aes_cbc_reference,
ARRAY_SIZE(aes_cbc_reference),
+ false,
false);
}
@@ -1027,7 +1062,8 @@ static void crypto_test_enc_alg_aes_cbc_ovr_iv(void)
ODP_AUTH_ALG_NULL,
aes_cbc_reference,
ARRAY_SIZE(aes_cbc_reference),
- true);
+ true,
+ false);
}
/* This test verifies the correctness of decode (ciphertext -> plaintext)
@@ -1042,6 +1078,7 @@ static void crypto_test_dec_alg_aes_cbc(void)
ODP_AUTH_ALG_NULL,
aes_cbc_reference,
ARRAY_SIZE(aes_cbc_reference),
+ false,
false);
}
@@ -1057,7 +1094,8 @@ static void crypto_test_dec_alg_aes_cbc_ovr_iv(void)
ODP_AUTH_ALG_NULL,
aes_cbc_reference,
ARRAY_SIZE(aes_cbc_reference),
- true);
+ true,
+ false);
}
static int check_alg_aes_ctr(void)
@@ -1076,6 +1114,7 @@ static void crypto_test_enc_alg_aes_ctr(void)
ODP_AUTH_ALG_NULL,
aes_ctr_reference,
ARRAY_SIZE(aes_ctr_reference),
+ false,
false);
}
@@ -1089,7 +1128,8 @@ static void crypto_test_enc_alg_aes_ctr_ovr_iv(void)
ODP_AUTH_ALG_NULL,
aes_ctr_reference,
ARRAY_SIZE(aes_ctr_reference),
- true);
+ true,
+ false);
}
/* This test verifies the correctness of decode (ciphertext -> plaintext)
@@ -1104,6 +1144,7 @@ static void crypto_test_dec_alg_aes_ctr(void)
ODP_AUTH_ALG_NULL,
aes_ctr_reference,
ARRAY_SIZE(aes_ctr_reference),
+ false,
false);
}
@@ -1119,7 +1160,8 @@ static void crypto_test_dec_alg_aes_ctr_ovr_iv(void)
ODP_AUTH_ALG_NULL,
aes_ctr_reference,
ARRAY_SIZE(aes_ctr_reference),
- true);
+ true,
+ false);
}
static int check_alg_hmac_md5(void)
@@ -1141,6 +1183,7 @@ static void crypto_test_gen_alg_hmac_md5(void)
ODP_AUTH_ALG_MD5_HMAC,
hmac_md5_reference,
ARRAY_SIZE(hmac_md5_reference),
+ false,
false);
}
@@ -1151,6 +1194,7 @@ static void crypto_test_check_alg_hmac_md5(void)
ODP_AUTH_ALG_MD5_HMAC,
hmac_md5_reference,
ARRAY_SIZE(hmac_md5_reference),
+ false,
false);
}
@@ -1173,6 +1217,7 @@ static void crypto_test_gen_alg_hmac_sha1(void)
ODP_AUTH_ALG_SHA1_HMAC,
hmac_sha1_reference,
ARRAY_SIZE(hmac_sha1_reference),
+ false,
false);
}
@@ -1183,6 +1228,7 @@ static void crypto_test_check_alg_hmac_sha1(void)
ODP_AUTH_ALG_SHA1_HMAC,
hmac_sha1_reference,
ARRAY_SIZE(hmac_sha1_reference),
+ false,
false);
}
@@ -1205,6 +1251,7 @@ static void crypto_test_gen_alg_hmac_sha256(void)
ODP_AUTH_ALG_SHA256_HMAC,
hmac_sha256_reference,
ARRAY_SIZE(hmac_sha256_reference),
+ false,
false);
}
@@ -1215,6 +1262,7 @@ static void crypto_test_check_alg_hmac_sha256(void)
ODP_AUTH_ALG_SHA256_HMAC,
hmac_sha256_reference,
ARRAY_SIZE(hmac_sha256_reference),
+ false,
false);
}
@@ -1237,6 +1285,7 @@ static void crypto_test_gen_alg_hmac_sha384(void)
ODP_AUTH_ALG_SHA384_HMAC,
hmac_sha384_reference,
ARRAY_SIZE(hmac_sha384_reference),
+ false,
false);
}
@@ -1247,6 +1296,7 @@ static void crypto_test_check_alg_hmac_sha384(void)
ODP_AUTH_ALG_SHA384_HMAC,
hmac_sha384_reference,
ARRAY_SIZE(hmac_sha384_reference),
+ false,
false);
}
@@ -1269,6 +1319,7 @@ static void crypto_test_gen_alg_hmac_sha512(void)
ODP_AUTH_ALG_SHA512_HMAC,
hmac_sha512_reference,
ARRAY_SIZE(hmac_sha512_reference),
+ false,
false);
}
@@ -1279,6 +1330,7 @@ static void crypto_test_check_alg_hmac_sha512(void)
ODP_AUTH_ALG_SHA512_HMAC,
hmac_sha512_reference,
ARRAY_SIZE(hmac_sha512_reference),
+ false,
false);
}
@@ -1302,6 +1354,7 @@ static void crypto_test_gen_alg_aes_xcbc(void)
ODP_AUTH_ALG_AES_XCBC_MAC,
aes_xcbc_reference,
ARRAY_SIZE(aes_xcbc_reference),
+ false,
false);
}
@@ -1312,6 +1365,7 @@ static void crypto_test_check_alg_aes_xcbc(void)
ODP_AUTH_ALG_AES_XCBC_MAC,
aes_xcbc_reference,
ARRAY_SIZE(aes_xcbc_reference),
+ false,
false);
}
@@ -1327,6 +1381,7 @@ static void crypto_test_gen_alg_aes_gmac(void)
ODP_AUTH_ALG_AES_GMAC,
aes_gmac_reference,
ARRAY_SIZE(aes_gmac_reference),
+ false,
false);
}
@@ -1337,7 +1392,8 @@ static void crypto_test_gen_alg_aes_gmac_ovr_iv(void)
ODP_AUTH_ALG_AES_GMAC,
aes_gmac_reference,
ARRAY_SIZE(aes_gmac_reference),
- true);
+ true,
+ false);
}
static void crypto_test_check_alg_aes_gmac(void)
@@ -1347,6 +1403,7 @@ static void crypto_test_check_alg_aes_gmac(void)
ODP_AUTH_ALG_AES_GMAC,
aes_gmac_reference,
ARRAY_SIZE(aes_gmac_reference),
+ false,
false);
}
@@ -1357,6 +1414,7 @@ static void crypto_test_check_alg_aes_gmac_ovr_iv(void)
ODP_AUTH_ALG_AES_GMAC,
aes_gmac_reference,
ARRAY_SIZE(aes_gmac_reference),
+ false,
false);
}
@@ -1372,6 +1430,7 @@ static void crypto_test_gen_alg_aes_cmac(void)
ODP_AUTH_ALG_AES_CMAC,
aes_cmac_reference,
ARRAY_SIZE(aes_cmac_reference),
+ false,
false);
}
@@ -1382,6 +1441,7 @@ static void crypto_test_check_alg_aes_cmac(void)
ODP_AUTH_ALG_AES_CMAC,
aes_cmac_reference,
ARRAY_SIZE(aes_cmac_reference),
+ false,
false);
}