cryptodev: move IV parameters to session
[dpdk.git] / lib / librte_cryptodev / rte_crypto_sym.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _RTE_CRYPTO_SYM_H_
34 #define _RTE_CRYPTO_SYM_H_
35
36 /**
37  * @file rte_crypto_sym.h
38  *
39  * RTE Definitions for Symmetric Cryptography
40  *
41  * Defines symmetric cipher and authentication algorithms and modes, as well
42  * as supported symmetric crypto operation combinations.
43  */
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #include <string.h>
50
51 #include <rte_mbuf.h>
52 #include <rte_memory.h>
53 #include <rte_mempool.h>
54 #include <rte_common.h>
55
56
57 /** Symmetric Cipher Algorithms */
58 enum rte_crypto_cipher_algorithm {
59         RTE_CRYPTO_CIPHER_NULL = 1,
60         /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
61
62         RTE_CRYPTO_CIPHER_3DES_CBC,
63         /**< Triple DES algorithm in CBC mode */
64         RTE_CRYPTO_CIPHER_3DES_CTR,
65         /**< Triple DES algorithm in CTR mode */
66         RTE_CRYPTO_CIPHER_3DES_ECB,
67         /**< Triple DES algorithm in ECB mode */
68
69         RTE_CRYPTO_CIPHER_AES_CBC,
70         /**< AES algorithm in CBC mode */
71         RTE_CRYPTO_CIPHER_AES_CCM,
72         /**< AES algorithm in CCM mode. When this cipher algorithm is used the
73          * *RTE_CRYPTO_AUTH_AES_CCM* element of the
74          * *rte_crypto_hash_algorithm* enum MUST be used to set up the related
75          * *rte_crypto_auth_xform* structure in the session context or in
76          * the op_params of the crypto operation structure in the case of a
77          * session-less crypto operation
78          */
79         RTE_CRYPTO_CIPHER_AES_CTR,
80         /**< AES algorithm in Counter mode */
81         RTE_CRYPTO_CIPHER_AES_ECB,
82         /**< AES algorithm in ECB mode */
83         RTE_CRYPTO_CIPHER_AES_F8,
84         /**< AES algorithm in F8 mode */
85         RTE_CRYPTO_CIPHER_AES_GCM,
86         /**< AES algorithm in GCM mode. When this cipher algorithm is used the
87          * *RTE_CRYPTO_AUTH_AES_GCM* or *RTE_CRYPTO_AUTH_AES_GMAC* element
88          * of the *rte_crypto_auth_algorithm* enum MUST be used to set up
89          * the related *rte_crypto_auth_setup_data* structure in the session
90          * context or in the op_params of the crypto operation structure
91          * in the case of a session-less crypto operation.
92          */
93         RTE_CRYPTO_CIPHER_AES_XTS,
94         /**< AES algorithm in XTS mode */
95
96         RTE_CRYPTO_CIPHER_ARC4,
97         /**< (A)RC4 cipher algorithm */
98
99         RTE_CRYPTO_CIPHER_KASUMI_F8,
100         /**< KASUMI algorithm in F8 mode */
101
102         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
103         /**< SNOW 3G algorithm in UEA2 mode */
104
105         RTE_CRYPTO_CIPHER_ZUC_EEA3,
106         /**< ZUC algorithm in EEA3 mode */
107
108         RTE_CRYPTO_CIPHER_DES_CBC,
109         /**< DES algorithm in CBC mode */
110
111         RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
112         /**< AES algorithm using modes required by
113          * DOCSIS Baseline Privacy Plus Spec.
114          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
115          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
116          */
117
118         RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
119         /**< DES algorithm using modes required by
120          * DOCSIS Baseline Privacy Plus Spec.
121          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
122          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
123          */
124
125         RTE_CRYPTO_CIPHER_LIST_END
126
127 };
128
129 /** Cipher algorithm name strings */
130 extern const char *
131 rte_crypto_cipher_algorithm_strings[];
132
133 /** Symmetric Cipher Direction */
134 enum rte_crypto_cipher_operation {
135         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
136         /**< Encrypt cipher operation */
137         RTE_CRYPTO_CIPHER_OP_DECRYPT
138         /**< Decrypt cipher operation */
139 };
140
141 /** Cipher operation name strings */
142 extern const char *
143 rte_crypto_cipher_operation_strings[];
144
145 /**
146  * Symmetric Cipher Setup Data.
147  *
148  * This structure contains data relating to Cipher (Encryption and Decryption)
149  *  use to create a session.
150  */
151 struct rte_crypto_cipher_xform {
152         enum rte_crypto_cipher_operation op;
153         /**< This parameter determines if the cipher operation is an encrypt or
154          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
155          * only encrypt operations are valid.
156          */
157         enum rte_crypto_cipher_algorithm algo;
158         /**< Cipher algorithm */
159
160         struct {
161                 uint8_t *data;  /**< pointer to key data */
162                 size_t length;  /**< key length in bytes */
163         } key;
164         /**< Cipher key
165          *
166          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
167          * point to a concatenation of the AES encryption key followed by a
168          * keymask. As per RFC3711, the keymask should be padded with trailing
169          * bytes to match the length of the encryption key used.
170          *
171          * For AES-XTS mode of operation, two keys must be provided and
172          * key.data must point to the two keys concatenated together (Key1 ||
173          * Key2). The cipher key length will contain the total size of both
174          * keys.
175          *
176          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
177          * 192 bits (24 bytes) or 256 bits (32 bytes).
178          *
179          * For the CCM mode of operation, the only supported key length is 128
180          * bits (16 bytes).
181          *
182          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
183          * should be set to the combined length of the encryption key and the
184          * keymask. Since the keymask and the encryption key are the same size,
185          * key.length should be set to 2 x the AES encryption key length.
186          *
187          * For the AES-XTS mode of operation:
188          *  - Two keys must be provided and key.length refers to total length of
189          *    the two keys.
190          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
191          *  - Both keys must have the same size.
192          **/
193         struct {
194                 uint16_t offset;
195                 /**< Starting point for Initialisation Vector or Counter,
196                  * specified as number of bytes from start of crypto
197                  * operation (rte_crypto_op).
198                  *
199                  * - For block ciphers in CBC or F8 mode, or for KASUMI
200                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
201                  * Initialisation Vector (IV) value.
202                  *
203                  * - For block ciphers in CTR mode, this is the counter.
204                  *
205                  * - For GCM mode, this is either the IV (if the length
206                  * is 96 bits) or J0 (for other sizes), where J0 is as
207                  * defined by NIST SP800-38D. Regardless of the IV
208                  * length, a full 16 bytes needs to be allocated.
209                  *
210                  * - For CCM mode, the first byte is reserved, and the
211                  * nonce should be written starting at &iv[1] (to allow
212                  * space for the implementation to write in the flags
213                  * in the first byte). Note that a full 16 bytes should
214                  * be allocated, even though the length field will
215                  * have a value less than this.
216                  *
217                  * - For AES-XTS, this is the 128bit tweak, i, from
218                  * IEEE Std 1619-2007.
219                  *
220                  * For optimum performance, the data pointed to SHOULD
221                  * be 8-byte aligned.
222                  */
223                 uint16_t length;
224                 /**< Length of valid IV data.
225                  *
226                  * - For block ciphers in CBC or F8 mode, or for KASUMI
227                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
228                  * length of the IV (which must be the same as the
229                  * block length of the cipher).
230                  *
231                  * - For block ciphers in CTR mode, this is the length
232                  * of the counter (which must be the same as the block
233                  * length of the cipher).
234                  *
235                  * - For GCM mode, this is either 12 (for 96-bit IVs)
236                  * or 16, in which case data points to J0.
237                  *
238                  * - For CCM mode, this is the length of the nonce,
239                  * which can be in the range 7 to 13 inclusive.
240                  */
241         } iv;   /**< Initialisation vector parameters */
242 };
243
244 /** Symmetric Authentication / Hash Algorithms */
245 enum rte_crypto_auth_algorithm {
246         RTE_CRYPTO_AUTH_NULL = 1,
247         /**< NULL hash algorithm. */
248
249         RTE_CRYPTO_AUTH_AES_CBC_MAC,
250         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
251         RTE_CRYPTO_AUTH_AES_CCM,
252         /**< AES algorithm in CCM mode. This is an authenticated cipher. When
253          * this hash algorithm is used, the *RTE_CRYPTO_CIPHER_AES_CCM*
254          * element of the *rte_crypto_cipher_algorithm* enum MUST be used to
255          * set up the related rte_crypto_cipher_setup_data structure in the
256          * session context or the corresponding parameter in the crypto
257          * operation data structures op_params parameter MUST be set for a
258          * session-less crypto operation.
259          */
260         RTE_CRYPTO_AUTH_AES_CMAC,
261         /**< AES CMAC algorithm. */
262         RTE_CRYPTO_AUTH_AES_GCM,
263         /**< AES algorithm in GCM mode. When this hash algorithm
264          * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
265          * rte_crypto_cipher_algorithm enum MUST be used to set up the related
266          * rte_crypto_cipher_setup_data structure in the session context, or
267          * the corresponding parameter in the crypto operation data structures
268          * op_params parameter MUST be set for a session-less crypto operation.
269          */
270         RTE_CRYPTO_AUTH_AES_GMAC,
271         /**< AES GMAC algorithm. When this hash algorithm
272         * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
273         * rte_crypto_cipher_algorithm enum MUST be used to set up the related
274         * rte_crypto_cipher_setup_data structure in the session context,  or
275         * the corresponding parameter in the crypto operation data structures
276         * op_params parameter MUST be set for a session-less crypto operation.
277         */
278         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
279         /**< AES XCBC algorithm. */
280
281         RTE_CRYPTO_AUTH_KASUMI_F9,
282         /**< KASUMI algorithm in F9 mode. */
283
284         RTE_CRYPTO_AUTH_MD5,
285         /**< MD5 algorithm */
286         RTE_CRYPTO_AUTH_MD5_HMAC,
287         /**< HMAC using MD5 algorithm */
288
289         RTE_CRYPTO_AUTH_SHA1,
290         /**< 128 bit SHA algorithm. */
291         RTE_CRYPTO_AUTH_SHA1_HMAC,
292         /**< HMAC using 128 bit SHA algorithm. */
293         RTE_CRYPTO_AUTH_SHA224,
294         /**< 224 bit SHA algorithm. */
295         RTE_CRYPTO_AUTH_SHA224_HMAC,
296         /**< HMAC using 224 bit SHA algorithm. */
297         RTE_CRYPTO_AUTH_SHA256,
298         /**< 256 bit SHA algorithm. */
299         RTE_CRYPTO_AUTH_SHA256_HMAC,
300         /**< HMAC using 256 bit SHA algorithm. */
301         RTE_CRYPTO_AUTH_SHA384,
302         /**< 384 bit SHA algorithm. */
303         RTE_CRYPTO_AUTH_SHA384_HMAC,
304         /**< HMAC using 384 bit SHA algorithm. */
305         RTE_CRYPTO_AUTH_SHA512,
306         /**< 512 bit SHA algorithm. */
307         RTE_CRYPTO_AUTH_SHA512_HMAC,
308         /**< HMAC using 512 bit SHA algorithm. */
309
310         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
311         /**< SNOW 3G algorithm in UIA2 mode. */
312
313         RTE_CRYPTO_AUTH_ZUC_EIA3,
314         /**< ZUC algorithm in EIA3 mode */
315
316         RTE_CRYPTO_AUTH_LIST_END
317 };
318
319 /** Authentication algorithm name strings */
320 extern const char *
321 rte_crypto_auth_algorithm_strings[];
322
323 /** Symmetric Authentication / Hash Operations */
324 enum rte_crypto_auth_operation {
325         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
326         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
327 };
328
329 /** Authentication operation name strings */
330 extern const char *
331 rte_crypto_auth_operation_strings[];
332
333 /**
334  * Authentication / Hash transform data.
335  *
336  * This structure contains data relating to an authentication/hash crypto
337  * transforms. The fields op, algo and digest_length are common to all
338  * authentication transforms and MUST be set.
339  */
340 struct rte_crypto_auth_xform {
341         enum rte_crypto_auth_operation op;
342         /**< Authentication operation type */
343         enum rte_crypto_auth_algorithm algo;
344         /**< Authentication algorithm selection */
345
346         struct {
347                 uint8_t *data;  /**< pointer to key data */
348                 size_t length;  /**< key length in bytes */
349         } key;
350         /**< Authentication key data.
351          * The authentication key length MUST be less than or equal to the
352          * block size of the algorithm. It is the callers responsibility to
353          * ensure that the key length is compliant with the standard being used
354          * (for example RFC 2104, FIPS 198a).
355          */
356
357         uint32_t digest_length;
358         /**< Length of the digest to be returned. If the verify option is set,
359          * this specifies the length of the digest to be compared for the
360          * session.
361          *
362          * It is the caller's responsibility to ensure that the
363          * digest length is compliant with the hash algorithm being used.
364          * If the value is less than the maximum length allowed by the hash,
365          * the result shall be truncated.
366          */
367
368         uint32_t add_auth_data_length;
369         /**< The length of the additional authenticated data (AAD) in bytes.
370          * The maximum permitted value is 65535 (2^16 - 1) bytes, unless
371          * otherwise specified below.
372          *
373          * This field must be specified when the hash algorithm is one of the
374          * following:
375          *
376          * - For SNOW 3G (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2), this is the
377          *   length of the IV (which should be 16).
378          *
379          * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM).  In this case, this is
380          *   the length of the Additional Authenticated Data (called A, in NIST
381          *   SP800-38D).
382          *
383          * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM).  In this case, this is
384          *   the length of the associated data (called A, in NIST SP800-38C).
385          *   Note that this does NOT include the length of any padding, or the
386          *   18 bytes reserved at the start of the above field to store the
387          *   block B0 and the encoded length.  The maximum permitted value in
388          *   this case is 222 bytes.
389          *
390          * @note
391          *  For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of operation
392          *  this field is not used and should be set to 0. Instead the length
393          *  of the AAD data is specified in additional authentication data
394          *  length field of the rte_crypto_sym_op_data structure
395          */
396 };
397
398 /** Crypto transformation types */
399 enum rte_crypto_sym_xform_type {
400         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
401         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
402         RTE_CRYPTO_SYM_XFORM_CIPHER             /**< Cipher xform  */
403 };
404
405 /**
406  * Symmetric crypto transform structure.
407  *
408  * This is used to specify the crypto transforms required, multiple transforms
409  * can be chained together to specify a chain transforms such as authentication
410  * then cipher, or cipher then authentication. Each transform structure can
411  * hold a single transform, the type field is used to specify which transform
412  * is contained within the union
413  */
414 struct rte_crypto_sym_xform {
415         struct rte_crypto_sym_xform *next;
416         /**< next xform in chain */
417         enum rte_crypto_sym_xform_type type
418         ; /**< xform type */
419         RTE_STD_C11
420         union {
421                 struct rte_crypto_auth_xform auth;
422                 /**< Authentication / hash xform */
423                 struct rte_crypto_cipher_xform cipher;
424                 /**< Cipher xform */
425         };
426 };
427
428 struct rte_cryptodev_sym_session;
429
430 /**
431  * Symmetric Cryptographic Operation.
432  *
433  * This structure contains data relating to performing symmetric cryptographic
434  * processing on a referenced mbuf data buffer.
435  *
436  * When a symmetric crypto operation is enqueued with the device for processing
437  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
438  * which contains the source data which the crypto operation is to be performed
439  * on.
440  * While the mbuf is in use by a crypto operation no part of the mbuf should be
441  * changed by the application as the device may read or write to any part of the
442  * mbuf. In the case of hardware crypto devices some or all of the mbuf
443  * may be DMAed in and out of the device, so writing over the original data,
444  * though only the part specified by the rte_crypto_sym_op for transformation
445  * will be changed.
446  * Out-of-place (OOP) operation, where the source mbuf is different to the
447  * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
448  * The part copied includes all the parts of the source mbuf that will be
449  * operated on, based on the cipher.data.offset+cipher.data.length and
450  * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
451  * indicated by the cipher parameters will be transformed, any extra data around
452  * this indicated by the auth parameters will be copied unchanged from source to
453  * destination mbuf.
454  * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
455  * both source and destination mbufs. As these offsets are relative to the
456  * data_off parameter in each mbuf this can result in the data written to the
457  * destination buffer being at a different alignment, relative to buffer start,
458  * to the data in the source buffer.
459  */
460 struct rte_crypto_sym_op {
461         struct rte_mbuf *m_src; /**< source mbuf */
462         struct rte_mbuf *m_dst; /**< destination mbuf */
463
464         RTE_STD_C11
465         union {
466                 struct rte_cryptodev_sym_session *session;
467                 /**< Handle for the initialised session context */
468                 struct rte_crypto_sym_xform *xform;
469                 /**< Session-less API crypto operation parameters */
470         };
471
472         struct {
473                 struct {
474                         uint32_t offset;
475                          /**< Starting point for cipher processing, specified
476                           * as number of bytes from start of data in the source
477                           * buffer. The result of the cipher operation will be
478                           * written back into the output buffer starting at
479                           * this location.
480                           *
481                           * @note
482                           * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
483                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
484                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
485                           * this field should be in bits.
486                           */
487
488                         uint32_t length;
489                          /**< The message length, in bytes, of the source buffer
490                           * on which the cryptographic operation will be
491                           * computed. This must be a multiple of the block size
492                           * if a block cipher is being used. This is also the
493                           * same as the result length.
494                           *
495                           * @note
496                           * In the case of CCM @ref RTE_CRYPTO_AUTH_AES_CCM,
497                           * this value should not include the length of the
498                           * padding or the length of the MAC; the driver will
499                           * compute the actual number of bytes over which the
500                           * encryption will occur, which will include these
501                           * values.
502                           *
503                           * @note
504                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this
505                           * field should be set to 0.
506                           *
507                           * @note
508                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
509                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
510                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
511                           * this field should be in bits.
512                           */
513                 } data; /**< Data offsets and length for ciphering */
514
515         } cipher;
516
517         struct {
518                 struct {
519                         uint32_t offset;
520                          /**< Starting point for hash processing, specified as
521                           * number of bytes from start of packet in source
522                           * buffer.
523                           *
524                           * @note
525                           * For CCM and GCM modes of operation, this field is
526                           * ignored. The field @ref aad field
527                           * should be set instead.
528                           *
529                           * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC)
530                           * mode of operation, this field is set to 0. aad data
531                           * pointer of rte_crypto_sym_op_data structure is
532                           * used instead
533                           *
534                           * @note
535                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
536                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
537                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
538                           * this field should be in bits.
539                           */
540
541                         uint32_t length;
542                          /**< The message length, in bytes, of the source
543                           * buffer that the hash will be computed on.
544                           *
545                           * @note
546                           * For CCM and GCM modes of operation, this field is
547                           * ignored. The field @ref aad field should be set
548                           * instead.
549                           *
550                           * @note
551                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode
552                           * of operation, this field is set to 0.
553                           * Auth.aad.length is used instead.
554                           *
555                           * @note
556                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
557                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
558                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
559                           * this field should be in bits.
560                           */
561                 } data; /**< Data offsets and length for authentication */
562
563                 struct {
564                         uint8_t *data;
565                         /**< This points to the location where the digest result
566                          * should be inserted (in the case of digest generation)
567                          * or where the purported digest exists (in the case of
568                          * digest verification).
569                          *
570                          * At session creation time, the client specified the
571                          * digest result length with the digest_length member
572                          * of the @ref rte_crypto_auth_xform structure. For
573                          * physical crypto devices the caller must allocate at
574                          * least digest_length of physically contiguous memory
575                          * at this location.
576                          *
577                          * For digest generation, the digest result will
578                          * overwrite any data at this location.
579                          *
580                          * @note
581                          * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
582                          * "digest result" read "authentication tag T".
583                          */
584                         phys_addr_t phys_addr;
585                         /**< Physical address of digest */
586                         uint16_t length;
587                         /**< Length of digest. This must be the same value as
588                          * @ref rte_crypto_auth_xform.digest_length.
589                          */
590                 } digest; /**< Digest parameters */
591
592                 struct {
593                         uint8_t *data;
594                         /**< Pointer to Additional Authenticated Data (AAD)
595                          * needed for authenticated cipher mechanisms (CCM and
596                          * GCM), and to the IV for SNOW 3G authentication
597                          * (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2). For other
598                          * authentication mechanisms this pointer is ignored.
599                          *
600                          * The length of the data pointed to by this field is
601                          * set up for the session in the @ref
602                          * rte_crypto_auth_xform structure as part of the @ref
603                          * rte_cryptodev_sym_session_create function call.
604                          * This length must not exceed 65535 (2^16-1) bytes.
605                          *
606                          * Specifically for CCM (@ref RTE_CRYPTO_AUTH_AES_CCM),
607                          * the caller should setup this field as follows:
608                          *
609                          * - the nonce should be written starting at an offset
610                          * of one byte into the array, leaving room for the
611                          * implementation to write in the flags to the first
612                          *  byte.
613                          *
614                          * - the additional  authentication data itself should
615                          * be written starting at an offset of 18 bytes into
616                          * the array, leaving room for the length encoding in
617                          * the first two bytes of the second block.
618                          *
619                          * - the array should be big enough to hold the above
620                          *  fields, plus any padding to round this up to the
621                          *  nearest multiple of the block size (16 bytes).
622                          *  Padding will be added by the implementation.
623                          *
624                          * Finally, for GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), the
625                          * caller should setup this field as follows:
626                          *
627                          * - the AAD is written in starting at byte 0
628                          * - the array must be big enough to hold the AAD, plus
629                          * any space to round this up to the nearest multiple
630                          * of the block size (16 bytes).
631                          *
632                          * @note
633                          * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of
634                          * operation, this field is used to pass plaintext.
635                          */
636                         phys_addr_t phys_addr;  /**< physical address */
637                         uint16_t length;
638                         /**< Length of additional authenticated data (AAD)
639                          * in bytes
640                          */
641                 } aad;
642                 /**< Additional authentication parameters */
643         } auth;
644 };
645
646
647 /**
648  * Reset the fields of a symmetric operation to their default values.
649  *
650  * @param       op      The crypto operation to be reset.
651  */
652 static inline void
653 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
654 {
655         memset(op, 0, sizeof(*op));
656 }
657
658
659 /**
660  * Allocate space for symmetric crypto xforms in the private data space of the
661  * crypto operation. This also defaults the crypto xform type to
662  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
663  * in the crypto operation
664  *
665  * @return
666  * - On success returns pointer to first crypto xform in crypto operations chain
667  * - On failure returns NULL
668  */
669 static inline struct rte_crypto_sym_xform *
670 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
671                 void *priv_data, uint8_t nb_xforms)
672 {
673         struct rte_crypto_sym_xform *xform;
674
675         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
676
677         do {
678                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
679                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
680         } while (xform);
681
682         return sym_op->xform;
683 }
684
685
686 /**
687  * Attach a session to a symmetric crypto operation
688  *
689  * @param       sym_op  crypto operation
690  * @param       sess    cryptodev session
691  */
692 static inline int
693 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
694                 struct rte_cryptodev_sym_session *sess)
695 {
696         sym_op->session = sess;
697
698         return 0;
699 }
700
701
702 #ifdef __cplusplus
703 }
704 #endif
705
706 #endif /* _RTE_CRYPTO_SYM_H_ */