New upstream version 17.11-rc3
[deb_dpdk.git] / test / test / test_cryptodev_blockcipher.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *       * Redistributions of source code must retain the above copyright
11  *         notice, this list of conditions and the following disclaimer.
12  *       * Redistributions in binary form must reproduce the above copyright
13  *         notice, this list of conditions and the following disclaimer in
14  *         the documentation and/or other materials provided with the
15  *         distribution.
16  *       * Neither the name of Intel Corporation nor the names of its
17  *         contributors may be used to endorse or promote products derived
18  *         from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef TEST_CRYPTODEV_BLOCKCIPHER_H_
34 #define TEST_CRYPTODEV_BLOCKCIPHER_H_
35
36 #ifndef BLOCKCIPHER_TEST_MSG_LEN
37 #define BLOCKCIPHER_TEST_MSG_LEN                256
38 #endif
39
40 #define BLOCKCIPHER_TEST_OP_ENCRYPT             0x01
41 #define BLOCKCIPHER_TEST_OP_DECRYPT             0x02
42 #define BLOCKCIPHER_TEST_OP_AUTH_GEN    0x04
43 #define BLOCKCIPHER_TEST_OP_AUTH_VERIFY 0x08
44
45 #define BLOCKCIPHER_TEST_FEATURE_OOP                    0x01
46 #define BLOCKCIPHER_TEST_FEATURE_SESSIONLESS    0x02
47 #define BLOCKCIPHER_TEST_FEATURE_STOPPER        0x04 /* stop upon failing */
48 #define BLOCKCIPHER_TEST_FEATURE_SG             0x08 /* Scatter Gather */
49
50 #define BLOCKCIPHER_TEST_TARGET_PMD_MB          0x0001 /* Multi-buffer flag */
51 #define BLOCKCIPHER_TEST_TARGET_PMD_QAT                 0x0002 /* QAT flag */
52 #define BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL     0x0004 /* SW OPENSSL flag */
53 #define BLOCKCIPHER_TEST_TARGET_PMD_ARMV8       0x0008 /* ARMv8 flag */
54 #define BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER   0x0010 /* Scheduler */
55 #define BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC   0x0020 /* DPAA2_SEC flag */
56 #define BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC    0x0040 /* DPAA_SEC flag */
57 #define BLOCKCIPHER_TEST_TARGET_PMD_MRVL        0x0080 /* Marvell flag */
58
59 #define BLOCKCIPHER_TEST_OP_CIPHER      (BLOCKCIPHER_TEST_OP_ENCRYPT | \
60                                         BLOCKCIPHER_TEST_OP_DECRYPT)
61
62 #define BLOCKCIPHER_TEST_OP_AUTH        (BLOCKCIPHER_TEST_OP_AUTH_GEN | \
63                                         BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
64
65 #define BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN        (BLOCKCIPHER_TEST_OP_ENCRYPT | \
66                                         BLOCKCIPHER_TEST_OP_AUTH_GEN)
67
68 #define BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC     (BLOCKCIPHER_TEST_OP_DECRYPT | \
69                                         BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
70
71 enum blockcipher_test_type {
72         BLKCIPHER_AES_CHAIN_TYPE,       /* use aes_chain_test_cases[] */
73         BLKCIPHER_AES_CIPHERONLY_TYPE,  /* use aes_cipheronly_test_cases[] */
74         BLKCIPHER_AES_DOCSIS_TYPE,      /* use aes_docsis_test_cases[] */
75         BLKCIPHER_3DES_CHAIN_TYPE,      /* use triple_des_chain_test_cases[] */
76         BLKCIPHER_3DES_CIPHERONLY_TYPE, /* triple_des_cipheronly_test_cases[] */
77         BLKCIPHER_AUTHONLY_TYPE,        /* use hash_test_cases[] */
78         BLKCIPHER_DES_CIPHERONLY_TYPE,  /* use des_cipheronly_test_cases[] */
79         BLKCIPHER_DES_DOCSIS_TYPE       /* use des_docsis_test_cases[] */
80 };
81
82 struct blockcipher_test_case {
83         const char *test_descr; /* test description */
84         const struct blockcipher_test_data *test_data;
85         uint8_t op_mask; /* operation mask */
86         uint8_t feature_mask;
87         uint32_t pmd_mask;
88 };
89
90 struct blockcipher_test_data {
91         enum rte_crypto_cipher_algorithm crypto_algo;
92
93         struct {
94                 uint8_t data[64];
95                 unsigned int len;
96         } cipher_key;
97
98         struct {
99                 uint8_t data[64] __rte_aligned(16);
100                 unsigned int len;
101         } iv;
102
103         struct {
104                 const uint8_t *data;
105                 unsigned int len;
106         } plaintext;
107
108         struct {
109                 const uint8_t *data;
110                 unsigned int len;
111         } ciphertext;
112
113         enum rte_crypto_auth_algorithm auth_algo;
114
115         struct {
116                 uint8_t data[128];
117                 unsigned int len;
118         } auth_key;
119
120         struct {
121                 uint8_t data[128];
122                 unsigned int len;               /* for qat */
123                 unsigned int truncated_len;     /* for mb */
124         } digest;
125 };
126
127 int
128 test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
129         struct rte_mempool *op_mpool,
130         struct rte_mempool *sess_mpool,
131         uint8_t dev_id,
132         int driver_id,
133         enum blockcipher_test_type test_type);
134
135 #endif /* TEST_CRYPTODEV_BLOCKCIPHER_H_ */