xref: /dpdk/app/test/test_security_proto.h (revision b22cdccdd366c06e45888713ed865061c3181e3a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2023 Marvell.
3  */
4 
5 #ifndef _TEST_SECURITY_PROTO_H_
6 #define _TEST_SECURITY_PROTO_H_
7 
8 #include <rte_cryptodev.h>
9 #include <rte_security.h>
10 
11 #include "test_cryptodev.h"
12 
13 #define TEST_SEC_CLEARTEXT_MAX_LEN  17408u
14 #define TEST_SEC_CIPHERTEXT_MAX_LEN 18437u
15 #define TEST_SEC_PKTS_MAX 32
16 
17 static_assert(TEST_SEC_CIPHERTEXT_MAX_LEN <= LARGE_MBUF_DATAPAYLOAD_SIZE,
18 	      "TEST_SEC_CIPHERTEXT_MAX_LEN should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
19 
20 struct crypto_param {
21 	enum rte_crypto_sym_xform_type type;
22 	union {
23 		enum rte_crypto_cipher_algorithm cipher;
24 		enum rte_crypto_auth_algorithm auth;
25 		enum rte_crypto_aead_algorithm aead;
26 	} alg;
27 	uint16_t key_length;
28 	uint16_t iv_length;
29 	uint16_t digest_length;
30 };
31 
32 static const struct crypto_param aead_list[] = {
33 	{
34 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
35 		.alg.aead =  RTE_CRYPTO_AEAD_AES_GCM,
36 		.key_length = 16,
37 		.digest_length = 16,
38 	},
39 	{
40 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
41 		.alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
42 		.key_length = 24,
43 		.digest_length = 16,
44 	},
45 	{
46 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
47 		.alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
48 		.key_length = 32,
49 		.digest_length = 16,
50 	},
51 	{
52 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
53 		.alg.aead = RTE_CRYPTO_AEAD_AES_CCM,
54 		.key_length = 32
55 	},
56 };
57 
58 static const struct crypto_param cipher_list[] = {
59 	{
60 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
61 		.alg.cipher =  RTE_CRYPTO_CIPHER_NULL,
62 		.key_length = 0,
63 		.iv_length = 0,
64 	},
65 	{
66 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
67 		.alg.cipher =  RTE_CRYPTO_CIPHER_DES_CBC,
68 		.key_length = 8,
69 		.iv_length = 8,
70 	},
71 	{
72 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
73 		.alg.cipher =  RTE_CRYPTO_CIPHER_3DES_CBC,
74 		.key_length = 24,
75 		.iv_length = 8,
76 	},
77 	{
78 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
79 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CBC,
80 		.key_length = 16,
81 		.iv_length = 16,
82 	},
83 	{
84 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
85 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CBC,
86 		.key_length = 32,
87 		.iv_length = 16,
88 	},
89 	{
90 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
91 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
92 		.key_length = 16,
93 		.iv_length = 16,
94 	},
95 	{
96 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
97 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
98 		.key_length = 24,
99 		.iv_length = 16,
100 	},
101 	{
102 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
103 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
104 		.key_length = 32,
105 		.iv_length = 16,
106 	},
107 };
108 
109 static const struct crypto_param auth_list[] = {
110 	{
111 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
112 		.alg.auth =  RTE_CRYPTO_AUTH_NULL,
113 	},
114 	{
115 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
116 		.alg.auth =  RTE_CRYPTO_AUTH_MD5_HMAC,
117 		.key_length = 16,
118 		.digest_length = 12,
119 	},
120 	{
121 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
122 		.alg.auth =  RTE_CRYPTO_AUTH_SHA1_HMAC,
123 		.key_length = 20,
124 		.digest_length = 12,
125 	},
126 	{
127 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
128 		.alg.auth =  RTE_CRYPTO_AUTH_SHA1_HMAC,
129 		.key_length = 20,
130 		.digest_length = 20,
131 	},
132 	{
133 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
134 		.alg.auth =  RTE_CRYPTO_AUTH_SHA256_HMAC,
135 		.key_length = 32,
136 		.digest_length = 16,
137 	},
138 	{
139 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
140 		.alg.auth =  RTE_CRYPTO_AUTH_SHA256_HMAC,
141 		.key_length = 32,
142 		.digest_length = 32,
143 	},
144 	{
145 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
146 		.alg.auth =  RTE_CRYPTO_AUTH_SHA384_HMAC,
147 		.key_length = 48,
148 		.digest_length = 24,
149 	},
150 	{
151 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
152 		.alg.auth =  RTE_CRYPTO_AUTH_SHA512_HMAC,
153 		.key_length = 64,
154 		.digest_length = 32,
155 	},
156 	{
157 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
158 		.alg.auth =  RTE_CRYPTO_AUTH_AES_XCBC_MAC,
159 		.key_length = 16,
160 		.digest_length = 12,
161 	},
162 	{
163 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
164 		.alg.auth =  RTE_CRYPTO_AUTH_AES_GMAC,
165 		.key_length = 16,
166 		.digest_length = 16,
167 		.iv_length = 12,
168 	},
169 };
170 
171 struct crypto_param_comb {
172 	const struct crypto_param *param1;
173 	const struct crypto_param *param2;
174 };
175 
176 extern struct crypto_param_comb sec_alg_list[RTE_DIM(aead_list) +
177 					     (RTE_DIM(cipher_list) * RTE_DIM(auth_list))];
178 
179 extern struct crypto_param_comb sec_auth_only_alg_list[2 * (RTE_DIM(auth_list) - 1)];
180 
181 void test_sec_alg_list_populate(void);
182 
183 void test_sec_auth_only_alg_list_populate(void);
184 
185 int test_sec_crypto_caps_aead_verify(const struct rte_security_capability *sec_cap,
186 		struct rte_crypto_sym_xform *aead);
187 
188 int test_sec_crypto_caps_cipher_verify(const struct rte_security_capability *sec_cap,
189 		struct rte_crypto_sym_xform *cipher);
190 
191 int test_sec_crypto_caps_auth_verify(const struct rte_security_capability *sec_cap,
192 		struct rte_crypto_sym_xform *auth);
193 
194 void test_sec_alg_display(const struct crypto_param *param1, const struct crypto_param *param2);
195 
196 void test_sec_proto_pattern_generate(void);
197 
198 void test_sec_proto_pattern_set(uint8_t *buf, int len);
199 
200 #endif
201