1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2016-2017 Intel Corporation 3 */ 4 5 #ifndef TEST_CRYPTODEV_BLOCKCIPHER_H_ 6 #define TEST_CRYPTODEV_BLOCKCIPHER_H_ 7 8 #ifndef BLOCKCIPHER_TEST_MSG_LEN 9 #define BLOCKCIPHER_TEST_MSG_LEN 256 10 #endif 11 12 #define BLOCKCIPHER_TEST_OP_ENCRYPT 0x01 13 #define BLOCKCIPHER_TEST_OP_DECRYPT 0x02 14 #define BLOCKCIPHER_TEST_OP_AUTH_GEN 0x04 15 #define BLOCKCIPHER_TEST_OP_AUTH_VERIFY 0x08 16 #define BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED 0x10 17 18 #define BLOCKCIPHER_TEST_FEATURE_OOP 0x01 19 #define BLOCKCIPHER_TEST_FEATURE_SESSIONLESS 0x02 20 #define BLOCKCIPHER_TEST_FEATURE_STOPPER 0x04 /* stop upon failing */ 21 #define BLOCKCIPHER_TEST_FEATURE_SG 0x08 /* Scatter Gather */ 22 #define BLOCKCIPHER_TEST_FEATURE_DIGEST_ENCRYPTED 0x10 23 24 #define BLOCKCIPHER_TEST_OP_CIPHER (BLOCKCIPHER_TEST_OP_ENCRYPT | \ 25 BLOCKCIPHER_TEST_OP_DECRYPT) 26 27 #define BLOCKCIPHER_TEST_OP_AUTH (BLOCKCIPHER_TEST_OP_AUTH_GEN | \ 28 BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 29 30 #define BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN (BLOCKCIPHER_TEST_OP_ENCRYPT | \ 31 BLOCKCIPHER_TEST_OP_AUTH_GEN) 32 33 #define BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC (BLOCKCIPHER_TEST_OP_DECRYPT | \ 34 BLOCKCIPHER_TEST_OP_AUTH_VERIFY) 35 36 #define BLOCKCIPHER_TEST_OP_AUTH_GEN_ENC (BLOCKCIPHER_TEST_OP_ENCRYPT | \ 37 BLOCKCIPHER_TEST_OP_AUTH_GEN | \ 38 BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 39 40 #define BLOCKCIPHER_TEST_OP_DEC_AUTH_VERIFY (BLOCKCIPHER_TEST_OP_DECRYPT | \ 41 BLOCKCIPHER_TEST_OP_AUTH_VERIFY | \ 42 BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) 43 44 enum blockcipher_test_type { 45 BLKCIPHER_AES_CHAIN_TYPE, /* use aes_chain_test_cases[] */ 46 BLKCIPHER_AES_CIPHERONLY_TYPE, /* use aes_cipheronly_test_cases[] */ 47 BLKCIPHER_AES_DOCSIS_TYPE, /* use aes_docsis_test_cases[] */ 48 BLKCIPHER_3DES_CHAIN_TYPE, /* use triple_des_chain_test_cases[] */ 49 BLKCIPHER_3DES_CIPHERONLY_TYPE, /* triple_des_cipheronly_test_cases[] */ 50 BLKCIPHER_AUTHONLY_TYPE, /* use hash_test_cases[] */ 51 BLKCIPHER_DES_CIPHERONLY_TYPE, /* use des_cipheronly_test_cases[] */ 52 BLKCIPHER_DES_DOCSIS_TYPE, /* use des_docsis_test_cases[] */ 53 BLKCIPHER_SM4_CHAIN_TYPE, /* use sm4_chain_test_cases[] */ 54 BLKCIPHER_SM4_CIPHERONLY_TYPE /* use sm4_cipheronly_test_cases[] */ 55 }; 56 57 struct blockcipher_test_case { 58 const char *test_descr; /* test description */ 59 const struct blockcipher_test_data *test_data; 60 uint8_t op_mask; /* operation mask */ 61 uint8_t feature_mask; 62 uint64_t sgl_flag; 63 uint8_t sgl_segs; 64 }; 65 66 struct blockcipher_test_data { 67 enum rte_crypto_cipher_algorithm crypto_algo; 68 69 struct { 70 uint8_t data[64]; 71 unsigned int len; 72 } cipher_key; 73 74 struct { 75 alignas(16) uint8_t data[64]; 76 unsigned int len; 77 } iv; 78 79 struct { 80 const uint8_t *data; 81 unsigned int len; 82 } plaintext; 83 84 struct { 85 const uint8_t *data; 86 unsigned int len; 87 } ciphertext; 88 89 enum rte_crypto_auth_algorithm auth_algo; 90 91 struct { 92 uint8_t data[128]; 93 unsigned int len; 94 } auth_key; 95 96 struct { 97 uint8_t data[128]; 98 unsigned int len; /* for qat */ 99 unsigned int truncated_len; /* for mb */ 100 } digest; 101 102 unsigned int cipher_offset; 103 unsigned int auth_offset; 104 uint32_t xts_dataunit_len; 105 bool wrapped_key; 106 }; 107 108 struct unit_test_suite * 109 build_blockcipher_test_suite(enum blockcipher_test_type test_type); 110 111 void 112 free_blockcipher_test_suite(struct unit_test_suite *ts); 113 114 #endif /* TEST_CRYPTODEV_BLOCKCIPHER_H_ */ 115