xref: /dpdk/doc/guides/prog_guide/cryptodev_lib.rst (revision 2f6fec53909b90fa653b5d6ace0c4aeb4cce25b7)
10318c02bSDeclan Doherty..  BSD LICENSE
20318c02bSDeclan Doherty    Copyright(c) 2016 Intel Corporation. All rights reserved.
30318c02bSDeclan Doherty
40318c02bSDeclan Doherty    Redistribution and use in source and binary forms, with or without
50318c02bSDeclan Doherty    modification, are permitted provided that the following conditions
60318c02bSDeclan Doherty    are met:
70318c02bSDeclan Doherty
80318c02bSDeclan Doherty    * Redistributions of source code must retain the above copyright
90318c02bSDeclan Doherty    notice, this list of conditions and the following disclaimer.
100318c02bSDeclan Doherty    * Redistributions in binary form must reproduce the above copyright
110318c02bSDeclan Doherty    notice, this list of conditions and the following disclaimer in
120318c02bSDeclan Doherty    the documentation and/or other materials provided with the
130318c02bSDeclan Doherty    distribution.
140318c02bSDeclan Doherty    * Neither the name of Intel Corporation nor the names of its
150318c02bSDeclan Doherty    contributors may be used to endorse or promote products derived
160318c02bSDeclan Doherty    from this software without specific prior written permission.
170318c02bSDeclan Doherty
180318c02bSDeclan Doherty    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
190318c02bSDeclan Doherty    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
200318c02bSDeclan Doherty    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
210318c02bSDeclan Doherty    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
220318c02bSDeclan Doherty    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
230318c02bSDeclan Doherty    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
240318c02bSDeclan Doherty    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
250318c02bSDeclan Doherty    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
260318c02bSDeclan Doherty    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
270318c02bSDeclan Doherty    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
280318c02bSDeclan Doherty    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
290318c02bSDeclan Doherty
300318c02bSDeclan Doherty
310318c02bSDeclan DohertyCryptography Device Library
320318c02bSDeclan Doherty===========================
330318c02bSDeclan Doherty
340318c02bSDeclan DohertyThe cryptodev library provides a Crypto device framework for management and
350318c02bSDeclan Dohertyprovisioning of hardware and software Crypto poll mode drivers, defining generic
360318c02bSDeclan DohertyAPIs which support a number of different Crypto operations. The framework
370318c02bSDeclan Dohertycurrently only supports cipher, authentication, chained cipher/authentication
380318c02bSDeclan Dohertyand AEAD symmetric Crypto operations.
390318c02bSDeclan Doherty
400318c02bSDeclan Doherty
410318c02bSDeclan DohertyDesign Principles
420318c02bSDeclan Doherty-----------------
430318c02bSDeclan Doherty
440318c02bSDeclan DohertyThe cryptodev library follows the same basic principles as those used in DPDKs
450318c02bSDeclan DohertyEthernet Device framework. The Crypto framework provides a generic Crypto device
460318c02bSDeclan Dohertyframework which supports both physical (hardware) and virtual (software) Crypto
470318c02bSDeclan Dohertydevices as well as a generic Crypto API which allows Crypto devices to be
480318c02bSDeclan Dohertymanaged and configured and supports Crypto operations to be provisioned on
490318c02bSDeclan DohertyCrypto poll mode driver.
500318c02bSDeclan Doherty
510318c02bSDeclan Doherty
520318c02bSDeclan DohertyDevice Management
530318c02bSDeclan Doherty-----------------
540318c02bSDeclan Doherty
550318c02bSDeclan DohertyDevice Creation
560318c02bSDeclan Doherty~~~~~~~~~~~~~~~
570318c02bSDeclan Doherty
580318c02bSDeclan DohertyPhysical Crypto devices are discovered during the PCI probe/enumeration of the
590318c02bSDeclan DohertyEAL function which is executed at DPDK initialization, based on
600318c02bSDeclan Dohertytheir PCI device identifier, each unique PCI BDF (bus/bridge, device,
610318c02bSDeclan Dohertyfunction). Specific physical Crypto devices, like other physical devices in DPDK
620318c02bSDeclan Dohertycan be white-listed or black-listed using the EAL command line options.
630318c02bSDeclan Doherty
640318c02bSDeclan DohertyVirtual devices can be created by two mechanisms, either using the EAL command
650318c02bSDeclan Dohertyline options or from within the application using an EAL API directly.
660318c02bSDeclan Doherty
670318c02bSDeclan DohertyFrom the command line using the --vdev EAL option
680318c02bSDeclan Doherty
690318c02bSDeclan Doherty.. code-block:: console
700318c02bSDeclan Doherty
710318c02bSDeclan Doherty   --vdev  'cryptodev_aesni_mb_pmd0,max_nb_queue_pairs=2,max_nb_sessions=1024,socket_id=0'
720318c02bSDeclan Doherty
73*2f6fec53SThomas MonjalonOur using the rte_vdev_init API within the application code.
740318c02bSDeclan Doherty
750318c02bSDeclan Doherty.. code-block:: c
760318c02bSDeclan Doherty
77*2f6fec53SThomas Monjalon   rte_vdev_init("cryptodev_aesni_mb_pmd",
780318c02bSDeclan Doherty                     "max_nb_queue_pairs=2,max_nb_sessions=1024,socket_id=0")
790318c02bSDeclan Doherty
800318c02bSDeclan DohertyAll virtual Crypto devices support the following initialization parameters:
810318c02bSDeclan Doherty
820318c02bSDeclan Doherty* ``max_nb_queue_pairs`` - maximum number of queue pairs supported by the device.
830318c02bSDeclan Doherty* ``max_nb_sessions`` - maximum number of sessions supported by the device
840318c02bSDeclan Doherty* ``socket_id`` - socket on which to allocate the device resources on.
850318c02bSDeclan Doherty
860318c02bSDeclan Doherty
870318c02bSDeclan DohertyDevice Identification
880318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~
890318c02bSDeclan Doherty
900318c02bSDeclan DohertyEach device, whether virtual or physical is uniquely designated by two
910318c02bSDeclan Dohertyidentifiers:
920318c02bSDeclan Doherty
930318c02bSDeclan Doherty- A unique device index used to designate the Crypto device in all functions
940318c02bSDeclan Doherty  exported by the cryptodev API.
950318c02bSDeclan Doherty
960318c02bSDeclan Doherty- A device name used to designate the Crypto device in console messages, for
970318c02bSDeclan Doherty  administration or debugging purposes. For ease of use, the port name includes
980318c02bSDeclan Doherty  the port index.
990318c02bSDeclan Doherty
1000318c02bSDeclan Doherty
1010318c02bSDeclan DohertyDevice Configuration
1020318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~
1030318c02bSDeclan Doherty
1040318c02bSDeclan DohertyThe configuration of each Crypto device includes the following operations:
1050318c02bSDeclan Doherty
1060318c02bSDeclan Doherty- Allocation of resources, including hardware resources if a physical device.
1070318c02bSDeclan Doherty- Resetting the device into a well-known default state.
1080318c02bSDeclan Doherty- Initialization of statistics counters.
1090318c02bSDeclan Doherty
1100318c02bSDeclan DohertyThe rte_cryptodev_configure API is used to configure a Crypto device.
1110318c02bSDeclan Doherty
1120318c02bSDeclan Doherty.. code-block:: c
1130318c02bSDeclan Doherty
1140318c02bSDeclan Doherty   int rte_cryptodev_configure(uint8_t dev_id,
1150318c02bSDeclan Doherty                               struct rte_cryptodev_config *config)
1160318c02bSDeclan Doherty
1170318c02bSDeclan DohertyThe ``rte_cryptodev_config`` structure is used to pass the configuration parameters.
1180318c02bSDeclan DohertyIn contains parameter for socket selection, number of queue pairs and the
1190318c02bSDeclan Dohertysession mempool configuration.
1200318c02bSDeclan Doherty
1210318c02bSDeclan Doherty.. code-block:: c
1220318c02bSDeclan Doherty
1230318c02bSDeclan Doherty    struct rte_cryptodev_config {
1240318c02bSDeclan Doherty        int socket_id;
1250318c02bSDeclan Doherty        /**< Socket to allocate resources on */
1260318c02bSDeclan Doherty        uint16_t nb_queue_pairs;
1270318c02bSDeclan Doherty        /**< Number of queue pairs to configure on device */
1280318c02bSDeclan Doherty
1290318c02bSDeclan Doherty        struct {
1300318c02bSDeclan Doherty            uint32_t nb_objs;
1310318c02bSDeclan Doherty            uint32_t cache_size;
1320318c02bSDeclan Doherty        } session_mp;
1330318c02bSDeclan Doherty        /**< Session mempool configuration */
1340318c02bSDeclan Doherty    };
1350318c02bSDeclan Doherty
1360318c02bSDeclan Doherty
1370318c02bSDeclan DohertyConfiguration of Queue Pairs
1380318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1390318c02bSDeclan Doherty
1400318c02bSDeclan DohertyEach Crypto devices queue pair is individually configured through the
1410318c02bSDeclan Doherty``rte_cryptodev_queue_pair_setup`` API.
1420318c02bSDeclan DohertyEach queue pairs resources may be allocated on a specified socket.
1430318c02bSDeclan Doherty
1440318c02bSDeclan Doherty.. code-block:: c
1450318c02bSDeclan Doherty
1460318c02bSDeclan Doherty    int rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
1470318c02bSDeclan Doherty                const struct rte_cryptodev_qp_conf *qp_conf,
1480318c02bSDeclan Doherty                int socket_id)
1490318c02bSDeclan Doherty
1500318c02bSDeclan Doherty    struct rte_cryptodev_qp_conf {
1510318c02bSDeclan Doherty        uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
1520318c02bSDeclan Doherty    };
1530318c02bSDeclan Doherty
1540318c02bSDeclan Doherty
1550318c02bSDeclan DohertyLogical Cores, Memory and Queues Pair Relationships
1560318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1570318c02bSDeclan Doherty
1580318c02bSDeclan DohertyThe Crypto device Library as the Poll Mode Driver library support NUMA for when
1590318c02bSDeclan Dohertya processor’s logical cores and interfaces utilize its local memory. Therefore
1600318c02bSDeclan DohertyCrypto operations, and in the case of symmetric Crypto operations, the session
1610318c02bSDeclan Dohertyand the mbuf being operated on, should be allocated from memory pools created
1620318c02bSDeclan Dohertyin the local memory. The buffers should, if possible, remain on the local
1630318c02bSDeclan Dohertyprocessor to obtain the best performance results and buffer descriptors should
1640318c02bSDeclan Dohertybe populated with mbufs allocated from a mempool allocated from local memory.
1650318c02bSDeclan Doherty
1660318c02bSDeclan DohertyThe run-to-completion model also performs better, especially in the case of
1670318c02bSDeclan Dohertyvirtual Crypto devices, if the Crypto operation and session and data buffer is
1680318c02bSDeclan Dohertyin local memory instead of a remote processor's memory. This is also true for
1690318c02bSDeclan Dohertythe pipe-line model provided all logical cores used are located on the same
1700318c02bSDeclan Dohertyprocessor.
1710318c02bSDeclan Doherty
1720318c02bSDeclan DohertyMultiple logical cores should never share the same queue pair for enqueuing
1730318c02bSDeclan Dohertyoperations or dequeuing operations on the same Crypto device since this would
1740318c02bSDeclan Dohertyrequire global locks and hinder performance. It is however possible to use a
1750318c02bSDeclan Dohertydifferent logical core to dequeue an operation on a queue pair from the logical
1760318c02bSDeclan Dohertycore which it was enqueued on. This means that a crypto burst enqueue/dequeue
1770318c02bSDeclan DohertyAPIs are a logical place to transition from one logical core to another in a
1780318c02bSDeclan Dohertypacket processing pipeline.
1790318c02bSDeclan Doherty
1800318c02bSDeclan Doherty
1810318c02bSDeclan DohertyDevice Features and Capabilities
1820318c02bSDeclan Doherty---------------------------------
1830318c02bSDeclan Doherty
1840318c02bSDeclan DohertyCrypto devices define their functionality through two mechanisms, global device
1850318c02bSDeclan Dohertyfeatures and algorithm capabilities. Global devices features identify device
1860318c02bSDeclan Dohertywide level features which are applicable to the whole device such as
1870318c02bSDeclan Dohertythe device having hardware acceleration or supporting symmetric Crypto
1880318c02bSDeclan Dohertyoperations,
1890318c02bSDeclan Doherty
1900318c02bSDeclan DohertyThe capabilities mechanism defines the individual algorithms/functions which
1910318c02bSDeclan Dohertythe device supports, such as a specific symmetric Crypto cipher or
1920318c02bSDeclan Dohertyauthentication operation.
1930318c02bSDeclan Doherty
1940318c02bSDeclan Doherty
1950318c02bSDeclan DohertyDevice Features
1960318c02bSDeclan Doherty~~~~~~~~~~~~~~~
1970318c02bSDeclan Doherty
1980318c02bSDeclan DohertyCurrently the following Crypto device features are defined:
1990318c02bSDeclan Doherty
2000318c02bSDeclan Doherty* Symmetric Crypto operations
2010318c02bSDeclan Doherty* Asymmetric Crypto operations
2020318c02bSDeclan Doherty* Chaining of symmetric Crypto operations
2030318c02bSDeclan Doherty* SSE accelerated SIMD vector operations
2040318c02bSDeclan Doherty* AVX accelerated SIMD vector operations
2050318c02bSDeclan Doherty* AVX2 accelerated SIMD vector operations
2060318c02bSDeclan Doherty* AESNI accelerated instructions
2070318c02bSDeclan Doherty* Hardware off-load processing
2080318c02bSDeclan Doherty
2090318c02bSDeclan Doherty
2100318c02bSDeclan DohertyDevice Operation Capabilities
2110318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2120318c02bSDeclan Doherty
2130318c02bSDeclan DohertyCrypto capabilities which identify particular algorithm which the Crypto PMD
2140318c02bSDeclan Dohertysupports are  defined by the operation type, the operation transform, the
2150318c02bSDeclan Dohertytransform identifier and then the particulars of the transform. For the full
2160318c02bSDeclan Dohertyscope of the Crypto capability see the definition of the structure in the
2170318c02bSDeclan Doherty*DPDK API Reference*.
2180318c02bSDeclan Doherty
2190318c02bSDeclan Doherty.. code-block:: c
2200318c02bSDeclan Doherty
2210318c02bSDeclan Doherty   struct rte_cryptodev_capabilities;
2220318c02bSDeclan Doherty
2230318c02bSDeclan DohertyEach Crypto poll mode driver defines its own private array of capabilities
2240318c02bSDeclan Dohertyfor the operations it supports. Below is an example of the capabilities for a
2250318c02bSDeclan DohertyPMD which supports the authentication algorithm SHA1_HMAC and the cipher
2260318c02bSDeclan Dohertyalgorithm AES_CBC.
2270318c02bSDeclan Doherty
2280318c02bSDeclan Doherty.. code-block:: c
2290318c02bSDeclan Doherty
2300318c02bSDeclan Doherty    static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
2310318c02bSDeclan Doherty        {    /* SHA1 HMAC */
2320318c02bSDeclan Doherty            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
2330318c02bSDeclan Doherty            .sym = {
2340318c02bSDeclan Doherty                .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
2350318c02bSDeclan Doherty                .auth = {
2360318c02bSDeclan Doherty                    .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
2370318c02bSDeclan Doherty                    .block_size = 64,
2380318c02bSDeclan Doherty                    .key_size = {
2390318c02bSDeclan Doherty                        .min = 64,
2400318c02bSDeclan Doherty                        .max = 64,
2410318c02bSDeclan Doherty                        .increment = 0
2420318c02bSDeclan Doherty                    },
2430318c02bSDeclan Doherty                    .digest_size = {
2440318c02bSDeclan Doherty                        .min = 12,
2450318c02bSDeclan Doherty                        .max = 12,
2460318c02bSDeclan Doherty                        .increment = 0
2470318c02bSDeclan Doherty                    },
2480318c02bSDeclan Doherty                    .aad_size = { 0 }
2490318c02bSDeclan Doherty                }
2500318c02bSDeclan Doherty            }
2510318c02bSDeclan Doherty        },
2520318c02bSDeclan Doherty        {    /* AES CBC */
2530318c02bSDeclan Doherty            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
2540318c02bSDeclan Doherty            .sym = {
2550318c02bSDeclan Doherty                .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
2560318c02bSDeclan Doherty                .cipher = {
2570318c02bSDeclan Doherty                    .algo = RTE_CRYPTO_CIPHER_AES_CBC,
2580318c02bSDeclan Doherty                    .block_size = 16,
2590318c02bSDeclan Doherty                    .key_size = {
2600318c02bSDeclan Doherty                        .min = 16,
2610318c02bSDeclan Doherty                        .max = 32,
2620318c02bSDeclan Doherty                        .increment = 8
2630318c02bSDeclan Doherty                    },
2640318c02bSDeclan Doherty                    .iv_size = {
2650318c02bSDeclan Doherty                        .min = 16,
2660318c02bSDeclan Doherty                        .max = 16,
2670318c02bSDeclan Doherty                        .increment = 0
2680318c02bSDeclan Doherty                    }
2690318c02bSDeclan Doherty                }
2700318c02bSDeclan Doherty            }
2710318c02bSDeclan Doherty        }
2720318c02bSDeclan Doherty    }
2730318c02bSDeclan Doherty
2740318c02bSDeclan Doherty
2750318c02bSDeclan DohertyCapabilities Discovery
2760318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~
2770318c02bSDeclan Doherty
2780318c02bSDeclan DohertyDiscovering the features and capabilities of a Crypto device poll mode driver
2790318c02bSDeclan Dohertyis achieved through the ``rte_cryptodev_info_get`` function.
2800318c02bSDeclan Doherty
2810318c02bSDeclan Doherty.. code-block:: c
2820318c02bSDeclan Doherty
2830318c02bSDeclan Doherty   void rte_cryptodev_info_get(uint8_t dev_id,
2840318c02bSDeclan Doherty                               struct rte_cryptodev_info *dev_info);
2850318c02bSDeclan Doherty
2860318c02bSDeclan DohertyThis allows the user to query a specific Crypto PMD and get all the device
2870318c02bSDeclan Dohertyfeatures and capabilities. The ``rte_cryptodev_info`` structure contains all the
2880318c02bSDeclan Dohertyrelevant information for the device.
2890318c02bSDeclan Doherty
2900318c02bSDeclan Doherty.. code-block:: c
2910318c02bSDeclan Doherty
2920318c02bSDeclan Doherty    struct rte_cryptodev_info {
2930318c02bSDeclan Doherty        const char *driver_name;
2940318c02bSDeclan Doherty        enum rte_cryptodev_type dev_type;
2950318c02bSDeclan Doherty        struct rte_pci_device *pci_dev;
2960318c02bSDeclan Doherty
2970318c02bSDeclan Doherty        uint64_t feature_flags;
2980318c02bSDeclan Doherty
2990318c02bSDeclan Doherty        const struct rte_cryptodev_capabilities *capabilities;
3000318c02bSDeclan Doherty
3010318c02bSDeclan Doherty        unsigned max_nb_queue_pairs;
3020318c02bSDeclan Doherty
3030318c02bSDeclan Doherty        struct {
3040318c02bSDeclan Doherty            unsigned max_nb_sessions;
3050318c02bSDeclan Doherty        } sym;
3060318c02bSDeclan Doherty    };
3070318c02bSDeclan Doherty
3080318c02bSDeclan Doherty
3090318c02bSDeclan DohertyOperation Processing
3100318c02bSDeclan Doherty--------------------
3110318c02bSDeclan Doherty
3120318c02bSDeclan DohertyScheduling of Crypto operations on DPDK's application data path is
3130318c02bSDeclan Dohertyperformed using a burst oriented asynchronous API set. A queue pair on a Crypto
3140318c02bSDeclan Dohertydevice accepts a burst of Crypto operations using enqueue burst API. On physical
3150318c02bSDeclan DohertyCrypto devices the enqueue burst API will place the operations to be processed
3160318c02bSDeclan Dohertyon the devices hardware input queue, for virtual devices the processing of the
3170318c02bSDeclan DohertyCrypto operations is usually completed during the enqueue call to the Crypto
3180318c02bSDeclan Dohertydevice. The dequeue burst API will retrieve any processed operations available
3190318c02bSDeclan Dohertyfrom the queue pair on the Crypto device, from physical devices this is usually
3200318c02bSDeclan Dohertydirectly from the devices processed queue, and for virtual device's from a
3210318c02bSDeclan Doherty``rte_ring`` where processed operations are place after being processed on the
3220318c02bSDeclan Dohertyenqueue call.
3230318c02bSDeclan Doherty
3240318c02bSDeclan Doherty
3250318c02bSDeclan DohertyEnqueue / Dequeue Burst APIs
3260318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3270318c02bSDeclan Doherty
3280318c02bSDeclan DohertyThe burst enqueue API uses a Crypto device identifier and a queue pair
3290318c02bSDeclan Dohertyidentifier to specify the Crypto device queue pair to schedule the processing on.
3300318c02bSDeclan DohertyThe ``nb_ops`` parameter is the number of operations to process which are
3310318c02bSDeclan Dohertysupplied in the ``ops`` array of ``rte_crypto_op`` structures.
3320318c02bSDeclan DohertyThe enqueue function returns the number of operations it actually enqueued for
3330318c02bSDeclan Dohertyprocessing, a return value equal to ``nb_ops`` means that all packets have been
3340318c02bSDeclan Dohertyenqueued.
3350318c02bSDeclan Doherty
3360318c02bSDeclan Doherty.. code-block:: c
3370318c02bSDeclan Doherty
3380318c02bSDeclan Doherty   uint16_t rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
3390318c02bSDeclan Doherty                                        struct rte_crypto_op **ops, uint16_t nb_ops)
3400318c02bSDeclan Doherty
3410318c02bSDeclan DohertyThe dequeue API uses the same format as the enqueue API of processed but
3420318c02bSDeclan Dohertythe ``nb_ops`` and ``ops`` parameters are now used to specify the max processed
3430318c02bSDeclan Dohertyoperations the user wishes to retrieve and the location in which to store them.
3440318c02bSDeclan DohertyThe API call returns the actual number of processed operations returned, this
3450318c02bSDeclan Dohertycan never be larger than ``nb_ops``.
3460318c02bSDeclan Doherty
3470318c02bSDeclan Doherty.. code-block:: c
3480318c02bSDeclan Doherty
3490318c02bSDeclan Doherty   uint16_t rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
3500318c02bSDeclan Doherty                                        struct rte_crypto_op **ops, uint16_t nb_ops)
3510318c02bSDeclan Doherty
3520318c02bSDeclan Doherty
3530318c02bSDeclan DohertyOperation Representation
3540318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~
3550318c02bSDeclan Doherty
3560318c02bSDeclan DohertyAn Crypto operation is represented by an rte_crypto_op structure, which is a
3570318c02bSDeclan Dohertygeneric metadata container for all necessary information required for the
3580318c02bSDeclan DohertyCrypto operation to be processed on a particular Crypto device poll mode driver.
3590318c02bSDeclan Doherty
3600318c02bSDeclan Doherty.. figure:: img/crypto_op.*
3610318c02bSDeclan Doherty
3620318c02bSDeclan DohertyThe operation structure includes the operation type and the operation status,
3630318c02bSDeclan Dohertya reference to the operation specific data, which can vary in size and content
3640318c02bSDeclan Dohertydepending on the operation being provisioned. It also contains the source
3650318c02bSDeclan Dohertymempool for the operation, if it allocate from a mempool. Finally an
3660318c02bSDeclan Dohertyopaque pointer for user specific data is provided.
3670318c02bSDeclan Doherty
3680318c02bSDeclan DohertyIf Crypto operations are allocated from a Crypto operation mempool, see next
3690318c02bSDeclan Dohertysection, there is also the ability to allocate private memory with the
3700318c02bSDeclan Dohertyoperation for applications purposes.
3710318c02bSDeclan Doherty
3720318c02bSDeclan DohertyApplication software is responsible for specifying all the operation specific
3730318c02bSDeclan Dohertyfields in the ``rte_crypto_op`` structure which are then used by the Crypto PMD
3740318c02bSDeclan Dohertyto process the requested operation.
3750318c02bSDeclan Doherty
3760318c02bSDeclan Doherty
3770318c02bSDeclan DohertyOperation Management and Allocation
3780318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3790318c02bSDeclan Doherty
3800318c02bSDeclan DohertyThe cryptodev library provides an API set for managing Crypto operations which
3810318c02bSDeclan Dohertyutilize the Mempool Library to allocate operation buffers. Therefore, it ensures
3820318c02bSDeclan Dohertythat the crytpo operation is interleaved optimally across the channels and
3830318c02bSDeclan Dohertyranks for optimal processing.
3840318c02bSDeclan DohertyA ``rte_crypto_op`` contains a field indicating the pool that it originated from.
3850318c02bSDeclan DohertyWhen calling ``rte_crypto_op_free(op)``, the operation returns to its original pool.
3860318c02bSDeclan Doherty
3870318c02bSDeclan Doherty.. code-block:: c
3880318c02bSDeclan Doherty
3890318c02bSDeclan Doherty   extern struct rte_mempool *
3900318c02bSDeclan Doherty   rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
3910318c02bSDeclan Doherty                             unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
3920318c02bSDeclan Doherty                             int socket_id);
3930318c02bSDeclan Doherty
3940318c02bSDeclan DohertyDuring pool creation ``rte_crypto_op_init()`` is called as a constructor to
3950318c02bSDeclan Dohertyinitialize each Crypto operation which subsequently calls
3960318c02bSDeclan Doherty``__rte_crypto_op_reset()`` to configure any operation type specific fields based
3970318c02bSDeclan Dohertyon the type parameter.
3980318c02bSDeclan Doherty
3990318c02bSDeclan Doherty
4000318c02bSDeclan Doherty``rte_crypto_op_alloc()`` and ``rte_crypto_op_bulk_alloc()`` are used to allocate
4010318c02bSDeclan DohertyCrypto operations of a specific type from a given Crypto operation mempool.
4020318c02bSDeclan Doherty``__rte_crypto_op_reset()`` is called on each operation before being returned to
4030318c02bSDeclan Dohertyallocate to a user so the operation is always in a good known state before use
4040318c02bSDeclan Dohertyby the application.
4050318c02bSDeclan Doherty
4060318c02bSDeclan Doherty.. code-block:: c
4070318c02bSDeclan Doherty
4080318c02bSDeclan Doherty   struct rte_crypto_op *rte_crypto_op_alloc(struct rte_mempool *mempool,
4090318c02bSDeclan Doherty                                             enum rte_crypto_op_type type)
4100318c02bSDeclan Doherty
4110318c02bSDeclan Doherty   unsigned rte_crypto_op_bulk_alloc(struct rte_mempool *mempool,
4120318c02bSDeclan Doherty                                     enum rte_crypto_op_type type,
4130318c02bSDeclan Doherty                                     struct rte_crypto_op **ops, uint16_t nb_ops)
4140318c02bSDeclan Doherty
4150318c02bSDeclan Doherty``rte_crypto_op_free()`` is called by the application to return an operation to
4160318c02bSDeclan Dohertyits allocating pool.
4170318c02bSDeclan Doherty
4180318c02bSDeclan Doherty.. code-block:: c
4190318c02bSDeclan Doherty
4200318c02bSDeclan Doherty   void rte_crypto_op_free(struct rte_crypto_op *op)
4210318c02bSDeclan Doherty
4220318c02bSDeclan Doherty
4230318c02bSDeclan DohertySymmetric Cryptography Support
4240318c02bSDeclan Doherty------------------------------
4250318c02bSDeclan Doherty
4260318c02bSDeclan DohertyThe cryptodev library currently provides support for the following symmetric
4270318c02bSDeclan DohertyCrypto operations; cipher, authentication, including chaining of these
4280318c02bSDeclan Dohertyoperations, as well as also supporting AEAD operations.
4290318c02bSDeclan Doherty
4300318c02bSDeclan Doherty
4310318c02bSDeclan DohertySession and Session Management
4320318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4330318c02bSDeclan Doherty
4340318c02bSDeclan DohertySession are used in symmetric cryptographic processing to store the immutable
4350318c02bSDeclan Dohertydata defined in a cryptographic transform which is used in the operation
4360318c02bSDeclan Dohertyprocessing of a packet flow. Sessions are used to manage information such as
4370318c02bSDeclan Dohertyexpand cipher keys and HMAC IPADs and OPADs, which need to be calculated for a
4380318c02bSDeclan Dohertyparticular Crypto operation, but are immutable on a packet to packet basis for
4390318c02bSDeclan Dohertya flow. Crypto sessions cache this immutable data in a optimal way for the
4400318c02bSDeclan Dohertyunderlying PMD and this allows further acceleration of the offload of
4410318c02bSDeclan DohertyCrypto workloads.
4420318c02bSDeclan Doherty
4430318c02bSDeclan Doherty.. figure:: img/cryptodev_sym_sess.*
4440318c02bSDeclan Doherty
4450318c02bSDeclan DohertyThe Crypto device framework provides a set of session pool management APIs for
4460318c02bSDeclan Dohertythe creation and freeing of the sessions, utilizing the Mempool Library.
4470318c02bSDeclan Doherty
4480318c02bSDeclan DohertyThe framework also provides hooks so the PMDs can pass the amount of memory
4490318c02bSDeclan Dohertyrequired for that PMDs private session parameters, as well as initialization
4500318c02bSDeclan Dohertyfunctions for the configuration of the session parameters and freeing function
4510318c02bSDeclan Dohertyso the PMD can managed the memory on destruction of a session.
4520318c02bSDeclan Doherty
4530318c02bSDeclan Doherty**Note**: Sessions created on a particular device can only be used on Crypto
4540318c02bSDeclan Dohertydevices of the same type, and if you try to use a session on a device different
4550318c02bSDeclan Dohertyto that on which it was created then the Crypto operation will fail.
4560318c02bSDeclan Doherty
4570318c02bSDeclan Doherty``rte_cryptodev_sym_session_create()`` is used to create a symmetric session on
4580318c02bSDeclan DohertyCrypto device. A symmetric transform chain is used to specify the particular
4590318c02bSDeclan Dohertyoperation and its parameters. See the section below for details on transforms.
4600318c02bSDeclan Doherty
4610318c02bSDeclan Doherty.. code-block:: c
4620318c02bSDeclan Doherty
4630318c02bSDeclan Doherty   struct rte_cryptodev_sym_session * rte_cryptodev_sym_session_create(
4640318c02bSDeclan Doherty          uint8_t dev_id, struct rte_crypto_sym_xform *xform);
4650318c02bSDeclan Doherty
4660318c02bSDeclan Doherty**Note**: For AEAD operations the algorithm selected for authentication and
4670318c02bSDeclan Dohertyciphering must aligned, eg AES_GCM.
4680318c02bSDeclan Doherty
4690318c02bSDeclan Doherty
4700318c02bSDeclan DohertyTransforms and Transform Chaining
4710318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4720318c02bSDeclan Doherty
4730318c02bSDeclan DohertySymmetric Crypto transforms (``rte_crypto_sym_xform``) are the mechanism used
4740318c02bSDeclan Dohertyto specify the details of the Crypto operation. For chaining of symmetric
4750318c02bSDeclan Dohertyoperations such as cipher encrypt and authentication generate, the next pointer
4760318c02bSDeclan Dohertyallows transform to be chained together. Crypto devices which support chaining
4770318c02bSDeclan Dohertymust publish the chaining of symmetric Crypto operations feature flag.
4780318c02bSDeclan Doherty
4790318c02bSDeclan DohertyCurrently there are two transforms types cipher and authentication, to specify
4800318c02bSDeclan Dohertyan AEAD operation it is required to chain a cipher and an authentication
4810318c02bSDeclan Dohertytransform together. Also it is important to note that the order in which the
4820318c02bSDeclan Dohertytransforms are passed indicates the order of the chaining.
4830318c02bSDeclan Doherty
4840318c02bSDeclan Doherty.. code-block:: c
4850318c02bSDeclan Doherty
4860318c02bSDeclan Doherty    struct rte_crypto_sym_xform {
4870318c02bSDeclan Doherty        struct rte_crypto_sym_xform *next;
4880318c02bSDeclan Doherty        /**< next xform in chain */
4890318c02bSDeclan Doherty        enum rte_crypto_sym_xform_type type;
4900318c02bSDeclan Doherty        /**< xform type */
4910318c02bSDeclan Doherty        union {
4920318c02bSDeclan Doherty            struct rte_crypto_auth_xform auth;
4930318c02bSDeclan Doherty            /**< Authentication / hash xform */
4940318c02bSDeclan Doherty            struct rte_crypto_cipher_xform cipher;
4950318c02bSDeclan Doherty            /**< Cipher xform */
4960318c02bSDeclan Doherty        };
4970318c02bSDeclan Doherty    };
4980318c02bSDeclan Doherty
4990318c02bSDeclan DohertyThe API does not place a limit on the number of transforms that can be chained
5000318c02bSDeclan Dohertytogether but this will be limited by the underlying Crypto device poll mode
5010318c02bSDeclan Dohertydriver which is processing the operation.
5020318c02bSDeclan Doherty
5030318c02bSDeclan Doherty.. figure:: img/crypto_xform_chain.*
5040318c02bSDeclan Doherty
5050318c02bSDeclan Doherty
5060318c02bSDeclan DohertySymmetric Operations
5070318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~~~~
5080318c02bSDeclan Doherty
5090318c02bSDeclan DohertyThe symmetric Crypto operation structure contains all the mutable data relating
5100318c02bSDeclan Dohertyto performing symmetric cryptographic processing on a referenced mbuf data
5110318c02bSDeclan Dohertybuffer. It is used for either cipher, authentication, AEAD and chained
5120318c02bSDeclan Dohertyoperations.
5130318c02bSDeclan Doherty
5140318c02bSDeclan DohertyAs a minimum the symmetric operation must have a source data buffer (``m_src``),
5150318c02bSDeclan Dohertythe session type (session-based/less), a valid session (or transform chain if in
5160318c02bSDeclan Dohertysession-less mode) and the minimum authentication/ cipher parameters required
5170318c02bSDeclan Dohertydepending on the type of operation specified in the session or the transform
5180318c02bSDeclan Dohertychain.
5190318c02bSDeclan Doherty
5200318c02bSDeclan Doherty.. code-block:: c
5210318c02bSDeclan Doherty
5220318c02bSDeclan Doherty    struct rte_crypto_sym_op {
5230318c02bSDeclan Doherty        struct rte_mbuf *m_src;
5240318c02bSDeclan Doherty        struct rte_mbuf *m_dst;
5250318c02bSDeclan Doherty
5260318c02bSDeclan Doherty        enum rte_crypto_sym_op_sess_type type;
5270318c02bSDeclan Doherty
5280318c02bSDeclan Doherty        union {
5290318c02bSDeclan Doherty            struct rte_cryptodev_sym_session *session;
5300318c02bSDeclan Doherty            /**< Handle for the initialised session context */
5310318c02bSDeclan Doherty            struct rte_crypto_sym_xform *xform;
5320318c02bSDeclan Doherty            /**< Session-less API Crypto operation parameters */
5330318c02bSDeclan Doherty        };
5340318c02bSDeclan Doherty
5350318c02bSDeclan Doherty        struct {
5360318c02bSDeclan Doherty            struct {
5370318c02bSDeclan Doherty                uint32_t offset;
5380318c02bSDeclan Doherty                uint32_t length;
5390318c02bSDeclan Doherty            } data;   /**< Data offsets and length for ciphering */
5400318c02bSDeclan Doherty
5410318c02bSDeclan Doherty            struct {
5420318c02bSDeclan Doherty                uint8_t *data;
5430318c02bSDeclan Doherty                phys_addr_t phys_addr;
5440318c02bSDeclan Doherty                uint16_t length;
5450318c02bSDeclan Doherty            } iv;     /**< Initialisation vector parameters */
5460318c02bSDeclan Doherty        } cipher;
5470318c02bSDeclan Doherty
5480318c02bSDeclan Doherty        struct {
5490318c02bSDeclan Doherty            struct {
5500318c02bSDeclan Doherty                uint32_t offset;
5510318c02bSDeclan Doherty                uint32_t length;
5520318c02bSDeclan Doherty            } data;   /**< Data offsets and length for authentication */
5530318c02bSDeclan Doherty
5540318c02bSDeclan Doherty            struct {
5550318c02bSDeclan Doherty                uint8_t *data;
5560318c02bSDeclan Doherty                phys_addr_t phys_addr;
5570318c02bSDeclan Doherty                uint16_t length;
5580318c02bSDeclan Doherty            } digest; /**< Digest parameters */
5590318c02bSDeclan Doherty
5600318c02bSDeclan Doherty            struct {
5610318c02bSDeclan Doherty                uint8_t *data;
5620318c02bSDeclan Doherty                phys_addr_t phys_addr;
5630318c02bSDeclan Doherty                uint16_t length;
5640318c02bSDeclan Doherty            } aad;    /**< Additional authentication parameters */
5650318c02bSDeclan Doherty        } auth;
5660318c02bSDeclan Doherty    }
5670318c02bSDeclan Doherty
5680318c02bSDeclan Doherty
5690318c02bSDeclan DohertyAsymmetric Cryptography
5700318c02bSDeclan Doherty-----------------------
5710318c02bSDeclan Doherty
5720318c02bSDeclan DohertyAsymmetric functionality is currently not supported by the cryptodev API.
5730318c02bSDeclan Doherty
5740318c02bSDeclan Doherty
5750318c02bSDeclan DohertyCrypto Device API
5760318c02bSDeclan Doherty~~~~~~~~~~~~~~~~~
5770318c02bSDeclan Doherty
5780318c02bSDeclan DohertyThe cryptodev Library API is described in the *DPDK API Reference* document.
579