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