cryptodev: add bit-wise handling for SNOW 3G
[dpdk.git] / lib / librte_cryptodev / rte_crypto_sym.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016 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
55
56 /** Symmetric Cipher Algorithms */
57 enum rte_crypto_cipher_algorithm {
58         RTE_CRYPTO_CIPHER_NULL = 1,
59         /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
60
61         RTE_CRYPTO_CIPHER_3DES_CBC,
62         /**< Triple DES algorithm in CBC mode */
63         RTE_CRYPTO_CIPHER_3DES_CTR,
64         /**< Triple DES algorithm in CTR mode */
65         RTE_CRYPTO_CIPHER_3DES_ECB,
66         /**< Triple DES algorithm in ECB mode */
67
68         RTE_CRYPTO_CIPHER_AES_CBC,
69         /**< AES algorithm in CBC mode */
70         RTE_CRYPTO_CIPHER_AES_CCM,
71         /**< AES algorithm in CCM mode. When this cipher algorithm is used the
72          * *RTE_CRYPTO_AUTH_AES_CCM* element of the
73          * *rte_crypto_hash_algorithm* enum MUST be used to set up the related
74          * *rte_crypto_auth_xform* structure in the session context or in
75          * the op_params of the crypto operation structure in the case of a
76          * session-less crypto operation
77          */
78         RTE_CRYPTO_CIPHER_AES_CTR,
79         /**< AES algorithm in Counter mode */
80         RTE_CRYPTO_CIPHER_AES_ECB,
81         /**< AES algorithm in ECB mode */
82         RTE_CRYPTO_CIPHER_AES_F8,
83         /**< AES algorithm in F8 mode */
84         RTE_CRYPTO_CIPHER_AES_GCM,
85         /**< AES algorithm in GCM mode. When this cipher algorithm is used the
86          * *RTE_CRYPTO_AUTH_AES_GCM* element of the
87          * *rte_crypto_auth_algorithm* enum MUST be used to set up the related
88          * *rte_crypto_auth_setup_data* structure in the session context or in
89          * the op_params of the crypto operation structure in the case of a
90          * session-less crypto operation.
91          */
92         RTE_CRYPTO_CIPHER_AES_XTS,
93         /**< AES algorithm in XTS mode */
94
95         RTE_CRYPTO_CIPHER_ARC4,
96         /**< (A)RC4 cipher algorithm */
97
98         RTE_CRYPTO_CIPHER_KASUMI_F8,
99         /**< Kasumi algorithm in F8 mode */
100
101         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
102         /**< SNOW3G algorithm in UEA2 mode */
103
104         RTE_CRYPTO_CIPHER_ZUC_EEA3
105         /**< ZUC algorithm in EEA3 mode */
106 };
107
108 /** Symmetric Cipher Direction */
109 enum rte_crypto_cipher_operation {
110         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
111         /**< Encrypt cipher operation */
112         RTE_CRYPTO_CIPHER_OP_DECRYPT
113         /**< Decrypt cipher operation */
114 };
115
116 /**
117  * Symmetric Cipher Setup Data.
118  *
119  * This structure contains data relating to Cipher (Encryption and Decryption)
120  *  use to create a session.
121  */
122 struct rte_crypto_cipher_xform {
123         enum rte_crypto_cipher_operation op;
124         /**< This parameter determines if the cipher operation is an encrypt or
125          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
126          * only encrypt operations are valid.
127          */
128         enum rte_crypto_cipher_algorithm algo;
129         /**< Cipher algorithm */
130
131         struct {
132                 uint8_t *data;  /**< pointer to key data */
133                 size_t length;  /**< key length in bytes */
134         } key;
135         /**< Cipher key
136          *
137          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
138          * point to a concatenation of the AES encryption key followed by a
139          * keymask. As per RFC3711, the keymask should be padded with trailing
140          * bytes to match the length of the encryption key used.
141          *
142          * For AES-XTS mode of operation, two keys must be provided and
143          * key.data must point to the two keys concatenated together (Key1 ||
144          * Key2). The cipher key length will contain the total size of both
145          * keys.
146          *
147          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
148          * 192 bits (24 bytes) or 256 bits (32 bytes).
149          *
150          * For the CCM mode of operation, the only supported key length is 128
151          * bits (16 bytes).
152          *
153          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
154          * should be set to the combined length of the encryption key and the
155          * keymask. Since the keymask and the encryption key are the same size,
156          * key.length should be set to 2 x the AES encryption key length.
157          *
158          * For the AES-XTS mode of operation:
159          *  - Two keys must be provided and key.length refers to total length of
160          *    the two keys.
161          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
162          *  - Both keys must have the same size.
163          **/
164 };
165
166 /** Symmetric Authentication / Hash Algorithms */
167 enum rte_crypto_auth_algorithm {
168         RTE_CRYPTO_AUTH_NULL = 1,
169         /**< NULL hash algorithm. */
170
171         RTE_CRYPTO_AUTH_AES_CBC_MAC,
172         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
173         RTE_CRYPTO_AUTH_AES_CCM,
174         /**< AES algorithm in CCM mode. This is an authenticated cipher. When
175          * this hash algorithm is used, the *RTE_CRYPTO_CIPHER_AES_CCM*
176          * element of the *rte_crypto_cipher_algorithm* enum MUST be used to
177          * set up the related rte_crypto_cipher_setup_data structure in the
178          * session context or the corresponding parameter in the crypto
179          * operation data structures op_params parameter MUST be set for a
180          * session-less crypto operation.
181          */
182         RTE_CRYPTO_AUTH_AES_CMAC,
183         /**< AES CMAC algorithm. */
184         RTE_CRYPTO_AUTH_AES_GCM,
185         /**< AES algorithm in GCM mode. When this hash algorithm
186          * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
187          * rte_crypto_cipher_algorithm enum MUST be used to set up the related
188          * rte_crypto_cipher_setup_data structure in the session context, or
189          * the corresponding parameter in the crypto operation data structures
190          * op_params parameter MUST be set for a session-less crypto operation.
191          */
192         RTE_CRYPTO_AUTH_AES_GMAC,
193         /**< AES GMAC algorithm. When this hash algorithm
194         * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
195         * rte_crypto_cipher_algorithm enum MUST be used to set up the related
196         * rte_crypto_cipher_setup_data structure in the session context,  or
197         * the corresponding parameter in the crypto operation data structures
198         * op_params parameter MUST be set for a session-less crypto operation.
199         */
200         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
201         /**< AES XCBC algorithm. */
202
203         RTE_CRYPTO_AUTH_KASUMI_F9,
204         /**< Kasumi algorithm in F9 mode. */
205
206         RTE_CRYPTO_AUTH_MD5,
207         /**< MD5 algorithm */
208         RTE_CRYPTO_AUTH_MD5_HMAC,
209         /**< HMAC using MD5 algorithm */
210
211         RTE_CRYPTO_AUTH_SHA1,
212         /**< 128 bit SHA algorithm. */
213         RTE_CRYPTO_AUTH_SHA1_HMAC,
214         /**< HMAC using 128 bit SHA algorithm. */
215         RTE_CRYPTO_AUTH_SHA224,
216         /**< 224 bit SHA algorithm. */
217         RTE_CRYPTO_AUTH_SHA224_HMAC,
218         /**< HMAC using 224 bit SHA algorithm. */
219         RTE_CRYPTO_AUTH_SHA256,
220         /**< 256 bit SHA algorithm. */
221         RTE_CRYPTO_AUTH_SHA256_HMAC,
222         /**< HMAC using 256 bit SHA algorithm. */
223         RTE_CRYPTO_AUTH_SHA384,
224         /**< 384 bit SHA algorithm. */
225         RTE_CRYPTO_AUTH_SHA384_HMAC,
226         /**< HMAC using 384 bit SHA algorithm. */
227         RTE_CRYPTO_AUTH_SHA512,
228         /**< 512 bit SHA algorithm. */
229         RTE_CRYPTO_AUTH_SHA512_HMAC,
230         /**< HMAC using 512 bit SHA algorithm. */
231
232         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
233         /**< SNOW3G algorithm in UIA2 mode. */
234
235         RTE_CRYPTO_AUTH_ZUC_EIA3,
236         /**< ZUC algorithm in EIA3 mode */
237 };
238
239 /** Symmetric Authentication / Hash Operations */
240 enum rte_crypto_auth_operation {
241         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
242         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
243 };
244
245 /**
246  * Authentication / Hash transform data.
247  *
248  * This structure contains data relating to an authentication/hash crypto
249  * transforms. The fields op, algo and digest_length are common to all
250  * authentication transforms and MUST be set.
251  */
252 struct rte_crypto_auth_xform {
253         enum rte_crypto_auth_operation op;
254         /**< Authentication operation type */
255         enum rte_crypto_auth_algorithm algo;
256         /**< Authentication algorithm selection */
257
258         struct {
259                 uint8_t *data;  /**< pointer to key data */
260                 size_t length;  /**< key length in bytes */
261         } key;
262         /**< Authentication key data.
263          * The authentication key length MUST be less than or equal to the
264          * block size of the algorithm. It is the callers responsibility to
265          * ensure that the key length is compliant with the standard being used
266          * (for example RFC 2104, FIPS 198a).
267          */
268
269         uint32_t digest_length;
270         /**< Length of the digest to be returned. If the verify option is set,
271          * this specifies the length of the digest to be compared for the
272          * session.
273          *
274          * If the value is less than the maximum length allowed by the hash,
275          * the result shall be truncated.  If the value is greater than the
276          * maximum length allowed by the hash then an error will be generated
277          * by *rte_cryptodev_sym_session_create* or by the
278          * *rte_cryptodev_sym_enqueue_burst* if using session-less APIs.
279          */
280
281         uint32_t add_auth_data_length;
282         /**< The length of the additional authenticated data (AAD) in bytes.
283          * The maximum permitted value is 240 bytes, unless otherwise specified
284          * below.
285          *
286          * This field must be specified when the hash algorithm is one of the
287          * following:
288          *
289          * - For SNOW3G (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2), this is the
290          *   length of the IV (which should be 16).
291          *
292          * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM).  In this case, this is
293          *   the length of the Additional Authenticated Data (called A, in NIST
294          *   SP800-38D).
295          *
296          * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM).  In this case, this is
297          *   the length of the associated data (called A, in NIST SP800-38C).
298          *   Note that this does NOT include the length of any padding, or the
299          *   18 bytes reserved at the start of the above field to store the
300          *   block B0 and the encoded length.  The maximum permitted value in
301          *   this case is 222 bytes.
302          *
303          * @note
304          *  For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of operation
305          *  this field is not used and should be set to 0. Instead the length
306          *  of the AAD data is specified in the message length to hash field of
307          *  the rte_crypto_sym_op_data structure.
308          */
309 };
310
311 /** Crypto transformation types */
312 enum rte_crypto_sym_xform_type {
313         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
314         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
315         RTE_CRYPTO_SYM_XFORM_CIPHER             /**< Cipher xform  */
316 };
317
318 /**
319  * Symmetric crypto transform structure.
320  *
321  * This is used to specify the crypto transforms required, multiple transforms
322  * can be chained together to specify a chain transforms such as authentication
323  * then cipher, or cipher then authentication. Each transform structure can
324  * hold a single transform, the type field is used to specify which transform
325  * is contained within the union
326  */
327 struct rte_crypto_sym_xform {
328         struct rte_crypto_sym_xform *next;
329         /**< next xform in chain */
330         enum rte_crypto_sym_xform_type type
331         ; /**< xform type */
332         union {
333                 struct rte_crypto_auth_xform auth;
334                 /**< Authentication / hash xform */
335                 struct rte_crypto_cipher_xform cipher;
336                 /**< Cipher xform */
337         };
338 };
339
340 /**
341  * Crypto operation session type. This is used to specify whether a crypto
342  * operation has session structure attached for immutable parameters or if all
343  * operation information is included in the operation data structure.
344  */
345 enum rte_crypto_sym_op_sess_type {
346         RTE_CRYPTO_SYM_OP_WITH_SESSION, /**< Session based crypto operation */
347         RTE_CRYPTO_SYM_OP_SESSIONLESS   /**< Session-less crypto operation */
348 };
349
350
351 struct rte_cryptodev_sym_session;
352
353 /**
354  * Symmetric Cryptographic Operation.
355  *
356  * This structure contains data relating to performing symmetric cryptographic
357  * processing on a referenced mbuf data buffer.
358  *
359  * When a symmetric crypto operation is enqueued with the device for processing
360  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
361  * which contains the source data which the crypto operation is to be performed
362  * on.
363  */
364 struct rte_crypto_sym_op {
365         struct rte_mbuf *m_src; /**< source mbuf */
366         struct rte_mbuf *m_dst; /**< destination mbuf */
367
368         enum rte_crypto_sym_op_sess_type type;
369
370         union {
371                 struct rte_cryptodev_sym_session *session;
372                 /**< Handle for the initialised session context */
373                 struct rte_crypto_sym_xform *xform;
374                 /**< Session-less API crypto operation parameters */
375         };
376
377         struct {
378                 struct {
379                         uint32_t offset;
380                          /**< Starting point for cipher processing, specified
381                           * as number of bytes from start of data in the source
382                           * buffer. The result of the cipher operation will be
383                           * written back into the output buffer starting at
384                           * this location.
385                           *
386                           * @note
387                           * For Snow3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
388                           * this field should be in bits.
389                           */
390
391                         uint32_t length;
392                          /**< The message length, in bytes, of the source buffer
393                           * on which the cryptographic operation will be
394                           * computed. This must be a multiple of the block size
395                           * if a block cipher is being used. This is also the
396                           * same as the result length.
397                           *
398                           * @note
399                           * In the case of CCM @ref RTE_CRYPTO_AUTH_AES_CCM,
400                           * this value should not include the length of the
401                           * padding or the length of the MAC; the driver will
402                           * compute the actual number of bytes over which the
403                           * encryption will occur, which will include these
404                           * values.
405                           *
406                           * @note
407                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this
408                           * field should be set to 0.
409                           *
410                           * @note
411                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2
412                           * this field should be in bits.
413                           */
414                 } data; /**< Data offsets and length for ciphering */
415
416                 struct {
417                         uint8_t *data;
418                         /**< Initialisation Vector or Counter.
419                          *
420                          * - For block ciphers in CBC or F8 mode, or for Kasumi
421                          * in F8 mode, or for SNOW3G in UEA2 mode, this is the
422                          * Initialisation Vector (IV) value.
423                          *
424                          * - For block ciphers in CTR mode, this is the counter.
425                          *
426                          * - For GCM mode, this is either the IV (if the length
427                          * is 96 bits) or J0 (for other sizes), where J0 is as
428                          * defined by NIST SP800-38D. Regardless of the IV
429                          * length, a full 16 bytes needs to be allocated.
430                          *
431                          * - For CCM mode, the first byte is reserved, and the
432                          * nonce should be written starting at &iv[1] (to allow
433                          * space for the implementation to write in the flags
434                          * in the first byte). Note that a full 16 bytes should
435                          * be allocated, even though the length field will
436                          * have a value less than this.
437                          *
438                          * - For AES-XTS, this is the 128bit tweak, i, from
439                          * IEEE Std 1619-2007.
440                          *
441                          * For optimum performance, the data pointed to SHOULD
442                          * be 8-byte aligned.
443                          */
444                         phys_addr_t phys_addr;
445                         uint16_t length;
446                         /**< Length of valid IV data.
447                          *
448                          * - For block ciphers in CBC or F8 mode, or for Kasumi
449                          * in F8 mode, or for SNOW3G in UEA2 mode, this is the
450                          * length of the IV (which must be the same as the
451                          * block length of the cipher).
452                          *
453                          * - For block ciphers in CTR mode, this is the length
454                          * of the counter (which must be the same as the block
455                          * length of the cipher).
456                          *
457                          * - For GCM mode, this is either 12 (for 96-bit IVs)
458                          * or 16, in which case data points to J0.
459                          *
460                          * - For CCM mode, this is the length of the nonce,
461                          * which can be in the range 7 to 13 inclusive.
462                          */
463                 } iv;   /**< Initialisation vector parameters */
464         } cipher;
465
466         struct {
467                 struct {
468                         uint32_t offset;
469                          /**< Starting point for hash processing, specified as
470                           * number of bytes from start of packet in source
471                           * buffer.
472                           *
473                           * @note
474                           * For CCM and GCM modes of operation, this field is
475                           * ignored. The field @ref aad field
476                           * should be set instead.
477                           *
478                           * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC)
479                           * mode of operation, this field specifies the start
480                           * of the AAD data in the source buffer.
481                           *
482                           * @note
483                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2
484                           * this field should be in bits.
485                           */
486
487                         uint32_t length;
488                          /**< The message length, in bytes, of the source
489                           * buffer that the hash will be computed on.
490                           *
491                           * @note
492                           * For CCM and GCM modes of operation, this field is
493                           * ignored. The field @ref aad field should be set
494                           * instead.
495                           *
496                           * @note
497                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode
498                           * of operation, this field specifies the length of
499                           * the AAD data in the source buffer.
500                           *
501                           * @note
502                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2
503                           * this field should be in bits.
504                           */
505                 } data; /**< Data offsets and length for authentication */
506
507                 struct {
508                         uint8_t *data;
509                         /**< If this member of this structure is set this is a
510                          * pointer to the location where the digest result
511                          * should be inserted (in the case of digest generation)
512                          * or where the purported digest exists (in the case of
513                          * digest verification).
514                          *
515                          * At session creation time, the client specified the
516                          * digest result length with the digest_length member
517                          * of the @ref rte_crypto_auth_xform structure. For
518                          * physical crypto devices the caller must allocate at
519                          * least digest_length of physically contiguous memory
520                          * at this location.
521                          *
522                          * For digest generation, the digest result will
523                          * overwrite any data at this location.
524                          *
525                          * @note
526                          * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
527                          * "digest result" read "authentication tag T".
528                          *
529                          * If this member is not set the digest result is
530                          * understood to be in the destination buffer for
531                          * digest generation, and in the source buffer for
532                          * digest verification. The location of the digest
533                          * result in this case is immediately following the
534                          * region over which the digest is computed.
535                          */
536                         phys_addr_t phys_addr;
537                         /**< Physical address of digest */
538                         uint16_t length;
539                         /**< Length of digest */
540                 } digest; /**< Digest parameters */
541
542                 struct {
543                         uint8_t *data;
544                         /**< Pointer to Additional Authenticated Data (AAD)
545                          * needed for authenticated cipher mechanisms (CCM and
546                          * GCM), and to the IV for SNOW3G authentication
547                          * (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2). For other
548                          * authentication mechanisms this pointer is ignored.
549                          *
550                          * The length of the data pointed to by this field is
551                          * set up for the session in the @ref
552                          * rte_crypto_auth_xform structure as part of the @ref
553                          * rte_cryptodev_sym_session_create function call.
554                          * This length must not exceed 240 bytes.
555                          *
556                          * Specifically for CCM (@ref RTE_CRYPTO_AUTH_AES_CCM),
557                          * the caller should setup this field as follows:
558                          *
559                          * - the nonce should be written starting at an offset
560                          * of one byte into the array, leaving room for the
561                          * implementation to write in the flags to the first
562                          *  byte.
563                          *
564                          * - the additional  authentication data itself should
565                          * be written starting at an offset of 18 bytes into
566                          * the array, leaving room for the length encoding in
567                          * the first two bytes of the second block.
568                          *
569                          * - the array should be big enough to hold the above
570                          *  fields, plus any padding to round this up to the
571                          *  nearest multiple of the block size (16 bytes).
572                          *  Padding will be added by the implementation.
573                          *
574                          * Finally, for GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), the
575                          * caller should setup this field as follows:
576                          *
577                          * - the AAD is written in starting at byte 0
578                          * - the array must be big enough to hold the AAD, plus
579                          * any space to round this up to the nearest multiple
580                          * of the block size (16 bytes).
581                          *
582                          * @note
583                          * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of
584                          * operation, this field is not used and should be set
585                          * to 0. Instead the AAD data should be placed in the
586                          * source buffer.
587                          */
588                         phys_addr_t phys_addr;  /**< physical address */
589                         uint16_t length;        /**< Length of digest */
590                 } aad;
591                 /**< Additional authentication parameters */
592         } auth;
593 } __rte_cache_aligned;
594
595
596 /**
597  * Reset the fields of a symmetric operation to their default values.
598  *
599  * @param       op      The crypto operation to be reset.
600  */
601 static inline void
602 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
603 {
604         memset(op, 0, sizeof(*op));
605
606         op->type = RTE_CRYPTO_SYM_OP_SESSIONLESS;
607 }
608
609
610 /**
611  * Allocate space for symmetric crypto xforms in the private data space of the
612  * crypto operation. This also defaults the crypto xform type to
613  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
614  * in the crypto operation
615  *
616  * @return
617  * - On success returns pointer to first crypto xform in crypto operations chain
618  * - On failure returns NULL
619  */
620 static inline struct rte_crypto_sym_xform *
621 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
622                 void *priv_data, uint8_t nb_xforms)
623 {
624         struct rte_crypto_sym_xform *xform;
625
626         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
627
628         do {
629                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
630                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
631         } while (xform);
632
633         return sym_op->xform;
634 }
635
636
637 /**
638  * Attach a session to a symmetric crypto operation
639  *
640  * @param       sym_op  crypto operation
641  * @param       sess    cryptodev session
642  */
643 static inline int
644 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
645                 struct rte_cryptodev_sym_session *sess)
646 {
647         sym_op->session = sess;
648         sym_op->type = RTE_CRYPTO_SYM_OP_WITH_SESSION;
649
650         return 0;
651 }
652
653
654 #ifdef __cplusplus
655 }
656 #endif
657
658 #endif /* _RTE_CRYPTO_SYM_H_ */