Signed-off-by: Nicolas Morey-Chaisemartin <nmo...@kalray.eu> --- test/validation/crypto/crypto.h | 1 + test/validation/crypto/odp_crypto_test_inp.c | 37 +++++++++++++++++++++++ test/validation/crypto/test_vectors.h | 44 ++++++++++++++++++++++++++++ test/validation/crypto/test_vectors_len.h | 6 ++++ 4 files changed, 88 insertions(+)
diff --git a/test/validation/crypto/crypto.h b/test/validation/crypto/crypto.h index 7cb60d4..fe23e04 100644 --- a/test/validation/crypto/crypto.h +++ b/test/validation/crypto/crypto.h @@ -15,6 +15,7 @@ void crypto_test_enc_alg_3des_cbc_ovr_iv(void); void crypto_test_dec_alg_3des_cbc(void); void crypto_test_dec_alg_3des_cbc_ovr_iv(void); void crypto_test_alg_hmac_md5(void); +void crypto_test_alg_hmac_sha256(void); /* test arrays: */ extern odp_testinfo_t crypto_suite[]; diff --git a/test/validation/crypto/odp_crypto_test_inp.c b/test/validation/crypto/odp_crypto_test_inp.c index 05b6885..838edc4 100644 --- a/test/validation/crypto/odp_crypto_test_inp.c +++ b/test/validation/crypto/odp_crypto_test_inp.c @@ -295,6 +295,42 @@ void crypto_test_alg_hmac_md5(void) } } +/* This test verifies the correctness of HMAC_MD5 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_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 }; + + unsigned int test_vec_num = (sizeof(hmac_sha256_reference_length) / + sizeof(hmac_sha256_reference_length[0])); + + unsigned int i; + + 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]); + + alg_test(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA256_128, + auth_key, + hmac_sha256_reference_plaintext[i], + hmac_sha256_reference_length[i], + hmac_sha256_reference_digest[i], + HMAC_SHA256_128_CHECK_LEN); + } +} + int crypto_suite_sync_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); @@ -325,5 +361,6 @@ odp_testinfo_t crypto_suite[] = { ODP_TEST_INFO(crypto_test_enc_alg_3des_cbc_ovr_iv), ODP_TEST_INFO(crypto_test_dec_alg_3des_cbc_ovr_iv), ODP_TEST_INFO(crypto_test_alg_hmac_md5), + ODP_TEST_INFO(crypto_test_alg_hmac_sha256), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/crypto/test_vectors.h b/test/validation/crypto/test_vectors.h index 490a3bc..09cf9c2 100644 --- a/test/validation/crypto/test_vectors.h +++ b/test/validation/crypto/test_vectors.h @@ -87,4 +87,48 @@ static uint8_t hmac_md5_reference_digest[][HMAC_MD5_DIGEST_LEN] = { 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 } }; +static uint8_t hmac_sha256_reference_key[][HMAC_SHA256_KEY_LEN] = { + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + + /* "Jefe" */ + { 0x4a, 0x65, 0x66, 0x65 }, + + { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa } +}; + +static uint32_t hmac_sha256_reference_length[] = { 8, 28, 50 }; + +static uint8_t +hmac_sha256_reference_plaintext[][HMAC_SHA256_MAX_DATA_LEN] = { + /* "Hi There" */ + { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + + /* what do ya want for nothing?*/ + { 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 }, + + { 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 } +}; + +static uint8_t hmac_sha256_reference_digest[][HMAC_SHA256_DIGEST_LEN] = { + { 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, + 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b }, + + { 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e, + 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7 }, + + { 0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46, + 0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7 } +}; + #endif diff --git a/test/validation/crypto/test_vectors_len.h b/test/validation/crypto/test_vectors_len.h index 8c83ba1..ceba39a 100644 --- a/test/validation/crypto/test_vectors_len.h +++ b/test/validation/crypto/test_vectors_len.h @@ -18,4 +18,10 @@ #define HMAC_MD5_DIGEST_LEN 16 #define HMAC_MD5_96_CHECK_LEN 12 +/* HMAC-SHA256 */ +#define HMAC_SHA256_KEY_LEN 32 +#define HMAC_SHA256_MAX_DATA_LEN 128 +#define HMAC_SHA256_DIGEST_LEN 32 +#define HMAC_SHA256_128_CHECK_LEN 16 + #endif -- 2.6.2.406.gaaaec35 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp