Test reference vectors from RFC3602 Signed-off-by: Nicolas Morey-Chaisemartin <nmo...@kalray.eu> --- test/validation/crypto/crypto.h | 4 + test/validation/crypto/odp_crypto_test_inp.c | 135 ++++++++++++++++++++++++++- test/validation/crypto/test_vectors.h | 67 +++++++++++++ test/validation/crypto/test_vectors_len.h | 4 + 4 files changed, 209 insertions(+), 1 deletion(-)
diff --git a/test/validation/crypto/crypto.h b/test/validation/crypto/crypto.h index fe23e04..4769fad 100644 --- a/test/validation/crypto/crypto.h +++ b/test/validation/crypto/crypto.h @@ -14,6 +14,10 @@ void crypto_test_enc_alg_3des_cbc(void); 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_enc_alg_aes128_cbc(void); +void crypto_test_enc_alg_aes128_cbc_ovr_iv(void); +void crypto_test_dec_alg_aes128_cbc(void); +void crypto_test_dec_alg_aes128_cbc_ovr_iv(void); void crypto_test_alg_hmac_md5(void); void crypto_test_alg_hmac_sha256(void); diff --git a/test/validation/crypto/odp_crypto_test_inp.c b/test/validation/crypto/odp_crypto_test_inp.c index 838edc4..5295c63 100644 --- a/test/validation/crypto/odp_crypto_test_inp.c +++ b/test/validation/crypto/odp_crypto_test_inp.c @@ -63,7 +63,7 @@ static void alg_test(odp_crypto_op_t op, ses_params.auth_key = auth_key; rc = odp_crypto_session_create(&ses_params, &session, &status); - CU_ASSERT(!rc); + CU_ASSERT_FATAL(!rc); CU_ASSERT(status == ODP_CRYPTO_SES_CREATE_ERR_NONE); CU_ASSERT(odp_crypto_session_to_u64(session) != odp_crypto_session_to_u64(ODP_CRYPTO_SESSION_INVALID)); @@ -259,6 +259,135 @@ void crypto_test_dec_alg_3des_cbc_ovr_iv(void) } } +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_CBC algorithm. IV for the operation is the session IV. + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer.*/ +void crypto_test_enc_alg_aes128_cbc(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv; + unsigned int test_vec_num = (sizeof(aes128_cbc_reference_length) / + sizeof(aes128_cbc_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + cipher_key.data = aes128_cbc_reference_key[i]; + cipher_key.length = sizeof(aes128_cbc_reference_key[i]); + iv.data = aes128_cbc_reference_iv[i]; + iv.length = sizeof(aes128_cbc_reference_iv[i]); + + alg_test(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES128_CBC, + iv, + NULL, + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + aes128_cbc_reference_plaintext[i], + aes128_cbc_reference_length[i], + aes128_cbc_reference_ciphertext[i], + aes128_cbc_reference_length[i]); + } +} + +/* This test verifies the correctness of encode (plaintext -> ciphertext) + * operation for AES128_CBC algorithm. IV for the operation is the operation IV. + * */ +void crypto_test_enc_alg_aes128_cbc_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_CBC_IV_LEN }; + unsigned int test_vec_num = (sizeof(aes128_cbc_reference_length) / + sizeof(aes128_cbc_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + cipher_key.data = aes128_cbc_reference_key[i]; + cipher_key.length = sizeof(aes128_cbc_reference_key[i]); + + alg_test(ODP_CRYPTO_OP_ENCODE, + ODP_CIPHER_ALG_AES128_CBC, + iv, + aes128_cbc_reference_iv[i], + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + aes128_cbc_reference_plaintext[i], + aes128_cbc_reference_length[i], + aes128_cbc_reference_ciphertext[i], + aes128_cbc_reference_length[i]); + } +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_CBC algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +void crypto_test_dec_alg_aes128_cbc(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(aes128_cbc_reference_length) / + sizeof(aes128_cbc_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + cipher_key.data = aes128_cbc_reference_key[i]; + cipher_key.length = sizeof(aes128_cbc_reference_key[i]); + iv.data = aes128_cbc_reference_iv[i]; + iv.length = sizeof(aes128_cbc_reference_iv[i]); + + alg_test(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES128_CBC, + iv, + NULL, + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + aes128_cbc_reference_ciphertext[i], + aes128_cbc_reference_length[i], + aes128_cbc_reference_plaintext[i], + aes128_cbc_reference_length[i]); + } +} + +/* This test verifies the correctness of decode (ciphertext -> plaintext) + * operation for AES128_CBC algorithm. IV for the operation is the session IV + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +void crypto_test_dec_alg_aes128_cbc_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_CBC_IV_LEN }; + unsigned int test_vec_num = (sizeof(aes128_cbc_reference_length) / + sizeof(aes128_cbc_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + cipher_key.data = aes128_cbc_reference_key[i]; + cipher_key.length = sizeof(aes128_cbc_reference_key[i]); + + alg_test(ODP_CRYPTO_OP_DECODE, + ODP_CIPHER_ALG_AES128_CBC, + iv, + aes128_cbc_reference_iv[i], + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + aes128_cbc_reference_ciphertext[i], + aes128_cbc_reference_length[i], + aes128_cbc_reference_plaintext[i], + aes128_cbc_reference_length[i]); + } +} + /* This test verifies the correctness of HMAC_MD5 digest operation. * The output check length is truncated to 12 bytes (96 bits) as @@ -360,6 +489,10 @@ odp_testinfo_t crypto_suite[] = { ODP_TEST_INFO(crypto_test_dec_alg_3des_cbc), 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_enc_alg_aes128_cbc), + ODP_TEST_INFO(crypto_test_dec_alg_aes128_cbc), + ODP_TEST_INFO(crypto_test_enc_alg_aes128_cbc_ovr_iv), + ODP_TEST_INFO(crypto_test_dec_alg_aes128_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 09cf9c2..73f54b5 100644 --- a/test/validation/crypto/test_vectors.h +++ b/test/validation/crypto/test_vectors.h @@ -45,6 +45,73 @@ tdes_cbc_reference_ciphertext[][TDES_CBC_MAX_DATA_LEN] = { 0xfb, 0xa7, 0xd2, 0xf5} }; +static uint8_t aes128_cbc_reference_key[][AES128_CBC_KEY_LEN] = { + {0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b, + 0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 }, + {0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, + 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a }, + {0x6c, 0x3e, 0xa0, 0x47, 0x76, 0x30, 0xce, 0x21, + 0xa2, 0xce, 0x33, 0x4a, 0xa7, 0x46, 0xc2, 0xcd }, + {0x56, 0xe4, 0x7a, 0x38, 0xc5, 0x59, 0x89, 0x74, + 0xbc, 0x46, 0x90, 0x3d, 0xba, 0x29, 0x03, 0x49 } +}; + +static uint8_t aes128_cbc_reference_iv[][AES128_CBC_IV_LEN] = { + { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, + 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 }, + { 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, + 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 }, + { 0xc7, 0x82, 0xdc, 0x4c, 0x09, 0x8c, 0x66, 0xcb, + 0xd9, 0xcd, 0x27, 0xd8, 0x25, 0x68, 0x2c, 0x81 }, + { 0x8c, 0xe8, 0x2e, 0xef, 0xbe, 0xa0, 0xda, 0x3c, + 0x44, 0x69, 0x9e, 0xd7, 0xdb, 0x51, 0xb7, 0xd9 } +}; + +/** length in bytes */ +static uint32_t aes128_cbc_reference_length[] = { 16, 32, 48, 64 }; + +static uint8_t +aes128_cbc_reference_plaintext[][AES128_CBC_MAX_DATA_LEN] = { + "Single block msg", + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, + "This is a 48-byte message (exactly 3 AES blocks)", + { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } +}; + +static uint8_t +aes128_cbc_reference_ciphertext[][AES128_CBC_MAX_DATA_LEN] = { + { 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, + 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a }, + { 0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a, + 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a, + 0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, + 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 }, + { 0xd0, 0xa0, 0x2b, 0x38, 0x36, 0x45, 0x17, 0x53, + 0xd4, 0x93, 0x66, 0x5d, 0x33, 0xf0, 0xe8, 0x86, + 0x2d, 0xea, 0x54, 0xcd, 0xb2, 0x93, 0xab, 0xc7, + 0x50, 0x69, 0x39, 0x27, 0x67, 0x72, 0xf8, 0xd5, + 0x02, 0x1c, 0x19, 0x21, 0x6b, 0xad, 0x52, 0x5c, + 0x85, 0x79, 0x69, 0x5d, 0x83, 0xba, 0x26, 0x84 }, + { 0xc3, 0x0e, 0x32, 0xff, 0xed, 0xc0, 0x77, 0x4e, + 0x6a, 0xff, 0x6a, 0xf0, 0x86, 0x9f, 0x71, 0xaa, + 0x0f, 0x3a, 0xf0, 0x7a, 0x9a, 0x31, 0xa9, 0xc6, + 0x84, 0xdb, 0x20, 0x7e, 0xb0, 0xef, 0x8e, 0x4e, + 0x35, 0x90, 0x7a, 0xa6, 0x32, 0xc3, 0xff, 0xdf, + 0x86, 0x8b, 0xb7, 0xb2, 0x9d, 0x3d, 0x46, 0xad, + 0x83, 0xce, 0x9f, 0x9a, 0x10, 0x2e, 0xe9, 0x9d, + 0x49, 0xa5, 0x3e, 0x87, 0xf4, 0xc3, 0xda, 0x55 } +}; + static uint8_t hmac_md5_reference_key[][HMAC_MD5_KEY_LEN] = { { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b } , diff --git a/test/validation/crypto/test_vectors_len.h b/test/validation/crypto/test_vectors_len.h index ceba39a..5bc6f4b 100644 --- a/test/validation/crypto/test_vectors_len.h +++ b/test/validation/crypto/test_vectors_len.h @@ -11,6 +11,10 @@ #define TDES_CBC_IV_LEN 8 #define TDES_CBC_MAX_DATA_LEN 16 +/* AES128-CBC */ +#define AES128_CBC_KEY_LEN 16 +#define AES128_CBC_IV_LEN 16 +#define AES128_CBC_MAX_DATA_LEN 64 /* HMAC-MD5 */ #define HMAC_MD5_KEY_LEN 16 -- 2.6.2.406.gaaaec35 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp