This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, master has been updated via 290decaf3259b036c3a402be428b04ba100f0f81 (commit) via 61d16e162788ac0923c544b4d31bb847fa3d9189 (commit) from 83fda5a447335b95bdd991187d4efb0a15a5709a (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 290decaf3259b036c3a402be428b04ba100f0f81 Author: yhe yhe@sonicwall.com Date: Wed Mar 28 08:51:20 2018 +0800
validation:crypto:implement AES-XCBC-MAC and SHA384-HMAC
Add AES-XCBC-MAC and SHA384-HMAC into the test case
Signed-off-by: Tom He yhe@sonicwall.com Reviewed-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 39ef3350..aa053dd5 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -47,8 +47,12 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_SHA1_HMAC"; case ODP_AUTH_ALG_SHA256_HMAC: return "ODP_AUTH_ALG_SHA256_HMAC"; + case ODP_AUTH_ALG_SHA384_HMAC: + return "ODP_AUTH_ALG_SHA384_HMAC"; case ODP_AUTH_ALG_SHA512_HMAC: return "ODP_AUTH_ALG_SHA512_HMAC"; + case ODP_AUTH_ALG_AES_XCBC_MAC: + return "ODP_AUTH_ALG_AES_XCBC_MAC"; case ODP_AUTH_ALG_AES_GCM: return "ODP_AUTH_ALG_AES_GCM"; case ODP_AUTH_ALG_AES_GMAC: @@ -527,9 +531,15 @@ static void check_alg(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC && !(capa.auths.bit.sha256_hmac)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA384_HMAC && + !(capa.auths.bit.sha384_hmac)) + rc = -1; if (auth_alg == ODP_AUTH_ALG_SHA512_HMAC && !(capa.auths.bit.sha512_hmac)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_AES_XCBC_MAC && + !(capa.auths.bit.aes_xcbc_mac)) + rc = -1;
CU_ASSERT(!rc); CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0); @@ -711,10 +721,18 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.sha256_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_SHA384_HMAC: + if (!capability.auths.bit.sha384_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_XCBC_MAC: + if (!capability.auths.bit.aes_xcbc_mac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_AES_GCM: if (!capability.auths.bit.aes_gcm) return ODP_TEST_INACTIVE; @@ -1205,6 +1223,38 @@ static void crypto_test_check_alg_hmac_sha256(void) false); }
+static int check_alg_hmac_sha384(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA384_HMAC); +} + +/* This test verifies the correctness of HMAC_SHA384 digest operation. + * The output check length is truncated to 24 bytes (192 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. + * */ +static void crypto_test_gen_alg_hmac_sha384(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA384_HMAC, + hmac_sha384_reference, + ARRAY_SIZE(hmac_sha384_reference), + false); +} + +static void crypto_test_check_alg_hmac_sha384(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_SHA384_HMAC, + hmac_sha384_reference, + ARRAY_SIZE(hmac_sha384_reference), + false); +} + static int check_alg_hmac_sha512(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512_HMAC); @@ -1237,6 +1287,39 @@ static void crypto_test_check_alg_hmac_sha512(void) false); }
+static int check_alg_aes_xcbc(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_XCBC_MAC); +} + +/* This test verifies the correctness of AES_XCBC_MAC 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. + * */ +static void crypto_test_gen_alg_aes_xcbc(void) +{ + check_alg(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_XCBC_MAC, + aes_xcbc_reference, + ARRAY_SIZE(aes_xcbc_reference), + false); +} + +static void crypto_test_check_alg_aes_xcbc(void) +{ + check_alg(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_NULL, + ODP_AUTH_ALG_AES_XCBC_MAC, + aes_xcbc_reference, + ARRAY_SIZE(aes_xcbc_reference), + false); +} + static int check_alg_aes_gmac(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_AES_GMAC); @@ -1424,10 +1507,18 @@ odp_testinfo_t crypto_suite[] = { 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_sha384, + check_alg_hmac_sha384), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha384, + check_alg_hmac_sha384), 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_CONDITIONAL(crypto_test_gen_alg_aes_xcbc, + check_alg_aes_xcbc), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_xcbc, + check_alg_aes_xcbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac, check_alg_aes_gmac), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac_ovr_iv, diff --git a/test/validation/api/crypto/test_vectors.h b/test/validation/api/crypto/test_vectors.h index 23ed9525..9adb4332 100644 --- a/test/validation/api/crypto/test_vectors.h +++ b/test/validation/api/crypto/test_vectors.h @@ -1188,6 +1188,134 @@ static crypto_test_reference_t hmac_sha256_reference[] = { } };
+static crypto_test_reference_t hmac_sha384_reference[] = { + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + .auth_key = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + .length = 8, + /* "Hi There" */ + .plaintext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .ciphertext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .digest_length = HMAC_SHA384_192_CHECK_LEN, + .digest = { 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62, + 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f, + 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6 } + }, + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + /* "Jefe" */ + .auth_key = { 0x4a, 0x65, 0x66, 0x65 }, + .length = 28, + /* what do ya want for nothing?*/ + .plaintext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .ciphertext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .digest_length = HMAC_SHA384_192_CHECK_LEN, + .digest = { 0xaf, 0x45, 0xd2, 0xe3, 0x76, 0x48, 0x40, 0x31, + 0x61, 0x7f, 0x78, 0xd2, 0xb5, 0x8a, 0x6b, 0x1b, + 0x9c, 0x7e, 0xf4, 0x64, 0xf5, 0xa0, 0x1b, 0x47 } + }, + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + .auth_key = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa }, + .length = 50, + .plaintext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .ciphertext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .digest_length = HMAC_SHA384_192_CHECK_LEN, + .digest = { 0x88, 0x06, 0x26, 0x08, 0xd3, 0xe6, 0xad, 0x8a, + 0x0a, 0xa2, 0xac, 0xe0, 0x14, 0xc8, 0xa8, 0x6f, + 0x0a, 0xa6, 0x35, 0xd9, 0x47, 0xac, 0x9f, 0xeb } + }, + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + .auth_key = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + .length = 8, + /* "Hi There" */ + .plaintext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .ciphertext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + .digest_length = HMAC_SHA384_CHECK_LEN, + .digest = { 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62, + 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f, + 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6, + 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c, + 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f, + 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6 } + }, + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + /* "Jefe" */ + .auth_key = { 0x4a, 0x65, 0x66, 0x65 }, + .length = 28, + /* what do ya want for nothing?*/ + .plaintext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .ciphertext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + .digest_length = HMAC_SHA384_CHECK_LEN, + .digest = { 0xaf, 0x45, 0xd2, 0xe3, 0x76, 0x48, 0x40, 0x31, + 0x61, 0x7f, 0x78, 0xd2, 0xb5, 0x8a, 0x6b, 0x1b, + 0x9c, 0x7e, 0xf4, 0x64, 0xf5, 0xa0, 0x1b, 0x47, + 0xe4, 0x2e, 0xc3, 0x73, 0x63, 0x22, 0x44, 0x5e, + 0x8e, 0x22, 0x40, 0xca, 0x5e, 0x69, 0xe2, 0xc7, + 0x8b, 0x32, 0x39, 0xec, 0xfa, 0xb2, 0x16, 0x49 } + }, + { + .auth_key_length = HMAC_SHA384_KEY_LEN, + .auth_key = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa }, + .length = 50, + .plaintext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .ciphertext = { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd }, + .digest_length = HMAC_SHA384_CHECK_LEN, + .digest = {0x88, 0x06, 0x26, 0x08, 0xd3, 0xe6, 0xad, 0x8a, + 0x0a, 0xa2, 0xac, 0xe0, 0x14, 0xc8, 0xa8, 0x6f, + 0x0a, 0xa6, 0x35, 0xd9, 0x47, 0xac, 0x9f, 0xeb, + 0xe8, 0x3e, 0xf4, 0xe5, 0x59, 0x66, 0x14, 0x4b, + 0x2a, 0x5a, 0xb3, 0x9d, 0xc1, 0x38, 0x14, 0xb9, + 0x4e, 0x3a, 0xb6, 0xe1, 0x01, 0xa3, 0x4f, 0x27 } + } +}; + static crypto_test_reference_t hmac_sha512_reference[] = { { .auth_key_length = HMAC_SHA512_KEY_LEN, @@ -1325,4 +1453,85 @@ static crypto_test_reference_t hmac_sha512_reference[] = { } };
+static crypto_test_reference_t aes_xcbc_reference[] = { + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 3, + .plaintext = { 0x00, 0x01, 0x02 }, + .ciphertext = { 0x00, 0x01, 0x02 }, + .digest_length = AES_XCBC_MAC_96_CHECK_LEN, + .digest = { 0x5b, 0x37, 0x65, 0x80, 0xae, 0x2f, 0x19, 0xaf, + 0xe7, 0x21, 0x9c, 0xee } + }, + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 16, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .ciphertext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .digest_length = AES_XCBC_MAC_96_CHECK_LEN, + .digest = { 0xd2, 0xa2, 0x46, 0xfa, 0x34, 0x9b, 0x68, 0xa7, + 0x99, 0x98, 0xa4, 0x39 } + }, + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 20, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13 }, + .ciphertext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13 }, + .digest_length = AES_XCBC_MAC_96_CHECK_LEN, + .digest = { 0x47, 0xf5, 0x1b, 0x45, 0x64, 0x96, 0x62, 0x15, + 0xb8, 0x98, 0x5c, 0x63 } + }, + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 3, + .plaintext = { 0x00, 0x01, 0x02 }, + .ciphertext = { 0x00, 0x01, 0x02 }, + .digest_length = AES_XCBC_MAC_CHECK_LEN, + .digest = { 0x5b, 0x37, 0x65, 0x80, 0xae, 0x2f, 0x19, 0xaf, + 0xe7, 0x21, 0x9c, 0xee, 0xf1, 0x72, 0x75, 0x6f } + }, + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 16, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .ciphertext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .digest_length = AES_XCBC_MAC_CHECK_LEN, + .digest = { 0xd2, 0xa2, 0x46, 0xfa, 0x34, 0x9b, 0x68, 0xa7, + 0x99, 0x98, 0xa4, 0x39, 0x4f, 0xf7, 0xa2, 0x63 } + }, + { + .auth_key_length = AES_XCBC_MAC_KEY_LEN, + .auth_key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + .length = 20, + .plaintext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13 }, + .ciphertext = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13 }, + .digest_length = AES_XCBC_MAC_CHECK_LEN, + .digest = { 0x47, 0xf5, 0x1b, 0x45, 0x64, 0x96, 0x62, 0x15, + 0xb8, 0x98, 0x5c, 0x63, 0x05, 0x5e, 0xd3, 0x08 } + } +}; + #endif diff --git a/test/validation/api/crypto/test_vectors_len.h b/test/validation/api/crypto/test_vectors_len.h index 860840cf..95d202b6 100644 --- a/test/validation/api/crypto/test_vectors_len.h +++ b/test/validation/api/crypto/test_vectors_len.h @@ -50,6 +50,11 @@ #define HMAC_SHA1_96_CHECK_LEN 12 #define HMAC_SHA1_CHECK_LEN 20
+/* HMAC-SHA384 */ +#define HMAC_SHA384_KEY_LEN 48 +#define HMAC_SHA384_192_CHECK_LEN 24 +#define HMAC_SHA384_CHECK_LEN 48 + /* HMAC-SHA512 */ #define HMAC_SHA512_KEY_LEN 64 #define HMAC_SHA512_256_CHECK_LEN 32 @@ -60,4 +65,9 @@ #define CHACHA20_POLY1305_IV_LEN 12 #define CHACHA20_POLY1305_CHECK_LEN 16
+/* AES-XCBC-MAC */ +#define AES_XCBC_MAC_KEY_LEN 16 +#define AES_XCBC_MAC_96_CHECK_LEN 12 +#define AES_XCBC_MAC_CHECK_LEN 16 + #endif diff --git a/test/validation/api/ipsec/ipsec.c b/test/validation/api/ipsec/ipsec.c index 3e2e743d..7c82d85a 100644 --- a/test/validation/api/ipsec/ipsec.c +++ b/test/validation/api/ipsec/ipsec.c @@ -204,10 +204,18 @@ int ipsec_check(odp_bool_t ah, if (!capa.auths.bit.sha256_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_SHA384_HMAC: + if (!capa.auths.bit.sha384_hmac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_SHA512_HMAC: if (!capa.auths.bit.sha512_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_AES_XCBC_MAC: + if (!capa.auths.bit.aes_xcbc_mac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_AES_GCM: if (!capa.auths.bit.aes_gcm) return ODP_TEST_INACTIVE;
commit 61d16e162788ac0923c544b4d31bb847fa3d9189 Author: yhe yhe@sonicwall.com Date: Wed Mar 21 22:06:58 2018 +0800
linux-gen:crypto:implement AES-XCBC-MAC and SHA384-HMAC
implement the algorithm AES-XCBC-MAC and SHA384-HMAC
Signed-off-by: Tom He yhe@sonicwall.com Reviewed-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 21449cfe..852f0212 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -35,6 +35,8 @@ #endif
#define MAX_SESSIONS 32 +#define AES_BLOCK_SIZE 16 +#define AES_KEY_LENGTH 16
/* * Cipher algorithm capabilities @@ -95,10 +97,18 @@ static const odp_crypto_auth_capability_t auth_capa_sha256_hmac[] = { {.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 32, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
+static const odp_crypto_auth_capability_t auth_capa_sha384_hmac[] = { +{.digest_len = 24, .key_len = 48, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 48, .key_len = 48, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_sha512_hmac[] = { {.digest_len = 32, .key_len = 64, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 64, .key_len = 64, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
+static const odp_crypto_auth_capability_t auth_capa_aes_xcbc[] = { +{.digest_len = 12, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_aes_gcm[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } };
@@ -308,6 +318,169 @@ void packet_hmac(odp_packet_t pkt, HMAC_Final(ctx, hash, NULL); }
+static void xor_block(uint8_t *res, const uint8_t *op) +{ + int i; + + for (i = 0; i < AES_BLOCK_SIZE; i++) + res[i] ^= op[i]; +} + +static void memxor(uint8_t *res, const uint8_t *op, size_t len) +{ + for (size_t i = 0; i < len; i++) + res[i] ^= op[i]; +} + +static +void packet_aes_xcbc_mac(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) +{ + uint8_t e[AES_BLOCK_SIZE] = {0}; + size_t eoff = 0; + uint32_t offset = param->auth_range.offset; + uint32_t len = param->auth_range.length; + uint32_t seglen = 0; + uint32_t datalen = 0; + int dummy_len = 0; + EVP_CIPHER_CTX *ctx; + void *mapaddr; + uint8_t *data = NULL; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + ODP_ASSERT(session != NULL); + ODP_ASSERT(sizeof(session->auth.key) >= 3 * AES_KEY_LENGTH); + + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, session->auth.evp_cipher, + NULL, session->auth.key, NULL); + + while (len > 0) { + mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + datalen = seglen >= len ? len : seglen; + data = (uint8_t *)mapaddr; + offset += datalen; + len -= datalen; + if (eoff != 0) { + if (eoff + datalen > AES_BLOCK_SIZE) { + memxor(e + eoff, data, AES_BLOCK_SIZE - eoff); + datalen -= (AES_BLOCK_SIZE - eoff); + eoff = 0; + EVP_EncryptUpdate(ctx, + e, &dummy_len, e, sizeof(e)); + } else { + memxor(e + eoff, data, datalen); + eoff += datalen; + continue; + } + } + while (datalen > AES_BLOCK_SIZE) { + xor_block(e, data); + EVP_EncryptUpdate(ctx, e, &dummy_len, e, sizeof(e)); + data += AES_BLOCK_SIZE; + datalen -= AES_BLOCK_SIZE; + } + /* Segmentation handle */ + if (datalen > 0) { + memxor(e, data, datalen); + eoff = datalen; + } + } + + if (eoff == AES_BLOCK_SIZE) { + xor_block(e, session->auth.key + AES_KEY_LENGTH); + } else { + e[eoff] ^= 0x80; + xor_block(e, session->auth.key + AES_KEY_LENGTH * 2); + } + EVP_EncryptUpdate(ctx, hash, &dummy_len, e, sizeof(e)); + EVP_CIPHER_CTX_free(ctx); +} + +static +odp_crypto_alg_err_t auth_xcbcmac_gen(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + uint8_t hash[EVP_MAX_MD_SIZE]; + + /* Hash it */ + packet_aes_xcbc_mac(pkt, param, session, hash); + + /* Copy to the output location */ + odp_packet_copy_from_mem(pkt, + param->hash_result_offset, + session->p.auth_digest_len, + hash); + + return ODP_CRYPTO_ALG_ERR_NONE; +} + +static odp_crypto_alg_err_t +auth_xcbcmac_check(odp_packet_t pkt, + const odp_crypto_packet_op_param_t *param, + odp_crypto_generic_session_t *session) +{ + uint32_t bytes = session->p.auth_digest_len; + uint8_t hash_in[EVP_MAX_MD_SIZE]; + uint8_t hash_out[EVP_MAX_MD_SIZE]; + + /* Copy current value out and clear it before authentication */ + odp_packet_copy_to_mem(pkt, param->hash_result_offset, + bytes, hash_in); + + _odp_packet_set_data(pkt, param->hash_result_offset, + 0, bytes); + + /* Hash it */ + packet_aes_xcbc_mac(pkt, param, session, hash_out); + + /* Verify match */ + if (0 != memcmp(hash_in, hash_out, bytes)) + return ODP_CRYPTO_ALG_ERR_ICV_CHECK; + + /* Matched */ + return ODP_CRYPTO_ALG_ERR_NONE; +} + +static int process_aesxcbc_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) +{ + uint32_t k1[4] = { 0x01010101, 0x01010101, 0x01010101, 0x01010101 }; + uint32_t k2[4] = { 0x02020202, 0x02020202, 0x02020202, 0x02020202 }; + uint32_t k3[4] = { 0x03030303, 0x03030303, 0x03030303, 0x03030303 }; + EVP_CIPHER_CTX *ctx; + int dummy_len = 0; + + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) + session->auth.func = auth_xcbcmac_gen; + else + session->auth.func = auth_xcbcmac_check; + session->auth.init = null_crypto_init_routine; + + session->auth.evp_cipher = cipher; + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, session->auth.evp_cipher, NULL, + session->p.auth_key.data, NULL); + /* K1 = 0x01010101010101010101010101010101 encrypted with Key K */ + EVP_EncryptUpdate(ctx, session->auth.key, + &dummy_len, (uint8_t *)k1, AES_BLOCK_SIZE); + + /* K2 = 0x02020202020202020202020202020202 encrypted with Key K */ + EVP_EncryptUpdate(ctx, session->auth.key + AES_KEY_LENGTH, + &dummy_len, (uint8_t *)k2, AES_BLOCK_SIZE); + + /* K3 = 0x03030303030303030303030303030303 encrypted with Key K */ + EVP_EncryptUpdate(ctx, session->auth.key + AES_KEY_LENGTH * 2, + &dummy_len, (uint8_t *)k3, AES_BLOCK_SIZE); + + EVP_CIPHER_CTX_free(ctx); + return 0; +} + static odp_crypto_alg_err_t auth_hmac_gen(odp_packet_t pkt, const odp_crypto_packet_op_param_t *param, @@ -1171,7 +1344,9 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->auths.bit.md5_hmac = 1; capa->auths.bit.sha1_hmac = 1; capa->auths.bit.sha256_hmac = 1; + capa->auths.bit.sha384_hmac = 1; capa->auths.bit.sha512_hmac = 1; + capa->auths.bit.aes_xcbc_mac = 1; capa->auths.bit.aes_gcm = 1; capa->auths.bit.aes_ccm = 1; capa->auths.bit.aes_gmac = 1; @@ -1268,10 +1443,18 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, src = auth_capa_sha256_hmac; num = sizeof(auth_capa_sha256_hmac) / size; break; + case ODP_AUTH_ALG_SHA384_HMAC: + src = auth_capa_sha384_hmac; + num = sizeof(auth_capa_sha384_hmac) / size; + break; case ODP_AUTH_ALG_SHA512_HMAC: src = auth_capa_sha512_hmac; num = sizeof(auth_capa_sha512_hmac) / size; break; + case ODP_AUTH_ALG_AES_XCBC_MAC: + src = auth_capa_aes_xcbc; + num = sizeof(auth_capa_aes_xcbc) / size; + break; case ODP_AUTH_ALG_AES_GCM: src = auth_capa_aes_gcm; num = sizeof(auth_capa_aes_gcm) / size; @@ -1481,9 +1664,15 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_SHA256_HMAC: rc = process_auth_hmac_param(session, EVP_sha256()); break; + case ODP_AUTH_ALG_SHA384_HMAC: + rc = process_auth_hmac_param(session, EVP_sha384()); + break; case ODP_AUTH_ALG_SHA512_HMAC: rc = process_auth_hmac_param(session, EVP_sha512()); break; + case ODP_AUTH_ALG_AES_XCBC_MAC: + rc = process_aesxcbc_param(session, EVP_aes_128_ecb()); + break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_AES128_GCM: if (param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM) diff --git a/platform/linux-generic/odp_ipsec_sad.c b/platform/linux-generic/odp_ipsec_sad.c index 8dab489c..c2126969 100644 --- a/platform/linux-generic/odp_ipsec_sad.c +++ b/platform/linux-generic/odp_ipsec_sad.c @@ -246,8 +246,12 @@ uint32_t _odp_ipsec_auth_digest_len(odp_auth_alg_t auth) #endif case ODP_AUTH_ALG_SHA256_HMAC: return 16; + case ODP_AUTH_ALG_SHA384_HMAC: + return 24; case ODP_AUTH_ALG_SHA512_HMAC: return 32; + case ODP_AUTH_ALG_AES_XCBC_MAC: + return 12; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_AES128_GCM: #endif
-----------------------------------------------------------------------
Summary of changes: platform/linux-generic/odp_crypto.c | 189 ++++++++++++++++++++ platform/linux-generic/odp_ipsec_sad.c | 4 + test/validation/api/crypto/odp_crypto_test_inp.c | 91 ++++++++++ test/validation/api/crypto/test_vectors.h | 209 +++++++++++++++++++++++ test/validation/api/crypto/test_vectors_len.h | 10 ++ test/validation/api/ipsec/ipsec.c | 8 + 6 files changed, 511 insertions(+)
hooks/post-receive