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