LCOV - code coverage report
Current view: top level - lib/cryptodev - rte_crypto_sym.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 6 30 20.0 %
Date: 2026-04-01 20:02:27 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 18 11.1 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _RTE_CRYPTO_SYM_H_
       6                 :            : #define _RTE_CRYPTO_SYM_H_
       7                 :            : 
       8                 :            : /**
       9                 :            :  * @file rte_crypto_sym.h
      10                 :            :  *
      11                 :            :  * RTE Definitions for Symmetric Cryptography
      12                 :            :  *
      13                 :            :  * Defines symmetric cipher and authentication algorithms and modes, as well
      14                 :            :  * as supported symmetric crypto operation combinations.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <string.h>
      18                 :            : 
      19                 :            : #include <rte_compat.h>
      20                 :            : #include <rte_mbuf.h>
      21                 :            : #include <rte_memory.h>
      22                 :            : #include <rte_mempool.h>
      23                 :            : #include <rte_common.h>
      24                 :            : 
      25                 :            : #ifdef __cplusplus
      26                 :            : extern "C" {
      27                 :            : #endif
      28                 :            : 
      29                 :            : /**
      30                 :            :  * Crypto IO Vector (in analogy with struct iovec)
      31                 :            :  * Supposed be used to pass input/output data buffers for crypto data-path
      32                 :            :  * functions.
      33                 :            :  */
      34                 :            : struct rte_crypto_vec {
      35                 :            :         /** virtual address of the data buffer */
      36                 :            :         void *base;
      37                 :            :         /** IOVA of the data buffer */
      38                 :            :         rte_iova_t iova;
      39                 :            :         /** length of the data buffer */
      40                 :            :         uint32_t len;
      41                 :            :         /** total buffer length */
      42                 :            :         uint32_t tot_len;
      43                 :            : };
      44                 :            : 
      45                 :            : /**
      46                 :            :  * Crypto scatter-gather list descriptor. Consists of a pointer to an array
      47                 :            :  * of Crypto IO vectors with its size.
      48                 :            :  */
      49                 :            : struct rte_crypto_sgl {
      50                 :            :         /** start of an array of vectors */
      51                 :            :         struct rte_crypto_vec *vec;
      52                 :            :         /** size of an array of vectors */
      53                 :            :         uint32_t num;
      54                 :            : };
      55                 :            : 
      56                 :            : /**
      57                 :            :  * Crypto virtual and IOVA address descriptor, used to describe cryptographic
      58                 :            :  * data buffer without the length information. The length information is
      59                 :            :  * normally predefined during session creation.
      60                 :            :  */
      61                 :            : struct rte_crypto_va_iova_ptr {
      62                 :            :         void *va;
      63                 :            :         rte_iova_t iova;
      64                 :            : };
      65                 :            : 
      66                 :            : /**
      67                 :            :  * Raw data operation descriptor.
      68                 :            :  * Supposed to be used with synchronous CPU crypto API call or asynchronous
      69                 :            :  * RAW data path API call.
      70                 :            :  */
      71                 :            : struct rte_crypto_sym_vec {
      72                 :            :         /** number of operations to perform */
      73                 :            :         uint32_t num;
      74                 :            :         /** array of SGL vectors */
      75                 :            :         struct rte_crypto_sgl *src_sgl;
      76                 :            :         /** array of SGL vectors for OOP, keep it NULL for inplace*/
      77                 :            :         struct rte_crypto_sgl *dest_sgl;
      78                 :            :         /** array of pointers to cipher IV */
      79                 :            :         struct rte_crypto_va_iova_ptr *iv;
      80                 :            :         /** array of pointers to digest */
      81                 :            :         struct rte_crypto_va_iova_ptr *digest;
      82                 :            : 
      83                 :            :         __extension__
      84                 :            :         union {
      85                 :            :                 /** array of pointers to auth IV, used for chain operation */
      86                 :            :                 struct rte_crypto_va_iova_ptr *auth_iv;
      87                 :            :                 /** array of pointers to AAD, used for AEAD operation */
      88                 :            :                 struct rte_crypto_va_iova_ptr *aad;
      89                 :            :         };
      90                 :            : 
      91                 :            :         /**
      92                 :            :          * array of statuses for each operation:
      93                 :            :          * - 0 on success
      94                 :            :          * - errno on error
      95                 :            :          */
      96                 :            :         int32_t *status;
      97                 :            : };
      98                 :            : 
      99                 :            : /**
     100                 :            :  * used for cpu_crypto_process_bulk() to specify head/tail offsets
     101                 :            :  * for auth/cipher processing.
     102                 :            :  */
     103                 :            : union rte_crypto_sym_ofs {
     104                 :            :         uint64_t raw;
     105                 :            :         struct {
     106                 :            :                 struct {
     107                 :            :                         uint16_t head;
     108                 :            :                         uint16_t tail;
     109                 :            :                 } auth, cipher;
     110                 :            :         } ofs;
     111                 :            : };
     112                 :            : 
     113                 :            : /** Symmetric Cipher Algorithms
     114                 :            :  *
     115                 :            :  * Note, to avoid ABI breakage across releases
     116                 :            :  * - LIST_END should not be added to this enum
     117                 :            :  * - the order of enums should not be changed
     118                 :            :  * - new algorithms should only be added to the end
     119                 :            :  */
     120                 :            : enum rte_crypto_cipher_algorithm {
     121                 :            :         RTE_CRYPTO_CIPHER_NULL = 1,
     122                 :            :         /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
     123                 :            : 
     124                 :            :         RTE_CRYPTO_CIPHER_3DES_CBC,
     125                 :            :         /**< Triple DES algorithm in CBC mode */
     126                 :            :         RTE_CRYPTO_CIPHER_3DES_CTR,
     127                 :            :         /**< Triple DES algorithm in CTR mode */
     128                 :            :         RTE_CRYPTO_CIPHER_3DES_ECB,
     129                 :            :         /**< Triple DES algorithm in ECB mode */
     130                 :            : 
     131                 :            :         RTE_CRYPTO_CIPHER_AES_CBC,
     132                 :            :         /**< AES algorithm in CBC mode */
     133                 :            :         RTE_CRYPTO_CIPHER_AES_CTR,
     134                 :            :         /**< AES algorithm in Counter mode */
     135                 :            :         RTE_CRYPTO_CIPHER_AES_ECB,
     136                 :            :         /**< AES algorithm in ECB mode */
     137                 :            :         RTE_CRYPTO_CIPHER_AES_F8,
     138                 :            :         /**< AES algorithm in F8 mode */
     139                 :            :         RTE_CRYPTO_CIPHER_AES_XTS,
     140                 :            :         /**< AES algorithm in XTS mode */
     141                 :            : 
     142                 :            :         RTE_CRYPTO_CIPHER_ARC4,
     143                 :            :         /**< (A)RC4 cipher algorithm */
     144                 :            : 
     145                 :            :         RTE_CRYPTO_CIPHER_KASUMI_F8,
     146                 :            :         /**< KASUMI algorithm in F8 mode */
     147                 :            : 
     148                 :            :         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
     149                 :            :         /**< SNOW 3G algorithm in UEA2 mode */
     150                 :            : 
     151                 :            :         RTE_CRYPTO_CIPHER_ZUC_EEA3,
     152                 :            :         /**< ZUC algorithm in EEA3 mode */
     153                 :            : 
     154                 :            :         RTE_CRYPTO_CIPHER_DES_CBC,
     155                 :            :         /**< DES algorithm in CBC mode */
     156                 :            : 
     157                 :            :         RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
     158                 :            :         /**< AES algorithm using modes required by
     159                 :            :          * DOCSIS Baseline Privacy Plus Spec.
     160                 :            :          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
     161                 :            :          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
     162                 :            :          */
     163                 :            : 
     164                 :            :         RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
     165                 :            :         /**< DES algorithm using modes required by
     166                 :            :          * DOCSIS Baseline Privacy Plus Spec.
     167                 :            :          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
     168                 :            :          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
     169                 :            :          */
     170                 :            : 
     171                 :            :         RTE_CRYPTO_CIPHER_SM4_ECB,
     172                 :            :         /**< ShangMi 4 (SM4) algorithm in ECB mode */
     173                 :            :         RTE_CRYPTO_CIPHER_SM4_CBC,
     174                 :            :         /**< ShangMi 4 (SM4) algorithm in CBC mode */
     175                 :            :         RTE_CRYPTO_CIPHER_SM4_CTR,
     176                 :            :         /**< ShangMi 4 (SM4) algorithm in CTR mode */
     177                 :            :         RTE_CRYPTO_CIPHER_SM4_OFB,
     178                 :            :         /**< ShangMi 4 (SM4) algorithm in OFB mode */
     179                 :            :         RTE_CRYPTO_CIPHER_SM4_CFB,
     180                 :            :         /**< ShangMi 4 (SM4) algorithm in CFB mode */
     181                 :            :         RTE_CRYPTO_CIPHER_SM4_XTS,
     182                 :            :         /**< ShangMi 4 (SM4) algorithm in XTS mode */
     183                 :            : 
     184                 :            :         RTE_CRYPTO_CIPHER_SNOW5G_NEA4,
     185                 :            :         /**< Snow 5G algorithm in NEA4 mode */
     186                 :            :         RTE_CRYPTO_CIPHER_AES_NEA5,
     187                 :            :         /**< AES algorithm in NEA5 mode */
     188                 :            :         RTE_CRYPTO_CIPHER_ZUC_NEA6,
     189                 :            :         /**< ZUC-256 algorithm in NEA6 mode */
     190                 :            : };
     191                 :            : 
     192                 :            : /** Symmetric Cipher Direction */
     193                 :            : enum rte_crypto_cipher_operation {
     194                 :            :         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
     195                 :            :         /**< Encrypt cipher operation */
     196                 :            :         RTE_CRYPTO_CIPHER_OP_DECRYPT
     197                 :            :         /**< Decrypt cipher operation */
     198                 :            : };
     199                 :            : 
     200                 :            : /** Cipher operation name strings */
     201                 :            : extern const char *
     202                 :            : rte_crypto_cipher_operation_strings[];
     203                 :            : 
     204                 :            : /**
     205                 :            :  * Symmetric Cipher Setup Data.
     206                 :            :  *
     207                 :            :  * This structure contains data relating to Cipher (Encryption and Decryption)
     208                 :            :  *  use to create a session.
     209                 :            :  */
     210                 :            : struct rte_crypto_cipher_xform {
     211                 :            :         enum rte_crypto_cipher_operation op;
     212                 :            :         /**< This parameter determines if the cipher operation is an encrypt or
     213                 :            :          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
     214                 :            :          * only encrypt operations are valid.
     215                 :            :          */
     216                 :            :         enum rte_crypto_cipher_algorithm algo;
     217                 :            :         /**< Cipher algorithm */
     218                 :            : 
     219                 :            :         struct {
     220                 :            :                 const uint8_t *data;    /**< pointer to key data */
     221                 :            :                 uint16_t length;        /**< key length in bytes */
     222                 :            :         } key;
     223                 :            :         /**< Cipher key
     224                 :            :          *
     225                 :            :          * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the
     226                 :            :          * original key data provided may be wrapped(encrypted) using key wrap
     227                 :            :          * algorithm such as AES key wrap (rfc3394) and hence length of the key
     228                 :            :          * may increase beyond the PMD advertised supported key size.
     229                 :            :          * PMD shall validate the key length and report EMSGSIZE error while
     230                 :            :          * configuring the session and application can skip checking the
     231                 :            :          * capability key length in such cases.
     232                 :            :          *
     233                 :            :          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
     234                 :            :          * point to a concatenation of the AES encryption key followed by a
     235                 :            :          * keymask. As per RFC3711, the keymask should be padded with trailing
     236                 :            :          * bytes to match the length of the encryption key used.
     237                 :            :          *
     238                 :            :          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
     239                 :            :          * 192 bits (24 bytes) or 256 bits (32 bytes).
     240                 :            :          *
     241                 :            :          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
     242                 :            :          * should be set to the combined length of the encryption key and the
     243                 :            :          * keymask. Since the keymask and the encryption key are the same size,
     244                 :            :          * key.length should be set to 2 x the AES encryption key length.
     245                 :            :          *
     246                 :            :          * For the AES-XTS mode of operation:
     247                 :            :          *  - Two keys must be provided and key.length refers to total length of
     248                 :            :          *    the two keys.
     249                 :            :          *  - key.data must point to the two keys concatenated together
     250                 :            :          *    (key1 || key2).
     251                 :            :          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
     252                 :            :          *  - Both keys must have the same size.
     253                 :            :          */
     254                 :            :         struct {
     255                 :            :                 uint16_t offset;
     256                 :            :                 /**< Starting point for Initialisation Vector or Counter,
     257                 :            :                  * specified as number of bytes from start of crypto
     258                 :            :                  * operation (rte_crypto_op).
     259                 :            :                  *
     260                 :            :                  * - For block ciphers in CBC or F8 mode, or for KASUMI
     261                 :            :                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
     262                 :            :                  * Initialisation Vector (IV) value.
     263                 :            :                  *
     264                 :            :                  * - For block ciphers in CTR mode, this is the counter.
     265                 :            :                  *
     266                 :            :                  * - For CCM mode, the first byte is reserved, and the
     267                 :            :                  * nonce should be written starting at &iv[1] (to allow
     268                 :            :                  * space for the implementation to write in the flags
     269                 :            :                  * in the first byte). Note that a full 16 bytes should
     270                 :            :                  * be allocated, even though the length field will
     271                 :            :                  * have a value less than this. Note that the PMDs may
     272                 :            :                  * modify the memory reserved (the first byte and the
     273                 :            :                  * final padding)
     274                 :            :                  *
     275                 :            :                  * - For AES-XTS, this is the 128bit tweak, i, from
     276                 :            :                  * IEEE Std 1619-2007.
     277                 :            :                  *
     278                 :            :                  * For optimum performance, the data pointed to SHOULD
     279                 :            :                  * be 8-byte aligned.
     280                 :            :                  */
     281                 :            :                 uint16_t length;
     282                 :            :                 /**< Length of valid IV data.
     283                 :            :                  *
     284                 :            :                  * - For block ciphers in CBC or F8 mode, or for KASUMI
     285                 :            :                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
     286                 :            :                  * length of the IV (which must be the same as the
     287                 :            :                  * block length of the cipher).
     288                 :            :                  *
     289                 :            :                  * - For block ciphers in CTR mode, this is the length
     290                 :            :                  * of the counter (which must be the same as the block
     291                 :            :                  * length of the cipher) or a 12-byte nonce (AES only)
     292                 :            :                  *
     293                 :            :                  * - For CCM mode, this is the length of the nonce,
     294                 :            :                  * which can be in the range 7 to 13 inclusive.
     295                 :            :                  */
     296                 :            :         } iv;   /**< Initialisation vector parameters */
     297                 :            : 
     298                 :            :         uint32_t dataunit_len;
     299                 :            :         /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled,
     300                 :            :          * this is the data-unit length of the algorithm,
     301                 :            :          * otherwise or when the value is 0, use the operation length.
     302                 :            :          * The value should be in the range defined by the dataunit_set field
     303                 :            :          * in the cipher capability.
     304                 :            :          *
     305                 :            :          * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
     306                 :            :          * For-each data-unit in the operation, the tweak (IV) value is
     307                 :            :          * assigned consecutively starting from the operation assigned IV.
     308                 :            :          */
     309                 :            : };
     310                 :            : 
     311                 :            : /** Symmetric Authentication / Hash Algorithms
     312                 :            :  *
     313                 :            :  * Note, to avoid ABI breakage across releases
     314                 :            :  * - LIST_END should not be added to this enum
     315                 :            :  * - the order of enums should not be changed
     316                 :            :  * - new algorithms should only be added to the end
     317                 :            :  */
     318                 :            : enum rte_crypto_auth_algorithm {
     319                 :            :         RTE_CRYPTO_AUTH_NULL = 1,
     320                 :            :         /**< NULL hash algorithm. */
     321                 :            : 
     322                 :            :         RTE_CRYPTO_AUTH_AES_CBC_MAC,
     323                 :            :         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
     324                 :            :         RTE_CRYPTO_AUTH_AES_CMAC,
     325                 :            :         /**< AES CMAC algorithm. */
     326                 :            :         RTE_CRYPTO_AUTH_AES_GMAC,
     327                 :            :         /**< AES GMAC algorithm. */
     328                 :            :         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
     329                 :            :         /**< AES XCBC algorithm. */
     330                 :            : 
     331                 :            :         RTE_CRYPTO_AUTH_KASUMI_F9,
     332                 :            :         /**< KASUMI algorithm in F9 mode. */
     333                 :            : 
     334                 :            :         RTE_CRYPTO_AUTH_MD5,
     335                 :            :         /**< MD5 algorithm */
     336                 :            :         RTE_CRYPTO_AUTH_MD5_HMAC,
     337                 :            :         /**< HMAC using MD5 algorithm */
     338                 :            : 
     339                 :            :         RTE_CRYPTO_AUTH_SHA1,
     340                 :            :         /**< 160 bit SHA algorithm. */
     341                 :            :         RTE_CRYPTO_AUTH_SHA1_HMAC,
     342                 :            :         /**< HMAC using 160 bit SHA algorithm.
     343                 :            :          * HMAC-SHA-1-96 can be generated by setting
     344                 :            :          * digest_length to 12 bytes in auth/aead xforms.
     345                 :            :          */
     346                 :            :         RTE_CRYPTO_AUTH_SHA224,
     347                 :            :         /**< 224 bit SHA algorithm. */
     348                 :            :         RTE_CRYPTO_AUTH_SHA224_HMAC,
     349                 :            :         /**< HMAC using 224 bit SHA algorithm. */
     350                 :            :         RTE_CRYPTO_AUTH_SHA256,
     351                 :            :         /**< 256 bit SHA algorithm. */
     352                 :            :         RTE_CRYPTO_AUTH_SHA256_HMAC,
     353                 :            :         /**< HMAC using 256 bit SHA algorithm. */
     354                 :            :         RTE_CRYPTO_AUTH_SHA384,
     355                 :            :         /**< 384 bit SHA algorithm. */
     356                 :            :         RTE_CRYPTO_AUTH_SHA384_HMAC,
     357                 :            :         /**< HMAC using 384 bit SHA algorithm. */
     358                 :            :         RTE_CRYPTO_AUTH_SHA512,
     359                 :            :         /**< 512 bit SHA algorithm. */
     360                 :            :         RTE_CRYPTO_AUTH_SHA512_HMAC,
     361                 :            :         /**< HMAC using 512 bit SHA algorithm. */
     362                 :            : 
     363                 :            :         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
     364                 :            :         /**< SNOW 3G algorithm in UIA2 mode. */
     365                 :            : 
     366                 :            :         RTE_CRYPTO_AUTH_ZUC_EIA3,
     367                 :            :         /**< ZUC algorithm in EIA3 mode */
     368                 :            : 
     369                 :            :         RTE_CRYPTO_AUTH_SHA3_224,
     370                 :            :         /**< 224 bit SHA3 algorithm. */
     371                 :            :         RTE_CRYPTO_AUTH_SHA3_224_HMAC,
     372                 :            :         /**< HMAC using 224 bit SHA3 algorithm. */
     373                 :            :         RTE_CRYPTO_AUTH_SHA3_256,
     374                 :            :         /**< 256 bit SHA3 algorithm. */
     375                 :            :         RTE_CRYPTO_AUTH_SHA3_256_HMAC,
     376                 :            :         /**< HMAC using 256 bit SHA3 algorithm. */
     377                 :            :         RTE_CRYPTO_AUTH_SHA3_384,
     378                 :            :         /**< 384 bit SHA3 algorithm. */
     379                 :            :         RTE_CRYPTO_AUTH_SHA3_384_HMAC,
     380                 :            :         /**< HMAC using 384 bit SHA3 algorithm. */
     381                 :            :         RTE_CRYPTO_AUTH_SHA3_512,
     382                 :            :         /**< 512 bit SHA3 algorithm. */
     383                 :            :         RTE_CRYPTO_AUTH_SHA3_512_HMAC,
     384                 :            :         /**< HMAC using 512 bit SHA3 algorithm. */
     385                 :            :         RTE_CRYPTO_AUTH_SM3,
     386                 :            :         /**< ShangMi 3 (SM3) algorithm */
     387                 :            : 
     388                 :            :         RTE_CRYPTO_AUTH_SHAKE_128,
     389                 :            :         /**< 128 bit SHAKE algorithm. */
     390                 :            :         RTE_CRYPTO_AUTH_SHAKE_256,
     391                 :            :         /**< 256 bit SHAKE algorithm. */
     392                 :            :         RTE_CRYPTO_AUTH_SM3_HMAC,
     393                 :            :         /** < HMAC using ShangMi 3 (SM3) algorithm */
     394                 :            : 
     395                 :            :         RTE_CRYPTO_AUTH_SNOW5G_NIA4,
     396                 :            :         /**< Snow 5G algorithm in NIA4 mode */
     397                 :            :         RTE_CRYPTO_AUTH_AES_NIA5,
     398                 :            :         /**< AES algorithm in NIA5 mode */
     399                 :            :         RTE_CRYPTO_AUTH_ZUC_NIA6,
     400                 :            :         /**< ZUC-256 algorithm in NIA6 mode */
     401                 :            : 
     402                 :            : };
     403                 :            : 
     404                 :            : /** Symmetric Authentication / Hash Operations */
     405                 :            : enum rte_crypto_auth_operation {
     406                 :            :         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
     407                 :            :         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
     408                 :            : };
     409                 :            : 
     410                 :            : /** Authentication operation name strings */
     411                 :            : extern const char *
     412                 :            : rte_crypto_auth_operation_strings[];
     413                 :            : 
     414                 :            : /**
     415                 :            :  * Authentication / Hash transform data.
     416                 :            :  *
     417                 :            :  * This structure contains data relating to an authentication/hash crypto
     418                 :            :  * transforms. The fields op, algo and digest_length are common to all
     419                 :            :  * authentication transforms and MUST be set.
     420                 :            :  */
     421                 :            : struct rte_crypto_auth_xform {
     422                 :            :         enum rte_crypto_auth_operation op;
     423                 :            :         /**< Authentication operation type */
     424                 :            :         enum rte_crypto_auth_algorithm algo;
     425                 :            :         /**< Authentication algorithm selection */
     426                 :            : 
     427                 :            :         struct {
     428                 :            :                 const uint8_t *data;    /**< pointer to key data */
     429                 :            :                 uint16_t length;        /**< key length in bytes */
     430                 :            :         } key;
     431                 :            :         /**< Authentication key data.
     432                 :            :          * The authentication key length MUST be less than or equal to the
     433                 :            :          * block size of the algorithm. It is the callers responsibility to
     434                 :            :          * ensure that the key length is compliant with the standard being used
     435                 :            :          * (for example RFC 2104, FIPS 198a).
     436                 :            :          */
     437                 :            : 
     438                 :            :         struct {
     439                 :            :                 uint16_t offset;
     440                 :            :                 /**< Starting point for Initialisation Vector or Counter,
     441                 :            :                  * specified as number of bytes from start of crypto
     442                 :            :                  * operation (rte_crypto_op).
     443                 :            :                  *
     444                 :            :                  * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
     445                 :            :                  *   this is the authentication Initialisation Vector
     446                 :            :                  *   (IV) value. For AES-GMAC IV description please refer
     447                 :            :                  *   to the field `length` in iv struct.
     448                 :            :                  *
     449                 :            :                  * - For KASUMI in F9 mode and other authentication
     450                 :            :                  *   algorithms, this field is not used.
     451                 :            :                  *
     452                 :            :                  * For optimum performance, the data pointed to SHOULD
     453                 :            :                  * be 8-byte aligned.
     454                 :            :                  */
     455                 :            :                 uint16_t length;
     456                 :            :                 /**< Length of valid IV data.
     457                 :            :                  *
     458                 :            :                  * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
     459                 :            :                  *   for AES-GMAC, this is the length of the IV.
     460                 :            :                  *
     461                 :            :                  * - For KASUMI in F9 mode and other authentication
     462                 :            :                  *   algorithms, this field is not used.
     463                 :            :                  *
     464                 :            :                  * - For GMAC mode, this is either:
     465                 :            :                  * 1) Number greater or equal to one, which means that IV
     466                 :            :                  *    is used and J0 will be computed internally, a minimum
     467                 :            :                  *    of 16 bytes must be allocated.
     468                 :            :                  * 2) Zero, in which case data points to J0. In this case
     469                 :            :                  *    16 bytes of J0 should be passed where J0 is defined
     470                 :            :                  *    by NIST SP800-38D.
     471                 :            :                  *
     472                 :            :                  */
     473                 :            :         } iv;   /**< Initialisation vector parameters */
     474                 :            : 
     475                 :            :         uint16_t digest_length;
     476                 :            :         /**< Length of the digest to be returned. If the verify option is set,
     477                 :            :          * this specifies the length of the digest to be compared for the
     478                 :            :          * session.
     479                 :            :          *
     480                 :            :          * It is the caller's responsibility to ensure that the
     481                 :            :          * digest length is compliant with the hash algorithm being used.
     482                 :            :          * If the value is less than the maximum length allowed by the hash,
     483                 :            :          * the result shall be truncated.
     484                 :            :          */
     485                 :            : };
     486                 :            : 
     487                 :            : 
     488                 :            : /** Symmetric AEAD Algorithms
     489                 :            :  *
     490                 :            :  * Note, to avoid ABI breakage across releases
     491                 :            :  * - LIST_END should not be added to this enum
     492                 :            :  * - the order of enums should not be changed
     493                 :            :  * - new algorithms should only be added to the end
     494                 :            :  */
     495                 :            : enum rte_crypto_aead_algorithm {
     496                 :            :         RTE_CRYPTO_AEAD_AES_CCM = 1,
     497                 :            :         /**< AES algorithm in CCM mode. */
     498                 :            :         RTE_CRYPTO_AEAD_AES_GCM,
     499                 :            :         /**< AES algorithm in GCM mode. */
     500                 :            :         RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
     501                 :            :         /**< Chacha20 cipher with poly1305 authenticator */
     502                 :            :         RTE_CRYPTO_AEAD_SM4_GCM,
     503                 :            :         /**< SM4 cipher in GCM mode */
     504                 :            : 
     505                 :            :         RTE_CRYPTO_AEAD_SNOW5G_NCA4,
     506                 :            :         /**< Snow 5G algorithm in NCA4 mode */
     507                 :            :         RTE_CRYPTO_AEAD_AES_NCA5,
     508                 :            :         /**< AES algorithm in NCA5 mode */
     509                 :            :         RTE_CRYPTO_AEAD_ZUC_NCA6,
     510                 :            :         /**< ZUC-256 algorithm in NCA6 mode */
     511                 :            : };
     512                 :            : 
     513                 :            : /** Symmetric AEAD Operations */
     514                 :            : enum rte_crypto_aead_operation {
     515                 :            :         RTE_CRYPTO_AEAD_OP_ENCRYPT,
     516                 :            :         /**< Encrypt and generate digest */
     517                 :            :         RTE_CRYPTO_AEAD_OP_DECRYPT
     518                 :            :         /**< Verify digest and decrypt */
     519                 :            : };
     520                 :            : 
     521                 :            : /** Authentication operation name strings */
     522                 :            : extern const char *
     523                 :            : rte_crypto_aead_operation_strings[];
     524                 :            : 
     525                 :            : struct rte_crypto_aead_xform {
     526                 :            :         enum rte_crypto_aead_operation op;
     527                 :            :         /**< AEAD operation type */
     528                 :            :         enum rte_crypto_aead_algorithm algo;
     529                 :            :         /**< AEAD algorithm selection */
     530                 :            : 
     531                 :            :         struct {
     532                 :            :                 const uint8_t *data;    /**< pointer to key data */
     533                 :            :                 uint16_t length;        /**< key length in bytes */
     534                 :            :         } key;
     535                 :            : 
     536                 :            :         struct {
     537                 :            :                 uint16_t offset;
     538                 :            :                 /**< Starting point for Initialisation Vector or Counter,
     539                 :            :                  * specified as number of bytes from start of crypto
     540                 :            :                  * operation (rte_crypto_op).
     541                 :            :                  *
     542                 :            :                  * - For CCM mode, the first byte is reserved, and the
     543                 :            :                  * nonce should be written starting at &iv[1] (to allow
     544                 :            :                  * space for the implementation to write in the flags
     545                 :            :                  * in the first byte). Note that a full 16 bytes should
     546                 :            :                  * be allocated, even though the length field will
     547                 :            :                  * have a value less than this.
     548                 :            :                  *
     549                 :            :                  * - For Chacha20-Poly1305 it is 96-bit nonce.
     550                 :            :                  * PMD sets initial counter for Poly1305 key generation
     551                 :            :                  * part to 0 and for Chacha20 encryption to 1 as per
     552                 :            :                  * rfc8439 2.8. AEAD construction.
     553                 :            :                  *
     554                 :            :                  * For optimum performance, the data pointed to SHOULD
     555                 :            :                  * be 8-byte aligned.
     556                 :            :                  */
     557                 :            :                 uint16_t length;
     558                 :            :                 /**< Length of valid IV data.
     559                 :            :                  *
     560                 :            :                  * - For GCM mode, this is either:
     561                 :            :                  * 1) Number greater or equal to one, which means that IV
     562                 :            :                  *    is used and J0 will be computed internally, a minimum
     563                 :            :                  *    of 16 bytes must be allocated.
     564                 :            :                  * 2) Zero, in which case data points to J0. In this case
     565                 :            :                  *    16 bytes of J0 should be passed where J0 is defined
     566                 :            :                  *    by NIST SP800-38D.
     567                 :            :                  *
     568                 :            :                  * - For CCM mode, this is the length of the nonce,
     569                 :            :                  * which can be in the range 7 to 13 inclusive.
     570                 :            :                  *
     571                 :            :                  * - For Chacha20-Poly1305 this field is always 12.
     572                 :            :                  */
     573                 :            :         } iv;   /**< Initialisation vector parameters */
     574                 :            : 
     575                 :            :         uint16_t digest_length;
     576                 :            : 
     577                 :            :         uint16_t aad_length;
     578                 :            :         /**< The length of the additional authenticated data (AAD) in bytes.
     579                 :            :          * For CCM mode, this is the length of the actual AAD, even though
     580                 :            :          * it is required to reserve 18 bytes before the AAD and padding
     581                 :            :          * at the end of it, so a multiple of 16 bytes is allocated.
     582                 :            :          */
     583                 :            : };
     584                 :            : 
     585                 :            : /** Crypto transformation types */
     586                 :            : enum rte_crypto_sym_xform_type {
     587                 :            :         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
     588                 :            :         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
     589                 :            :         RTE_CRYPTO_SYM_XFORM_CIPHER,            /**< Cipher xform  */
     590                 :            :         RTE_CRYPTO_SYM_XFORM_AEAD               /**< AEAD xform  */
     591                 :            : };
     592                 :            : 
     593                 :            : /**
     594                 :            :  * Symmetric crypto transform structure.
     595                 :            :  *
     596                 :            :  * This is used to specify the crypto transforms required, multiple transforms
     597                 :            :  * can be chained together to specify a chain transforms such as authentication
     598                 :            :  * then cipher, or cipher then authentication. Each transform structure can
     599                 :            :  * hold a single transform, the type field is used to specify which transform
     600                 :            :  * is contained within the union
     601                 :            :  */
     602                 :            : /* Structure rte_crypto_sym_xform 8< */
     603                 :            : struct rte_crypto_sym_xform {
     604                 :            :         struct rte_crypto_sym_xform *next;
     605                 :            :         /**< next xform in chain */
     606                 :            :         enum rte_crypto_sym_xform_type type
     607                 :            :         ; /**< xform type */
     608                 :            :         union {
     609                 :            :                 struct rte_crypto_auth_xform auth;
     610                 :            :                 /**< Authentication / hash xform */
     611                 :            :                 struct rte_crypto_cipher_xform cipher;
     612                 :            :                 /**< Cipher xform */
     613                 :            :                 struct rte_crypto_aead_xform aead;
     614                 :            :                 /**< AEAD xform */
     615                 :            :         };
     616                 :            : };
     617                 :            : /* >8 End of structure rte_crypto_sym_xform. */
     618                 :            : 
     619                 :            : /**
     620                 :            :  * Symmetric Cryptographic Operation.
     621                 :            :  *
     622                 :            :  * This structure contains data relating to performing symmetric cryptographic
     623                 :            :  * processing on a referenced mbuf data buffer.
     624                 :            :  *
     625                 :            :  * When a symmetric crypto operation is enqueued with the device for processing
     626                 :            :  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
     627                 :            :  * which contains the source data which the crypto operation is to be performed
     628                 :            :  * on.
     629                 :            :  * While the mbuf is in use by a crypto operation no part of the mbuf should be
     630                 :            :  * changed by the application as the device may read or write to any part of the
     631                 :            :  * mbuf. In the case of hardware crypto devices some or all of the mbuf
     632                 :            :  * may be DMAed in and out of the device, so writing over the original data,
     633                 :            :  * though only the part specified by the rte_crypto_sym_op for transformation
     634                 :            :  * will be changed.
     635                 :            :  * Out-of-place (OOP) operation, where the source mbuf is different to the
     636                 :            :  * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
     637                 :            :  * The part copied includes all the parts of the source mbuf that will be
     638                 :            :  * operated on, based on the cipher.data.offset+cipher.data.length and
     639                 :            :  * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
     640                 :            :  * indicated by the cipher parameters will be transformed, any extra data around
     641                 :            :  * this indicated by the auth parameters will be copied unchanged from source to
     642                 :            :  * destination mbuf.
     643                 :            :  * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
     644                 :            :  * both source and destination mbufs. As these offsets are relative to the
     645                 :            :  * data_off parameter in each mbuf this can result in the data written to the
     646                 :            :  * destination buffer being at a different alignment, relative to buffer start,
     647                 :            :  * to the data in the source buffer.
     648                 :            :  */
     649                 :            : /* Structure rte_crypto_sym_op 8< */
     650                 :            : struct rte_crypto_sym_op {
     651                 :            :         struct rte_mbuf *m_src; /**< source mbuf */
     652                 :            :         struct rte_mbuf *m_dst; /**< destination mbuf */
     653                 :            : 
     654                 :            :         union {
     655                 :            :                 void *session;
     656                 :            :                 /**< Handle for the initialised crypto/security session context */
     657                 :            :                 struct rte_crypto_sym_xform *xform;
     658                 :            :                 /**< Session-less API crypto operation parameters */
     659                 :            :         };
     660                 :            : 
     661                 :            :         union {
     662                 :            :                 struct {
     663                 :            :                         struct {
     664                 :            :                                 uint32_t offset;
     665                 :            :                                  /**< Starting point for AEAD processing, specified as
     666                 :            :                                   * number of bytes from start of packet in source
     667                 :            :                                   * buffer.
     668                 :            :                                   */
     669                 :            :                                 uint32_t length;
     670                 :            :                                  /**< The message length, in bytes, of the source buffer
     671                 :            :                                   * on which the cryptographic operation will be
     672                 :            :                                   * computed.
     673                 :            :                                   */
     674                 :            :                         } data; /**< Data offsets and length for AEAD */
     675                 :            :                         struct {
     676                 :            :                                 uint8_t *data;
     677                 :            :                                 /**< This points to the location where the digest result
     678                 :            :                                  * should be inserted (in the case of digest generation)
     679                 :            :                                  * or where the purported digest exists (in the case of
     680                 :            :                                  * digest verification).
     681                 :            :                                  *
     682                 :            :                                  * At session creation time, the client specified the
     683                 :            :                                  * digest result length with the digest_length member
     684                 :            :                                  * of the @ref rte_crypto_auth_xform structure. For
     685                 :            :                                  * physical crypto devices the caller must allocate at
     686                 :            :                                  * least digest_length of physically contiguous memory
     687                 :            :                                  * at this location.
     688                 :            :                                  *
     689                 :            :                                  * For digest generation, the digest result will
     690                 :            :                                  * overwrite any data at this location.
     691                 :            :                                  *
     692                 :            :                                  * @note
     693                 :            :                                  * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
     694                 :            :                                  * "digest result" read "authentication tag T".
     695                 :            :                                  */
     696                 :            :                                 rte_iova_t phys_addr;
     697                 :            :                                 /**< Physical address of digest */
     698                 :            :                         } digest; /**< Digest parameters */
     699                 :            :                         struct {
     700                 :            :                                 uint8_t *data;
     701                 :            :                                 /**< Pointer to Additional Authenticated Data (AAD)
     702                 :            :                                  * needed for authenticated cipher mechanisms (CCM and
     703                 :            :                                  * GCM)
     704                 :            :                                  *
     705                 :            :                                  * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
     706                 :            :                                  * the caller should setup this field as follows:
     707                 :            :                                  *
     708                 :            :                                  * - the additional authentication data itself should
     709                 :            :                                  * be written starting at an offset of 18 bytes into
     710                 :            :                                  * the array, leaving room for the first block (16 bytes)
     711                 :            :                                  * and the length encoding in the first two bytes of the
     712                 :            :                                  * second block.
     713                 :            :                                  *
     714                 :            :                                  * - Note that PMDs may modify the memory reserved
     715                 :            :                                  * (first 18 bytes and the final padding).
     716                 :            :                                  *
     717                 :            :                                  * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
     718                 :            :                                  * caller should setup this field as follows:
     719                 :            :                                  *
     720                 :            :                                  */
     721                 :            :                                 rte_iova_t phys_addr;   /**< physical address */
     722                 :            :                         } aad;
     723                 :            :                         /**< Additional authentication parameters */
     724                 :            :                 } aead;
     725                 :            : 
     726                 :            :                 struct {
     727                 :            :                         struct {
     728                 :            :                                 struct {
     729                 :            :                                         uint32_t offset;
     730                 :            :                                          /**< Starting point for cipher processing,
     731                 :            :                                           * specified as number of bytes from start
     732                 :            :                                           * of data in the source buffer.
     733                 :            :                                           * The result of the cipher operation will be
     734                 :            :                                           * written back into the output buffer
     735                 :            :                                           * starting at this location.
     736                 :            :                                           *
     737                 :            :                                           * @note
     738                 :            :                                           * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
     739                 :            :                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8,
     740                 :            :                                           * ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
     741                 :            :                                           * SNOW 5G @ RTE_CRYPTO_CIPHER_SNOW5G_NEA4,
     742                 :            :                                           * AES @ RTE_CRYPTO_CIPHER_AES_NEA5
     743                 :            :                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_NEA6
     744                 :            :                                           * this field should be in bits. For
     745                 :            :                                           * digest-encrypted cases this must be
     746                 :            :                                           * an 8-bit multiple.
     747                 :            :                                           */
     748                 :            :                                         uint32_t length;
     749                 :            :                                          /**< The message length, in bytes, of the
     750                 :            :                                           * source buffer on which the cryptographic
     751                 :            :                                           * operation will be computed.
     752                 :            :                                           * This is also the same as the result length.
     753                 :            :                                           * For block ciphers, this must be a
     754                 :            :                                           * multiple of the block size,
     755                 :            :                                           * or for the AES-XTS a multiple of the data-unit length
     756                 :            :                                           * as described in xform.
     757                 :            :                                           *
     758                 :            :                                           * @note
     759                 :            :                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
     760                 :            :                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8,
     761                 :            :                                           * ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
     762                 :            :                                           * SNOW 5G @ RTE_CRYPTO_CIPHER_SNOW5G_NEA4,
     763                 :            :                                           * AES @ RTE_CRYPTO_CIPHER_AES_NEA5
     764                 :            :                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_NEA6
     765                 :            :                                           * this field should be in bits. For
     766                 :            :                                           * digest-encrypted cases this must be
     767                 :            :                                           * an 8-bit multiple.
     768                 :            :                                           */
     769                 :            :                                 } data; /**< Data offsets and length for ciphering */
     770                 :            :                         } cipher;
     771                 :            : 
     772                 :            :                         struct {
     773                 :            :                                 struct {
     774                 :            :                                         uint32_t offset;
     775                 :            :                                          /**< Starting point for hash processing,
     776                 :            :                                           * specified as number of bytes from start of
     777                 :            :                                           * packet in source buffer.
     778                 :            :                                           *
     779                 :            :                                           * @note
     780                 :            :                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
     781                 :            :                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
     782                 :            :                                           * ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
     783                 :            :                                           * SNOW 5G @ RTE_CRYPTO_AUTH_SNOW5G_NIA4,
     784                 :            :                                           * AES @ RTE_CRYPTO_AUTH_AES_NIA5
     785                 :            :                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_NIA6
     786                 :            :                                           * this field should be in bits. For
     787                 :            :                                           * digest-encrypted cases this must be
     788                 :            :                                           * an 8-bit multiple.
     789                 :            :                                           *
     790                 :            :                                           * @note
     791                 :            :                                           * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
     792                 :            :                                           * this offset should be such that
     793                 :            :                                           * data to authenticate starts at COUNT.
     794                 :            :                                           *
     795                 :            :                                           * @note
     796                 :            :                                           * For DOCSIS security protocol, this
     797                 :            :                                           * offset is the DOCSIS header length
     798                 :            :                                           * and, therefore, also the CRC offset
     799                 :            :                                           * i.e. the number of bytes into the
     800                 :            :                                           * packet at which CRC calculation
     801                 :            :                                           * should begin.
     802                 :            :                                           */
     803                 :            :                                         uint32_t length;
     804                 :            :                                          /**< The message length, in bytes, of the source
     805                 :            :                                           * buffer that the hash will be computed on.
     806                 :            :                                           *
     807                 :            :                                           * @note
     808                 :            :                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
     809                 :            :                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
     810                 :            :                                           * ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
     811                 :            :                                           * SNOW 5G @ RTE_CRYPTO_AUTH_SNOW5G_NIA4,
     812                 :            :                                           * AES @ RTE_CRYPTO_AUTH_AES_NIA5
     813                 :            :                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_NIA6
     814                 :            :                                           * this field should be in bits. For
     815                 :            :                                           * digest-encrypted cases this must be
     816                 :            :                                           * an 8-bit multiple.
     817                 :            :                                           *
     818                 :            :                                           * @note
     819                 :            :                                           * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
     820                 :            :                                           * the length should include the COUNT,
     821                 :            :                                           * FRESH, message, direction bit and padding
     822                 :            :                                           * (to be multiple of 8 bits).
     823                 :            :                                           *
     824                 :            :                                           * @note
     825                 :            :                                           * For DOCSIS security protocol, this
     826                 :            :                                           * is the CRC length i.e. the number of
     827                 :            :                                           * bytes in the packet over which the
     828                 :            :                                           * CRC should be calculated
     829                 :            :                                           */
     830                 :            :                                 } data;
     831                 :            :                                 /**< Data offsets and length for authentication */
     832                 :            : 
     833                 :            :                                 struct {
     834                 :            :                                         uint8_t *data;
     835                 :            :                                         /**< This points to the location where
     836                 :            :                                          * the digest result should be inserted
     837                 :            :                                          * (in the case of digest generation)
     838                 :            :                                          * or where the purported digest exists
     839                 :            :                                          * (in the case of digest verification).
     840                 :            :                                          *
     841                 :            :                                          * At session creation time, the client
     842                 :            :                                          * specified the digest result length with
     843                 :            :                                          * the digest_length member of the
     844                 :            :                                          * @ref rte_crypto_auth_xform structure.
     845                 :            :                                          * For physical crypto devices the caller
     846                 :            :                                          * must allocate at least digest_length of
     847                 :            :                                          * physically contiguous memory at this
     848                 :            :                                          * location.
     849                 :            :                                          *
     850                 :            :                                          * For digest generation, the digest result
     851                 :            :                                          * will overwrite any data at this location.
     852                 :            :                                          *
     853                 :            :                                          * @note
     854                 :            :                                          * Digest-encrypted case.
     855                 :            :                                          * Digest can be generated, appended to
     856                 :            :                                          * the end of raw data and encrypted
     857                 :            :                                          * together using chained digest
     858                 :            :                                          * generation
     859                 :            :                                          * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
     860                 :            :                                          * and encryption
     861                 :            :                                          * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
     862                 :            :                                          * xforms. Similarly, authentication
     863                 :            :                                          * of the raw data against appended,
     864                 :            :                                          * decrypted digest, can be performed
     865                 :            :                                          * using decryption
     866                 :            :                                          * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
     867                 :            :                                          * and digest verification
     868                 :            :                                          * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
     869                 :            :                                          * chained xforms.
     870                 :            :                                          * To perform those operations, a few
     871                 :            :                                          * additional conditions must be met:
     872                 :            :                                          * - caller must allocate at least
     873                 :            :                                          * digest_length of memory at the end of
     874                 :            :                                          * source and (in case of out-of-place
     875                 :            :                                          * operations) destination buffer; those
     876                 :            :                                          * buffers can be linear or split using
     877                 :            :                                          * scatter-gather lists,
     878                 :            :                                          * - digest data pointer must point to
     879                 :            :                                          * the end of source or (in case of
     880                 :            :                                          * out-of-place operations) destination
     881                 :            :                                          * data, which is pointer to the
     882                 :            :                                          * data buffer + auth.data.offset +
     883                 :            :                                          * auth.data.length,
     884                 :            :                                          * - cipher.data.offset +
     885                 :            :                                          * cipher.data.length must be greater
     886                 :            :                                          * than auth.data.offset +
     887                 :            :                                          * auth.data.length and is typically
     888                 :            :                                          * equal to auth.data.offset +
     889                 :            :                                          * auth.data.length + digest_length.
     890                 :            :                                          * - for wireless algorithms, i.e.
     891                 :            :                                          * SNOW 3G, KASUMI and ZUC, as the
     892                 :            :                                          * cipher.data.length,
     893                 :            :                                          * cipher.data.offset,
     894                 :            :                                          * auth.data.length and
     895                 :            :                                          * auth.data.offset are in bits, they
     896                 :            :                                          * must be 8-bit multiples.
     897                 :            :                                          *
     898                 :            :                                          * Note, that for security reasons, it
     899                 :            :                                          * is PMDs' responsibility to not
     900                 :            :                                          * leave an unencrypted digest in any
     901                 :            :                                          * buffer after performing auth-cipher
     902                 :            :                                          * operations.
     903                 :            :                                          *
     904                 :            :                                          */
     905                 :            :                                         rte_iova_t phys_addr;
     906                 :            :                                         /**< Physical address of digest */
     907                 :            :                                 } digest; /**< Digest parameters */
     908                 :            :                         } auth;
     909                 :            :                 };
     910                 :            :         };
     911                 :            : };
     912                 :            : /* >8 End of structure rte_crypto_sym_op. */
     913                 :            : 
     914                 :            : 
     915                 :            : /**
     916                 :            :  * Reset the fields of a symmetric operation to their default values.
     917                 :            :  *
     918                 :            :  * @param       op      The crypto operation to be reset.
     919                 :            :  */
     920                 :            : static inline void
     921                 :            : __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
     922                 :            : {
     923                 :            :         memset(op, 0, sizeof(*op));
     924                 :       8464 : }
     925                 :            : 
     926                 :            : 
     927                 :            : /**
     928                 :            :  * Allocate space for symmetric crypto xforms in the private data space of the
     929                 :            :  * crypto operation. This also defaults the crypto xform type to
     930                 :            :  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
     931                 :            :  * in the crypto operation
     932                 :            :  *
     933                 :            :  * @return
     934                 :            :  * - On success returns pointer to first crypto xform in crypto operations chain
     935                 :            :  * - On failure returns NULL
     936                 :            :  */
     937                 :            : static inline struct rte_crypto_sym_xform *
     938                 :            : __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
     939                 :            :                 void *priv_data, uint8_t nb_xforms)
     940                 :            : {
     941                 :            :         struct rte_crypto_sym_xform *xform;
     942                 :            : 
     943                 :         10 :         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
     944                 :            : 
     945                 :            :         do {
     946                 :         18 :                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
     947         [ +  + ]:         18 :                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
     948                 :            :         } while (xform);
     949                 :            : 
     950                 :         10 :         return sym_op->xform;
     951                 :            : }
     952                 :            : 
     953                 :            : 
     954                 :            : /**
     955                 :            :  * Attach a session to a symmetric crypto operation
     956                 :            :  *
     957                 :            :  * @param       sym_op  crypto operation
     958                 :            :  * @param       sess    cryptodev session
     959                 :            :  */
     960                 :            : static inline int
     961                 :            : __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess)
     962                 :            : {
     963                 :        264 :         sym_op->session = sess;
     964                 :            : 
     965                 :            :         return 0;
     966                 :            : }
     967                 :            : 
     968                 :            : /**
     969                 :            :  * Converts portion of mbuf data into a vector representation.
     970                 :            :  * Each segment will be represented as a separate entry in *vec* array.
     971                 :            :  * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
     972                 :            :  * @param mb
     973                 :            :  *   Pointer to the *rte_mbuf* object.
     974                 :            :  * @param ofs
     975                 :            :  *   Offset within mbuf data to start with.
     976                 :            :  * @param len
     977                 :            :  *   Length of data to represent.
     978                 :            :  * @param vec
     979                 :            :  *   Pointer to an output array of IO vectors.
     980                 :            :  * @param num
     981                 :            :  *   Size of an output array.
     982                 :            :  * @return
     983                 :            :  *   - number of successfully filled entries in *vec* array.
     984                 :            :  *   - negative number of elements in *vec* array required.
     985                 :            :  */
     986                 :            : __rte_experimental
     987                 :            : static inline int
     988                 :          0 : rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
     989                 :            :         struct rte_crypto_vec vec[], uint32_t num)
     990                 :            : {
     991                 :            :         uint32_t i;
     992                 :            :         struct rte_mbuf *nseg;
     993                 :            :         uint32_t left;
     994                 :            :         uint32_t seglen;
     995                 :            : 
     996                 :            :         /* assuming that requested data starts in the first segment */
     997                 :            :         RTE_ASSERT(mb->data_len > ofs);
     998                 :            : 
     999         [ #  # ]:          0 :         if (mb->nb_segs > num)
    1000                 :          0 :                 return -mb->nb_segs;
    1001                 :            : 
    1002         [ #  # ]:          0 :         vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
    1003                 :          0 :         vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
    1004         [ #  # ]:          0 :         vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
    1005                 :            : 
    1006                 :            :         /* whole data lies in the first segment */
    1007                 :          0 :         seglen = mb->data_len - ofs;
    1008         [ #  # ]:          0 :         if (len <= seglen) {
    1009                 :          0 :                 vec[0].len = len;
    1010                 :          0 :                 return 1;
    1011                 :            :         }
    1012                 :            : 
    1013                 :            :         /* data spread across segments */
    1014                 :          0 :         vec[0].len = seglen;
    1015                 :          0 :         left = len - seglen;
    1016         [ #  # ]:          0 :         for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
    1017                 :            : 
    1018         [ #  # ]:          0 :                 vec[i].base = rte_pktmbuf_mtod(nseg, void *);
    1019                 :          0 :                 vec[i].iova = rte_pktmbuf_iova(nseg);
    1020         [ #  # ]:          0 :                 vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
    1021                 :            : 
    1022                 :          0 :                 seglen = nseg->data_len;
    1023         [ #  # ]:          0 :                 if (left <= seglen) {
    1024                 :            :                         /* whole requested data is completed */
    1025                 :          0 :                         vec[i].len = left;
    1026                 :            :                         left = 0;
    1027                 :          0 :                         i++;
    1028                 :          0 :                         break;
    1029                 :            :                 }
    1030                 :            : 
    1031                 :            :                 /* use whole segment */
    1032                 :          0 :                 vec[i].len = seglen;
    1033                 :          0 :                 left -= seglen;
    1034                 :            :         }
    1035                 :            : 
    1036                 :            :         RTE_ASSERT(left == 0);
    1037                 :          0 :         return i;
    1038                 :            : }
    1039                 :            : 
    1040                 :            : 
    1041                 :            : #ifdef __cplusplus
    1042                 :            : }
    1043                 :            : #endif
    1044                 :            : 
    1045                 :            : #endif /* _RTE_CRYPTO_SYM_H_ */

Generated by: LCOV version 1.14