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