1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2020 Intel Corporation
5 #ifndef _RTE_CRYPTO_SYM_H_
6 #define _RTE_CRYPTO_SYM_H_
9 * @file rte_crypto_sym.h
11 * RTE Definitions for Symmetric Cryptography
13 * Defines symmetric cipher and authentication algorithms and modes, as well
14 * as supported symmetric crypto operation combinations.
24 #include <rte_memory.h>
25 #include <rte_mempool.h>
26 #include <rte_common.h>
29 * Crypto IO Vector (in analogy with struct iovec)
30 * Supposed be used to pass input/output data buffers for crypto data-path
33 struct rte_crypto_vec {
34 /** virtual address of the data buffer */
36 /** IOVA of the data buffer */
38 /** length of the data buffer */
43 * Crypto scatter-gather list descriptor. Consists of a pointer to an array
44 * of Crypto IO vectors with its size.
46 struct rte_crypto_sgl {
47 /** start of an array of vectors */
48 struct rte_crypto_vec *vec;
49 /** size of an array of vectors */
54 * Synchronous operation descriptor.
55 * Supposed to be used with CPU crypto API call.
57 struct rte_crypto_sym_vec {
58 /** array of SGL vectors */
59 struct rte_crypto_sgl *sgl;
60 /** array of pointers to IV */
62 /** array of pointers to AAD */
64 /** array of pointers to digest */
67 * array of statuses for each operation:
72 /** number of operations to perform */
77 * used for cpu_crypto_process_bulk() to specify head/tail offsets
78 * for auth/cipher processing.
80 union rte_crypto_sym_ofs {
90 /** Symmetric Cipher Algorithms */
91 enum rte_crypto_cipher_algorithm {
92 RTE_CRYPTO_CIPHER_NULL = 1,
93 /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
95 RTE_CRYPTO_CIPHER_3DES_CBC,
96 /**< Triple DES algorithm in CBC mode */
97 RTE_CRYPTO_CIPHER_3DES_CTR,
98 /**< Triple DES algorithm in CTR mode */
99 RTE_CRYPTO_CIPHER_3DES_ECB,
100 /**< Triple DES algorithm in ECB mode */
102 RTE_CRYPTO_CIPHER_AES_CBC,
103 /**< AES algorithm in CBC mode */
104 RTE_CRYPTO_CIPHER_AES_CTR,
105 /**< AES algorithm in Counter mode */
106 RTE_CRYPTO_CIPHER_AES_ECB,
107 /**< AES algorithm in ECB mode */
108 RTE_CRYPTO_CIPHER_AES_F8,
109 /**< AES algorithm in F8 mode */
110 RTE_CRYPTO_CIPHER_AES_XTS,
111 /**< AES algorithm in XTS mode */
113 RTE_CRYPTO_CIPHER_ARC4,
114 /**< (A)RC4 cipher algorithm */
116 RTE_CRYPTO_CIPHER_KASUMI_F8,
117 /**< KASUMI algorithm in F8 mode */
119 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
120 /**< SNOW 3G algorithm in UEA2 mode */
122 RTE_CRYPTO_CIPHER_ZUC_EEA3,
123 /**< ZUC algorithm in EEA3 mode */
125 RTE_CRYPTO_CIPHER_DES_CBC,
126 /**< DES algorithm in CBC mode */
128 RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
129 /**< AES algorithm using modes required by
130 * DOCSIS Baseline Privacy Plus Spec.
131 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
132 * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
135 RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
136 /**< DES algorithm using modes required by
137 * DOCSIS Baseline Privacy Plus Spec.
138 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
139 * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
142 RTE_CRYPTO_CIPHER_LIST_END
146 /** Cipher algorithm name strings */
148 rte_crypto_cipher_algorithm_strings[];
150 /** Symmetric Cipher Direction */
151 enum rte_crypto_cipher_operation {
152 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
153 /**< Encrypt cipher operation */
154 RTE_CRYPTO_CIPHER_OP_DECRYPT
155 /**< Decrypt cipher operation */
158 /** Cipher operation name strings */
160 rte_crypto_cipher_operation_strings[];
163 * Symmetric Cipher Setup Data.
165 * This structure contains data relating to Cipher (Encryption and Decryption)
166 * use to create a session.
168 struct rte_crypto_cipher_xform {
169 enum rte_crypto_cipher_operation op;
170 /**< This parameter determines if the cipher operation is an encrypt or
171 * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
172 * only encrypt operations are valid.
174 enum rte_crypto_cipher_algorithm algo;
175 /**< Cipher algorithm */
178 const uint8_t *data; /**< pointer to key data */
179 uint16_t length; /**< key length in bytes */
183 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
184 * point to a concatenation of the AES encryption key followed by a
185 * keymask. As per RFC3711, the keymask should be padded with trailing
186 * bytes to match the length of the encryption key used.
188 * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
189 * 192 bits (24 bytes) or 256 bits (32 bytes).
191 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
192 * should be set to the combined length of the encryption key and the
193 * keymask. Since the keymask and the encryption key are the same size,
194 * key.length should be set to 2 x the AES encryption key length.
196 * For the AES-XTS mode of operation:
197 * - Two keys must be provided and key.length refers to total length of
199 * - key.data must point to the two keys concatenated together
201 * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
202 * - Both keys must have the same size.
206 /**< Starting point for Initialisation Vector or Counter,
207 * specified as number of bytes from start of crypto
208 * operation (rte_crypto_op).
210 * - For block ciphers in CBC or F8 mode, or for KASUMI
211 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
212 * Initialisation Vector (IV) value.
214 * - For block ciphers in CTR mode, this is the counter.
216 * - For CCM mode, the first byte is reserved, and the
217 * nonce should be written starting at &iv[1] (to allow
218 * space for the implementation to write in the flags
219 * in the first byte). Note that a full 16 bytes should
220 * be allocated, even though the length field will
221 * have a value less than this. Note that the PMDs may
222 * modify the memory reserved (the first byte and the
225 * - For AES-XTS, this is the 128bit tweak, i, from
226 * IEEE Std 1619-2007.
228 * For optimum performance, the data pointed to SHOULD
232 /**< Length of valid IV data.
234 * - For block ciphers in CBC or F8 mode, or for KASUMI
235 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
236 * length of the IV (which must be the same as the
237 * block length of the cipher).
239 * - For block ciphers in CTR mode, this is the length
240 * of the counter (which must be the same as the block
241 * length of the cipher).
243 * - For CCM mode, this is the length of the nonce,
244 * which can be in the range 7 to 13 inclusive.
246 } iv; /**< Initialisation vector parameters */
249 /** Symmetric Authentication / Hash Algorithms */
250 enum rte_crypto_auth_algorithm {
251 RTE_CRYPTO_AUTH_NULL = 1,
252 /**< NULL hash algorithm. */
254 RTE_CRYPTO_AUTH_AES_CBC_MAC,
255 /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
256 RTE_CRYPTO_AUTH_AES_CMAC,
257 /**< AES CMAC algorithm. */
258 RTE_CRYPTO_AUTH_AES_GMAC,
259 /**< AES GMAC algorithm. */
260 RTE_CRYPTO_AUTH_AES_XCBC_MAC,
261 /**< AES XCBC algorithm. */
263 RTE_CRYPTO_AUTH_KASUMI_F9,
264 /**< KASUMI algorithm in F9 mode. */
267 /**< MD5 algorithm */
268 RTE_CRYPTO_AUTH_MD5_HMAC,
269 /**< HMAC using MD5 algorithm */
271 RTE_CRYPTO_AUTH_SHA1,
272 /**< 128 bit SHA algorithm. */
273 RTE_CRYPTO_AUTH_SHA1_HMAC,
274 /**< HMAC using 128 bit SHA algorithm. */
275 RTE_CRYPTO_AUTH_SHA224,
276 /**< 224 bit SHA algorithm. */
277 RTE_CRYPTO_AUTH_SHA224_HMAC,
278 /**< HMAC using 224 bit SHA algorithm. */
279 RTE_CRYPTO_AUTH_SHA256,
280 /**< 256 bit SHA algorithm. */
281 RTE_CRYPTO_AUTH_SHA256_HMAC,
282 /**< HMAC using 256 bit SHA algorithm. */
283 RTE_CRYPTO_AUTH_SHA384,
284 /**< 384 bit SHA algorithm. */
285 RTE_CRYPTO_AUTH_SHA384_HMAC,
286 /**< HMAC using 384 bit SHA algorithm. */
287 RTE_CRYPTO_AUTH_SHA512,
288 /**< 512 bit SHA algorithm. */
289 RTE_CRYPTO_AUTH_SHA512_HMAC,
290 /**< HMAC using 512 bit SHA algorithm. */
292 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
293 /**< SNOW 3G algorithm in UIA2 mode. */
295 RTE_CRYPTO_AUTH_ZUC_EIA3,
296 /**< ZUC algorithm in EIA3 mode */
298 RTE_CRYPTO_AUTH_SHA3_224,
299 /**< 224 bit SHA3 algorithm. */
300 RTE_CRYPTO_AUTH_SHA3_224_HMAC,
301 /**< HMAC using 224 bit SHA3 algorithm. */
302 RTE_CRYPTO_AUTH_SHA3_256,
303 /**< 256 bit SHA3 algorithm. */
304 RTE_CRYPTO_AUTH_SHA3_256_HMAC,
305 /**< HMAC using 256 bit SHA3 algorithm. */
306 RTE_CRYPTO_AUTH_SHA3_384,
307 /**< 384 bit SHA3 algorithm. */
308 RTE_CRYPTO_AUTH_SHA3_384_HMAC,
309 /**< HMAC using 384 bit SHA3 algorithm. */
310 RTE_CRYPTO_AUTH_SHA3_512,
311 /**< 512 bit SHA3 algorithm. */
312 RTE_CRYPTO_AUTH_SHA3_512_HMAC,
313 /**< HMAC using 512 bit SHA3 algorithm. */
315 RTE_CRYPTO_AUTH_LIST_END
318 /** Authentication algorithm name strings */
320 rte_crypto_auth_algorithm_strings[];
322 /** Symmetric Authentication / Hash Operations */
323 enum rte_crypto_auth_operation {
324 RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
325 RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
328 /** Authentication operation name strings */
330 rte_crypto_auth_operation_strings[];
333 * Authentication / Hash transform data.
335 * This structure contains data relating to an authentication/hash crypto
336 * transforms. The fields op, algo and digest_length are common to all
337 * authentication transforms and MUST be set.
339 struct rte_crypto_auth_xform {
340 enum rte_crypto_auth_operation op;
341 /**< Authentication operation type */
342 enum rte_crypto_auth_algorithm algo;
343 /**< Authentication algorithm selection */
346 const uint8_t *data; /**< pointer to key data */
347 uint16_t length; /**< key length in bytes */
349 /**< Authentication key data.
350 * The authentication key length MUST be less than or equal to the
351 * block size of the algorithm. It is the callers responsibility to
352 * ensure that the key length is compliant with the standard being used
353 * (for example RFC 2104, FIPS 198a).
358 /**< Starting point for Initialisation Vector or Counter,
359 * specified as number of bytes from start of crypto
360 * operation (rte_crypto_op).
362 * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
363 * this is the authentication Initialisation Vector
364 * (IV) value. For AES-GMAC IV description please refer
365 * to the field `length` in iv struct.
367 * - For KASUMI in F9 mode and other authentication
368 * algorithms, this field is not used.
370 * For optimum performance, the data pointed to SHOULD
374 /**< Length of valid IV data.
376 * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
377 * for AES-GMAC, this is the length of the IV.
379 * - For KASUMI in F9 mode and other authentication
380 * algorithms, this field is not used.
382 * - For GMAC mode, this is either:
383 * 1) Number greater or equal to one, which means that IV
384 * is used and J0 will be computed internally, a minimum
385 * of 16 bytes must be allocated.
386 * 2) Zero, in which case data points to J0. In this case
387 * 16 bytes of J0 should be passed where J0 is defined
391 } iv; /**< Initialisation vector parameters */
393 uint16_t digest_length;
394 /**< Length of the digest to be returned. If the verify option is set,
395 * this specifies the length of the digest to be compared for the
398 * It is the caller's responsibility to ensure that the
399 * digest length is compliant with the hash algorithm being used.
400 * If the value is less than the maximum length allowed by the hash,
401 * the result shall be truncated.
406 /** Symmetric AEAD Algorithms */
407 enum rte_crypto_aead_algorithm {
408 RTE_CRYPTO_AEAD_AES_CCM = 1,
409 /**< AES algorithm in CCM mode. */
410 RTE_CRYPTO_AEAD_AES_GCM,
411 /**< AES algorithm in GCM mode. */
412 RTE_CRYPTO_AEAD_LIST_END
415 /** AEAD algorithm name strings */
417 rte_crypto_aead_algorithm_strings[];
419 /** Symmetric AEAD Operations */
420 enum rte_crypto_aead_operation {
421 RTE_CRYPTO_AEAD_OP_ENCRYPT,
422 /**< Encrypt and generate digest */
423 RTE_CRYPTO_AEAD_OP_DECRYPT
424 /**< Verify digest and decrypt */
427 /** Authentication operation name strings */
429 rte_crypto_aead_operation_strings[];
431 struct rte_crypto_aead_xform {
432 enum rte_crypto_aead_operation op;
433 /**< AEAD operation type */
434 enum rte_crypto_aead_algorithm algo;
435 /**< AEAD algorithm selection */
438 const uint8_t *data; /**< pointer to key data */
439 uint16_t length; /**< key length in bytes */
444 /**< Starting point for Initialisation Vector or Counter,
445 * specified as number of bytes from start of crypto
446 * operation (rte_crypto_op).
448 * - For CCM mode, the first byte is reserved, and the
449 * nonce should be written starting at &iv[1] (to allow
450 * space for the implementation to write in the flags
451 * in the first byte). Note that a full 16 bytes should
452 * be allocated, even though the length field will
453 * have a value less than this.
455 * For optimum performance, the data pointed to SHOULD
459 /**< Length of valid IV data.
461 * - For GCM mode, this is either:
462 * 1) Number greater or equal to one, which means that IV
463 * is used and J0 will be computed internally, a minimum
464 * of 16 bytes must be allocated.
465 * 2) Zero, in which case data points to J0. In this case
466 * 16 bytes of J0 should be passed where J0 is defined
469 * - For CCM mode, this is the length of the nonce,
470 * which can be in the range 7 to 13 inclusive.
472 } iv; /**< Initialisation vector parameters */
474 uint16_t digest_length;
477 /**< The length of the additional authenticated data (AAD) in bytes.
478 * For CCM mode, this is the length of the actual AAD, even though
479 * it is required to reserve 18 bytes before the AAD and padding
480 * at the end of it, so a multiple of 16 bytes is allocated.
484 /** Crypto transformation types */
485 enum rte_crypto_sym_xform_type {
486 RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
487 RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
488 RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */
489 RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */
493 * Symmetric crypto transform structure.
495 * This is used to specify the crypto transforms required, multiple transforms
496 * can be chained together to specify a chain transforms such as authentication
497 * then cipher, or cipher then authentication. Each transform structure can
498 * hold a single transform, the type field is used to specify which transform
499 * is contained within the union
501 struct rte_crypto_sym_xform {
502 struct rte_crypto_sym_xform *next;
503 /**< next xform in chain */
504 enum rte_crypto_sym_xform_type type
508 struct rte_crypto_auth_xform auth;
509 /**< Authentication / hash xform */
510 struct rte_crypto_cipher_xform cipher;
512 struct rte_crypto_aead_xform aead;
517 struct rte_cryptodev_sym_session;
520 * Symmetric Cryptographic Operation.
522 * This structure contains data relating to performing symmetric cryptographic
523 * processing on a referenced mbuf data buffer.
525 * When a symmetric crypto operation is enqueued with the device for processing
526 * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
527 * which contains the source data which the crypto operation is to be performed
529 * While the mbuf is in use by a crypto operation no part of the mbuf should be
530 * changed by the application as the device may read or write to any part of the
531 * mbuf. In the case of hardware crypto devices some or all of the mbuf
532 * may be DMAed in and out of the device, so writing over the original data,
533 * though only the part specified by the rte_crypto_sym_op for transformation
535 * Out-of-place (OOP) operation, where the source mbuf is different to the
536 * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
537 * The part copied includes all the parts of the source mbuf that will be
538 * operated on, based on the cipher.data.offset+cipher.data.length and
539 * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
540 * indicated by the cipher parameters will be transformed, any extra data around
541 * this indicated by the auth parameters will be copied unchanged from source to
543 * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
544 * both source and destination mbufs. As these offsets are relative to the
545 * data_off parameter in each mbuf this can result in the data written to the
546 * destination buffer being at a different alignment, relative to buffer start,
547 * to the data in the source buffer.
549 struct rte_crypto_sym_op {
550 struct rte_mbuf *m_src; /**< source mbuf */
551 struct rte_mbuf *m_dst; /**< destination mbuf */
555 struct rte_cryptodev_sym_session *session;
556 /**< Handle for the initialised session context */
557 struct rte_crypto_sym_xform *xform;
558 /**< Session-less API crypto operation parameters */
559 struct rte_security_session *sec_session;
560 /**< Handle for the initialised security session context */
568 /**< Starting point for AEAD processing, specified as
569 * number of bytes from start of packet in source
573 /**< The message length, in bytes, of the source buffer
574 * on which the cryptographic operation will be
575 * computed. This must be a multiple of the block size
577 } data; /**< Data offsets and length for AEAD */
580 /**< This points to the location where the digest result
581 * should be inserted (in the case of digest generation)
582 * or where the purported digest exists (in the case of
583 * digest verification).
585 * At session creation time, the client specified the
586 * digest result length with the digest_length member
587 * of the @ref rte_crypto_auth_xform structure. For
588 * physical crypto devices the caller must allocate at
589 * least digest_length of physically contiguous memory
592 * For digest generation, the digest result will
593 * overwrite any data at this location.
596 * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
597 * "digest result" read "authentication tag T".
599 rte_iova_t phys_addr;
600 /**< Physical address of digest */
601 } digest; /**< Digest parameters */
604 /**< Pointer to Additional Authenticated Data (AAD)
605 * needed for authenticated cipher mechanisms (CCM and
608 * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
609 * the caller should setup this field as follows:
611 * - the additional authentication data itself should
612 * be written starting at an offset of 18 bytes into
613 * the array, leaving room for the first block (16 bytes)
614 * and the length encoding in the first two bytes of the
617 * - the array should be big enough to hold the above
618 * fields, plus any padding to round this up to the
619 * nearest multiple of the block size (16 bytes).
620 * Padding will be added by the implementation.
622 * - Note that PMDs may modify the memory reserved
623 * (first 18 bytes and the final padding).
625 * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
626 * caller should setup this field as follows:
628 * - the AAD is written in starting at byte 0
629 * - the array must be big enough to hold the AAD, plus
630 * any space to round this up to the nearest multiple
631 * of the block size (16 bytes).
634 rte_iova_t phys_addr; /**< physical address */
636 /**< Additional authentication parameters */
643 /**< Starting point for cipher processing,
644 * specified as number of bytes from start
645 * of data in the source buffer.
646 * The result of the cipher operation will be
647 * written back into the output buffer
648 * starting at this location.
651 * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
652 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
653 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
654 * this field should be in bits. For
655 * digest-encrypted cases this must be
659 /**< The message length, in bytes, of the
660 * source buffer on which the cryptographic
661 * operation will be computed.
662 * This must be a multiple of the block size
663 * if a block cipher is being used. This is
664 * also the same as the result length.
667 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
668 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
669 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
670 * this field should be in bits. For
671 * digest-encrypted cases this must be
674 } data; /**< Data offsets and length for ciphering */
680 /**< Starting point for hash processing,
681 * specified as number of bytes from start of
682 * packet in source buffer.
685 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
686 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
687 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
688 * this field should be in bits. For
689 * digest-encrypted cases this must be
693 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
694 * this offset should be such that
695 * data to authenticate starts at COUNT.
698 /**< The message length, in bytes, of the source
699 * buffer that the hash will be computed on.
702 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
703 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
704 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
705 * this field should be in bits. For
706 * digest-encrypted cases this must be
710 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
711 * the length should include the COUNT,
712 * FRESH, message, direction bit and padding
713 * (to be multiple of 8 bits).
716 /**< Data offsets and length for authentication */
720 /**< This points to the location where
721 * the digest result should be inserted
722 * (in the case of digest generation)
723 * or where the purported digest exists
724 * (in the case of digest verification).
726 * At session creation time, the client
727 * specified the digest result length with
728 * the digest_length member of the
729 * @ref rte_crypto_auth_xform structure.
730 * For physical crypto devices the caller
731 * must allocate at least digest_length of
732 * physically contiguous memory at this
735 * For digest generation, the digest result
736 * will overwrite any data at this location.
739 * Digest-encrypted case.
740 * Digest can be generated, appended to
741 * the end of raw data and encrypted
742 * together using chained digest
744 * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
746 * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
747 * xforms. Similarly, authentication
748 * of the raw data against appended,
749 * decrypted digest, can be performed
751 * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
752 * and digest verification
753 * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
755 * To perform those operations, a few
756 * additional conditions must be met:
757 * - caller must allocate at least
758 * digest_length of memory at the end of
759 * source and (in case of out-of-place
760 * operations) destination buffer; those
761 * buffers can be linear or split using
762 * scatter-gather lists,
763 * - digest data pointer must point to
764 * the end of source or (in case of
765 * out-of-place operations) destination
766 * data, which is pointer to the
767 * data buffer + auth.data.offset +
769 * - cipher.data.offset +
770 * cipher.data.length must be greater
771 * than auth.data.offset +
772 * auth.data.length and is typically
773 * equal to auth.data.offset +
774 * auth.data.length + digest_length.
775 * - for wireless algorithms, i.e.
776 * SNOW 3G, KASUMI and ZUC, as the
777 * cipher.data.length,
778 * cipher.data.offset,
779 * auth.data.length and
780 * auth.data.offset are in bits, they
781 * must be 8-bit multiples.
783 * Note, that for security reasons, it
784 * is PMDs' responsibility to not
785 * leave an unencrypted digest in any
786 * buffer after performing auth-cipher
790 rte_iova_t phys_addr;
791 /**< Physical address of digest */
792 } digest; /**< Digest parameters */
800 * Reset the fields of a symmetric operation to their default values.
802 * @param op The crypto operation to be reset.
805 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
807 memset(op, 0, sizeof(*op));
812 * Allocate space for symmetric crypto xforms in the private data space of the
813 * crypto operation. This also defaults the crypto xform type to
814 * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
815 * in the crypto operation
818 * - On success returns pointer to first crypto xform in crypto operations chain
819 * - On failure returns NULL
821 static inline struct rte_crypto_sym_xform *
822 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
823 void *priv_data, uint8_t nb_xforms)
825 struct rte_crypto_sym_xform *xform;
827 sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
830 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
831 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
834 return sym_op->xform;
839 * Attach a session to a symmetric crypto operation
841 * @param sym_op crypto operation
842 * @param sess cryptodev session
845 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
846 struct rte_cryptodev_sym_session *sess)
848 sym_op->session = sess;
854 * Converts portion of mbuf data into a vector representation.
855 * Each segment will be represented as a separate entry in *vec* array.
856 * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
858 * Pointer to the *rte_mbuf* object.
860 * Offset within mbuf data to start with.
862 * Length of data to represent.
864 * Pointer to an output array of IO vectors.
866 * Size of an output array.
868 * - number of successfully filled entries in *vec* array.
869 * - negative number of elements in *vec* array required.
873 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
874 struct rte_crypto_vec vec[], uint32_t num)
877 struct rte_mbuf *nseg;
881 /* assuming that requested data starts in the first segment */
882 RTE_ASSERT(mb->data_len > ofs);
884 if (mb->nb_segs > num)
887 vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
888 vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
890 /* whole data lies in the first segment */
891 seglen = mb->data_len - ofs;
897 /* data spread across segments */
900 for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
902 vec[i].base = rte_pktmbuf_mtod(nseg, void *);
903 vec[i].iova = rte_pktmbuf_iova(nseg);
905 seglen = nseg->data_len;
906 if (left <= seglen) {
907 /* whole requested data is completed */
913 /* use whole segment */
918 RTE_ASSERT(left == 0);
927 #endif /* _RTE_CRYPTO_SYM_H_ */