cryptodev: add Chacha20-Poly1305 AEAD algorithm
[dpdk.git] / lib / librte_cryptodev / rte_crypto_sym.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2019 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_mbuf.h>
24 #include <rte_memory.h>
25 #include <rte_mempool.h>
26 #include <rte_common.h>
27
28
29 /** Symmetric Cipher Algorithms */
30 enum rte_crypto_cipher_algorithm {
31         RTE_CRYPTO_CIPHER_NULL = 1,
32         /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
33
34         RTE_CRYPTO_CIPHER_3DES_CBC,
35         /**< Triple DES algorithm in CBC mode */
36         RTE_CRYPTO_CIPHER_3DES_CTR,
37         /**< Triple DES algorithm in CTR mode */
38         RTE_CRYPTO_CIPHER_3DES_ECB,
39         /**< Triple DES algorithm in ECB mode */
40
41         RTE_CRYPTO_CIPHER_AES_CBC,
42         /**< AES algorithm in CBC mode */
43         RTE_CRYPTO_CIPHER_AES_CTR,
44         /**< AES algorithm in Counter mode */
45         RTE_CRYPTO_CIPHER_AES_ECB,
46         /**< AES algorithm in ECB mode */
47         RTE_CRYPTO_CIPHER_AES_F8,
48         /**< AES algorithm in F8 mode */
49         RTE_CRYPTO_CIPHER_AES_XTS,
50         /**< AES algorithm in XTS mode */
51
52         RTE_CRYPTO_CIPHER_ARC4,
53         /**< (A)RC4 cipher algorithm */
54
55         RTE_CRYPTO_CIPHER_KASUMI_F8,
56         /**< KASUMI algorithm in F8 mode */
57
58         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
59         /**< SNOW 3G algorithm in UEA2 mode */
60
61         RTE_CRYPTO_CIPHER_ZUC_EEA3,
62         /**< ZUC algorithm in EEA3 mode */
63
64         RTE_CRYPTO_CIPHER_DES_CBC,
65         /**< DES algorithm in CBC mode */
66
67         RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
68         /**< AES algorithm using modes required by
69          * DOCSIS Baseline Privacy Plus Spec.
70          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
71          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
72          */
73
74         RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
75         /**< DES algorithm using modes required by
76          * DOCSIS Baseline Privacy Plus Spec.
77          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
78          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
79          */
80
81         RTE_CRYPTO_CIPHER_LIST_END
82
83 };
84
85 /** Cipher algorithm name strings */
86 extern const char *
87 rte_crypto_cipher_algorithm_strings[];
88
89 /** Symmetric Cipher Direction */
90 enum rte_crypto_cipher_operation {
91         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
92         /**< Encrypt cipher operation */
93         RTE_CRYPTO_CIPHER_OP_DECRYPT
94         /**< Decrypt cipher operation */
95 };
96
97 /** Cipher operation name strings */
98 extern const char *
99 rte_crypto_cipher_operation_strings[];
100
101 /**
102  * Symmetric Cipher Setup Data.
103  *
104  * This structure contains data relating to Cipher (Encryption and Decryption)
105  *  use to create a session.
106  */
107 struct rte_crypto_cipher_xform {
108         enum rte_crypto_cipher_operation op;
109         /**< This parameter determines if the cipher operation is an encrypt or
110          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
111          * only encrypt operations are valid.
112          */
113         enum rte_crypto_cipher_algorithm algo;
114         /**< Cipher algorithm */
115
116         struct {
117                 const uint8_t *data;    /**< pointer to key data */
118                 uint16_t length;        /**< key length in bytes */
119         } key;
120         /**< Cipher key
121          *
122          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
123          * point to a concatenation of the AES encryption key followed by a
124          * keymask. As per RFC3711, the keymask should be padded with trailing
125          * bytes to match the length of the encryption key used.
126          *
127          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
128          * 192 bits (24 bytes) or 256 bits (32 bytes).
129          *
130          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
131          * should be set to the combined length of the encryption key and the
132          * keymask. Since the keymask and the encryption key are the same size,
133          * key.length should be set to 2 x the AES encryption key length.
134          *
135          * For the AES-XTS mode of operation:
136          *  - Two keys must be provided and key.length refers to total length of
137          *    the two keys.
138          *  - key.data must point to the two keys concatenated together
139          *    (key1 || key2).
140          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
141          *  - Both keys must have the same size.
142          **/
143         struct {
144                 uint16_t offset;
145                 /**< Starting point for Initialisation Vector or Counter,
146                  * specified as number of bytes from start of crypto
147                  * operation (rte_crypto_op).
148                  *
149                  * - For block ciphers in CBC or F8 mode, or for KASUMI
150                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
151                  * Initialisation Vector (IV) value.
152                  *
153                  * - For block ciphers in CTR mode, this is the counter.
154                  *
155                  * - For CCM mode, the first byte is reserved, and the
156                  * nonce should be written starting at &iv[1] (to allow
157                  * space for the implementation to write in the flags
158                  * in the first byte). Note that a full 16 bytes should
159                  * be allocated, even though the length field will
160                  * have a value less than this. Note that the PMDs may
161                  * modify the memory reserved (the first byte and the
162                  * final padding)
163                  *
164                  * - For AES-XTS, this is the 128bit tweak, i, from
165                  * IEEE Std 1619-2007.
166                  *
167                  * For optimum performance, the data pointed to SHOULD
168                  * be 8-byte aligned.
169                  */
170                 uint16_t length;
171                 /**< Length of valid IV data.
172                  *
173                  * - For block ciphers in CBC or F8 mode, or for KASUMI
174                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
175                  * length of the IV (which must be the same as the
176                  * block length of the cipher).
177                  *
178                  * - For block ciphers in CTR mode, this is the length
179                  * of the counter (which must be the same as the block
180                  * length of the cipher).
181                  *
182                  * - For CCM mode, this is the length of the nonce,
183                  * which can be in the range 7 to 13 inclusive.
184                  */
185         } iv;   /**< Initialisation vector parameters */
186 };
187
188 /** Symmetric Authentication / Hash Algorithms */
189 enum rte_crypto_auth_algorithm {
190         RTE_CRYPTO_AUTH_NULL = 1,
191         /**< NULL hash algorithm. */
192
193         RTE_CRYPTO_AUTH_AES_CBC_MAC,
194         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
195         RTE_CRYPTO_AUTH_AES_CMAC,
196         /**< AES CMAC algorithm. */
197         RTE_CRYPTO_AUTH_AES_GMAC,
198         /**< AES GMAC algorithm. */
199         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
200         /**< AES XCBC algorithm. */
201
202         RTE_CRYPTO_AUTH_KASUMI_F9,
203         /**< KASUMI algorithm in F9 mode. */
204
205         RTE_CRYPTO_AUTH_MD5,
206         /**< MD5 algorithm */
207         RTE_CRYPTO_AUTH_MD5_HMAC,
208         /**< HMAC using MD5 algorithm */
209
210         RTE_CRYPTO_AUTH_SHA1,
211         /**< 128 bit SHA algorithm. */
212         RTE_CRYPTO_AUTH_SHA1_HMAC,
213         /**< HMAC using 128 bit SHA algorithm. */
214         RTE_CRYPTO_AUTH_SHA224,
215         /**< 224 bit SHA algorithm. */
216         RTE_CRYPTO_AUTH_SHA224_HMAC,
217         /**< HMAC using 224 bit SHA algorithm. */
218         RTE_CRYPTO_AUTH_SHA256,
219         /**< 256 bit SHA algorithm. */
220         RTE_CRYPTO_AUTH_SHA256_HMAC,
221         /**< HMAC using 256 bit SHA algorithm. */
222         RTE_CRYPTO_AUTH_SHA384,
223         /**< 384 bit SHA algorithm. */
224         RTE_CRYPTO_AUTH_SHA384_HMAC,
225         /**< HMAC using 384 bit SHA algorithm. */
226         RTE_CRYPTO_AUTH_SHA512,
227         /**< 512 bit SHA algorithm. */
228         RTE_CRYPTO_AUTH_SHA512_HMAC,
229         /**< HMAC using 512 bit SHA algorithm. */
230
231         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
232         /**< SNOW 3G algorithm in UIA2 mode. */
233
234         RTE_CRYPTO_AUTH_ZUC_EIA3,
235         /**< ZUC algorithm in EIA3 mode */
236
237         RTE_CRYPTO_AUTH_SHA3_224,
238         /**< 224 bit SHA3 algorithm. */
239         RTE_CRYPTO_AUTH_SHA3_224_HMAC,
240         /**< HMAC using 224 bit SHA3 algorithm. */
241         RTE_CRYPTO_AUTH_SHA3_256,
242         /**< 256 bit SHA3 algorithm. */
243         RTE_CRYPTO_AUTH_SHA3_256_HMAC,
244         /**< HMAC using 256 bit SHA3 algorithm. */
245         RTE_CRYPTO_AUTH_SHA3_384,
246         /**< 384 bit SHA3 algorithm. */
247         RTE_CRYPTO_AUTH_SHA3_384_HMAC,
248         /**< HMAC using 384 bit SHA3 algorithm. */
249         RTE_CRYPTO_AUTH_SHA3_512,
250         /**< 512 bit SHA3 algorithm. */
251         RTE_CRYPTO_AUTH_SHA3_512_HMAC,
252         /**< HMAC using 512 bit SHA3 algorithm. */
253
254         RTE_CRYPTO_AUTH_LIST_END
255 };
256
257 /** Authentication algorithm name strings */
258 extern const char *
259 rte_crypto_auth_algorithm_strings[];
260
261 /** Symmetric Authentication / Hash Operations */
262 enum rte_crypto_auth_operation {
263         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
264         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
265 };
266
267 /** Authentication operation name strings */
268 extern const char *
269 rte_crypto_auth_operation_strings[];
270
271 /**
272  * Authentication / Hash transform data.
273  *
274  * This structure contains data relating to an authentication/hash crypto
275  * transforms. The fields op, algo and digest_length are common to all
276  * authentication transforms and MUST be set.
277  */
278 struct rte_crypto_auth_xform {
279         enum rte_crypto_auth_operation op;
280         /**< Authentication operation type */
281         enum rte_crypto_auth_algorithm algo;
282         /**< Authentication algorithm selection */
283
284         struct {
285                 const uint8_t *data;    /**< pointer to key data */
286                 uint16_t length;        /**< key length in bytes */
287         } key;
288         /**< Authentication key data.
289          * The authentication key length MUST be less than or equal to the
290          * block size of the algorithm. It is the callers responsibility to
291          * ensure that the key length is compliant with the standard being used
292          * (for example RFC 2104, FIPS 198a).
293          */
294
295         struct {
296                 uint16_t offset;
297                 /**< Starting point for Initialisation Vector or Counter,
298                  * specified as number of bytes from start of crypto
299                  * operation (rte_crypto_op).
300                  *
301                  * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
302                  *   this is the authentication Initialisation Vector
303                  *   (IV) value. For AES-GMAC IV description please refer
304                  *   to the field `length` in iv struct.
305                  *
306                  * - For KASUMI in F9 mode and other authentication
307                  *   algorithms, this field is not used.
308                  *
309                  * For optimum performance, the data pointed to SHOULD
310                  * be 8-byte aligned.
311                  */
312                 uint16_t length;
313                 /**< Length of valid IV data.
314                  *
315                  * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
316                  *   for AES-GMAC, this is the length of the IV.
317                  *
318                  * - For KASUMI in F9 mode and other authentication
319                  *   algorithms, this field is not used.
320                  *
321                  * - For GMAC mode, this is either:
322                  * 1) Number greater or equal to one, which means that IV
323                  *    is used and J0 will be computed internally, a minimum
324                  *    of 16 bytes must be allocated.
325                  * 2) Zero, in which case data points to J0. In this case
326                  *    16 bytes of J0 should be passed where J0 is defined
327                  *    by NIST SP800-38D.
328                  *
329                  */
330         } iv;   /**< Initialisation vector parameters */
331
332         uint16_t digest_length;
333         /**< Length of the digest to be returned. If the verify option is set,
334          * this specifies the length of the digest to be compared for the
335          * session.
336          *
337          * It is the caller's responsibility to ensure that the
338          * digest length is compliant with the hash algorithm being used.
339          * If the value is less than the maximum length allowed by the hash,
340          * the result shall be truncated.
341          */
342 };
343
344
345 /** Symmetric AEAD Algorithms */
346 enum rte_crypto_aead_algorithm {
347         RTE_CRYPTO_AEAD_AES_CCM = 1,
348         /**< AES algorithm in CCM mode. */
349         RTE_CRYPTO_AEAD_AES_GCM,
350         /**< AES algorithm in GCM mode. */
351         RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
352         /**< Chacha20 cipher with poly1305 authenticator */
353         RTE_CRYPTO_AEAD_LIST_END
354 };
355
356 /** AEAD algorithm name strings */
357 extern const char *
358 rte_crypto_aead_algorithm_strings[];
359
360 /** Symmetric AEAD Operations */
361 enum rte_crypto_aead_operation {
362         RTE_CRYPTO_AEAD_OP_ENCRYPT,
363         /**< Encrypt and generate digest */
364         RTE_CRYPTO_AEAD_OP_DECRYPT
365         /**< Verify digest and decrypt */
366 };
367
368 /** Authentication operation name strings */
369 extern const char *
370 rte_crypto_aead_operation_strings[];
371
372 struct rte_crypto_aead_xform {
373         enum rte_crypto_aead_operation op;
374         /**< AEAD operation type */
375         enum rte_crypto_aead_algorithm algo;
376         /**< AEAD algorithm selection */
377
378         struct {
379                 const uint8_t *data;    /**< pointer to key data */
380                 uint16_t length;        /**< key length in bytes */
381         } key;
382
383         struct {
384                 uint16_t offset;
385                 /**< Starting point for Initialisation Vector or Counter,
386                  * specified as number of bytes from start of crypto
387                  * operation (rte_crypto_op).
388                  *
389                  * - For CCM mode, the first byte is reserved, and the
390                  * nonce should be written starting at &iv[1] (to allow
391                  * space for the implementation to write in the flags
392                  * in the first byte). Note that a full 16 bytes should
393                  * be allocated, even though the length field will
394                  * have a value less than this.
395                  *
396                  * - For Chacha20-Poly1305 it is 96-bit nonce.
397                  * PMD sets initial counter for Poly1305 key generation
398                  * part to 0 and for Chacha20 encryption to 1 as per
399                  * rfc8439 2.8. AEAD construction.
400                  *
401                  * For optimum performance, the data pointed to SHOULD
402                  * be 8-byte aligned.
403                  */
404                 uint16_t length;
405                 /**< Length of valid IV data.
406                  *
407                  * - For GCM mode, this is either:
408                  * 1) Number greater or equal to one, which means that IV
409                  *    is used and J0 will be computed internally, a minimum
410                  *    of 16 bytes must be allocated.
411                  * 2) Zero, in which case data points to J0. In this case
412                  *    16 bytes of J0 should be passed where J0 is defined
413                  *    by NIST SP800-38D.
414                  *
415                  * - For CCM mode, this is the length of the nonce,
416                  * which can be in the range 7 to 13 inclusive.
417                  *
418                  * - For Chacha20-Poly1305 this field is always 12.
419                  */
420         } iv;   /**< Initialisation vector parameters */
421
422         uint16_t digest_length;
423
424         uint16_t aad_length;
425         /**< The length of the additional authenticated data (AAD) in bytes.
426          * For CCM mode, this is the length of the actual AAD, even though
427          * it is required to reserve 18 bytes before the AAD and padding
428          * at the end of it, so a multiple of 16 bytes is allocated.
429          */
430 };
431
432 /** Crypto transformation types */
433 enum rte_crypto_sym_xform_type {
434         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
435         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
436         RTE_CRYPTO_SYM_XFORM_CIPHER,            /**< Cipher xform  */
437         RTE_CRYPTO_SYM_XFORM_AEAD               /**< AEAD xform  */
438 };
439
440 /**
441  * Symmetric crypto transform structure.
442  *
443  * This is used to specify the crypto transforms required, multiple transforms
444  * can be chained together to specify a chain transforms such as authentication
445  * then cipher, or cipher then authentication. Each transform structure can
446  * hold a single transform, the type field is used to specify which transform
447  * is contained within the union
448  */
449 struct rte_crypto_sym_xform {
450         struct rte_crypto_sym_xform *next;
451         /**< next xform in chain */
452         enum rte_crypto_sym_xform_type type
453         ; /**< xform type */
454         RTE_STD_C11
455         union {
456                 struct rte_crypto_auth_xform auth;
457                 /**< Authentication / hash xform */
458                 struct rte_crypto_cipher_xform cipher;
459                 /**< Cipher xform */
460                 struct rte_crypto_aead_xform aead;
461                 /**< AEAD xform */
462         };
463 };
464
465 struct rte_cryptodev_sym_session;
466
467 /**
468  * Symmetric Cryptographic Operation.
469  *
470  * This structure contains data relating to performing symmetric cryptographic
471  * processing on a referenced mbuf data buffer.
472  *
473  * When a symmetric crypto operation is enqueued with the device for processing
474  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
475  * which contains the source data which the crypto operation is to be performed
476  * on.
477  * While the mbuf is in use by a crypto operation no part of the mbuf should be
478  * changed by the application as the device may read or write to any part of the
479  * mbuf. In the case of hardware crypto devices some or all of the mbuf
480  * may be DMAed in and out of the device, so writing over the original data,
481  * though only the part specified by the rte_crypto_sym_op for transformation
482  * will be changed.
483  * Out-of-place (OOP) operation, where the source mbuf is different to the
484  * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
485  * The part copied includes all the parts of the source mbuf that will be
486  * operated on, based on the cipher.data.offset+cipher.data.length and
487  * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
488  * indicated by the cipher parameters will be transformed, any extra data around
489  * this indicated by the auth parameters will be copied unchanged from source to
490  * destination mbuf.
491  * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
492  * both source and destination mbufs. As these offsets are relative to the
493  * data_off parameter in each mbuf this can result in the data written to the
494  * destination buffer being at a different alignment, relative to buffer start,
495  * to the data in the source buffer.
496  */
497 struct rte_crypto_sym_op {
498         struct rte_mbuf *m_src; /**< source mbuf */
499         struct rte_mbuf *m_dst; /**< destination mbuf */
500
501         RTE_STD_C11
502         union {
503                 struct rte_cryptodev_sym_session *session;
504                 /**< Handle for the initialised session context */
505                 struct rte_crypto_sym_xform *xform;
506                 /**< Session-less API crypto operation parameters */
507                 struct rte_security_session *sec_session;
508                 /**< Handle for the initialised security session context */
509         };
510
511         RTE_STD_C11
512         union {
513                 struct {
514                         struct {
515                                 uint32_t offset;
516                                  /**< Starting point for AEAD processing, specified as
517                                   * number of bytes from start of packet in source
518                                   * buffer.
519                                   */
520                                 uint32_t length;
521                                  /**< The message length, in bytes, of the source buffer
522                                   * on which the cryptographic operation will be
523                                   * computed. This must be a multiple of the block size
524                                   */
525                         } data; /**< Data offsets and length for AEAD */
526                         struct {
527                                 uint8_t *data;
528                                 /**< This points to the location where the digest result
529                                  * should be inserted (in the case of digest generation)
530                                  * or where the purported digest exists (in the case of
531                                  * digest verification).
532                                  *
533                                  * At session creation time, the client specified the
534                                  * digest result length with the digest_length member
535                                  * of the @ref rte_crypto_auth_xform structure. For
536                                  * physical crypto devices the caller must allocate at
537                                  * least digest_length of physically contiguous memory
538                                  * at this location.
539                                  *
540                                  * For digest generation, the digest result will
541                                  * overwrite any data at this location.
542                                  *
543                                  * @note
544                                  * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
545                                  * "digest result" read "authentication tag T".
546                                  */
547                                 rte_iova_t phys_addr;
548                                 /**< Physical address of digest */
549                         } digest; /**< Digest parameters */
550                         struct {
551                                 uint8_t *data;
552                                 /**< Pointer to Additional Authenticated Data (AAD)
553                                  * needed for authenticated cipher mechanisms (CCM and
554                                  * GCM)
555                                  *
556                                  * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
557                                  * the caller should setup this field as follows:
558                                  *
559                                  * - the additional authentication data itself should
560                                  * be written starting at an offset of 18 bytes into
561                                  * the array, leaving room for the first block (16 bytes)
562                                  * and the length encoding in the first two bytes of the
563                                  * second block.
564                                  *
565                                  * - the array should be big enough to hold the above
566                                  * fields, plus any padding to round this up to the
567                                  * nearest multiple of the block size (16 bytes).
568                                  * Padding will be added by the implementation.
569                                  *
570                                  * - Note that PMDs may modify the memory reserved
571                                  * (first 18 bytes and the final padding).
572                                  *
573                                  * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
574                                  * caller should setup this field as follows:
575                                  *
576                                  * - the AAD is written in starting at byte 0
577                                  * - the array must be big enough to hold the AAD, plus
578                                  * any space to round this up to the nearest multiple
579                                  * of the block size (16 bytes).
580                                  *
581                                  */
582                                 rte_iova_t phys_addr;   /**< physical address */
583                         } aad;
584                         /**< Additional authentication parameters */
585                 } aead;
586
587                 struct {
588                         struct {
589                                 struct {
590                                         uint32_t offset;
591                                          /**< Starting point for cipher processing,
592                                           * specified as number of bytes from start
593                                           * of data in the source buffer.
594                                           * The result of the cipher operation will be
595                                           * written back into the output buffer
596                                           * starting at this location.
597                                           *
598                                           * @note
599                                           * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
600                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
601                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
602                                           * this field should be in bits. For
603                                           * digest-encrypted cases this must be
604                                           * an 8-bit multiple.
605                                           */
606                                         uint32_t length;
607                                          /**< The message length, in bytes, of the
608                                           * source buffer on which the cryptographic
609                                           * operation will be computed.
610                                           * This must be a multiple of the block size
611                                           * if a block cipher is being used. This is
612                                           * also the same as the result length.
613                                           *
614                                           * @note
615                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
616                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
617                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
618                                           * this field should be in bits. For
619                                           * digest-encrypted cases this must be
620                                           * an 8-bit multiple.
621                                           */
622                                 } data; /**< Data offsets and length for ciphering */
623                         } cipher;
624
625                         struct {
626                                 struct {
627                                         uint32_t offset;
628                                          /**< Starting point for hash processing,
629                                           * specified as number of bytes from start of
630                                           * packet in source buffer.
631                                           *
632                                           * @note
633                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
634                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
635                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
636                                           * this field should be in bits. For
637                                           * digest-encrypted cases this must be
638                                           * an 8-bit multiple.
639                                           *
640                                           * @note
641                                           * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
642                                           * this offset should be such that
643                                           * data to authenticate starts at COUNT.
644                                           */
645                                         uint32_t length;
646                                          /**< The message length, in bytes, of the source
647                                           * buffer that the hash will be computed on.
648                                           *
649                                           * @note
650                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
651                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
652                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
653                                           * this field should be in bits. For
654                                           * digest-encrypted cases this must be
655                                           * an 8-bit multiple.
656                                           *
657                                           * @note
658                                           * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
659                                           * the length should include the COUNT,
660                                           * FRESH, message, direction bit and padding
661                                           * (to be multiple of 8 bits).
662                                           */
663                                 } data;
664                                 /**< Data offsets and length for authentication */
665
666                                 struct {
667                                         uint8_t *data;
668                                         /**< This points to the location where
669                                          * the digest result should be inserted
670                                          * (in the case of digest generation)
671                                          * or where the purported digest exists
672                                          * (in the case of digest verification).
673                                          *
674                                          * At session creation time, the client
675                                          * specified the digest result length with
676                                          * the digest_length member of the
677                                          * @ref rte_crypto_auth_xform structure.
678                                          * For physical crypto devices the caller
679                                          * must allocate at least digest_length of
680                                          * physically contiguous memory at this
681                                          * location.
682                                          *
683                                          * For digest generation, the digest result
684                                          * will overwrite any data at this location.
685                                          *
686                                          * @note
687                                          * Digest-encrypted case.
688                                          * Digest can be generated, appended to
689                                          * the end of raw data and encrypted
690                                          * together using chained digest
691                                          * generation
692                                          * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
693                                          * and encryption
694                                          * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
695                                          * xforms. Similarly, authentication
696                                          * of the raw data against appended,
697                                          * decrypted digest, can be performed
698                                          * using decryption
699                                          * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
700                                          * and digest verification
701                                          * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
702                                          * chained xforms.
703                                          * To perform those operations, a few
704                                          * additional conditions must be met:
705                                          * - caller must allocate at least
706                                          * digest_length of memory at the end of
707                                          * source and (in case of out-of-place
708                                          * operations) destination buffer; those
709                                          * buffers can be linear or split using
710                                          * scatter-gather lists,
711                                          * - digest data pointer must point to
712                                          * the end of source or (in case of
713                                          * out-of-place operations) destination
714                                          * data, which is pointer to the
715                                          * data buffer + auth.data.offset +
716                                          * auth.data.length,
717                                          * - cipher.data.offset +
718                                          * cipher.data.length must be greater
719                                          * than auth.data.offset +
720                                          * auth.data.length and is typically
721                                          * equal to auth.data.offset +
722                                          * auth.data.length + digest_length.
723                                          * - for wireless algorithms, i.e.
724                                          * SNOW 3G, KASUMI and ZUC, as the
725                                          * cipher.data.length,
726                                          * cipher.data.offset,
727                                          * auth.data.length and
728                                          * auth.data.offset are in bits, they
729                                          * must be 8-bit multiples.
730                                          *
731                                          * Note, that for security reasons, it
732                                          * is PMDs' responsibility to not
733                                          * leave an unencrypted digest in any
734                                          * buffer after performing auth-cipher
735                                          * operations.
736                                          *
737                                          */
738                                         rte_iova_t phys_addr;
739                                         /**< Physical address of digest */
740                                 } digest; /**< Digest parameters */
741                         } auth;
742                 };
743         };
744 };
745
746
747 /**
748  * Reset the fields of a symmetric operation to their default values.
749  *
750  * @param       op      The crypto operation to be reset.
751  */
752 static inline void
753 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
754 {
755         memset(op, 0, sizeof(*op));
756 }
757
758
759 /**
760  * Allocate space for symmetric crypto xforms in the private data space of the
761  * crypto operation. This also defaults the crypto xform type to
762  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
763  * in the crypto operation
764  *
765  * @return
766  * - On success returns pointer to first crypto xform in crypto operations chain
767  * - On failure returns NULL
768  */
769 static inline struct rte_crypto_sym_xform *
770 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
771                 void *priv_data, uint8_t nb_xforms)
772 {
773         struct rte_crypto_sym_xform *xform;
774
775         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
776
777         do {
778                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
779                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
780         } while (xform);
781
782         return sym_op->xform;
783 }
784
785
786 /**
787  * Attach a session to a symmetric crypto operation
788  *
789  * @param       sym_op  crypto operation
790  * @param       sess    cryptodev session
791  */
792 static inline int
793 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
794                 struct rte_cryptodev_sym_session *sess)
795 {
796         sym_op->session = sess;
797
798         return 0;
799 }
800
801
802 #ifdef __cplusplus
803 }
804 #endif
805
806 #endif /* _RTE_CRYPTO_SYM_H_ */