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