Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2016-2020 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _RTE_CRYPTO_SYM_H_
6 : : #define _RTE_CRYPTO_SYM_H_
7 : :
8 : : /**
9 : : * @file rte_crypto_sym.h
10 : : *
11 : : * RTE Definitions for Symmetric Cryptography
12 : : *
13 : : * Defines symmetric cipher and authentication algorithms and modes, as well
14 : : * as supported symmetric crypto operation combinations.
15 : : */
16 : :
17 : : #ifdef __cplusplus
18 : : extern "C" {
19 : : #endif
20 : :
21 : : #include <string.h>
22 : :
23 : : #include <rte_compat.h>
24 : : #include <rte_mbuf.h>
25 : : #include <rte_memory.h>
26 : : #include <rte_mempool.h>
27 : : #include <rte_common.h>
28 : :
29 : : /**
30 : : * Crypto IO Vector (in analogy with struct iovec)
31 : : * Supposed be used to pass input/output data buffers for crypto data-path
32 : : * functions.
33 : : */
34 : : struct rte_crypto_vec {
35 : : /** virtual address of the data buffer */
36 : : void *base;
37 : : /** IOVA of the data buffer */
38 : : rte_iova_t iova;
39 : : /** length of the data buffer */
40 : : uint32_t len;
41 : : /** total buffer length */
42 : : uint32_t tot_len;
43 : : };
44 : :
45 : : /**
46 : : * Crypto scatter-gather list descriptor. Consists of a pointer to an array
47 : : * of Crypto IO vectors with its size.
48 : : */
49 : : struct rte_crypto_sgl {
50 : : /** start of an array of vectors */
51 : : struct rte_crypto_vec *vec;
52 : : /** size of an array of vectors */
53 : : uint32_t num;
54 : : };
55 : :
56 : : /**
57 : : * Crypto virtual and IOVA address descriptor, used to describe cryptographic
58 : : * data buffer without the length information. The length information is
59 : : * normally predefined during session creation.
60 : : */
61 : : struct rte_crypto_va_iova_ptr {
62 : : void *va;
63 : : rte_iova_t iova;
64 : : };
65 : :
66 : : /**
67 : : * Raw data operation descriptor.
68 : : * Supposed to be used with synchronous CPU crypto API call or asynchronous
69 : : * RAW data path API call.
70 : : */
71 : : struct rte_crypto_sym_vec {
72 : : /** number of operations to perform */
73 : : uint32_t num;
74 : : /** array of SGL vectors */
75 : : struct rte_crypto_sgl *src_sgl;
76 : : /** array of SGL vectors for OOP, keep it NULL for inplace*/
77 : : struct rte_crypto_sgl *dest_sgl;
78 : : /** array of pointers to cipher IV */
79 : : struct rte_crypto_va_iova_ptr *iv;
80 : : /** array of pointers to digest */
81 : : struct rte_crypto_va_iova_ptr *digest;
82 : :
83 : : __extension__
84 : : union {
85 : : /** array of pointers to auth IV, used for chain operation */
86 : : struct rte_crypto_va_iova_ptr *auth_iv;
87 : : /** array of pointers to AAD, used for AEAD operation */
88 : : struct rte_crypto_va_iova_ptr *aad;
89 : : };
90 : :
91 : : /**
92 : : * array of statuses for each operation:
93 : : * - 0 on success
94 : : * - errno on error
95 : : */
96 : : int32_t *status;
97 : : };
98 : :
99 : : /**
100 : : * used for cpu_crypto_process_bulk() to specify head/tail offsets
101 : : * for auth/cipher processing.
102 : : */
103 : : union rte_crypto_sym_ofs {
104 : : uint64_t raw;
105 : : struct {
106 : : struct {
107 : : uint16_t head;
108 : : uint16_t tail;
109 : : } auth, cipher;
110 : : } ofs;
111 : : };
112 : :
113 : : /** Symmetric Cipher Algorithms
114 : : *
115 : : * Note, to avoid ABI breakage across releases
116 : : * - LIST_END should not be added to this enum
117 : : * - the order of enums should not be changed
118 : : * - new algorithms should only be added to the end
119 : : */
120 : : enum rte_crypto_cipher_algorithm {
121 : : RTE_CRYPTO_CIPHER_NULL = 1,
122 : : /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
123 : :
124 : : RTE_CRYPTO_CIPHER_3DES_CBC,
125 : : /**< Triple DES algorithm in CBC mode */
126 : : RTE_CRYPTO_CIPHER_3DES_CTR,
127 : : /**< Triple DES algorithm in CTR mode */
128 : : RTE_CRYPTO_CIPHER_3DES_ECB,
129 : : /**< Triple DES algorithm in ECB mode */
130 : :
131 : : RTE_CRYPTO_CIPHER_AES_CBC,
132 : : /**< AES algorithm in CBC mode */
133 : : RTE_CRYPTO_CIPHER_AES_CTR,
134 : : /**< AES algorithm in Counter mode */
135 : : RTE_CRYPTO_CIPHER_AES_ECB,
136 : : /**< AES algorithm in ECB mode */
137 : : RTE_CRYPTO_CIPHER_AES_F8,
138 : : /**< AES algorithm in F8 mode */
139 : : RTE_CRYPTO_CIPHER_AES_XTS,
140 : : /**< AES algorithm in XTS mode */
141 : :
142 : : RTE_CRYPTO_CIPHER_ARC4,
143 : : /**< (A)RC4 cipher algorithm */
144 : :
145 : : RTE_CRYPTO_CIPHER_KASUMI_F8,
146 : : /**< KASUMI algorithm in F8 mode */
147 : :
148 : : RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
149 : : /**< SNOW 3G algorithm in UEA2 mode */
150 : :
151 : : RTE_CRYPTO_CIPHER_ZUC_EEA3,
152 : : /**< ZUC algorithm in EEA3 mode */
153 : :
154 : : RTE_CRYPTO_CIPHER_DES_CBC,
155 : : /**< DES algorithm in CBC mode */
156 : :
157 : : RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
158 : : /**< AES algorithm using modes required by
159 : : * DOCSIS Baseline Privacy Plus Spec.
160 : : * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
161 : : * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
162 : : */
163 : :
164 : : RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
165 : : /**< DES algorithm using modes required by
166 : : * DOCSIS Baseline Privacy Plus Spec.
167 : : * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
168 : : * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
169 : : */
170 : :
171 : : RTE_CRYPTO_CIPHER_SM4_ECB,
172 : : /**< ShangMi 4 (SM4) algorithm in ECB mode */
173 : : RTE_CRYPTO_CIPHER_SM4_CBC,
174 : : /**< ShangMi 4 (SM4) algorithm in CBC mode */
175 : : RTE_CRYPTO_CIPHER_SM4_CTR,
176 : : /**< ShangMi 4 (SM4) algorithm in CTR mode */
177 : : RTE_CRYPTO_CIPHER_SM4_OFB,
178 : : /**< ShangMi 4 (SM4) algorithm in OFB mode */
179 : : RTE_CRYPTO_CIPHER_SM4_CFB
180 : : /**< ShangMi 4 (SM4) algorithm in CFB mode */
181 : : };
182 : :
183 : : /** Symmetric Cipher Direction */
184 : : enum rte_crypto_cipher_operation {
185 : : RTE_CRYPTO_CIPHER_OP_ENCRYPT,
186 : : /**< Encrypt cipher operation */
187 : : RTE_CRYPTO_CIPHER_OP_DECRYPT
188 : : /**< Decrypt cipher operation */
189 : : };
190 : :
191 : : /** Cipher operation name strings */
192 : : extern const char *
193 : : rte_crypto_cipher_operation_strings[];
194 : :
195 : : /**
196 : : * Symmetric Cipher Setup Data.
197 : : *
198 : : * This structure contains data relating to Cipher (Encryption and Decryption)
199 : : * use to create a session.
200 : : */
201 : : struct rte_crypto_cipher_xform {
202 : : enum rte_crypto_cipher_operation op;
203 : : /**< This parameter determines if the cipher operation is an encrypt or
204 : : * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
205 : : * only encrypt operations are valid.
206 : : */
207 : : enum rte_crypto_cipher_algorithm algo;
208 : : /**< Cipher algorithm */
209 : :
210 : : struct {
211 : : const uint8_t *data; /**< pointer to key data */
212 : : uint16_t length; /**< key length in bytes */
213 : : } key;
214 : : /**< Cipher key
215 : : *
216 : : * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the
217 : : * original key data provided may be wrapped(encrypted) using key wrap
218 : : * algorithm such as AES key wrap (rfc3394) and hence length of the key
219 : : * may increase beyond the PMD advertised supported key size.
220 : : * PMD shall validate the key length and report EMSGSIZE error while
221 : : * configuring the session and application can skip checking the
222 : : * capability key length in such cases.
223 : : *
224 : : * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
225 : : * point to a concatenation of the AES encryption key followed by a
226 : : * keymask. As per RFC3711, the keymask should be padded with trailing
227 : : * bytes to match the length of the encryption key used.
228 : : *
229 : : * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
230 : : * 192 bits (24 bytes) or 256 bits (32 bytes).
231 : : *
232 : : * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
233 : : * should be set to the combined length of the encryption key and the
234 : : * keymask. Since the keymask and the encryption key are the same size,
235 : : * key.length should be set to 2 x the AES encryption key length.
236 : : *
237 : : * For the AES-XTS mode of operation:
238 : : * - Two keys must be provided and key.length refers to total length of
239 : : * the two keys.
240 : : * - key.data must point to the two keys concatenated together
241 : : * (key1 || key2).
242 : : * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
243 : : * - Both keys must have the same size.
244 : : */
245 : : struct {
246 : : uint16_t offset;
247 : : /**< Starting point for Initialisation Vector or Counter,
248 : : * specified as number of bytes from start of crypto
249 : : * operation (rte_crypto_op).
250 : : *
251 : : * - For block ciphers in CBC or F8 mode, or for KASUMI
252 : : * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
253 : : * Initialisation Vector (IV) value.
254 : : *
255 : : * - For block ciphers in CTR mode, this is the counter.
256 : : *
257 : : * - For CCM mode, the first byte is reserved, and the
258 : : * nonce should be written starting at &iv[1] (to allow
259 : : * space for the implementation to write in the flags
260 : : * in the first byte). Note that a full 16 bytes should
261 : : * be allocated, even though the length field will
262 : : * have a value less than this. Note that the PMDs may
263 : : * modify the memory reserved (the first byte and the
264 : : * final padding)
265 : : *
266 : : * - For AES-XTS, this is the 128bit tweak, i, from
267 : : * IEEE Std 1619-2007.
268 : : *
269 : : * For optimum performance, the data pointed to SHOULD
270 : : * be 8-byte aligned.
271 : : */
272 : : uint16_t length;
273 : : /**< Length of valid IV data.
274 : : *
275 : : * - For block ciphers in CBC or F8 mode, or for KASUMI
276 : : * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
277 : : * length of the IV (which must be the same as the
278 : : * block length of the cipher).
279 : : *
280 : : * - For block ciphers in CTR mode, this is the length
281 : : * of the counter (which must be the same as the block
282 : : * length of the cipher) or a 12-byte nonce (AES only)
283 : : *
284 : : * - For CCM mode, this is the length of the nonce,
285 : : * which can be in the range 7 to 13 inclusive.
286 : : */
287 : : } iv; /**< Initialisation vector parameters */
288 : :
289 : : uint32_t dataunit_len;
290 : : /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled,
291 : : * this is the data-unit length of the algorithm,
292 : : * otherwise or when the value is 0, use the operation length.
293 : : * The value should be in the range defined by the dataunit_set field
294 : : * in the cipher capability.
295 : : *
296 : : * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
297 : : * For-each data-unit in the operation, the tweak (IV) value is
298 : : * assigned consecutively starting from the operation assigned IV.
299 : : */
300 : : };
301 : :
302 : : /** Symmetric Authentication / Hash Algorithms
303 : : *
304 : : * Note, to avoid ABI breakage across releases
305 : : * - LIST_END should not be added to this enum
306 : : * - the order of enums should not be changed
307 : : * - new algorithms should only be added to the end
308 : : */
309 : : enum rte_crypto_auth_algorithm {
310 : : RTE_CRYPTO_AUTH_NULL = 1,
311 : : /**< NULL hash algorithm. */
312 : :
313 : : RTE_CRYPTO_AUTH_AES_CBC_MAC,
314 : : /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
315 : : RTE_CRYPTO_AUTH_AES_CMAC,
316 : : /**< AES CMAC algorithm. */
317 : : RTE_CRYPTO_AUTH_AES_GMAC,
318 : : /**< AES GMAC algorithm. */
319 : : RTE_CRYPTO_AUTH_AES_XCBC_MAC,
320 : : /**< AES XCBC algorithm. */
321 : :
322 : : RTE_CRYPTO_AUTH_KASUMI_F9,
323 : : /**< KASUMI algorithm in F9 mode. */
324 : :
325 : : RTE_CRYPTO_AUTH_MD5,
326 : : /**< MD5 algorithm */
327 : : RTE_CRYPTO_AUTH_MD5_HMAC,
328 : : /**< HMAC using MD5 algorithm */
329 : :
330 : : RTE_CRYPTO_AUTH_SHA1,
331 : : /**< 160 bit SHA algorithm. */
332 : : RTE_CRYPTO_AUTH_SHA1_HMAC,
333 : : /**< HMAC using 160 bit SHA algorithm.
334 : : * HMAC-SHA-1-96 can be generated by setting
335 : : * digest_length to 12 bytes in auth/aead xforms.
336 : : */
337 : : RTE_CRYPTO_AUTH_SHA224,
338 : : /**< 224 bit SHA algorithm. */
339 : : RTE_CRYPTO_AUTH_SHA224_HMAC,
340 : : /**< HMAC using 224 bit SHA algorithm. */
341 : : RTE_CRYPTO_AUTH_SHA256,
342 : : /**< 256 bit SHA algorithm. */
343 : : RTE_CRYPTO_AUTH_SHA256_HMAC,
344 : : /**< HMAC using 256 bit SHA algorithm. */
345 : : RTE_CRYPTO_AUTH_SHA384,
346 : : /**< 384 bit SHA algorithm. */
347 : : RTE_CRYPTO_AUTH_SHA384_HMAC,
348 : : /**< HMAC using 384 bit SHA algorithm. */
349 : : RTE_CRYPTO_AUTH_SHA512,
350 : : /**< 512 bit SHA algorithm. */
351 : : RTE_CRYPTO_AUTH_SHA512_HMAC,
352 : : /**< HMAC using 512 bit SHA algorithm. */
353 : :
354 : : RTE_CRYPTO_AUTH_SNOW3G_UIA2,
355 : : /**< SNOW 3G algorithm in UIA2 mode. */
356 : :
357 : : RTE_CRYPTO_AUTH_ZUC_EIA3,
358 : : /**< ZUC algorithm in EIA3 mode */
359 : :
360 : : RTE_CRYPTO_AUTH_SHA3_224,
361 : : /**< 224 bit SHA3 algorithm. */
362 : : RTE_CRYPTO_AUTH_SHA3_224_HMAC,
363 : : /**< HMAC using 224 bit SHA3 algorithm. */
364 : : RTE_CRYPTO_AUTH_SHA3_256,
365 : : /**< 256 bit SHA3 algorithm. */
366 : : RTE_CRYPTO_AUTH_SHA3_256_HMAC,
367 : : /**< HMAC using 256 bit SHA3 algorithm. */
368 : : RTE_CRYPTO_AUTH_SHA3_384,
369 : : /**< 384 bit SHA3 algorithm. */
370 : : RTE_CRYPTO_AUTH_SHA3_384_HMAC,
371 : : /**< HMAC using 384 bit SHA3 algorithm. */
372 : : RTE_CRYPTO_AUTH_SHA3_512,
373 : : /**< 512 bit SHA3 algorithm. */
374 : : RTE_CRYPTO_AUTH_SHA3_512_HMAC,
375 : : /**< HMAC using 512 bit SHA3 algorithm. */
376 : : RTE_CRYPTO_AUTH_SM3,
377 : : /**< ShangMi 3 (SM3) algorithm */
378 : :
379 : : RTE_CRYPTO_AUTH_SHAKE_128,
380 : : /**< 128 bit SHAKE algorithm. */
381 : : RTE_CRYPTO_AUTH_SHAKE_256,
382 : : /**< 256 bit SHAKE algorithm. */
383 : : RTE_CRYPTO_AUTH_SM3_HMAC,
384 : : /** < HMAC using ShangMi 3 (SM3) algorithm */
385 : : };
386 : :
387 : : /** Symmetric Authentication / Hash Operations */
388 : : enum rte_crypto_auth_operation {
389 : : RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
390 : : RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
391 : : };
392 : :
393 : : /** Authentication operation name strings */
394 : : extern const char *
395 : : rte_crypto_auth_operation_strings[];
396 : :
397 : : /**
398 : : * Authentication / Hash transform data.
399 : : *
400 : : * This structure contains data relating to an authentication/hash crypto
401 : : * transforms. The fields op, algo and digest_length are common to all
402 : : * authentication transforms and MUST be set.
403 : : */
404 : : struct rte_crypto_auth_xform {
405 : : enum rte_crypto_auth_operation op;
406 : : /**< Authentication operation type */
407 : : enum rte_crypto_auth_algorithm algo;
408 : : /**< Authentication algorithm selection */
409 : :
410 : : struct {
411 : : const uint8_t *data; /**< pointer to key data */
412 : : uint16_t length; /**< key length in bytes */
413 : : } key;
414 : : /**< Authentication key data.
415 : : * The authentication key length MUST be less than or equal to the
416 : : * block size of the algorithm. It is the callers responsibility to
417 : : * ensure that the key length is compliant with the standard being used
418 : : * (for example RFC 2104, FIPS 198a).
419 : : */
420 : :
421 : : struct {
422 : : uint16_t offset;
423 : : /**< Starting point for Initialisation Vector or Counter,
424 : : * specified as number of bytes from start of crypto
425 : : * operation (rte_crypto_op).
426 : : *
427 : : * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
428 : : * this is the authentication Initialisation Vector
429 : : * (IV) value. For AES-GMAC IV description please refer
430 : : * to the field `length` in iv struct.
431 : : *
432 : : * - For KASUMI in F9 mode and other authentication
433 : : * algorithms, this field is not used.
434 : : *
435 : : * For optimum performance, the data pointed to SHOULD
436 : : * be 8-byte aligned.
437 : : */
438 : : uint16_t length;
439 : : /**< Length of valid IV data.
440 : : *
441 : : * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
442 : : * for AES-GMAC, this is the length of the IV.
443 : : *
444 : : * - For KASUMI in F9 mode and other authentication
445 : : * algorithms, this field is not used.
446 : : *
447 : : * - For GMAC mode, this is either:
448 : : * 1) Number greater or equal to one, which means that IV
449 : : * is used and J0 will be computed internally, a minimum
450 : : * of 16 bytes must be allocated.
451 : : * 2) Zero, in which case data points to J0. In this case
452 : : * 16 bytes of J0 should be passed where J0 is defined
453 : : * by NIST SP800-38D.
454 : : *
455 : : */
456 : : } iv; /**< Initialisation vector parameters */
457 : :
458 : : uint16_t digest_length;
459 : : /**< Length of the digest to be returned. If the verify option is set,
460 : : * this specifies the length of the digest to be compared for the
461 : : * session.
462 : : *
463 : : * It is the caller's responsibility to ensure that the
464 : : * digest length is compliant with the hash algorithm being used.
465 : : * If the value is less than the maximum length allowed by the hash,
466 : : * the result shall be truncated.
467 : : */
468 : : };
469 : :
470 : :
471 : : /** Symmetric AEAD Algorithms
472 : : *
473 : : * Note, to avoid ABI breakage across releases
474 : : * - LIST_END should not be added to this enum
475 : : * - the order of enums should not be changed
476 : : * - new algorithms should only be added to the end
477 : : */
478 : : enum rte_crypto_aead_algorithm {
479 : : RTE_CRYPTO_AEAD_AES_CCM = 1,
480 : : /**< AES algorithm in CCM mode. */
481 : : RTE_CRYPTO_AEAD_AES_GCM,
482 : : /**< AES algorithm in GCM mode. */
483 : : RTE_CRYPTO_AEAD_CHACHA20_POLY1305
484 : : /**< Chacha20 cipher with poly1305 authenticator */
485 : : };
486 : :
487 : : /** Symmetric AEAD Operations */
488 : : enum rte_crypto_aead_operation {
489 : : RTE_CRYPTO_AEAD_OP_ENCRYPT,
490 : : /**< Encrypt and generate digest */
491 : : RTE_CRYPTO_AEAD_OP_DECRYPT
492 : : /**< Verify digest and decrypt */
493 : : };
494 : :
495 : : /** Authentication operation name strings */
496 : : extern const char *
497 : : rte_crypto_aead_operation_strings[];
498 : :
499 : : struct rte_crypto_aead_xform {
500 : : enum rte_crypto_aead_operation op;
501 : : /**< AEAD operation type */
502 : : enum rte_crypto_aead_algorithm algo;
503 : : /**< AEAD algorithm selection */
504 : :
505 : : struct {
506 : : const uint8_t *data; /**< pointer to key data */
507 : : uint16_t length; /**< key length in bytes */
508 : : } key;
509 : :
510 : : struct {
511 : : uint16_t offset;
512 : : /**< Starting point for Initialisation Vector or Counter,
513 : : * specified as number of bytes from start of crypto
514 : : * operation (rte_crypto_op).
515 : : *
516 : : * - For CCM mode, the first byte is reserved, and the
517 : : * nonce should be written starting at &iv[1] (to allow
518 : : * space for the implementation to write in the flags
519 : : * in the first byte). Note that a full 16 bytes should
520 : : * be allocated, even though the length field will
521 : : * have a value less than this.
522 : : *
523 : : * - For Chacha20-Poly1305 it is 96-bit nonce.
524 : : * PMD sets initial counter for Poly1305 key generation
525 : : * part to 0 and for Chacha20 encryption to 1 as per
526 : : * rfc8439 2.8. AEAD construction.
527 : : *
528 : : * For optimum performance, the data pointed to SHOULD
529 : : * be 8-byte aligned.
530 : : */
531 : : uint16_t length;
532 : : /**< Length of valid IV data.
533 : : *
534 : : * - For GCM mode, this is either:
535 : : * 1) Number greater or equal to one, which means that IV
536 : : * is used and J0 will be computed internally, a minimum
537 : : * of 16 bytes must be allocated.
538 : : * 2) Zero, in which case data points to J0. In this case
539 : : * 16 bytes of J0 should be passed where J0 is defined
540 : : * by NIST SP800-38D.
541 : : *
542 : : * - For CCM mode, this is the length of the nonce,
543 : : * which can be in the range 7 to 13 inclusive.
544 : : *
545 : : * - For Chacha20-Poly1305 this field is always 12.
546 : : */
547 : : } iv; /**< Initialisation vector parameters */
548 : :
549 : : uint16_t digest_length;
550 : :
551 : : uint16_t aad_length;
552 : : /**< The length of the additional authenticated data (AAD) in bytes.
553 : : * For CCM mode, this is the length of the actual AAD, even though
554 : : * it is required to reserve 18 bytes before the AAD and padding
555 : : * at the end of it, so a multiple of 16 bytes is allocated.
556 : : */
557 : : };
558 : :
559 : : /** Crypto transformation types */
560 : : enum rte_crypto_sym_xform_type {
561 : : RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
562 : : RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
563 : : RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */
564 : : RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */
565 : : };
566 : :
567 : : /**
568 : : * Symmetric crypto transform structure.
569 : : *
570 : : * This is used to specify the crypto transforms required, multiple transforms
571 : : * can be chained together to specify a chain transforms such as authentication
572 : : * then cipher, or cipher then authentication. Each transform structure can
573 : : * hold a single transform, the type field is used to specify which transform
574 : : * is contained within the union
575 : : */
576 : : /* Structure rte_crypto_sym_xform 8< */
577 : : struct rte_crypto_sym_xform {
578 : : struct rte_crypto_sym_xform *next;
579 : : /**< next xform in chain */
580 : : enum rte_crypto_sym_xform_type type
581 : : ; /**< xform type */
582 : : union {
583 : : struct rte_crypto_auth_xform auth;
584 : : /**< Authentication / hash xform */
585 : : struct rte_crypto_cipher_xform cipher;
586 : : /**< Cipher xform */
587 : : struct rte_crypto_aead_xform aead;
588 : : /**< AEAD xform */
589 : : };
590 : : };
591 : : /* >8 End of structure rte_crypto_sym_xform. */
592 : :
593 : : /**
594 : : * Symmetric Cryptographic Operation.
595 : : *
596 : : * This structure contains data relating to performing symmetric cryptographic
597 : : * processing on a referenced mbuf data buffer.
598 : : *
599 : : * When a symmetric crypto operation is enqueued with the device for processing
600 : : * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
601 : : * which contains the source data which the crypto operation is to be performed
602 : : * on.
603 : : * While the mbuf is in use by a crypto operation no part of the mbuf should be
604 : : * changed by the application as the device may read or write to any part of the
605 : : * mbuf. In the case of hardware crypto devices some or all of the mbuf
606 : : * may be DMAed in and out of the device, so writing over the original data,
607 : : * though only the part specified by the rte_crypto_sym_op for transformation
608 : : * will be changed.
609 : : * Out-of-place (OOP) operation, where the source mbuf is different to the
610 : : * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
611 : : * The part copied includes all the parts of the source mbuf that will be
612 : : * operated on, based on the cipher.data.offset+cipher.data.length and
613 : : * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
614 : : * indicated by the cipher parameters will be transformed, any extra data around
615 : : * this indicated by the auth parameters will be copied unchanged from source to
616 : : * destination mbuf.
617 : : * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
618 : : * both source and destination mbufs. As these offsets are relative to the
619 : : * data_off parameter in each mbuf this can result in the data written to the
620 : : * destination buffer being at a different alignment, relative to buffer start,
621 : : * to the data in the source buffer.
622 : : */
623 : : /* Structure rte_crypto_sym_op 8< */
624 : : struct rte_crypto_sym_op {
625 : : struct rte_mbuf *m_src; /**< source mbuf */
626 : : struct rte_mbuf *m_dst; /**< destination mbuf */
627 : :
628 : : union {
629 : : void *session;
630 : : /**< Handle for the initialised crypto/security session context */
631 : : struct rte_crypto_sym_xform *xform;
632 : : /**< Session-less API crypto operation parameters */
633 : : };
634 : :
635 : : union {
636 : : struct {
637 : : struct {
638 : : uint32_t offset;
639 : : /**< Starting point for AEAD processing, specified as
640 : : * number of bytes from start of packet in source
641 : : * buffer.
642 : : */
643 : : uint32_t length;
644 : : /**< The message length, in bytes, of the source buffer
645 : : * on which the cryptographic operation will be
646 : : * computed.
647 : : */
648 : : } data; /**< Data offsets and length for AEAD */
649 : : struct {
650 : : uint8_t *data;
651 : : /**< This points to the location where the digest result
652 : : * should be inserted (in the case of digest generation)
653 : : * or where the purported digest exists (in the case of
654 : : * digest verification).
655 : : *
656 : : * At session creation time, the client specified the
657 : : * digest result length with the digest_length member
658 : : * of the @ref rte_crypto_auth_xform structure. For
659 : : * physical crypto devices the caller must allocate at
660 : : * least digest_length of physically contiguous memory
661 : : * at this location.
662 : : *
663 : : * For digest generation, the digest result will
664 : : * overwrite any data at this location.
665 : : *
666 : : * @note
667 : : * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
668 : : * "digest result" read "authentication tag T".
669 : : */
670 : : rte_iova_t phys_addr;
671 : : /**< Physical address of digest */
672 : : } digest; /**< Digest parameters */
673 : : struct {
674 : : uint8_t *data;
675 : : /**< Pointer to Additional Authenticated Data (AAD)
676 : : * needed for authenticated cipher mechanisms (CCM and
677 : : * GCM)
678 : : *
679 : : * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
680 : : * the caller should setup this field as follows:
681 : : *
682 : : * - the additional authentication data itself should
683 : : * be written starting at an offset of 18 bytes into
684 : : * the array, leaving room for the first block (16 bytes)
685 : : * and the length encoding in the first two bytes of the
686 : : * second block.
687 : : *
688 : : * - Note that PMDs may modify the memory reserved
689 : : * (first 18 bytes and the final padding).
690 : : *
691 : : * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
692 : : * caller should setup this field as follows:
693 : : *
694 : : */
695 : : rte_iova_t phys_addr; /**< physical address */
696 : : } aad;
697 : : /**< Additional authentication parameters */
698 : : } aead;
699 : :
700 : : struct {
701 : : struct {
702 : : struct {
703 : : uint32_t offset;
704 : : /**< Starting point for cipher processing,
705 : : * specified as number of bytes from start
706 : : * of data in the source buffer.
707 : : * The result of the cipher operation will be
708 : : * written back into the output buffer
709 : : * starting at this location.
710 : : *
711 : : * @note
712 : : * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
713 : : * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
714 : : * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
715 : : * this field should be in bits. For
716 : : * digest-encrypted cases this must be
717 : : * an 8-bit multiple.
718 : : */
719 : : uint32_t length;
720 : : /**< The message length, in bytes, of the
721 : : * source buffer on which the cryptographic
722 : : * operation will be computed.
723 : : * This is also the same as the result length.
724 : : * For block ciphers, this must be a
725 : : * multiple of the block size,
726 : : * or for the AES-XTS a multiple of the data-unit length
727 : : * as described in xform.
728 : : *
729 : : * @note
730 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
731 : : * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
732 : : * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
733 : : * this field should be in bits. For
734 : : * digest-encrypted cases this must be
735 : : * an 8-bit multiple.
736 : : */
737 : : } data; /**< Data offsets and length for ciphering */
738 : : } cipher;
739 : :
740 : : struct {
741 : : struct {
742 : : uint32_t offset;
743 : : /**< Starting point for hash processing,
744 : : * specified as number of bytes from start of
745 : : * packet in source buffer.
746 : : *
747 : : * @note
748 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
749 : : * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
750 : : * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
751 : : * this field should be in bits. For
752 : : * digest-encrypted cases this must be
753 : : * an 8-bit multiple.
754 : : *
755 : : * @note
756 : : * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
757 : : * this offset should be such that
758 : : * data to authenticate starts at COUNT.
759 : : *
760 : : * @note
761 : : * For DOCSIS security protocol, this
762 : : * offset is the DOCSIS header length
763 : : * and, therefore, also the CRC offset
764 : : * i.e. the number of bytes into the
765 : : * packet at which CRC calculation
766 : : * should begin.
767 : : */
768 : : uint32_t length;
769 : : /**< The message length, in bytes, of the source
770 : : * buffer that the hash will be computed on.
771 : : *
772 : : * @note
773 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
774 : : * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
775 : : * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
776 : : * this field should be in bits. For
777 : : * digest-encrypted cases this must be
778 : : * an 8-bit multiple.
779 : : *
780 : : * @note
781 : : * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
782 : : * the length should include the COUNT,
783 : : * FRESH, message, direction bit and padding
784 : : * (to be multiple of 8 bits).
785 : : *
786 : : * @note
787 : : * For DOCSIS security protocol, this
788 : : * is the CRC length i.e. the number of
789 : : * bytes in the packet over which the
790 : : * CRC should be calculated
791 : : */
792 : : } data;
793 : : /**< Data offsets and length for authentication */
794 : :
795 : : struct {
796 : : uint8_t *data;
797 : : /**< This points to the location where
798 : : * the digest result should be inserted
799 : : * (in the case of digest generation)
800 : : * or where the purported digest exists
801 : : * (in the case of digest verification).
802 : : *
803 : : * At session creation time, the client
804 : : * specified the digest result length with
805 : : * the digest_length member of the
806 : : * @ref rte_crypto_auth_xform structure.
807 : : * For physical crypto devices the caller
808 : : * must allocate at least digest_length of
809 : : * physically contiguous memory at this
810 : : * location.
811 : : *
812 : : * For digest generation, the digest result
813 : : * will overwrite any data at this location.
814 : : *
815 : : * @note
816 : : * Digest-encrypted case.
817 : : * Digest can be generated, appended to
818 : : * the end of raw data and encrypted
819 : : * together using chained digest
820 : : * generation
821 : : * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
822 : : * and encryption
823 : : * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
824 : : * xforms. Similarly, authentication
825 : : * of the raw data against appended,
826 : : * decrypted digest, can be performed
827 : : * using decryption
828 : : * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
829 : : * and digest verification
830 : : * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
831 : : * chained xforms.
832 : : * To perform those operations, a few
833 : : * additional conditions must be met:
834 : : * - caller must allocate at least
835 : : * digest_length of memory at the end of
836 : : * source and (in case of out-of-place
837 : : * operations) destination buffer; those
838 : : * buffers can be linear or split using
839 : : * scatter-gather lists,
840 : : * - digest data pointer must point to
841 : : * the end of source or (in case of
842 : : * out-of-place operations) destination
843 : : * data, which is pointer to the
844 : : * data buffer + auth.data.offset +
845 : : * auth.data.length,
846 : : * - cipher.data.offset +
847 : : * cipher.data.length must be greater
848 : : * than auth.data.offset +
849 : : * auth.data.length and is typically
850 : : * equal to auth.data.offset +
851 : : * auth.data.length + digest_length.
852 : : * - for wireless algorithms, i.e.
853 : : * SNOW 3G, KASUMI and ZUC, as the
854 : : * cipher.data.length,
855 : : * cipher.data.offset,
856 : : * auth.data.length and
857 : : * auth.data.offset are in bits, they
858 : : * must be 8-bit multiples.
859 : : *
860 : : * Note, that for security reasons, it
861 : : * is PMDs' responsibility to not
862 : : * leave an unencrypted digest in any
863 : : * buffer after performing auth-cipher
864 : : * operations.
865 : : *
866 : : */
867 : : rte_iova_t phys_addr;
868 : : /**< Physical address of digest */
869 : : } digest; /**< Digest parameters */
870 : : } auth;
871 : : };
872 : : };
873 : : };
874 : : /* >8 End of structure rte_crypto_sym_op. */
875 : :
876 : :
877 : : /**
878 : : * Reset the fields of a symmetric operation to their default values.
879 : : *
880 : : * @param op The crypto operation to be reset.
881 : : */
882 : : static inline void
883 : : __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
884 : : {
885 : : memset(op, 0, sizeof(*op));
886 : 0 : }
887 : :
888 : :
889 : : /**
890 : : * Allocate space for symmetric crypto xforms in the private data space of the
891 : : * crypto operation. This also defaults the crypto xform type to
892 : : * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
893 : : * in the crypto operation
894 : : *
895 : : * @return
896 : : * - On success returns pointer to first crypto xform in crypto operations chain
897 : : * - On failure returns NULL
898 : : */
899 : : static inline struct rte_crypto_sym_xform *
900 : : __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
901 : : void *priv_data, uint8_t nb_xforms)
902 : : {
903 : : struct rte_crypto_sym_xform *xform;
904 : :
905 : 0 : sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
906 : :
907 : : do {
908 : 0 : xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
909 [ # # ]: 0 : xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
910 : : } while (xform);
911 : :
912 : 0 : return sym_op->xform;
913 : : }
914 : :
915 : :
916 : : /**
917 : : * Attach a session to a symmetric crypto operation
918 : : *
919 : : * @param sym_op crypto operation
920 : : * @param sess cryptodev session
921 : : */
922 : : static inline int
923 : : __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess)
924 : : {
925 : 0 : sym_op->session = sess;
926 : :
927 : : return 0;
928 : : }
929 : :
930 : : /**
931 : : * Converts portion of mbuf data into a vector representation.
932 : : * Each segment will be represented as a separate entry in *vec* array.
933 : : * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
934 : : * @param mb
935 : : * Pointer to the *rte_mbuf* object.
936 : : * @param ofs
937 : : * Offset within mbuf data to start with.
938 : : * @param len
939 : : * Length of data to represent.
940 : : * @param vec
941 : : * Pointer to an output array of IO vectors.
942 : : * @param num
943 : : * Size of an output array.
944 : : * @return
945 : : * - number of successfully filled entries in *vec* array.
946 : : * - negative number of elements in *vec* array required.
947 : : */
948 : : __rte_experimental
949 : : static inline int
950 : 0 : rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
951 : : struct rte_crypto_vec vec[], uint32_t num)
952 : : {
953 : : uint32_t i;
954 : : struct rte_mbuf *nseg;
955 : : uint32_t left;
956 : : uint32_t seglen;
957 : :
958 : : /* assuming that requested data starts in the first segment */
959 : : RTE_ASSERT(mb->data_len > ofs);
960 : :
961 [ # # ]: 0 : if (mb->nb_segs > num)
962 : 0 : return -mb->nb_segs;
963 : :
964 [ # # ]: 0 : vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
965 : 0 : vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
966 [ # # ]: 0 : vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
967 : :
968 : : /* whole data lies in the first segment */
969 : 0 : seglen = mb->data_len - ofs;
970 [ # # ]: 0 : if (len <= seglen) {
971 : 0 : vec[0].len = len;
972 : 0 : return 1;
973 : : }
974 : :
975 : : /* data spread across segments */
976 : 0 : vec[0].len = seglen;
977 : 0 : left = len - seglen;
978 [ # # ]: 0 : for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
979 : :
980 [ # # ]: 0 : vec[i].base = rte_pktmbuf_mtod(nseg, void *);
981 : 0 : vec[i].iova = rte_pktmbuf_iova(nseg);
982 [ # # ]: 0 : vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
983 : :
984 : 0 : seglen = nseg->data_len;
985 [ # # ]: 0 : if (left <= seglen) {
986 : : /* whole requested data is completed */
987 : 0 : vec[i].len = left;
988 : : left = 0;
989 : 0 : i++;
990 : 0 : break;
991 : : }
992 : :
993 : : /* use whole segment */
994 : 0 : vec[i].len = seglen;
995 : 0 : left -= seglen;
996 : : }
997 : :
998 : : RTE_ASSERT(left == 0);
999 : 0 : return i;
1000 : : }
1001 : :
1002 : :
1003 : : #ifdef __cplusplus
1004 : : }
1005 : : #endif
1006 : :
1007 : : #endif /* _RTE_CRYPTO_SYM_H_ */
|