]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2019 Intel Corporation | |
3 | */ | |
4 | ||
5 | #include <rte_cryptodev.h> | |
6 | #include <rte_cryptodev_pmd.h> | |
7 | ||
8 | #include "fips_dev_self_test.h" | |
9 | ||
10 | #define IV_OFF (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op)) | |
11 | ||
12 | #define FIPS_DEV_TEST_DATA_MAX_SIZE 8096 | |
13 | #define AES_CCM_AAD_PAD_SIZE 18 | |
14 | ||
15 | struct fips_dev_self_test_vector { | |
16 | const char *name; | |
17 | enum rte_crypto_sym_xform_type operation_type; | |
18 | ||
19 | struct { | |
20 | uint8_t data[64]; | |
21 | uint16_t len; | |
22 | } digest; | |
23 | ||
24 | struct { | |
25 | uint8_t data[256]; | |
26 | uint16_t len; | |
27 | } key; | |
28 | ||
29 | struct { | |
30 | uint8_t data[16]; | |
31 | uint8_t len; | |
32 | } iv; | |
33 | ||
34 | union { | |
35 | struct { | |
36 | enum rte_crypto_cipher_algorithm algo; | |
37 | } cipher; | |
38 | ||
39 | struct { | |
40 | enum rte_crypto_aead_algorithm algo; | |
41 | struct { | |
42 | uint8_t data[FIPS_DEV_TEST_DATA_MAX_SIZE]; | |
43 | uint16_t len; | |
44 | } aad; | |
45 | } aead; | |
46 | ||
47 | struct { | |
48 | enum rte_crypto_auth_algorithm algo; | |
49 | } auth; | |
50 | }; | |
51 | ||
52 | struct { | |
53 | const uint8_t data[FIPS_DEV_TEST_DATA_MAX_SIZE]; | |
54 | uint16_t len; | |
55 | } input; | |
56 | ||
57 | struct { | |
58 | uint8_t data[FIPS_DEV_TEST_DATA_MAX_SIZE]; | |
59 | uint16_t len; | |
60 | } output; | |
61 | }; | |
62 | ||
63 | #define GET_MBUF_DATA(data, len, m) \ | |
64 | do { \ | |
65 | len = rte_pktmbuf_pkt_len(m); \ | |
66 | data = rte_pktmbuf_mtod(m, uint8_t *); \ | |
67 | } while (0) | |
68 | ||
69 | ||
70 | /* <-- SHA-x HMAC --> */ | |
71 | static struct fips_dev_self_test_vector | |
72 | SELF_TEST_SHA1_HMAC_test_vector = { | |
73 | .name = "SELF_TEST_SHA1_HMAC_test_vector", | |
74 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
75 | ||
76 | .auth = { | |
77 | .algo = RTE_CRYPTO_AUTH_SHA1_HMAC, | |
78 | }, | |
79 | .input = { | |
80 | .data = { | |
81 | 0xed, 0xb2, 0xba, 0x09, 0x99, 0x61, 0xd3, 0x8f, | |
82 | 0xd0, 0xa0, 0xa6, 0xa2, 0x35, 0xd6, 0x12, 0x71, | |
83 | 0xcb, 0x4d, 0x49, 0x3b, 0x64, 0xd9, 0xde, 0x13, | |
84 | 0x5c, 0xbb, 0x1f, 0xe0, 0x86, 0xc4, 0xa4, 0xa7, | |
85 | 0x67, 0xbe, 0x28, 0x0d, 0xa2, 0x07, 0x98, 0x17, | |
86 | 0xb4, 0x7f, 0x6a, 0x35, 0xe1, 0xa4, 0x30, 0x7f, | |
87 | 0x6e, 0xfc, 0x6d, 0x3e, 0x11, 0xb4, 0xa7, 0xae, | |
88 | 0xa6, 0x86, 0xbd, 0x02, 0x23, 0xe0, 0x7b, 0xa9, | |
89 | 0xce, 0x42, 0x6c, 0xd0, 0xae, 0xe7, 0xef, 0x28, | |
90 | 0x3f, 0xa9, 0x8d, 0xe9, 0x6a, 0x1f, 0x8a, 0x17, | |
91 | 0xb3, 0x08, 0xba, 0x04, 0xb5, 0xec, 0x96, 0x16, | |
92 | 0xcb, 0x00, 0x8f, 0xca, 0x11, 0x4b, 0xa3, 0xf9, | |
93 | 0x8b, 0x07, 0x2d, 0x5a, 0xa3, 0x4a, 0x01, 0x49, | |
94 | 0xd9, 0xe5, 0xb8, 0xc6, 0xb6, 0x8c, 0x49, 0xc1, | |
95 | 0x01, 0x38, 0xda, 0x95, 0x36, 0xca, 0xd5, 0xd2, | |
96 | 0x34, 0xf1, 0x3d, 0x3f, 0x36, 0x4d, 0x43, 0x1f | |
97 | }, | |
98 | .len = 128, | |
99 | }, | |
100 | .key = { | |
101 | .data = { | |
102 | 0x8d, 0x8d, 0x15, 0xd8, 0xa9, 0x57, 0x9a, 0xdb, | |
103 | 0x2d, 0x62 | |
104 | }, | |
105 | .len = 10, | |
106 | }, | |
107 | .digest = { | |
108 | .data = { | |
109 | 0x0c, 0x66, 0x2e, 0x47, 0x93, 0x93, 0x8c, 0xc3, | |
110 | 0x7f, 0x3d, 0x51, 0xd2, 0xb4, 0x05, 0x48, 0xec, | |
111 | 0x55, 0x91, 0x4f, 0x0d | |
112 | }, | |
113 | .len = 20, | |
114 | }, | |
115 | }; | |
116 | ||
117 | static struct fips_dev_self_test_vector | |
118 | SELF_TEST_SHA224_HMAC_test_vector = { | |
119 | .name = "SELF_TEST_SHA224_HMAC_test_vector", | |
120 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
121 | .auth = { | |
122 | .algo = RTE_CRYPTO_AUTH_SHA224_HMAC, | |
123 | }, | |
124 | .input = { | |
125 | .data = { | |
126 | 0x41, 0x18, 0x43, 0xa2, 0x13, 0x87, 0x84, 0x6f, | |
127 | 0x3b, 0x9e, 0xd5, 0xfc, 0x54, 0x5a, 0xca, 0xdf, | |
128 | 0xa5, 0xb7, 0x03, 0x86, 0xf6, 0x2d, 0xa4, 0xd9, | |
129 | 0xa2, 0x7b, 0x04, 0x1b, 0xee, 0xa3, 0xaa, 0x11, | |
130 | 0x99, 0x36, 0x75, 0x67, 0xb4, 0xd1, 0x1a, 0x4f, | |
131 | 0xb4, 0xe8, 0xd4, 0x6b, 0xc6, 0xc2, 0x56, 0xed, | |
132 | 0x62, 0xc5, 0x05, 0xfd, 0x23, 0xf4, 0x64, 0x5b, | |
133 | 0xd6, 0xb6, 0xcf, 0x45, 0xd1, 0xd9, 0x6d, 0x9b, | |
134 | 0x86, 0xd6, 0x60, 0x41, 0x57, 0x57, 0x3e, 0xc5, | |
135 | 0xac, 0xf6, 0xc5, 0x41, 0x43, 0x48, 0xca, 0x83, | |
136 | 0xc8, 0x1a, 0x73, 0x6c, 0xa6, 0xfa, 0xa6, 0x96, | |
137 | 0x1c, 0xfa, 0xc1, 0x39, 0x93, 0xb0, 0x8c, 0x50, | |
138 | 0x2f, 0x81, 0x6c, 0xf7, 0xa4, 0x20, 0xd9, 0x18, | |
139 | 0x4b, 0x51, 0x11, 0x46, 0x75, 0xf3, 0x0e, 0xe9, | |
140 | 0xff, 0x3d, 0xb6, 0x9c, 0x26, 0x48, 0x53, 0xd3, | |
141 | 0x9d, 0xcd, 0x42, 0xc1, 0xdd, 0x31, 0xef, 0x79 | |
142 | ||
143 | }, | |
144 | .len = 128, | |
145 | }, | |
146 | .key = { | |
147 | .data = { | |
148 | 0x37, 0x14, 0x70, 0x78, 0x39, 0xda, 0xf7, 0x91, | |
149 | 0x22, 0xc7, 0x82, 0x41, 0x63, 0x51, 0x38, 0x5e, | |
150 | 0x88, 0xa8, 0x1d, 0x31, 0xc9, 0xf6, 0x41, 0xd8, | |
151 | 0xdc, 0xe5, 0x38, 0xe9, 0x0e, 0x63, 0xc9, 0x58, | |
152 | 0x92, 0xa2, 0xea, 0x9b, 0x19, 0x62, 0xed, 0x0b, | |
153 | 0xa3, 0x72, 0xf4, 0x8e, 0x94, 0x74, 0xaa, 0x73, | |
154 | 0x0a, 0xe2 | |
155 | }, | |
156 | .len = 50, | |
157 | }, | |
158 | .digest = { | |
159 | .data = { | |
160 | 0x33, 0xf1, 0x7a, 0xc8, 0xa5, 0xc6, 0xb5, 0x25, | |
161 | 0xdb, 0x8b, 0x86, 0x44, 0xb6, 0xab | |
162 | ||
163 | }, | |
164 | .len = 14, | |
165 | }, | |
166 | }; | |
167 | ||
168 | ||
169 | static struct fips_dev_self_test_vector | |
170 | SELF_TEST_SHA256_HMAC_test_vector = { | |
171 | .name = "SELF_TEST_SHA256_HMAC_test_vector", | |
172 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
173 | .auth = { | |
174 | .algo = RTE_CRYPTO_AUTH_SHA256_HMAC, | |
175 | }, | |
176 | .input = { | |
177 | .data = { | |
178 | 0x1c, 0x43, 0x96, 0xf7, 0xb7, 0xf9, 0x22, 0x8e, | |
179 | 0x83, 0x2a, 0x13, 0x69, 0x20, 0x02, 0xba, 0x2a, | |
180 | 0xff, 0x43, 0x9d, 0xcb, 0x7f, 0xdd, 0xbf, 0xd4, | |
181 | 0x56, 0xc0, 0x22, 0xd1, 0x33, 0xee, 0x89, 0x03, | |
182 | 0xa2, 0xd4, 0x82, 0x56, 0x2f, 0xda, 0xa4, 0x93, | |
183 | 0xce, 0x39, 0x16, 0xd7, 0x7a, 0x0c, 0x51, 0x44, | |
184 | 0x1d, 0xab, 0x26, 0xf6, 0xb0, 0x34, 0x02, 0x38, | |
185 | 0xa3, 0x6a, 0x71, 0xf8, 0x7f, 0xc3, 0xe1, 0x79, | |
186 | 0xca, 0xbc, 0xa9, 0x48, 0x2b, 0x70, 0x49, 0x71, | |
187 | 0xce, 0x69, 0xf3, 0xf2, 0x0a, 0xb6, 0x4b, 0x70, | |
188 | 0x41, 0x3d, 0x6c, 0x29, 0x08, 0x53, 0x2b, 0x2a, | |
189 | 0x88, 0x8a, 0x9f, 0xc2, 0x24, 0xca, 0xe1, 0x36, | |
190 | 0x5d, 0xa4, 0x10, 0xb6, 0xf2, 0xe2, 0x98, 0x90, | |
191 | 0x4b, 0x63, 0xb4, 0xa4, 0x17, 0x26, 0x32, 0x18, | |
192 | 0x35, 0xa4, 0x77, 0x4d, 0xd0, 0x63, 0xc2, 0x11, | |
193 | 0xcf, 0xc8, 0xb5, 0x16, 0x6c, 0x2d, 0x11, 0xa2 | |
194 | }, | |
195 | .len = 128, | |
196 | }, | |
197 | .key = { | |
198 | .data = { | |
199 | 0x54, 0x48, 0x99, 0x8f, 0x9d, 0x8f, 0x98, 0x53, | |
200 | 0x4a, 0xdd, 0xf0, 0xc8, 0xba, 0x63, 0x1c, 0x49, | |
201 | 0x6b, 0xf8, 0xa8, 0x00, 0x6c, 0xbb, 0x46, 0xad, | |
202 | 0x15, 0xfa, 0x1f, 0xa2, 0xf5, 0x53, 0x67, 0x12, | |
203 | 0x0c, 0x19, 0x34, 0x8c, 0x3a, 0xfa, 0x90, 0xc3 | |
204 | }, | |
205 | .len = 40, | |
206 | }, | |
207 | .digest = { | |
208 | .data = { | |
209 | 0x7e, 0x8c, 0xba, 0x9d, 0xd9, 0xf0, 0x6e, 0xbd, | |
210 | 0xd7, 0xf9, 0x2e, 0x0f, 0x1a, 0x67, 0xc7, 0xf4, | |
211 | 0xdf, 0x52, 0x69, 0x3c, 0x21, 0x2b, 0xdd, 0x84, | |
212 | 0xf6, 0x73, 0x70, 0xb3, 0x51, 0x53, 0x3c, 0x6c | |
213 | }, | |
214 | .len = 32, | |
215 | }, | |
216 | }; | |
217 | ||
218 | /* HMAC count=34 L=48 SHA384 GENERATE*/ | |
219 | static struct fips_dev_self_test_vector | |
220 | SELF_TEST_SHA384_HMAC_test_vector = { | |
221 | .name = "SELF_TEST_SHA384_HMAC_test_vector", | |
222 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
223 | .auth = { | |
224 | .algo = RTE_CRYPTO_AUTH_SHA384_HMAC, | |
225 | }, | |
226 | .input = { | |
227 | .data = { | |
228 | 0xf5, 0x10, 0x86, 0xfe, 0x78, 0x15, 0x0f, 0xe4, | |
229 | 0x8b, 0xd1, 0x41, 0x5a, 0x47, 0x85, 0xac, 0xc0, | |
230 | 0x5a, 0xb8, 0x0e, 0xf0, 0x0b, 0x29, 0x75, 0xce, | |
231 | 0x78, 0x07, 0xa4, 0x21, 0x22, 0x64, 0xb8, 0xa1, | |
232 | 0xac, 0xe8, 0x0b, 0x50, 0xe0, 0xc2, 0x59, 0x0e, | |
233 | 0xf3, 0xe4, 0x21, 0x68, 0x0a, 0x70, 0x4e, 0xb2, | |
234 | 0xfc, 0x6d, 0x17, 0x55, 0x5a, 0xbf, 0x24, 0x69, | |
235 | 0xad, 0x56, 0xf2, 0x87, 0xfe, 0xa5, 0x78, 0xd8, | |
236 | 0x9c, 0x56, 0x0b, 0x72, 0x19, 0x3c, 0x7f, 0xe5, | |
237 | 0x96, 0x89, 0x8f, 0x10, 0x40, 0x41, 0x7e, 0x3a, | |
238 | 0x1b, 0xee, 0xff, 0x5e, 0xff, 0x96, 0x53, 0xc5, | |
239 | 0xe0, 0xea, 0xb1, 0xda, 0x52, 0xc0, 0xea, 0x3b, | |
240 | 0x4b, 0xc3, 0x4d, 0x0c, 0x2b, 0x69, 0xc8, 0x90, | |
241 | 0xfb, 0x26, 0x51, 0xfa, 0xf2, 0xe0, 0x84, 0x80, | |
242 | 0x3e, 0xa2, 0x8e, 0xb2, 0x01, 0x94, 0x49, 0x0a, | |
243 | 0x99, 0x2b, 0xa8, 0xc4, 0x24, 0x9d, 0x56, 0xef | |
244 | }, | |
245 | .len = 128, | |
246 | }, | |
247 | .key = { | |
248 | .data = { | |
249 | 0x91, 0x7a, 0x69, 0x8c, 0x82, 0xf4, 0x4f, 0x19, | |
250 | 0x57, 0x3b, 0x64, 0x5c, 0x48, 0x79, 0xb8, 0x73, | |
251 | 0x0b, 0x58, 0xdf, 0xf4, 0xed, 0xc6, 0xa0, 0xd3, | |
252 | 0x21, 0xf5, 0xf1, 0x86, 0x58, 0xa5, 0x24, 0x66, | |
253 | 0x92, 0xa5, 0x5b, 0x59, 0x33, 0x97, 0x41, 0xae, | |
254 | 0x59, 0xf5, 0xfc, 0x48, 0x6d, 0x51, 0x5d, 0xff, | |
255 | 0xf8, 0xe1 | |
256 | }, | |
257 | .len = 50, | |
258 | }, | |
259 | .digest = { | |
260 | .data = { | |
261 | 0x77, 0xbf, 0x56, 0x15, 0xec, 0x52, 0xf7, 0x06, | |
262 | 0xca, 0x74, 0x64, 0x01, 0xe9, 0xfd, 0xe4, 0x3f, | |
263 | 0x15, 0x60, 0x52, 0x37, 0xe5, 0x50, 0xb9, 0x3a, | |
264 | 0x84, 0x72, 0xfd, 0x14, 0x4f, 0xc3, 0x9e, 0x5e, | |
265 | 0xca, 0x0f, 0xe8, 0x90, 0x83, 0x88, 0x28, 0xa0 | |
266 | }, | |
267 | .len = 40, | |
268 | }, | |
269 | }; | |
270 | ||
271 | /* HMAC count=28 L=64 SHA512 GENERATE*/ | |
272 | static struct fips_dev_self_test_vector | |
273 | SELF_TEST_SHA512_HMAC_test_vector = { | |
274 | .name = "SELF_TEST_SHA512_HMAC_test_vector", | |
275 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
276 | .auth = { | |
277 | .algo = RTE_CRYPTO_AUTH_SHA512_HMAC, | |
278 | }, | |
279 | .input = { | |
280 | .data = { | |
281 | 0x0a, 0x33, 0x1c, 0xe2, 0x00, 0x89, 0xb2, 0x9e, | |
282 | 0x94, 0xb2, 0xc5, 0xf5, 0x18, 0xc8, 0xdb, 0xea, | |
283 | 0xd4, 0x04, 0x17, 0xa2, 0xa8, 0xd5, 0x00, 0x18, | |
284 | 0xf3, 0x2f, 0x85, 0x12, 0xb3, 0x26, 0x3d, 0x54, | |
285 | 0xed, 0xbb, 0xf3, 0x13, 0x4f, 0xf6, 0x61, 0xac, | |
286 | 0x14, 0x35, 0x3c, 0x96, 0x28, 0xc3, 0x71, 0x95, | |
287 | 0x8c, 0xac, 0xaf, 0x31, 0xfd, 0xd0, 0x25, 0x67, | |
288 | 0xd0, 0x37, 0x8d, 0x9e, 0x21, 0xa4, 0x69, 0xdd, | |
289 | 0x2c, 0x6d, 0x8c, 0x3a, 0xfb, 0x89, 0xdd, 0x96, | |
290 | 0x42, 0xeb, 0x58, 0x87, 0x87, 0x0e, 0x55, 0x96, | |
291 | 0x85, 0xd2, 0x0d, 0xab, 0xd3, 0x86, 0x5a, 0xc5, | |
292 | 0xc1, 0x46, 0xbe, 0xee, 0x83, 0x87, 0xa7, 0x6f, | |
293 | 0x91, 0xf0, 0xf1, 0x40, 0x4d, 0x6c, 0xad, 0xc2, | |
294 | 0xe6, 0x7d, 0x21, 0xb0, 0x7d, 0xd3, 0x0f, 0x53, | |
295 | 0x87, 0x1d, 0x3b, 0xf6, 0x73, 0x1f, 0x27, 0x9a, | |
296 | 0x8c, 0x04, 0x21, 0xeb, 0x20, 0xf6, 0x7f, 0x72 | |
297 | }, | |
298 | .len = 128, | |
299 | }, | |
300 | .key = { | |
301 | .data = { | |
302 | 0x39, 0xb8, 0x77, 0xb8, 0xe8, 0x2e, 0xcb, 0xd9, | |
303 | 0x74, 0x03, 0x25, 0x82, 0x8f, 0xaf, 0x67, 0x21, | |
304 | 0xc1, 0x29, 0x04, 0x6e, 0xb0, 0x13, 0x61, 0x44, | |
305 | 0xa0, 0x31, 0x82, 0xb1, 0x36, 0x20, 0xe2, 0x49, | |
306 | 0x81, 0x45, 0xa2, 0xbf, 0x3b, 0x03, 0xe6, 0xb6, | |
307 | 0x4b, 0x31, 0x7d, 0xd4, 0x8f, 0xcb, 0xc0, 0x18, | |
308 | 0xd9, 0xe7, 0xbc, 0x6e, 0x37, 0xeb, 0x93, 0x81, | |
309 | 0x78, 0xfe, 0x1f, 0xd1, 0xeb, 0xbc, 0xd9, 0x05, | |
310 | 0x6a, 0x2e, 0xf9, 0x82, 0x97, 0xf9, 0xdf, 0x3c, | |
311 | 0x66, 0xd5, 0xb2, 0xcc, 0xdc, 0x41, 0x47, 0xc4, | |
312 | 0x16, 0x76, 0x44, 0x3f, 0x8c, 0x99, 0x85, 0xbc, | |
313 | 0x97, 0x34, 0xbe, 0x2c, 0x31, 0xe7, 0x62, 0x49, | |
314 | 0xfc, 0x5b, 0xc4, 0x2a | |
315 | }, | |
316 | .len = 100, | |
317 | }, | |
318 | .digest = { | |
319 | .data = { | |
320 | 0x97, 0x16, 0x8f, 0x55, 0x13, 0xc2, 0xe9, 0xbc, | |
321 | 0x4b, 0xc5, 0x25, 0xce, 0x27, 0x03, 0x74, 0x0b, | |
322 | 0xce, 0x1a, 0x06, 0xec, 0xfe, 0x99, 0xa5, 0x70, | |
323 | 0xac, 0x66, 0xc8, 0x3e, 0xde, 0x96, 0x67, 0xcc, | |
324 | 0x07, 0xed, 0xf6, 0x64, 0x61, 0x7c, 0xe5, 0x3c | |
325 | }, | |
326 | .len = 40, | |
327 | }, | |
328 | }; | |
329 | ||
330 | /* <-- AES CMAC --> */ | |
331 | static struct fips_dev_self_test_vector | |
332 | SELF_TEST_AES_CMAC_test_vector = { | |
333 | .name = "SELF_TEST_AES_CMAC_test_vector", | |
334 | .operation_type = RTE_CRYPTO_SYM_XFORM_AUTH, | |
335 | .auth = { | |
336 | .algo = RTE_CRYPTO_AUTH_AES_CMAC, | |
337 | }, | |
338 | .input = { | |
339 | .data = { | |
340 | 0x57, 0x88, 0xf6, 0x1e, 0x02, 0x30, 0x47, 0x91, | |
341 | 0xb5, 0x2f, 0x40, 0x05, 0x7a, 0xbb, 0x4e, 0x04, | |
342 | 0x46, 0x40, 0x3e, 0xf3, 0x74, 0x02, 0x53, 0xdf, | |
343 | 0x72, 0x05, 0x96, 0x79, 0xbb, 0x2a, 0x6e, 0x5e, | |
344 | 0x05, 0x9a, 0x70, 0x9c, 0xbb | |
345 | }, | |
346 | .len = 37, | |
347 | }, | |
348 | .key = { | |
349 | .data = { | |
350 | 0x18, 0x42, 0x15, 0x14, 0x5d, 0xa4, 0x9d, 0xb4, | |
351 | 0x17, 0xe8, 0xbd, 0xd5, 0x73, 0xd6, 0x28, 0x2d | |
352 | }, | |
353 | .len = 16, | |
354 | }, | |
355 | .digest = { | |
356 | .data = { | |
357 | 0x8d, 0xa8, 0xcc, 0xa9, 0xb3, 0x6f, 0x68, 0x57, | |
358 | 0x1c, 0x6c, 0x0e, 0x40, 0xa3, 0xf4, 0x10 | |
359 | }, | |
360 | .len = 15, | |
361 | }, | |
362 | }; | |
363 | ||
364 | /* <-- AES CCM --> */ | |
365 | static struct fips_dev_self_test_vector | |
366 | SELF_TEST_AES128_CCM_test_vector = { | |
367 | .name = "SELF_TEST_AES128_CCM_test_vector", | |
368 | .operation_type = RTE_CRYPTO_SYM_XFORM_AEAD, | |
369 | .iv = { | |
370 | .data = { | |
371 | 0x00, 0x50, 0x30, 0xF1, 0x84, 0x44, 0x08, 0xB5, | |
372 | 0x03, 0x97, 0x76, 0xE7, 0x0C | |
373 | }, | |
374 | .len = 13, | |
375 | }, | |
376 | .aead = { | |
377 | .algo = RTE_CRYPTO_AEAD_AES_CCM, | |
378 | .aad = { | |
379 | .data = { | |
380 | /* 18 bytes padding for AAD */ | |
381 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
382 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
383 | 0x00, 0x00, | |
384 | 0x08, 0x40, 0x0F, 0xD2, 0xE1, 0x28, 0xA5, 0x7C, | |
385 | 0x50, 0x30, 0xF1, 0x84, 0x44, 0x08, 0xAB, 0xAE, | |
386 | 0xA5, 0xB8, 0xFC, 0xBA, 0x00, 0x00 | |
387 | }, | |
388 | .len = 22, | |
389 | }, | |
390 | }, | |
391 | .input = { | |
392 | .data = { | |
393 | 0xF8, 0xBA, 0x1A, 0x55, 0xD0, 0x2F, 0x85, 0xAE, | |
394 | 0x96, 0x7B, 0xB6, 0x2F, 0xB6, 0xCD, 0xA8, 0xEB, | |
395 | 0x7E, 0x78, 0xA0, 0x50 | |
396 | }, | |
397 | .len = 20, | |
398 | }, | |
399 | .key = { | |
400 | .data = { | |
401 | 0xC9, 0x7C, 0x1F, 0x67, 0xCE, 0x37, 0x11, 0x85, | |
402 | 0x51, 0x4A, 0x8A, 0x19, 0xF2, 0xBD, 0xD5, 0x2F | |
403 | }, | |
404 | .len = 16, | |
405 | }, | |
406 | .output = { | |
407 | .data = { | |
408 | 0xF3, 0xD0, 0xA2, 0xFE, 0x9A, 0x3D, 0xBF, 0x23, | |
409 | 0x42, 0xA6, 0x43, 0xE4, 0x32, 0x46, 0xE8, 0x0C, | |
410 | 0x3C, 0x04, 0xD0, 0x19 | |
411 | }, | |
412 | .len = 20, | |
413 | }, | |
414 | .digest = { | |
415 | .data = { | |
416 | 0x78, 0x45, 0xCE, 0x0B, 0x16, 0xF9, 0x76, 0x23 | |
417 | }, | |
418 | .len = 8, | |
419 | }, | |
420 | }; | |
421 | ||
422 | /* <-- AES CBC --> */ | |
423 | static struct fips_dev_self_test_vector | |
424 | SELF_TEST_AES128_CBC_test_vector = { | |
425 | .name = "SELF_TEST_AES128_CBC_test_vector", | |
426 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
427 | ||
428 | .iv = { | |
429 | .data = { | |
430 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
431 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | |
432 | }, | |
433 | .len = 16, | |
434 | }, | |
435 | .cipher = { | |
436 | .algo = RTE_CRYPTO_CIPHER_AES_CBC, | |
437 | }, | |
438 | .input = { | |
439 | .data = { | |
440 | 0x57, 0x68, 0x61, 0x74, 0x20, 0x61, 0x20, 0x6C, | |
441 | 0x6F, 0x75, 0x73, 0x79, 0x20, 0x65, 0x61, 0x72, | |
442 | 0x74, 0x68, 0x21, 0x20, 0x48, 0x65, 0x20, 0x77, | |
443 | 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, | |
444 | }, | |
445 | .len = 32, | |
446 | }, | |
447 | .key = { | |
448 | .data = { | |
449 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, | |
450 | 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A | |
451 | }, | |
452 | .len = 16, | |
453 | }, | |
454 | .output = { | |
455 | .data = { | |
456 | 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, | |
457 | 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, | |
458 | 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, | |
459 | 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, | |
460 | }, | |
461 | .len = 32, | |
462 | }, | |
463 | }; | |
464 | ||
465 | static struct fips_dev_self_test_vector | |
466 | SELF_TEST_AES192_CBC_test_vector = { | |
467 | .name = "SELF_TEST_AES192_CBC_test_vector", | |
468 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
469 | ||
470 | .iv = { | |
471 | .data = { | |
472 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
473 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | |
474 | }, | |
475 | .len = 16, | |
476 | }, | |
477 | .cipher = { | |
478 | .algo = RTE_CRYPTO_CIPHER_AES_CBC, | |
479 | }, | |
480 | .input = { | |
481 | .data = { | |
482 | 0x57, 0x68, 0x61, 0x74, 0x20, 0x61, 0x20, 0x6C, | |
483 | 0x6F, 0x75, 0x73, 0x79, 0x20, 0x65, 0x61, 0x72, | |
484 | 0x74, 0x68, 0x21, 0x20, 0x48, 0x65, 0x20, 0x77, | |
485 | 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, | |
486 | }, | |
487 | .len = 32, | |
488 | }, | |
489 | .key = { | |
490 | .data = { | |
491 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, | |
492 | 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A, | |
493 | 0xD4, 0xC3, 0xA3, 0xAA, 0x33, 0x62, 0x61, 0xE0 | |
494 | }, | |
495 | .len = 24, | |
496 | }, | |
497 | .output = { | |
498 | .data = { | |
499 | 0x45, 0xEE, 0x9A, 0xEA, 0x3C, 0x03, 0xFC, 0x4C, | |
500 | 0x84, 0x36, 0xB0, 0xDA, 0xB0, 0xDC, 0xF3, 0x5B, | |
501 | 0x75, 0xA7, 0xBE, 0x0E, 0xC0, 0x8D, 0x6C, 0xF8, | |
502 | 0xC1, 0x0F, 0xD0, 0x35, 0x1D, 0x82, 0xAE, 0x7C, | |
503 | }, | |
504 | .len = 32, | |
505 | }, | |
506 | }; | |
507 | ||
508 | /* AES-256 CBC ENCRYPT*/ | |
509 | static struct fips_dev_self_test_vector | |
510 | SELF_TEST_AES256_CBC_test_vector = { | |
511 | .name = "SELF_TEST_AES256_CBC_test_vector", | |
512 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
513 | ||
514 | .iv = { | |
515 | .data = { | |
516 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
517 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | |
518 | }, | |
519 | .len = 16, | |
520 | }, | |
521 | .cipher = { | |
522 | .algo = RTE_CRYPTO_CIPHER_AES_CBC, | |
523 | }, | |
524 | .input = { | |
525 | .data = { | |
526 | 0x57, 0x68, 0x61, 0x74, 0x20, 0x61, 0x20, 0x6C, | |
527 | 0x6F, 0x75, 0x73, 0x79, 0x20, 0x65, 0x61, 0x72, | |
528 | 0x74, 0x68, 0x21, 0x20, 0x48, 0x65, 0x20, 0x77, | |
529 | 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, | |
530 | }, | |
531 | .len = 32, | |
532 | }, | |
533 | .key = { | |
534 | .data = { | |
535 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, | |
536 | 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A, | |
537 | 0xD4, 0xC3, 0xA3, 0xAA, 0x33, 0x62, 0x61, 0xE0, | |
538 | 0x37, 0x07, 0xB8, 0x23, 0xA2, 0xA3, 0xB5, 0x8D | |
539 | }, | |
540 | .len = 32, | |
541 | }, | |
542 | .output = { | |
543 | .data = { | |
544 | 0xF3, 0xDD, 0xF0, 0x0B, 0xFF, 0xA2, 0x6A, 0x04, | |
545 | 0xBE, 0xDA, 0x52, 0xA6, 0xFE, 0x6B, 0xA6, 0xA7, | |
546 | 0x48, 0x1D, 0x7D, 0x98, 0x65, 0xDB, 0xEF, 0x06, | |
547 | 0x26, 0xB5, 0x8E, 0xEB, 0x05, 0x0E, 0x77, 0x98, | |
548 | }, | |
549 | .len = 32, | |
550 | }, | |
551 | }; | |
552 | ||
553 | /* DES-128 CBC ENCRYPT*/ | |
554 | static struct fips_dev_self_test_vector | |
555 | SELF_TEST_3DES_2KEY_CBC_test_vector = { | |
556 | .name = "SELF_TEST_3DES_2KEY_CBC_test_vector", | |
557 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
558 | .iv = { | |
559 | .data = { | |
560 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 | |
561 | }, | |
562 | .len = 8, | |
563 | }, | |
564 | .cipher = { | |
565 | .algo = RTE_CRYPTO_CIPHER_3DES_CBC, | |
566 | }, | |
567 | .input = { | |
568 | .data = { | |
569 | 0x57, 0x68, 0x61, 0x74, 0x20, 0x61, 0x20, 0x6C, | |
570 | 0x6F, 0x75, 0x73, 0x79, 0x20, 0x65, 0x61, 0x72, | |
571 | 0x74, 0x68, 0x21, 0x20, 0x48, 0x65, 0x20, 0x77, | |
572 | 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, | |
573 | }, | |
574 | .len = 32, | |
575 | }, | |
576 | .key = { | |
577 | .data = { | |
578 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, | |
579 | 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A, | |
580 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2 | |
581 | }, | |
582 | .len = 24, | |
583 | }, | |
584 | .output = { | |
585 | .data = { | |
586 | 0x28, 0x2a, 0xff, 0x15, 0x5c, 0xdf, 0xd9, 0x6b, | |
587 | 0x54, 0xbc, 0x7b, 0xfb, 0xc5, 0x64, 0x4d, 0xdd, | |
588 | 0x3e, 0xf2, 0x9e, 0xb7, 0x53, 0x65, 0x37, 0x05, | |
589 | 0xe0, 0xdf, 0xae, 0xf7, 0xc9, 0x27, 0xe4, 0xec, | |
590 | }, | |
591 | .len = 32, | |
592 | }, | |
593 | }; | |
594 | ||
595 | static struct fips_dev_self_test_vector | |
596 | SELF_TEST_3DES_3KEY_CBC_test_vector = { | |
597 | .name = "SELF_TEST_3DES_3KEY_CBC_test_vector", | |
598 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
599 | ||
600 | .iv = { | |
601 | .data = { | |
602 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 | |
603 | }, | |
604 | .len = 8, | |
605 | }, | |
606 | .cipher = { | |
607 | .algo = RTE_CRYPTO_CIPHER_3DES_CBC, | |
608 | }, | |
609 | .input = { | |
610 | .data = { | |
611 | 0x57, 0x68, 0x61, 0x74, 0x20, 0x61, 0x20, 0x6C, | |
612 | 0x6F, 0x75, 0x73, 0x79, 0x20, 0x65, 0x61, 0x72, | |
613 | 0x74, 0x68, 0x21, 0x20, 0x48, 0x65, 0x20, 0x77, | |
614 | 0x6F, 0x6E, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, | |
615 | }, | |
616 | .len = 32, | |
617 | }, | |
618 | .key = { | |
619 | .data = { | |
620 | 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, | |
621 | 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A, | |
622 | 0xD4, 0xC3, 0xA3, 0xAA, 0x33, 0x62, 0x61, 0xE0 | |
623 | }, | |
624 | .len = 24, | |
625 | }, | |
626 | .output = { | |
627 | .data = { | |
628 | 0xd0, 0xc9, 0xdc, 0x51, 0x29, 0x97, 0x03, 0x64, | |
629 | 0xcd, 0x22, 0xba, 0x3d, 0x2b, 0xbc, 0x21, 0x37, | |
630 | 0x7b, 0x1e, 0x29, 0x23, 0xeb, 0x51, 0x6e, 0xac, | |
631 | 0xbe, 0x5b, 0xd3, 0x67, 0xe0, 0x3f, 0xc3, 0xb5, | |
632 | }, | |
633 | .len = 32, | |
634 | }, | |
635 | }; | |
636 | ||
637 | /* <-- AES GCM --> */ | |
638 | static struct fips_dev_self_test_vector | |
639 | SELF_TEST_AES128_GCM_encrypt_test_vector = { | |
640 | .name = "SELF_TEST_AES128_GCM_encrypt_test_vector", | |
641 | .operation_type = RTE_CRYPTO_SYM_XFORM_AEAD, | |
642 | ||
643 | .iv = { | |
644 | .data = { | |
645 | 0x5a, 0xdb, 0x96, 0x09, 0xdb, 0xae, 0xb5, 0x8c, | |
646 | 0xbd, 0x6e, 0x72, 0x75 | |
647 | }, | |
648 | .len = 12, | |
649 | }, | |
650 | .aead = { | |
651 | .algo = RTE_CRYPTO_AEAD_AES_GCM, | |
652 | .aad = { | |
653 | .data = { | |
654 | 0x88, 0x31, 0x9d, 0x6e, 0x1d, 0x3f, 0xfa, 0x5f, | |
655 | 0x98, 0x71, 0x99, 0x16, 0x6c, 0x8a, 0x9b, 0x56, | |
656 | 0xc2, 0xae, 0xba, 0x5a | |
657 | }, | |
658 | .len = 20, | |
659 | }, | |
660 | }, | |
661 | .input = { | |
662 | .data = { | |
663 | 0x7c, 0x0e, 0x88, 0xc8, 0x88, 0x99, 0xa7, 0x79, | |
664 | 0x22, 0x84, 0x65, 0x07, 0x47, 0x97, 0xcd, 0x4c, | |
665 | 0x2e, 0x14, 0x98, 0xd2, 0x59, 0xb5, 0x43, 0x90, | |
666 | 0xb8, 0x5e, 0x3e, 0xef, 0x1c, 0x02, 0xdf, 0x60, | |
667 | 0xe7, 0x43, 0xf1, 0xb8, 0x40, 0x38, 0x2c, 0x4b, | |
668 | 0xcc, 0xaf, 0x3b, 0xaf, 0xb4, 0xca, 0x84, 0x29, | |
669 | 0xbe, 0xa0, 0x63 | |
670 | }, | |
671 | .len = 51, | |
672 | }, | |
673 | .key = { | |
674 | .data = { | |
675 | 0xfe, 0x47, 0xfc, 0xce, 0x5f, 0xc3, 0x26, 0x65, | |
676 | 0xd2, 0xae, 0x39, 0x9e, 0x4e, 0xec, 0x72, 0xba | |
677 | }, | |
678 | .len = 16, | |
679 | }, | |
680 | .output = { | |
681 | .data = { | |
682 | 0x98, 0xf4, 0x82, 0x6f, 0x05, 0xa2, 0x65, 0xe6, | |
683 | 0xdd, 0x2b, 0xe8, 0x2d, 0xb2, 0x41, 0xc0, 0xfb, | |
684 | 0xbb, 0xf9, 0xff, 0xb1, 0xc1, 0x73, 0xaa, 0x83, | |
685 | 0x96, 0x4b, 0x7c, 0xf5, 0x39, 0x30, 0x43, 0x73, | |
686 | 0x63, 0x65, 0x25, 0x3d, 0xdb, 0xc5, 0xdb, 0x87, | |
687 | 0x78, 0x37, 0x14, 0x95, 0xda, 0x76, 0xd2, 0x69, | |
688 | 0xe5, 0xdb, 0x3e | |
689 | }, | |
690 | .len = 51, | |
691 | }, | |
692 | .digest = { | |
693 | .data = { | |
694 | 0x29, 0x1e, 0xf1, 0x98, 0x2e, 0x4d, 0xef, 0xed, | |
695 | 0xaa, 0x22, 0x49, 0xf8, 0x98, 0x55, 0x6b, 0x47 | |
696 | }, | |
697 | .len = 16, | |
698 | }, | |
699 | }; | |
700 | ||
701 | static struct fips_dev_self_test_vector | |
702 | SELF_TEST_AES192_GCM_encrypt_test_vector = { | |
703 | .operation_type = RTE_CRYPTO_SYM_XFORM_AEAD, | |
704 | .name = "SELF_TEST_AES192_GCM_encrypt_test_vector", | |
705 | .iv = { | |
706 | .data = { | |
707 | 0x0b, 0xd4, 0x4f, 0xf4, 0xd2, 0x0c, 0x15, 0xd0, | |
708 | 0x4f, 0xc6, 0x1e, 0xe7 | |
709 | }, | |
710 | .len = 12, | |
711 | }, | |
712 | .aead = { | |
713 | .algo = RTE_CRYPTO_AEAD_AES_GCM, | |
714 | .aad = { | |
715 | .data = { | |
716 | 0x9e, 0xa4, 0x2c, 0x50, 0xa7, 0xfd, 0xb8, 0x5e, | |
717 | 0x14, 0x1a, 0xa0, 0x84, 0xb4, 0x6b, 0xde, 0x12 | |
718 | }, | |
719 | .len = 16, | |
720 | }, | |
721 | }, | |
722 | .input = { | |
723 | .data = { | |
724 | 0x56, 0x7c, 0xcb, 0x3f, 0xa0, 0xdb, 0x89, 0x70, | |
725 | 0x8a, 0xf3, 0xff, 0x2b, 0xb0, 0x29, 0xdd, 0xec, | |
726 | 0x52, 0xc6, 0x69, 0x47, 0x58, 0x5d, 0x29, 0x1a, | |
727 | 0x28, 0x56, 0x4b, 0xf5, 0x6d, 0xb7, 0x06, 0xf7 | |
728 | }, | |
729 | .len = 32, | |
730 | }, | |
731 | .key = { | |
732 | .data = { | |
733 | 0x0d, 0x4a, 0x90, 0x0d, 0x1b, 0x0b, 0xb5, 0xb7, | |
734 | 0xbe, 0x24, 0x38, 0xc2, 0xba, 0x48, 0xfc, 0x45, | |
735 | 0x13, 0x4c, 0xc1, 0x98, 0x10, 0x8c, 0xf8, 0x85 | |
736 | }, | |
737 | .len = 24, | |
738 | }, | |
739 | .output = { | |
740 | .data = { | |
741 | 0x2f, 0x8a, 0x42, 0xcd, 0x18, 0x3b, 0x03, 0x14, | |
742 | 0xfd, 0x20, 0xa3, 0xd9, 0x7d, 0x9e, 0x0c, 0x52, | |
743 | 0x17, 0xb0, 0xf0, 0x88, 0xd2, 0xca, 0x87, 0xa8, | |
744 | 0x29, 0x0d, 0x4b, 0xae, 0x69, 0xad, 0x83, 0xf5 | |
745 | }, | |
746 | .len = 32, | |
747 | }, | |
748 | .digest = { | |
749 | .data = { | |
750 | 0xde, 0x41, 0x45, 0x92, 0xd7, 0x7f, 0x2f, 0x0b, | |
751 | 0x50, 0xdf, 0x4a, 0xec, 0x71, 0x4f, 0xad, 0x43 | |
752 | }, | |
753 | .len = 16, | |
754 | }, | |
755 | }; | |
756 | ||
757 | static struct fips_dev_self_test_vector | |
758 | SELF_TEST_AES256_GCM_encrypt_test_vector = { | |
759 | .operation_type = RTE_CRYPTO_SYM_XFORM_AEAD, | |
760 | .name = "SELF_TEST_AES256_GCM_encrypt_test_vector", | |
761 | .iv = { | |
762 | .data = { | |
763 | 0x5c, 0x1b, 0x21, 0xc8, 0x99, 0x8e, 0xd6, 0x29, | |
764 | 0x90, 0x06, 0xd3, 0xf9 | |
765 | }, | |
766 | .len = 12, | |
767 | }, | |
768 | .aead = { | |
769 | .algo = RTE_CRYPTO_AEAD_AES_GCM, | |
770 | .aad = { | |
771 | .data = { | |
772 | 0x22, 0xed, 0x23, 0x59, 0x46, 0x23, 0x5a, 0x85, | |
773 | 0xa4, 0x5b, 0xc5, 0xfa, 0xd7, 0x14, 0x0b, 0xfa | |
774 | }, | |
775 | .len = 16, | |
776 | }, | |
777 | }, | |
778 | .input = { | |
779 | .data = { | |
780 | 0xad, 0x42, 0x60, 0xe3, 0xcd, 0xc7, 0x6b, 0xcc, | |
781 | 0x10, 0xc7, 0xb2, 0xc0, 0x6b, 0x80, 0xb3, 0xbe, | |
782 | 0x94, 0x82, 0x58, 0xe5, 0xef, 0x20, 0xc5, 0x08, | |
783 | 0xa8, 0x1f, 0x51, 0xe9, 0x6a, 0x51, 0x83, 0x88 | |
784 | }, | |
785 | .len = 32, | |
786 | }, | |
787 | .key = { | |
788 | .data = { | |
789 | 0x37, 0xcc, 0xdb, 0xa1, 0xd9, 0x29, 0xd6, 0x43, | |
790 | 0x6c, 0x16, 0xbb, 0xa5, 0xb5, 0xff, 0x34, 0xde, | |
791 | 0xec, 0x88, 0xed, 0x7d, 0xf3, 0xd1, 0x5d, 0x0f, | |
792 | 0x4d, 0xdf, 0x80, 0xc0, 0xc7, 0x31, 0xee, 0x1f | |
793 | }, | |
794 | .len = 32, | |
795 | }, | |
796 | .output = { | |
797 | .data = { | |
798 | 0x3b, 0x33, 0x5f, 0x8b, 0x08, 0xd3, 0x3c, 0xcd, | |
799 | 0xca, 0xd2, 0x28, 0xa7, 0x47, 0x00, 0xf1, 0x00, | |
800 | 0x75, 0x42, 0xa4, 0xd1, 0xe7, 0xfc, 0x1e, 0xbe, | |
801 | 0x3f, 0x44, 0x7f, 0xe7, 0x1a, 0xf2, 0x98, 0x16 | |
802 | }, | |
803 | .len = 32, | |
804 | }, | |
805 | .digest = { | |
806 | .data = { | |
807 | 0x1f, 0xbf, 0x49, 0xcc, 0x46, 0xf4, 0x58, 0xbf, | |
808 | 0x6e, 0x88, 0xf6, 0x37, 0x09, 0x75, 0xe6, 0xd4 | |
809 | }, | |
810 | .len = 16, | |
811 | }, | |
812 | }; | |
813 | ||
814 | ||
815 | /* <-- AES CTR --> */ | |
816 | static struct fips_dev_self_test_vector | |
817 | SELF_TEST_AES128_CTR_test_vector = { | |
818 | .name = "SELF_TEST_AES128_CTR_test_vector", | |
819 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
820 | ||
821 | .iv = { | |
822 | .data = { | |
823 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, | |
824 | 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF | |
825 | }, | |
826 | .len = 16, | |
827 | }, | |
828 | .cipher = { | |
829 | .algo = RTE_CRYPTO_CIPHER_AES_CTR, | |
830 | }, | |
831 | .input = { | |
832 | .data = { | |
833 | 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, | |
834 | 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, | |
835 | 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, | |
836 | 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, | |
837 | }, | |
838 | .len = 32, | |
839 | }, | |
840 | .key = { | |
841 | .data = { | |
842 | 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, | |
843 | 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C | |
844 | }, | |
845 | .len = 16, | |
846 | }, | |
847 | .output = { | |
848 | .data = { | |
849 | 0x87, 0x4D, 0x61, 0x91, 0xB6, 0x20, 0xE3, 0x26, | |
850 | 0x1B, 0xEF, 0x68, 0x64, 0x99, 0x0D, 0xB6, 0xCE, | |
851 | 0x98, 0x06, 0xF6, 0x6B, 0x79, 0x70, 0xFD, 0xFF, | |
852 | 0x86, 0x17, 0x18, 0x7B, 0xB9, 0xFF, 0xFD, 0xFF, | |
853 | }, | |
854 | .len = 32, | |
855 | }, | |
856 | }; | |
857 | ||
858 | static struct fips_dev_self_test_vector | |
859 | SELF_TEST_AES192_CTR_test_vector = { | |
860 | .name = "SELF_TEST_AES192_CTR_test_vector", | |
861 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
862 | ||
863 | .iv = { | |
864 | .data = { | |
865 | 0x3F, 0x69, 0xA8, 0xCD, 0xE8, 0xF0, 0xEF, 0x40, | |
866 | 0xB8, 0x7A, 0x4B, 0xED, 0x2B, 0xAF, 0xBF, 0x57 | |
867 | }, | |
868 | .len = 16, | |
869 | }, | |
870 | .cipher = { | |
871 | .algo = RTE_CRYPTO_CIPHER_AES_CTR, | |
872 | }, | |
873 | .input = { | |
874 | .data = { | |
875 | 0x01, 0x0F, 0x10, 0x1F, 0x20, 0x1C, 0x0E, 0xB8, | |
876 | 0xFB, 0x5C, 0xCD, 0xCC, 0x1F, 0xF9, 0xAF, 0x0B, | |
877 | 0x95, 0x03, 0x74, 0x99, 0x49, 0xE7, 0x62, 0x55, | |
878 | 0xDA, 0xEA, 0x13, 0x20, 0x1D, 0xC6, 0xCC, 0xCC, | |
879 | }, | |
880 | .len = 32, | |
881 | }, | |
882 | .key = { | |
883 | .data = { | |
884 | 0xCB, 0xC5, 0xED, 0x5B, 0xE7, 0x7C, 0xBD, 0x8C, | |
885 | 0x50, 0xD9, 0x30, 0xF2, 0xB5, 0x6A, 0x0E, 0x5F, | |
886 | 0xAA, 0xAE, 0xAD, 0xA2, 0x1F, 0x49, 0x52, 0xD4 | |
887 | }, | |
888 | .len = 24, | |
889 | }, | |
890 | .output = { | |
891 | .data = { | |
892 | 0x4A, 0x6C, 0xC8, 0xCC, 0x96, 0x2A, 0x13, 0x84, | |
893 | 0x1C, 0x36, 0x88, 0xE9, 0xE5, 0x94, 0x70, 0xB2, | |
894 | 0x14, 0x5B, 0x13, 0x80, 0xEA, 0xD8, 0x8D, 0x37, | |
895 | 0xFD, 0x70, 0xA8, 0x83, 0xE8, 0x2B, 0x88, 0x1E, | |
896 | }, | |
897 | .len = 32, | |
898 | }, | |
899 | }; | |
900 | ||
901 | static struct fips_dev_self_test_vector | |
902 | SELF_TEST_AES256_CTR_test_vector = { | |
903 | .name = "SELF_TEST_AES256_CTR_test_vector", | |
904 | .operation_type = RTE_CRYPTO_SYM_XFORM_CIPHER, | |
905 | ||
906 | .iv = { | |
907 | .data = { | |
908 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, | |
909 | 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF | |
910 | }, | |
911 | .len = 16, | |
912 | }, | |
913 | .cipher = { | |
914 | .algo = RTE_CRYPTO_CIPHER_AES_CTR, | |
915 | }, | |
916 | .input = { | |
917 | .data = { | |
918 | 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, | |
919 | 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, | |
920 | 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, | |
921 | 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, | |
922 | }, | |
923 | .len = 32, | |
924 | }, | |
925 | .key = { | |
926 | .data = { | |
927 | 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, | |
928 | 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, | |
929 | 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, | |
930 | 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 | |
931 | }, | |
932 | .len = 32, | |
933 | }, | |
934 | .output = { | |
935 | .data = { | |
936 | 0x60, 0x1E, 0xC3, 0x13, 0x77, 0x57, 0x89, 0xA5, | |
937 | 0xB7, 0xA7, 0xF5, 0x04, 0xBB, 0xF3, 0xD2, 0x28, | |
938 | 0xF4, 0x43, 0xE3, 0xCA, 0x4D, 0x62, 0xB5, 0x9A, | |
939 | 0xCA, 0x84, 0xE9, 0x90, 0xCA, 0xCA, 0xF5, 0xC5, | |
940 | }, | |
941 | .len = 32, | |
942 | }, | |
943 | }; | |
944 | ||
945 | ||
946 | struct fips_dev_self_test_vector | |
947 | *self_test_vectors[] = { | |
948 | &SELF_TEST_AES128_CBC_test_vector, | |
949 | &SELF_TEST_AES192_CBC_test_vector, | |
950 | &SELF_TEST_AES256_CBC_test_vector, | |
951 | &SELF_TEST_3DES_2KEY_CBC_test_vector, | |
952 | &SELF_TEST_3DES_3KEY_CBC_test_vector, | |
953 | &SELF_TEST_AES128_CCM_test_vector, | |
954 | &SELF_TEST_SHA1_HMAC_test_vector, | |
955 | &SELF_TEST_SHA224_HMAC_test_vector, | |
956 | &SELF_TEST_SHA256_HMAC_test_vector, | |
957 | &SELF_TEST_SHA384_HMAC_test_vector, | |
958 | &SELF_TEST_SHA512_HMAC_test_vector, | |
959 | &SELF_TEST_AES_CMAC_test_vector, | |
960 | &SELF_TEST_AES128_GCM_encrypt_test_vector, | |
961 | &SELF_TEST_AES192_GCM_encrypt_test_vector, | |
962 | &SELF_TEST_AES256_GCM_encrypt_test_vector, | |
963 | &SELF_TEST_AES128_CTR_test_vector, | |
964 | &SELF_TEST_AES192_CTR_test_vector, | |
965 | &SELF_TEST_AES256_CTR_test_vector, | |
966 | }; | |
967 | ||
968 | struct fips_dev_auto_test_env { | |
969 | struct rte_mempool *mpool; | |
970 | struct rte_mempool *op_pool; | |
971 | struct rte_mempool *sess_pool; | |
972 | struct rte_mempool *sess_priv_pool; | |
973 | struct rte_mbuf *mbuf; | |
974 | struct rte_crypto_op *op; | |
975 | }; | |
976 | ||
977 | typedef int (*fips_dev_self_test_prepare_xform_t)(uint8_t, | |
978 | struct rte_crypto_sym_xform *, | |
979 | struct fips_dev_self_test_vector *, | |
980 | uint32_t, uint8_t *, | |
981 | uint32_t); | |
982 | ||
983 | typedef int (*fips_dev_self_test_prepare_op_t)(struct rte_crypto_op *, | |
984 | struct rte_mbuf *, struct rte_cryptodev_sym_session *, | |
985 | uint32_t, struct fips_dev_self_test_vector *); | |
986 | ||
987 | typedef int (*fips_dev_self_test_check_result_t)(struct rte_crypto_op *, | |
988 | struct fips_dev_self_test_vector *, uint32_t); | |
989 | ||
990 | struct fips_dev_self_test_ops { | |
991 | enum rte_crypto_sym_xform_type last_operation_type; | |
992 | fips_dev_self_test_prepare_xform_t prepare_xform; | |
993 | fips_dev_self_test_prepare_op_t prepare_op; | |
994 | fips_dev_self_test_check_result_t check_result; | |
995 | }; | |
996 | ||
997 | static int | |
998 | prepare_cipher_xform(uint8_t dev_id, | |
999 | struct rte_crypto_sym_xform *xform, | |
1000 | struct fips_dev_self_test_vector *vec, | |
1001 | uint32_t dir, | |
1002 | uint8_t *key, | |
1003 | uint32_t neg_test) | |
1004 | { | |
1005 | const struct rte_cryptodev_symmetric_capability *cap; | |
1006 | struct rte_cryptodev_sym_capability_idx cap_idx; | |
1007 | struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher; | |
1008 | ||
1009 | memset(xform, 0, sizeof(*xform)); | |
1010 | ||
1011 | /** negative test, key is xored */ | |
1012 | if (neg_test) { | |
1013 | uint32_t i; | |
1014 | ||
1015 | for (i = 0; i < vec->key.len; i++) | |
1016 | key[i] ^= vec->key.data[i]; | |
1017 | } else | |
1018 | memcpy(key, vec->key.data, vec->key.len); | |
1019 | ||
1020 | xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; | |
1021 | ||
1022 | cipher_xform->algo = vec->cipher.algo; | |
1023 | cipher_xform->op = (dir == self_test_dir_enc_auth_gen) ? | |
1024 | RTE_CRYPTO_CIPHER_OP_ENCRYPT : | |
1025 | RTE_CRYPTO_CIPHER_OP_DECRYPT; | |
1026 | cipher_xform->key.data = key; | |
1027 | cipher_xform->key.length = vec->key.len; | |
1028 | cipher_xform->iv.length = vec->iv.len; | |
1029 | cipher_xform->iv.offset = IV_OFF; | |
1030 | ||
1031 | cap_idx.algo.cipher = cipher_xform->algo; | |
1032 | cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; | |
1033 | ||
1034 | cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx); | |
1035 | if (!cap) { | |
1036 | RTE_LOG(ERR, PMD, "Failed to get capability for cdev %u\n", | |
1037 | dev_id); | |
1038 | return -EACCES; | |
1039 | } | |
1040 | ||
1041 | if (rte_cryptodev_sym_capability_check_cipher(cap, | |
1042 | cipher_xform->key.length, | |
1043 | cipher_xform->iv.length) != 0) { | |
1044 | RTE_LOG(ERR, PMD, "PMD %s key length %u IV length %u\n", | |
1045 | rte_cryptodev_name_get(dev_id), | |
1046 | cipher_xform->key.length, | |
1047 | cipher_xform->iv.length); | |
1048 | return -EACCES; | |
1049 | } | |
1050 | ||
1051 | return 0; | |
1052 | } | |
1053 | ||
1054 | static int | |
1055 | prepare_auth_xform(uint8_t dev_id, | |
1056 | struct rte_crypto_sym_xform *xform, | |
1057 | struct fips_dev_self_test_vector *vec, | |
1058 | uint32_t dir, | |
1059 | uint8_t *key, | |
1060 | uint32_t neg_test) | |
1061 | { | |
1062 | const struct rte_cryptodev_symmetric_capability *cap; | |
1063 | struct rte_cryptodev_sym_capability_idx cap_idx; | |
1064 | struct rte_crypto_auth_xform *auth_xform = &xform->auth; | |
1065 | ||
1066 | memset(xform, 0, sizeof(*xform)); | |
1067 | ||
1068 | /** negative test, key is xored */ | |
1069 | if (neg_test) { | |
1070 | uint32_t i; | |
1071 | ||
1072 | for (i = 0; i < vec->key.len; i++) | |
1073 | key[i] ^= vec->key.data[i]; | |
1074 | } else | |
1075 | memcpy(key, vec->key.data, vec->key.len); | |
1076 | ||
1077 | xform->type = RTE_CRYPTO_SYM_XFORM_AUTH; | |
1078 | ||
1079 | auth_xform->algo = vec->auth.algo; | |
1080 | auth_xform->op = (dir == self_test_dir_enc_auth_gen) ? | |
1081 | RTE_CRYPTO_AUTH_OP_GENERATE : | |
1082 | RTE_CRYPTO_AUTH_OP_VERIFY; | |
1083 | auth_xform->digest_length = vec->digest.len; | |
1084 | auth_xform->key.data = key; | |
1085 | auth_xform->key.length = vec->key.len; | |
1086 | ||
1087 | cap_idx.algo.auth = auth_xform->algo; | |
1088 | cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; | |
1089 | ||
1090 | cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx); | |
1091 | if (!cap) { | |
1092 | RTE_LOG(ERR, PMD, "Failed to get capability for cdev %u\n", | |
1093 | dev_id); | |
1094 | return -EACCES; | |
1095 | } | |
1096 | ||
1097 | if (rte_cryptodev_sym_capability_check_auth(cap, | |
1098 | auth_xform->key.length, | |
1099 | auth_xform->digest_length, 0) != 0) { | |
1100 | RTE_LOG(ERR, PMD, "PMD %s key length %u Digest length %u\n", | |
1101 | rte_cryptodev_name_get(dev_id), | |
1102 | auth_xform->key.length, | |
1103 | auth_xform->digest_length); | |
1104 | return -EACCES; | |
1105 | } | |
1106 | ||
1107 | return 0; | |
1108 | } | |
1109 | ||
1110 | static int | |
1111 | prepare_aead_xform(uint8_t dev_id, | |
1112 | struct rte_crypto_sym_xform *xform, | |
1113 | struct fips_dev_self_test_vector *vec, | |
1114 | uint32_t dir, | |
1115 | uint8_t *key, | |
1116 | uint32_t neg_test) | |
1117 | { | |
1118 | const struct rte_cryptodev_symmetric_capability *cap; | |
1119 | struct rte_cryptodev_sym_capability_idx cap_idx; | |
1120 | struct rte_crypto_aead_xform *aead_xform = &xform->aead; | |
1121 | ||
1122 | memset(xform, 0, sizeof(*xform)); | |
1123 | ||
1124 | /** negative test, key is xored */ | |
1125 | if (neg_test) { | |
1126 | uint32_t i; | |
1127 | ||
1128 | for (i = 0; i < vec->key.len; i++) | |
1129 | key[i] ^= vec->key.data[i]; | |
1130 | } else | |
1131 | memcpy(key, vec->key.data, vec->key.len); | |
1132 | ||
1133 | xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; | |
1134 | ||
1135 | aead_xform->algo = vec->aead.algo; | |
1136 | aead_xform->op = (dir == self_test_dir_enc_auth_gen) ? | |
1137 | RTE_CRYPTO_AEAD_OP_ENCRYPT : | |
1138 | RTE_CRYPTO_AEAD_OP_DECRYPT; | |
1139 | aead_xform->aad_length = vec->aead.aad.len; | |
1140 | aead_xform->digest_length = vec->digest.len; | |
1141 | aead_xform->iv.offset = IV_OFF; | |
1142 | aead_xform->iv.length = vec->iv.len; | |
1143 | aead_xform->key.data = key; | |
1144 | aead_xform->key.length = vec->key.len; | |
1145 | ||
1146 | cap_idx.algo.aead = aead_xform->algo; | |
1147 | cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; | |
1148 | ||
1149 | cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx); | |
1150 | if (!cap) { | |
1151 | RTE_LOG(ERR, PMD, "Failed to get capability for cdev %u\n", | |
1152 | dev_id); | |
1153 | return -EACCES; | |
1154 | } | |
1155 | ||
1156 | if (rte_cryptodev_sym_capability_check_aead(cap, | |
1157 | aead_xform->key.length, | |
1158 | aead_xform->digest_length, aead_xform->aad_length, | |
1159 | aead_xform->iv.length) != 0) { | |
1160 | RTE_LOG(ERR, PMD, | |
1161 | "PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n", | |
1162 | rte_cryptodev_name_get(dev_id), | |
1163 | aead_xform->key.length, | |
1164 | aead_xform->digest_length, | |
1165 | aead_xform->aad_length, | |
1166 | aead_xform->iv.length); | |
1167 | return -EACCES; | |
1168 | } | |
1169 | ||
1170 | return 0; | |
1171 | } | |
1172 | ||
1173 | static int | |
1174 | prepare_cipher_op(struct rte_crypto_op *op, | |
1175 | struct rte_mbuf *mbuf, | |
1176 | struct rte_cryptodev_sym_session *session, | |
1177 | uint32_t dir, | |
1178 | struct fips_dev_self_test_vector *vec) | |
1179 | { | |
1180 | struct rte_crypto_sym_op *sym = op->sym; | |
1181 | uint8_t *iv = rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFF); | |
1182 | uint8_t *dst; | |
1183 | const uint8_t *src; | |
1184 | uint32_t len; | |
1185 | ||
1186 | if (dir == self_test_dir_enc_auth_gen) { | |
1187 | src = vec->input.data; | |
1188 | len = vec->input.len; | |
1189 | } else { | |
1190 | src = vec->output.data; | |
1191 | len = vec->output.len; | |
1192 | } | |
1193 | ||
1194 | sym->cipher.data.offset = 0; | |
1195 | memcpy(iv, vec->iv.data, vec->iv.len); | |
1196 | ||
1197 | dst = (uint8_t *)rte_pktmbuf_append(mbuf, len); | |
1198 | if (!dst) { | |
1199 | RTE_LOG(ERR, PMD, "Error %i: MBUF too small\n", -ENOMEM); | |
1200 | return -ENOMEM; | |
1201 | } | |
1202 | ||
1203 | memcpy(dst, src, len); | |
1204 | ||
1205 | sym->cipher.data.length = len; | |
1206 | ||
1207 | rte_crypto_op_attach_sym_session(op, session); | |
1208 | ||
1209 | return 0; | |
1210 | } | |
1211 | ||
1212 | static int | |
1213 | prepare_auth_op(struct rte_crypto_op *op, | |
1214 | struct rte_mbuf *mbuf, | |
1215 | struct rte_cryptodev_sym_session *session, | |
1216 | uint32_t dir, | |
1217 | struct fips_dev_self_test_vector *vec) | |
1218 | { | |
1219 | struct rte_crypto_sym_op *sym = op->sym; | |
1220 | uint8_t *dst; | |
1221 | ||
1222 | if (vec->input.len + vec->digest.len > RTE_MBUF_MAX_NB_SEGS) { | |
1223 | RTE_LOG(ERR, PMD, "Error %i: Test data too long (%u).\n", | |
1224 | -ENOMEM, vec->input.len + vec->digest.len); | |
1225 | return -ENOMEM; | |
1226 | } | |
1227 | ||
1228 | sym->auth.data.offset = 0; | |
1229 | ||
1230 | dst = (uint8_t *)rte_pktmbuf_append(mbuf, vec->input.len + | |
1231 | vec->digest.len); | |
1232 | if (!dst) { | |
1233 | RTE_LOG(ERR, PMD, "Error %i: MBUF too small\n", -ENOMEM); | |
1234 | return -ENOMEM; | |
1235 | } | |
1236 | ||
1237 | memcpy(dst, vec->input.data, vec->input.len); | |
1238 | sym->auth.data.length = vec->input.len; | |
1239 | sym->auth.digest.data = dst + vec->input.len; | |
1240 | sym->auth.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf, | |
1241 | vec->input.len); | |
1242 | ||
1243 | if (dir == self_test_dir_dec_auth_verify) | |
1244 | memcpy(dst + vec->input.len, vec->digest.data, vec->digest.len); | |
1245 | ||
1246 | rte_crypto_op_attach_sym_session(op, session); | |
1247 | ||
1248 | return 0; | |
1249 | } | |
1250 | ||
1251 | static int | |
1252 | prepare_aead_op(struct rte_crypto_op *op, | |
1253 | struct rte_mbuf *mbuf, | |
1254 | struct rte_cryptodev_sym_session *session, | |
1255 | uint32_t dir, | |
1256 | struct fips_dev_self_test_vector *vec) | |
1257 | { | |
1258 | struct rte_crypto_sym_op *sym = op->sym; | |
1259 | uint8_t *iv = rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFF); | |
1260 | uint8_t *dst; | |
1261 | const uint8_t *src; | |
1262 | uint32_t len; | |
1263 | ||
1264 | if (dir == self_test_dir_enc_auth_gen) { | |
1265 | len = vec->input.len; | |
1266 | src = vec->input.data; | |
1267 | } else { | |
1268 | len = vec->output.len; | |
1269 | src = vec->output.data; | |
1270 | } | |
1271 | ||
1272 | if (vec->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) | |
1273 | memcpy(iv + 1, vec->iv.data, vec->iv.len); | |
1274 | else | |
1275 | memcpy(iv, vec->iv.data, vec->iv.len); | |
1276 | ||
1277 | if (len + vec->digest.len > RTE_MBUF_MAX_NB_SEGS) { | |
1278 | RTE_LOG(ERR, PMD, "Error %i: Test data too long (%u).\n", | |
1279 | -ENOMEM, len + vec->digest.len); | |
1280 | return -ENOMEM; | |
1281 | } | |
1282 | ||
1283 | dst = (uint8_t *)rte_pktmbuf_append(mbuf, RTE_ALIGN_CEIL(len + | |
1284 | vec->digest.len, 16)); | |
1285 | if (!dst) { | |
1286 | RTE_LOG(ERR, PMD, "Error %i: MBUF too small\n", -ENOMEM); | |
1287 | return -ENOMEM; | |
1288 | } | |
1289 | ||
1290 | sym->m_src = mbuf; | |
1291 | sym->aead.data.length = len; | |
1292 | sym->aead.data.offset = 0; | |
1293 | memcpy(dst, src, len); | |
1294 | ||
1295 | sym->aead.digest.data = dst + vec->input.len; | |
1296 | sym->aead.digest.phys_addr = rte_pktmbuf_iova_offset(mbuf, | |
1297 | vec->input.len); | |
1298 | if (dir == self_test_dir_dec_auth_verify) | |
1299 | memcpy(sym->aead.digest.data, vec->digest.data, vec->digest.len); | |
1300 | ||
1301 | len = (vec->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) ? | |
1302 | (vec->aead.aad.len + AES_CCM_AAD_PAD_SIZE) : | |
1303 | vec->aead.aad.len; | |
1304 | ||
1305 | dst = rte_malloc(NULL, len, 16); | |
1306 | if (!dst) { | |
1307 | RTE_LOG(ERR, PMD, "Error %i: Not enough memory\n", -ENOMEM); | |
1308 | return -ENOMEM; | |
1309 | } | |
1310 | ||
1311 | sym->aead.aad.data = dst; | |
1312 | sym->aead.aad.phys_addr = rte_malloc_virt2iova(dst); | |
1313 | if (vec->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) | |
1314 | memcpy(dst, vec->aead.aad.data, | |
1315 | vec->aead.aad.len + AES_CCM_AAD_PAD_SIZE); | |
1316 | else | |
1317 | memcpy(dst, vec->aead.aad.data, | |
1318 | vec->aead.aad.len); | |
1319 | ||
1320 | rte_crypto_op_attach_sym_session(op, session); | |
1321 | ||
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | static int | |
1326 | check_cipher_result(struct rte_crypto_op *op, | |
1327 | struct fips_dev_self_test_vector *vec, | |
1328 | uint32_t dir) | |
1329 | { | |
1330 | struct rte_mbuf *mbuf = op->sym->m_src; | |
1331 | uint8_t *data; | |
1332 | const uint8_t *src; | |
1333 | uint32_t len, src_len; | |
1334 | int ret; | |
1335 | ||
f67539c2 TL |
1336 | if (!mbuf) |
1337 | return -1; | |
1338 | ||
9f95a23c TL |
1339 | if (dir == self_test_dir_enc_auth_gen) { |
1340 | src = vec->output.data; | |
1341 | src_len = vec->output.len; | |
1342 | } else { | |
1343 | src = vec->input.data; | |
1344 | src_len = vec->input.len; | |
1345 | } | |
1346 | ||
1347 | GET_MBUF_DATA(data, len, mbuf); | |
f67539c2 | 1348 | if (!len) |
9f95a23c TL |
1349 | return -1; |
1350 | ||
1351 | ret = memcmp(data, src, src_len); | |
1352 | if (ret != 0) | |
1353 | return -1; | |
1354 | ||
1355 | return 0; | |
1356 | } | |
1357 | ||
1358 | static int | |
1359 | check_auth_result(struct rte_crypto_op *op, | |
1360 | struct fips_dev_self_test_vector *vec, | |
1361 | uint32_t dir) | |
1362 | { | |
1363 | struct rte_mbuf *mbuf = op->sym->m_src; | |
1364 | uint8_t *data; | |
1365 | uint32_t len; | |
1366 | int ret; | |
1367 | ||
f67539c2 TL |
1368 | if (mbuf == NULL) |
1369 | return -1; | |
1370 | ||
9f95a23c | 1371 | GET_MBUF_DATA(data, len, mbuf); |
f67539c2 | 1372 | if (!len) |
9f95a23c TL |
1373 | return -1; |
1374 | ||
1375 | if (dir == self_test_dir_enc_auth_gen) { | |
1376 | data += vec->input.len; | |
1377 | ret = memcmp(data, vec->digest.data, vec->digest.len); | |
1378 | if (ret != 0) | |
1379 | return -1; | |
1380 | } | |
1381 | ||
1382 | return 0; | |
1383 | } | |
1384 | ||
1385 | static int | |
1386 | check_aead_result(struct rte_crypto_op *op, | |
1387 | struct fips_dev_self_test_vector *vec, | |
1388 | uint32_t dir) | |
1389 | { | |
1390 | struct rte_mbuf *mbuf = op->sym->m_src; | |
1391 | uint8_t *data; | |
1392 | const uint8_t *src; | |
1393 | uint32_t len, src_len; | |
1394 | int ret; | |
1395 | ||
f67539c2 TL |
1396 | if (!mbuf) |
1397 | return -1; | |
1398 | ||
9f95a23c TL |
1399 | if (op->sym->aead.aad.data) |
1400 | rte_free(op->sym->aead.aad.data); | |
1401 | ||
1402 | if (dir == self_test_dir_enc_auth_gen) { | |
1403 | src = vec->output.data; | |
1404 | src_len = vec->output.len; | |
1405 | } else { | |
1406 | src = vec->input.data; | |
1407 | src_len = vec->input.len; | |
1408 | } | |
1409 | ||
1410 | GET_MBUF_DATA(data, len, mbuf); | |
f67539c2 | 1411 | if (!len) |
9f95a23c TL |
1412 | return -1; |
1413 | ||
1414 | ret = memcmp(data, src, src_len); | |
1415 | if (ret != 0) | |
1416 | return -1; | |
1417 | ||
1418 | if (dir == self_test_dir_enc_auth_gen) { | |
1419 | data += src_len; | |
1420 | ret = memcmp(data, vec->digest.data, vec->digest.len); | |
1421 | if (ret != 0) | |
1422 | return -1; | |
1423 | } | |
1424 | ||
1425 | return 0; | |
1426 | } | |
1427 | ||
1428 | static void | |
1429 | init_test_op(struct fips_dev_self_test_ops *test_ops, | |
1430 | struct fips_dev_self_test_vector *vec) | |
1431 | { | |
1432 | if (test_ops->last_operation_type == vec->operation_type) | |
1433 | return; | |
1434 | ||
1435 | switch (vec->operation_type) { | |
1436 | case RTE_CRYPTO_SYM_XFORM_CIPHER: | |
1437 | test_ops->prepare_xform = prepare_cipher_xform; | |
1438 | test_ops->prepare_op = prepare_cipher_op; | |
1439 | test_ops->check_result = check_cipher_result; | |
1440 | break; | |
1441 | case RTE_CRYPTO_SYM_XFORM_AUTH: | |
1442 | test_ops->prepare_xform = prepare_auth_xform; | |
1443 | test_ops->prepare_op = prepare_auth_op; | |
1444 | test_ops->check_result = check_auth_result; | |
1445 | break; | |
1446 | case RTE_CRYPTO_SYM_XFORM_AEAD: | |
1447 | test_ops->prepare_xform = prepare_aead_xform; | |
1448 | test_ops->prepare_op = prepare_aead_op; | |
1449 | test_ops->check_result = check_aead_result; | |
1450 | break; | |
1451 | default: | |
1452 | break; | |
1453 | } | |
1454 | ||
1455 | test_ops->last_operation_type = vec->operation_type; | |
1456 | } | |
1457 | ||
1458 | static int | |
1459 | run_single_test(uint8_t dev_id, | |
1460 | struct fips_dev_self_test_vector *vec, | |
1461 | const struct fips_dev_self_test_ops *test_ops, | |
1462 | struct fips_dev_auto_test_env *env, | |
1463 | uint32_t dir, | |
1464 | uint32_t negative_test) | |
1465 | { | |
1466 | struct rte_crypto_sym_xform xform; | |
1467 | struct rte_cryptodev_sym_session *sess; | |
1468 | uint16_t n_deqd; | |
1469 | uint8_t key[256]; | |
1470 | int ret; | |
1471 | ||
1472 | __rte_crypto_op_reset(env->op, RTE_CRYPTO_OP_TYPE_SYMMETRIC); | |
1473 | rte_pktmbuf_reset(env->mbuf); | |
1474 | env->op->sym->m_src = env->mbuf; | |
1475 | ||
1476 | ret = test_ops->prepare_xform(dev_id, &xform, vec, dir, key, | |
1477 | negative_test); | |
1478 | if (ret < 0) { | |
1479 | RTE_LOG(ERR, PMD, "Error %i: Prepare Xform\n", ret); | |
1480 | return ret; | |
1481 | } | |
1482 | ||
1483 | sess = rte_cryptodev_sym_session_create(env->sess_pool); | |
1484 | if (!sess) | |
1485 | return -ENOMEM; | |
1486 | ||
1487 | ret = rte_cryptodev_sym_session_init(dev_id, | |
1488 | sess, &xform, env->sess_priv_pool); | |
1489 | if (ret < 0) { | |
1490 | RTE_LOG(ERR, PMD, "Error %i: Init session\n", ret); | |
1491 | return ret; | |
1492 | } | |
1493 | ||
1494 | ret = test_ops->prepare_op(env->op, env->mbuf, sess, dir, vec); | |
1495 | if (ret < 0) { | |
1496 | RTE_LOG(ERR, PMD, "Error %i: Prepare op\n", ret); | |
1497 | return ret; | |
1498 | } | |
1499 | ||
1500 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &env->op, 1) < 1) { | |
1501 | RTE_LOG(ERR, PMD, "Error: Failed enqueue\n"); | |
1502 | return ret; | |
1503 | } | |
1504 | ||
1505 | do { | |
1506 | struct rte_crypto_op *deqd_op; | |
1507 | ||
1508 | n_deqd = rte_cryptodev_dequeue_burst(dev_id, 0, &deqd_op, | |
1509 | 1); | |
1510 | } while (n_deqd == 0); | |
1511 | ||
1512 | rte_cryptodev_sym_session_clear(dev_id, sess); | |
1513 | rte_cryptodev_sym_session_free(sess); | |
1514 | ||
1515 | if (env->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) | |
1516 | return -1; | |
1517 | ||
1518 | return test_ops->check_result(env->op, vec, dir); | |
1519 | } | |
1520 | ||
1521 | ||
1522 | static void | |
1523 | fips_dev_auto_test_uninit(uint8_t dev_id, | |
1524 | struct fips_dev_auto_test_env *env) | |
1525 | { | |
1526 | struct rte_cryptodev *dev = rte_cryptodev_pmd_get_dev(dev_id); | |
1527 | uint32_t i; | |
1528 | ||
1529 | if (!dev) | |
1530 | return; | |
1531 | ||
1532 | if (env->mbuf) | |
1533 | rte_pktmbuf_free(env->mbuf); | |
1534 | if (env->op) | |
1535 | rte_crypto_op_free(env->op); | |
1536 | if (env->mpool) | |
1537 | rte_mempool_free(env->mpool); | |
1538 | if (env->op_pool) | |
1539 | rte_mempool_free(env->op_pool); | |
1540 | if (env->sess_pool) | |
1541 | rte_mempool_free(env->sess_pool); | |
1542 | if (env->sess_priv_pool) | |
1543 | rte_mempool_free(env->sess_priv_pool); | |
1544 | ||
1545 | if (dev->data->dev_started) | |
1546 | rte_cryptodev_stop(dev_id); | |
1547 | ||
1548 | if (dev->data->nb_queue_pairs) { | |
1549 | for (i = 0; i < dev->data->nb_queue_pairs; i++) | |
1550 | (*dev->dev_ops->queue_pair_release)(dev, i); | |
1551 | dev->data->nb_queue_pairs = 0; | |
1552 | rte_free(dev->data->queue_pairs); | |
1553 | dev->data->queue_pairs = NULL; | |
1554 | } | |
1555 | } | |
1556 | ||
1557 | static int | |
1558 | fips_dev_auto_test_init(uint8_t dev_id, struct fips_dev_auto_test_env *env) | |
1559 | { | |
9f95a23c TL |
1560 | struct rte_cryptodev_qp_conf qp_conf = {128, NULL, NULL}; |
1561 | uint32_t sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id); | |
f67539c2 | 1562 | struct rte_cryptodev_config conf; |
9f95a23c TL |
1563 | char name[128]; |
1564 | int ret; | |
1565 | ||
f67539c2 TL |
1566 | conf.socket_id = rte_cryptodev_socket_id(dev_id); |
1567 | conf.nb_queue_pairs = 1; | |
1568 | conf.ff_disable = 0; | |
1569 | ||
9f95a23c TL |
1570 | ret = rte_cryptodev_configure(dev_id, &conf); |
1571 | if (ret < 0) | |
1572 | return ret; | |
1573 | ||
1574 | memset(name, 0, 128); | |
1575 | snprintf(name, 128, "%s%u", "SELF_TEST_MEMPOOL", dev_id); | |
1576 | ||
1577 | memset(env, 0, sizeof(*env)); | |
1578 | ||
1579 | env->mpool = rte_pktmbuf_pool_create(name, 128, 0, 0, | |
1580 | UINT16_MAX, rte_cryptodev_socket_id(dev_id)); | |
1581 | if (!env->mpool) { | |
1582 | ret = -ENOMEM; | |
1583 | goto error_exit; | |
1584 | } | |
1585 | ||
1586 | memset(name, 0, 128); | |
1587 | snprintf(name, 128, "%s%u", "SELF_TEST_OP_POOL", dev_id); | |
1588 | ||
1589 | env->op_pool = rte_crypto_op_pool_create( | |
1590 | name, | |
1591 | RTE_CRYPTO_OP_TYPE_SYMMETRIC, | |
1592 | 16, 0, | |
1593 | 16, | |
1594 | rte_socket_id()); | |
1595 | if (!env->op_pool) { | |
1596 | ret = -ENOMEM; | |
1597 | goto error_exit; | |
1598 | } | |
1599 | ||
1600 | memset(name, 0, 128); | |
1601 | snprintf(name, 128, "%s%u", "SELF_TEST_SESS_POOL", dev_id); | |
1602 | ||
1603 | env->sess_pool = rte_cryptodev_sym_session_pool_create(name, | |
1604 | 128, 0, 0, 0, rte_cryptodev_socket_id(dev_id)); | |
1605 | if (!env->sess_pool) { | |
1606 | ret = -ENOMEM; | |
1607 | goto error_exit; | |
1608 | } | |
1609 | ||
1610 | memset(name, 0, 128); | |
1611 | snprintf(name, 128, "%s%u", "SELF_TEST_SESS_PRIV_POOL", dev_id); | |
1612 | ||
1613 | env->sess_priv_pool = rte_mempool_create(name, | |
1614 | 128, sess_sz, 0, 0, NULL, NULL, NULL, | |
1615 | NULL, rte_cryptodev_socket_id(dev_id), 0); | |
1616 | if (!env->sess_priv_pool) { | |
1617 | ret = -ENOMEM; | |
1618 | goto error_exit; | |
1619 | } | |
1620 | ||
1621 | qp_conf.mp_session = env->sess_pool; | |
1622 | qp_conf.mp_session_private = env->sess_priv_pool; | |
1623 | ||
1624 | ret = rte_cryptodev_queue_pair_setup(dev_id, 0, &qp_conf, | |
1625 | rte_cryptodev_socket_id(dev_id)); | |
1626 | if (ret < 0) | |
1627 | goto error_exit; | |
1628 | ||
1629 | env->mbuf = rte_pktmbuf_alloc(env->mpool); | |
1630 | if (!env->mbuf) { | |
1631 | ret = -ENOMEM; | |
1632 | goto error_exit; | |
1633 | } | |
1634 | ||
1635 | env->op = rte_crypto_op_alloc(env->op_pool, | |
1636 | RTE_CRYPTO_OP_TYPE_SYMMETRIC); | |
1637 | if (!env->op) { | |
1638 | ret = -ENOMEM; | |
1639 | goto error_exit; | |
1640 | } | |
1641 | ||
1642 | ret = rte_cryptodev_start(dev_id); | |
1643 | if (ret < 0) | |
1644 | goto error_exit; | |
1645 | ||
1646 | ||
1647 | return 0; | |
1648 | ||
1649 | error_exit: | |
1650 | ||
1651 | fips_dev_auto_test_uninit(dev_id, env); | |
1652 | ||
1653 | return ret; | |
1654 | } | |
1655 | ||
1656 | int | |
1657 | fips_dev_self_test(uint8_t dev_id, | |
1658 | struct fips_dev_broken_test_config *config) | |
1659 | { | |
1660 | struct fips_dev_self_test_ops test_ops = {0}; | |
1661 | struct fips_dev_auto_test_env env; | |
1662 | uint32_t i, j, negative_test; | |
1663 | int ret; | |
1664 | ||
1665 | ret = fips_dev_auto_test_init(dev_id, &env); | |
1666 | if (ret < 0) { | |
1667 | RTE_LOG(ERR, PMD, "Failed to init self-test for PMD %u\n", | |
1668 | dev_id); | |
1669 | return ret; | |
1670 | } | |
1671 | ||
1672 | for (i = 0; i < RTE_DIM(self_test_vectors); i++) { | |
1673 | struct fips_dev_self_test_vector *vec = | |
1674 | self_test_vectors[i]; | |
1675 | ||
1676 | init_test_op(&test_ops, vec); | |
1677 | ||
1678 | for (j = 0; j < self_test_dir_max; j++) { | |
1679 | if (!config) | |
1680 | negative_test = 0; | |
1681 | else { | |
1682 | if ((config->expect_fail_test_idx == i) && | |
1683 | (config->expect_fail_dir == j)) | |
1684 | negative_test = 1; | |
1685 | else | |
1686 | negative_test = 0; | |
1687 | } | |
1688 | ||
1689 | RTE_LOG(INFO, PMD, "Testing (ID %u) %s %s%s...\n", | |
1690 | i, | |
1691 | vec->name, | |
1692 | j == self_test_dir_enc_auth_gen ? | |
1693 | "Encrypt" : "Decrypt", | |
1694 | negative_test ? " (Expect Fail)" : ""); | |
1695 | ||
1696 | ret = run_single_test(dev_id, vec, &test_ops, | |
1697 | &env, j, negative_test); | |
1698 | switch (ret) { | |
1699 | case 0: | |
1700 | if (!negative_test) | |
1701 | break; | |
1702 | ret = -1; | |
1703 | RTE_LOG(ERR, PMD, "PMD %u Failed test %s %s\n", | |
1704 | dev_id, vec->name, | |
1705 | j == self_test_dir_enc_auth_gen ? | |
1706 | "Encrypt" : "Decrypt"); | |
1707 | goto error_exit; | |
1708 | case -EACCES: | |
1709 | RTE_LOG(ERR, PMD, "Not supported by %s. Skip\n", | |
1710 | rte_cryptodev_name_get(dev_id)); | |
1711 | ret = 0; | |
1712 | break; | |
1713 | default: | |
1714 | RTE_LOG(ERR, PMD, "PMD %u Failed test %s %s\n", | |
1715 | dev_id, vec->name, | |
1716 | j == self_test_dir_enc_auth_gen ? | |
1717 | "Encrypt" : "Decrypt"); | |
1718 | goto error_exit; | |
1719 | } | |
1720 | } | |
1721 | } | |
1722 | ||
1723 | error_exit: | |
1724 | fips_dev_auto_test_uninit(dev_id, &env); | |
1725 | ||
1726 | if (ret == 0) { | |
1727 | RTE_LOG(INFO, PMD, "PMD %u finished self-test successfully\n", | |
1728 | dev_id); | |
1729 | } | |
1730 | ||
1731 | return ret; | |
1732 | } |