1d81734caSHemant Agrawal.. SPDX-License-Identifier: BSD-3-Clause 2d81734caSHemant Agrawal Copyright 2017 NXP 340ff8c99SAkhil Goyal 440ff8c99SAkhil Goyal 540ff8c99SAkhil Goyal 640ff8c99SAkhil GoyalSecurity Library 740ff8c99SAkhil Goyal================ 840ff8c99SAkhil Goyal 940ff8c99SAkhil GoyalThe security library provides a framework for management and provisioning 1040ff8c99SAkhil Goyalof security protocol operations offloaded to hardware based devices. The 1140ff8c99SAkhil Goyallibrary defines generic APIs to create and free security sessions which can 1240ff8c99SAkhil Goyalsupport full protocol offload as well as inline crypto operation with 138b593b8cSAkhil GoyalNIC or crypto devices. The framework currently only supports the IPsec and PDCP 148b593b8cSAkhil Goyalprotocol and associated operations, other protocols will be added in future. 1540ff8c99SAkhil Goyal 1640ff8c99SAkhil GoyalDesign Principles 1740ff8c99SAkhil Goyal----------------- 1840ff8c99SAkhil Goyal 1940ff8c99SAkhil GoyalThe security library provides an additional offload capability to an existing 2040ff8c99SAkhil Goyalcrypto device and/or ethernet device. 2140ff8c99SAkhil Goyal 2240ff8c99SAkhil Goyal.. code-block:: console 2340ff8c99SAkhil Goyal 2440ff8c99SAkhil Goyal +---------------+ 2540ff8c99SAkhil Goyal | rte_security | 2640ff8c99SAkhil Goyal +---------------+ 2740ff8c99SAkhil Goyal \ / 2840ff8c99SAkhil Goyal +-----------+ +--------------+ 2940ff8c99SAkhil Goyal | NIC PMD | | CRYPTO PMD | 3040ff8c99SAkhil Goyal +-----------+ +--------------+ 3140ff8c99SAkhil Goyal 3240ff8c99SAkhil Goyal.. note:: 3340ff8c99SAkhil Goyal 3440ff8c99SAkhil Goyal Currently, the security library does not support the case of multi-process. 3540ff8c99SAkhil Goyal It will be updated in the future releases. 3640ff8c99SAkhil Goyal 3740ff8c99SAkhil GoyalThe supported offload types are explained in the sections below. 3840ff8c99SAkhil Goyal 3940ff8c99SAkhil GoyalInline Crypto 4040ff8c99SAkhil Goyal~~~~~~~~~~~~~ 4140ff8c99SAkhil Goyal 4240ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO: 43*d629b7b5SJohn McNamaraThe crypto processing for security protocol (e.g. IPsec) is processed 4440ff8c99SAkhil Goyalinline during receive and transmission on NIC port. The flow based 4540ff8c99SAkhil Goyalsecurity action should be configured on the port. 4640ff8c99SAkhil Goyal 4740ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in RX path and relevant 4840ff8c99SAkhil Goyalcrypto status is set in Rx descriptors. After the successful inline 4940ff8c99SAkhil Goyalcrypto processing the packet is presented to host as a regular Rx packet 5040ff8c99SAkhil Goyalhowever all security protocol related headers are still attached to the 51*d629b7b5SJohn McNamarapacket. e.g. In case of IPsec, the IPsec tunnel headers (if any), 5240ff8c99SAkhil GoyalESP/AH headers will remain in the packet but the received packet 5340ff8c99SAkhil Goyalcontains the decrypted data where the encrypted data was when the packet 5440ff8c99SAkhil Goyalarrived. The driver Rx path check the descriptors and and based on the 5540ff8c99SAkhil Goyalcrypto status sets additional flags in the rte_mbuf.ol_flags field. 5640ff8c99SAkhil Goyal 5740ff8c99SAkhil Goyal.. note:: 5840ff8c99SAkhil Goyal 5940ff8c99SAkhil Goyal The underlying device may not support crypto processing for all ingress packet 6040ff8c99SAkhil Goyal matching to a particular flow (e.g. fragmented packets), such packets will 6140ff8c99SAkhil Goyal be passed as encrypted packets. It is the responsibility of application to 6240ff8c99SAkhil Goyal process such encrypted packets using other crypto driver instance. 6340ff8c99SAkhil Goyal 6440ff8c99SAkhil GoyalEgress Data path - The software prepares the egress packet by adding 6540ff8c99SAkhil Goyalrelevant security protocol headers. Only the data will not be 6640ff8c99SAkhil Goyalencrypted by the software. The driver will accordingly configure the 6740ff8c99SAkhil Goyaltx descriptors. The hardware device will encrypt the data before sending the 6840ff8c99SAkhil Goyalthe packet out. 6940ff8c99SAkhil Goyal 7040ff8c99SAkhil Goyal.. note:: 7140ff8c99SAkhil Goyal 7240ff8c99SAkhil Goyal The underlying device may support post encryption TSO. 7340ff8c99SAkhil Goyal 7440ff8c99SAkhil Goyal.. code-block:: console 7540ff8c99SAkhil Goyal 7640ff8c99SAkhil Goyal Egress Data Path 7740ff8c99SAkhil Goyal | 7840ff8c99SAkhil Goyal +--------|--------+ 7940ff8c99SAkhil Goyal | egress IPsec | 8040ff8c99SAkhil Goyal | | | 8140ff8c99SAkhil Goyal | +------V------+ | 8240ff8c99SAkhil Goyal | | SADB lookup | | 8340ff8c99SAkhil Goyal | +------|------+ | 8440ff8c99SAkhil Goyal | +------V------+ | 8540ff8c99SAkhil Goyal | | Tunnel | | <------ Add tunnel header to packet 8640ff8c99SAkhil Goyal | +------|------+ | 8740ff8c99SAkhil Goyal | +------V------+ | 8840ff8c99SAkhil Goyal | | ESP | | <------ Add ESP header without trailer to packet 8940ff8c99SAkhil Goyal | | | | <------ Mark packet to be offloaded, add trailer 9040ff8c99SAkhil Goyal | +------|------+ | meta-data to mbuf 9140ff8c99SAkhil Goyal +--------V--------+ 9240ff8c99SAkhil Goyal | 9340ff8c99SAkhil Goyal +--------V--------+ 9440ff8c99SAkhil Goyal | L2 Stack | 9540ff8c99SAkhil Goyal +--------|--------+ 9640ff8c99SAkhil Goyal | 9740ff8c99SAkhil Goyal +--------V--------+ 9840ff8c99SAkhil Goyal | | 9940ff8c99SAkhil Goyal | NIC PMD | <------ Set hw context for inline crypto offload 10040ff8c99SAkhil Goyal | | 10140ff8c99SAkhil Goyal +--------|--------+ 10240ff8c99SAkhil Goyal | 10340ff8c99SAkhil Goyal +--------|--------+ 10440ff8c99SAkhil Goyal | HW ACCELERATED | <------ Packet Encryption and 10540ff8c99SAkhil Goyal | NIC | Authentication happens inline 10640ff8c99SAkhil Goyal | | 10740ff8c99SAkhil Goyal +-----------------+ 10840ff8c99SAkhil Goyal 10940ff8c99SAkhil Goyal 11040ff8c99SAkhil GoyalInline protocol offload 11140ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~ 11240ff8c99SAkhil Goyal 11340ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL: 114*d629b7b5SJohn McNamaraThe crypto and protocol processing for security protocol (e.g. IPsec) 11540ff8c99SAkhil Goyalis processed inline during receive and transmission. The flow based 11640ff8c99SAkhil Goyalsecurity action should be configured on the port. 11740ff8c99SAkhil Goyal 11840ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in the RX path and relevant 11940ff8c99SAkhil Goyalcrypto status is set in the Rx descriptors. After the successful inline 12040ff8c99SAkhil Goyalcrypto processing the packet is presented to the host as a regular Rx packet 12140ff8c99SAkhil Goyalbut all security protocol related headers are optionally removed from the 122*d629b7b5SJohn McNamarapacket. e.g. in the case of IPsec, the IPsec tunnel headers (if any), 12340ff8c99SAkhil GoyalESP/AH headers will be removed from the packet and the received packet 12440ff8c99SAkhil Goyalwill contains the decrypted packet only. The driver Rx path checks the 12540ff8c99SAkhil Goyaldescriptors and based on the crypto status sets additional flags in 1261a08c379SAnoob Joseph``rte_mbuf.ol_flags`` field. The driver would also set device-specific 1271a08c379SAnoob Josephmetadata in ``rte_mbuf.udata64`` field. This will allow the application 1281a08c379SAnoob Josephto identify the security processing done on the packet. 12940ff8c99SAkhil Goyal 13040ff8c99SAkhil Goyal.. note:: 13140ff8c99SAkhil Goyal 13240ff8c99SAkhil Goyal The underlying device in this case is stateful. It is expected that 13340ff8c99SAkhil Goyal the device shall support crypto processing for all kind of packets matching 13440ff8c99SAkhil Goyal to a given flow, this includes fragmented packets (post reassembly). 135*d629b7b5SJohn McNamara E.g. in case of IPsec the device may internally manage anti-replay etc. 13640ff8c99SAkhil Goyal It will provide a configuration option for anti-replay behavior i.e. to drop 13740ff8c99SAkhil Goyal the packets or pass them to driver with error flags set in the descriptor. 13840ff8c99SAkhil Goyal 13940ff8c99SAkhil GoyalEgress Data path - The software will send the plain packet without any 14040ff8c99SAkhil Goyalsecurity protocol headers added to the packet. The driver will configure 14140ff8c99SAkhil Goyalthe security index and other requirement in tx descriptors. 14240ff8c99SAkhil GoyalThe hardware device will do security processing on the packet that includes 14340ff8c99SAkhil Goyaladding the relevant protocol headers and encrypting the data before sending 14440ff8c99SAkhil Goyalthe packet out. The software should make sure that the buffer 14540ff8c99SAkhil Goyalhas required head room and tail room for any protocol header addition. The 14640ff8c99SAkhil Goyalsoftware may also do early fragmentation if the resultant packet is expected 14740ff8c99SAkhil Goyalto cross the MTU size. 14840ff8c99SAkhil Goyal 14940ff8c99SAkhil Goyal 15040ff8c99SAkhil Goyal.. note:: 15140ff8c99SAkhil Goyal 15240ff8c99SAkhil Goyal The underlying device will manage state information required for egress 153*d629b7b5SJohn McNamara processing. E.g. in case of IPsec, the seq number will be added to the 15440ff8c99SAkhil Goyal packet, however the device shall provide indication when the sequence number 15540ff8c99SAkhil Goyal is about to overflow. The underlying device may support post encryption TSO. 15640ff8c99SAkhil Goyal 15740ff8c99SAkhil Goyal.. code-block:: console 15840ff8c99SAkhil Goyal 15940ff8c99SAkhil Goyal Egress Data Path 16040ff8c99SAkhil Goyal | 16140ff8c99SAkhil Goyal +--------|--------+ 16240ff8c99SAkhil Goyal | egress IPsec | 16340ff8c99SAkhil Goyal | | | 16440ff8c99SAkhil Goyal | +------V------+ | 16540ff8c99SAkhil Goyal | | SADB lookup | | 16640ff8c99SAkhil Goyal | +------|------+ | 16740ff8c99SAkhil Goyal | +------V------+ | 16840ff8c99SAkhil Goyal | | Desc | | <------ Mark packet to be offloaded 16940ff8c99SAkhil Goyal | +------|------+ | 17040ff8c99SAkhil Goyal +--------V--------+ 17140ff8c99SAkhil Goyal | 17240ff8c99SAkhil Goyal +--------V--------+ 17340ff8c99SAkhil Goyal | L2 Stack | 17440ff8c99SAkhil Goyal +--------|--------+ 17540ff8c99SAkhil Goyal | 17640ff8c99SAkhil Goyal +--------V--------+ 17740ff8c99SAkhil Goyal | | 17840ff8c99SAkhil Goyal | NIC PMD | <------ Set hw context for inline crypto offload 17940ff8c99SAkhil Goyal | | 18040ff8c99SAkhil Goyal +--------|--------+ 18140ff8c99SAkhil Goyal | 18240ff8c99SAkhil Goyal +--------|--------+ 18340ff8c99SAkhil Goyal | HW ACCELERATED | <------ Add tunnel, ESP header etc header to 18440ff8c99SAkhil Goyal | NIC | packet. Packet Encryption and 18540ff8c99SAkhil Goyal | | Authentication happens inline. 18640ff8c99SAkhil Goyal +-----------------+ 18740ff8c99SAkhil Goyal 18840ff8c99SAkhil Goyal 18940ff8c99SAkhil GoyalLookaside protocol offload 19040ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~ 19140ff8c99SAkhil Goyal 19240ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL: 19340ff8c99SAkhil GoyalThis extends librte_cryptodev to support the programming of IPsec 19440ff8c99SAkhil GoyalSecurity Association (SA) as part of a crypto session creation including 19540ff8c99SAkhil Goyalthe definition. In addition to standard crypto processing, as defined by 19640ff8c99SAkhil Goyalthe cryptodev, the security protocol processing is also offloaded to the 19740ff8c99SAkhil Goyalcrypto device. 19840ff8c99SAkhil Goyal 19940ff8c99SAkhil GoyalDecryption: The packet is sent to the crypto device for security 20040ff8c99SAkhil Goyalprotocol processing. The device will decrypt the packet and it will also 20140ff8c99SAkhil Goyaloptionally remove additional security headers from the packet. 202*d629b7b5SJohn McNamaraE.g. in case of IPsec, IPsec tunnel headers (if any), ESP/AH headers 20340ff8c99SAkhil Goyalwill be removed from the packet and the decrypted packet may contain 20440ff8c99SAkhil Goyalplain data only. 20540ff8c99SAkhil Goyal 20640ff8c99SAkhil Goyal.. note:: 20740ff8c99SAkhil Goyal 208*d629b7b5SJohn McNamara In case of IPsec the device may internally manage anti-replay etc. 20940ff8c99SAkhil Goyal It will provide a configuration option for anti-replay behavior i.e. to drop 21040ff8c99SAkhil Goyal the packets or pass them to driver with error flags set in descriptor. 21140ff8c99SAkhil Goyal 21240ff8c99SAkhil GoyalEncryption: The software will submit the packet to cryptodev as usual 21340ff8c99SAkhil Goyalfor encryption, the hardware device in this case will also add the relevant 21440ff8c99SAkhil Goyalsecurity protocol header along with encrypting the packet. The software 21540ff8c99SAkhil Goyalshould make sure that the buffer has required head room and tail room 21640ff8c99SAkhil Goyalfor any protocol header addition. 21740ff8c99SAkhil Goyal 21840ff8c99SAkhil Goyal.. note:: 21940ff8c99SAkhil Goyal 220*d629b7b5SJohn McNamara In the case of IPsec, the seq number will be added to the packet, 22140ff8c99SAkhil Goyal It shall provide an indication when the sequence number is about to 22240ff8c99SAkhil Goyal overflow. 22340ff8c99SAkhil Goyal 22440ff8c99SAkhil Goyal.. code-block:: console 22540ff8c99SAkhil Goyal 22640ff8c99SAkhil Goyal Egress Data Path 22740ff8c99SAkhil Goyal | 22840ff8c99SAkhil Goyal +--------|--------+ 22940ff8c99SAkhil Goyal | egress IPsec | 23040ff8c99SAkhil Goyal | | | 23140ff8c99SAkhil Goyal | +------V------+ | 23240ff8c99SAkhil Goyal | | SADB lookup | | <------ SA maps to cryptodev session 23340ff8c99SAkhil Goyal | +------|------+ | 23440ff8c99SAkhil Goyal | +------|------+ | 23540ff8c99SAkhil Goyal | | \--------------------\ 23640ff8c99SAkhil Goyal | | Crypto | | | <- Crypto processing through 23740ff8c99SAkhil Goyal | | /----------------\ | inline crypto PMD 23840ff8c99SAkhil Goyal | +------|------+ | | | 23940ff8c99SAkhil Goyal +--------V--------+ | | 24040ff8c99SAkhil Goyal | | | 24140ff8c99SAkhil Goyal +--------V--------+ | | create <-- SA is added to hw 24240ff8c99SAkhil Goyal | L2 Stack | | | inline using existing create 24340ff8c99SAkhil Goyal +--------|--------+ | | session sym session APIs 24440ff8c99SAkhil Goyal | | | | 24540ff8c99SAkhil Goyal +--------V--------+ +---|---|----V---+ 24640ff8c99SAkhil Goyal | | | \---/ | | <--- Add tunnel, ESP header etc 24740ff8c99SAkhil Goyal | NIC PMD | | INLINE | | header to packet.Packet 24840ff8c99SAkhil Goyal | | | CRYPTO PMD | | Encryption/Decryption and 24940ff8c99SAkhil Goyal +--------|--------+ +----------------+ Authentication happens 25040ff8c99SAkhil Goyal | inline. 25140ff8c99SAkhil Goyal +--------|--------+ 25240ff8c99SAkhil Goyal | NIC | 25340ff8c99SAkhil Goyal +--------|--------+ 25440ff8c99SAkhil Goyal V 25540ff8c99SAkhil Goyal 2568b593b8cSAkhil GoyalPDCP Flow Diagram 2578b593b8cSAkhil Goyal~~~~~~~~~~~~~~~~~ 2588b593b8cSAkhil Goyal 2598b593b8cSAkhil GoyalBased on 3GPP TS 36.323 Evolved Universal Terrestrial Radio Access (E-UTRA); 2608b593b8cSAkhil GoyalPacket Data Convergence Protocol (PDCP) specification 2618b593b8cSAkhil Goyal 2628b593b8cSAkhil Goyal.. code-block:: c 2638b593b8cSAkhil Goyal 2648b593b8cSAkhil Goyal Transmitting PDCP Entity Receiving PDCP Entity 2658b593b8cSAkhil Goyal | ^ 2668b593b8cSAkhil Goyal | +-----------|-----------+ 2678b593b8cSAkhil Goyal V | In order delivery and | 2688b593b8cSAkhil Goyal +---------|----------+ | Duplicate detection | 2698b593b8cSAkhil Goyal | Sequence Numbering | | (Data Plane only) | 2708b593b8cSAkhil Goyal +---------|----------+ +-----------|-----------+ 2718b593b8cSAkhil Goyal | | 2728b593b8cSAkhil Goyal +---------|----------+ +-----------|----------+ 2738b593b8cSAkhil Goyal | Header Compression*| | Header Decompression*| 2748b593b8cSAkhil Goyal | (Data-Plane only) | | (Data Plane only) | 2758b593b8cSAkhil Goyal +---------|----------+ +-----------|----------+ 2768b593b8cSAkhil Goyal | | 2778b593b8cSAkhil Goyal +---------|-----------+ +-----------|----------+ 2788b593b8cSAkhil Goyal | Integrity Protection| |Integrity Verification| 2798b593b8cSAkhil Goyal | (Control Plane only)| | (Control Plane only) | 2808b593b8cSAkhil Goyal +---------|-----------+ +-----------|----------+ 2818b593b8cSAkhil Goyal +---------|-----------+ +----------|----------+ 2828b593b8cSAkhil Goyal | Ciphering | | Deciphering | 2838b593b8cSAkhil Goyal +---------|-----------+ +----------|----------+ 2848b593b8cSAkhil Goyal +---------|-----------+ +----------|----------+ 2858b593b8cSAkhil Goyal | Add PDCP header | | Remove PDCP Header | 2868b593b8cSAkhil Goyal +---------|-----------+ +----------|----------+ 2878b593b8cSAkhil Goyal | | 2888b593b8cSAkhil Goyal +----------------->>----------------+ 2898b593b8cSAkhil Goyal 2908b593b8cSAkhil Goyal 2918b593b8cSAkhil Goyal.. note:: 2928b593b8cSAkhil Goyal 2938b593b8cSAkhil Goyal * Header Compression and decompression are not supported currently. 2948b593b8cSAkhil Goyal 2958b593b8cSAkhil GoyalJust like IPsec, in case of PDCP also header addition/deletion, cipher/ 2968b593b8cSAkhil Goyalde-cipher, integrity protection/verification is done based on the action 2978b593b8cSAkhil Goyaltype chosen. 2988b593b8cSAkhil Goyal 29940ff8c99SAkhil GoyalDevice Features and Capabilities 30040ff8c99SAkhil Goyal--------------------------------- 30140ff8c99SAkhil Goyal 30240ff8c99SAkhil GoyalDevice Capabilities For Security Operations 30340ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30440ff8c99SAkhil Goyal 30540ff8c99SAkhil GoyalThe device (crypto or ethernet) capabilities which support security operations, 30640ff8c99SAkhil Goyalare defined by the security action type, security protocol, protocol 30740ff8c99SAkhil Goyalcapabilities and corresponding crypto capabilities for security. For the full 30840ff8c99SAkhil Goyalscope of the Security capability see definition of rte_security_capability 30940ff8c99SAkhil Goyalstructure in the *DPDK API Reference*. 31040ff8c99SAkhil Goyal 31140ff8c99SAkhil Goyal.. code-block:: c 31240ff8c99SAkhil Goyal 31340ff8c99SAkhil Goyal struct rte_security_capability; 31440ff8c99SAkhil Goyal 31540ff8c99SAkhil GoyalEach driver (crypto or ethernet) defines its own private array of capabilities 31640ff8c99SAkhil Goyalfor the operations it supports. Below is an example of the capabilities for a 3178b593b8cSAkhil GoyalPMD which supports the IPsec and PDCP protocol. 31840ff8c99SAkhil Goyal 31940ff8c99SAkhil Goyal.. code-block:: c 32040ff8c99SAkhil Goyal 32140ff8c99SAkhil Goyal static const struct rte_security_capability pmd_security_capabilities[] = { 32240ff8c99SAkhil Goyal { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */ 32340ff8c99SAkhil Goyal .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 32440ff8c99SAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 32540ff8c99SAkhil Goyal .ipsec = { 32640ff8c99SAkhil Goyal .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, 32740ff8c99SAkhil Goyal .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 32840ff8c99SAkhil Goyal .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS, 32940ff8c99SAkhil Goyal .options = { 0 } 33040ff8c99SAkhil Goyal }, 33140ff8c99SAkhil Goyal .crypto_capabilities = pmd_capabilities 33240ff8c99SAkhil Goyal }, 33340ff8c99SAkhil Goyal { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */ 33440ff8c99SAkhil Goyal .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 33540ff8c99SAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 33640ff8c99SAkhil Goyal .ipsec = { 33740ff8c99SAkhil Goyal .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, 33840ff8c99SAkhil Goyal .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 33940ff8c99SAkhil Goyal .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, 34040ff8c99SAkhil Goyal .options = { 0 } 34140ff8c99SAkhil Goyal }, 34240ff8c99SAkhil Goyal .crypto_capabilities = pmd_capabilities 34340ff8c99SAkhil Goyal }, 3448b593b8cSAkhil Goyal { /* PDCP Lookaside Protocol offload Data Plane */ 3458b593b8cSAkhil Goyal .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 3468b593b8cSAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_PDCP, 3478b593b8cSAkhil Goyal .pdcp = { 3488b593b8cSAkhil Goyal .domain = RTE_SECURITY_PDCP_MODE_DATA, 3498b593b8cSAkhil Goyal .capa_flags = 0 3508b593b8cSAkhil Goyal }, 3518b593b8cSAkhil Goyal .crypto_capabilities = pmd_capabilities 3528b593b8cSAkhil Goyal }, 3538b593b8cSAkhil Goyal { /* PDCP Lookaside Protocol offload Control */ 3548b593b8cSAkhil Goyal .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 3558b593b8cSAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_PDCP, 3568b593b8cSAkhil Goyal .pdcp = { 3578b593b8cSAkhil Goyal .domain = RTE_SECURITY_PDCP_MODE_CONTROL, 3588b593b8cSAkhil Goyal .capa_flags = 0 3598b593b8cSAkhil Goyal }, 3608b593b8cSAkhil Goyal .crypto_capabilities = pmd_capabilities 3618b593b8cSAkhil Goyal }, 36240ff8c99SAkhil Goyal { 36340ff8c99SAkhil Goyal .action = RTE_SECURITY_ACTION_TYPE_NONE 36440ff8c99SAkhil Goyal } 36540ff8c99SAkhil Goyal }; 36640ff8c99SAkhil Goyal static const struct rte_cryptodev_capabilities pmd_capabilities[] = { 36740ff8c99SAkhil Goyal { /* SHA1 HMAC */ 36840ff8c99SAkhil Goyal .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, 36940ff8c99SAkhil Goyal .sym = { 37040ff8c99SAkhil Goyal .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, 37140ff8c99SAkhil Goyal .auth = { 37240ff8c99SAkhil Goyal .algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 37340ff8c99SAkhil Goyal .block_size = 64, 37440ff8c99SAkhil Goyal .key_size = { 37540ff8c99SAkhil Goyal .min = 64, 37640ff8c99SAkhil Goyal .max = 64, 37740ff8c99SAkhil Goyal .increment = 0 37840ff8c99SAkhil Goyal }, 37940ff8c99SAkhil Goyal .digest_size = { 38040ff8c99SAkhil Goyal .min = 12, 38140ff8c99SAkhil Goyal .max = 12, 38240ff8c99SAkhil Goyal .increment = 0 38340ff8c99SAkhil Goyal }, 38440ff8c99SAkhil Goyal .aad_size = { 0 }, 38540ff8c99SAkhil Goyal .iv_size = { 0 } 38640ff8c99SAkhil Goyal } 38740ff8c99SAkhil Goyal } 38840ff8c99SAkhil Goyal }, 38940ff8c99SAkhil Goyal { /* AES CBC */ 39040ff8c99SAkhil Goyal .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, 39140ff8c99SAkhil Goyal .sym = { 39240ff8c99SAkhil Goyal .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, 39340ff8c99SAkhil Goyal .cipher = { 39440ff8c99SAkhil Goyal .algo = RTE_CRYPTO_CIPHER_AES_CBC, 39540ff8c99SAkhil Goyal .block_size = 16, 39640ff8c99SAkhil Goyal .key_size = { 39740ff8c99SAkhil Goyal .min = 16, 39840ff8c99SAkhil Goyal .max = 32, 39940ff8c99SAkhil Goyal .increment = 8 40040ff8c99SAkhil Goyal }, 40140ff8c99SAkhil Goyal .iv_size = { 40240ff8c99SAkhil Goyal .min = 16, 40340ff8c99SAkhil Goyal .max = 16, 40440ff8c99SAkhil Goyal .increment = 0 40540ff8c99SAkhil Goyal } 40640ff8c99SAkhil Goyal } 40740ff8c99SAkhil Goyal } 40840ff8c99SAkhil Goyal } 40940ff8c99SAkhil Goyal } 41040ff8c99SAkhil Goyal 41140ff8c99SAkhil Goyal 41240ff8c99SAkhil GoyalCapabilities Discovery 41340ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~ 41440ff8c99SAkhil Goyal 41540ff8c99SAkhil GoyalDiscovering the features and capabilities of a driver (crypto/ethernet) 41640ff8c99SAkhil Goyalis achieved through the ``rte_security_capabilities_get()`` function. 41740ff8c99SAkhil Goyal 41840ff8c99SAkhil Goyal.. code-block:: c 41940ff8c99SAkhil Goyal 42040ff8c99SAkhil Goyal const struct rte_security_capability *rte_security_capabilities_get(uint16_t id); 42140ff8c99SAkhil Goyal 42240ff8c99SAkhil GoyalThis allows the user to query a specific driver and get all device 42340ff8c99SAkhil Goyalsecurity capabilities. It returns an array of ``rte_security_capability`` structures 42440ff8c99SAkhil Goyalwhich contains all the capabilities for that device. 42540ff8c99SAkhil Goyal 42640ff8c99SAkhil GoyalSecurity Session Create/Free 42740ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42840ff8c99SAkhil Goyal 42940ff8c99SAkhil GoyalSecurity Sessions are created to store the immutable fields of a particular Security 43040ff8c99SAkhil GoyalAssociation for a particular protocol which is defined by a security session 43140ff8c99SAkhil Goyalconfiguration structure which is used in the operation processing of a packet flow. 43240ff8c99SAkhil GoyalSessions are used to manage protocol specific information as well as crypto parameters. 43340ff8c99SAkhil GoyalSecurity sessions cache this immutable data in a optimal way for the underlying PMD 43440ff8c99SAkhil Goyaland this allows further acceleration of the offload of Crypto workloads. 43540ff8c99SAkhil Goyal 43640ff8c99SAkhil GoyalThe Security framework provides APIs to create and free sessions for crypto/ethernet 43740ff8c99SAkhil Goyaldevices, where sessions are mempool objects. It is the application's responsibility 43840ff8c99SAkhil Goyalto create and manage the session mempools. The mempool object size should be able to 43940ff8c99SAkhil Goyalaccommodate the driver's private data of security session. 44040ff8c99SAkhil Goyal 44140ff8c99SAkhil GoyalOnce the session mempools have been created, ``rte_security_session_create()`` 44240ff8c99SAkhil Goyalis used to allocate and initialize a session for the required crypto/ethernet device. 44340ff8c99SAkhil Goyal 44440ff8c99SAkhil GoyalSession APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet 44540ff8c99SAkhil Goyalsecurity ops. This parameter can be retrieved using the APIs 44640ff8c99SAkhil Goyal``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx`` 44740ff8c99SAkhil Goyal(for ethernet port). 44840ff8c99SAkhil Goyal 44940ff8c99SAkhil GoyalSessions already created can be updated with ``rte_security_session_update()``. 45040ff8c99SAkhil Goyal 45140ff8c99SAkhil GoyalWhen a session is no longer used, the user must call ``rte_security_session_destroy()`` 45240ff8c99SAkhil Goyalto free the driver private session data and return the memory back to the mempool. 45340ff8c99SAkhil Goyal 45440ff8c99SAkhil GoyalFor look aside protocol offload to hardware crypto device, the ``rte_crypto_op`` 45540ff8c99SAkhil Goyalcreated by the application is attached to the security session by the API 45640ff8c99SAkhil Goyal``rte_security_attach_session()``. 45740ff8c99SAkhil Goyal 45840ff8c99SAkhil GoyalFor Inline Crypto and Inline protocol offload, device specific defined metadata is 45940ff8c99SAkhil Goyalupdated in the mbuf using ``rte_security_set_pkt_metadata()`` if 46040ff8c99SAkhil Goyal``DEV_TX_OFFLOAD_SEC_NEED_MDATA`` is set. 46140ff8c99SAkhil Goyal 4621a08c379SAnoob JosephFor inline protocol offloaded ingress traffic, the application can register a 4631a08c379SAnoob Josephpointer, ``userdata`` , in the security session. When the packet is received, 4641a08c379SAnoob Joseph``rte_security_get_userdata()`` would return the userdata registered for the 4651a08c379SAnoob Josephsecurity session which processed the packet. 4661a08c379SAnoob Joseph 4671a08c379SAnoob Joseph.. note:: 4681a08c379SAnoob Joseph 4691a08c379SAnoob Joseph In case of inline processed packets, ``rte_mbuf.udata64`` field would be 4701a08c379SAnoob Joseph used by the driver to relay information on the security processing 4711a08c379SAnoob Joseph associated with the packet. In ingress, the driver would set this in Rx 4721a08c379SAnoob Joseph path while in egress, ``rte_security_set_pkt_metadata()`` would perform a 4731a08c379SAnoob Joseph similar operation. The application is expected not to modify the field 4741a08c379SAnoob Joseph when it has relevant info. For ingress, this device-specific 64 bit value 4751a08c379SAnoob Joseph is required to derive other information (like userdata), required for 4761a08c379SAnoob Joseph identifying the security processing done on the packet. 4771a08c379SAnoob Joseph 47840ff8c99SAkhil GoyalSecurity session configuration 47940ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 48040ff8c99SAkhil Goyal 48140ff8c99SAkhil GoyalSecurity Session configuration structure is defined as ``rte_security_session_conf`` 48240ff8c99SAkhil Goyal 48340ff8c99SAkhil Goyal.. code-block:: c 48440ff8c99SAkhil Goyal 48540ff8c99SAkhil Goyal struct rte_security_session_conf { 48640ff8c99SAkhil Goyal enum rte_security_session_action_type action_type; 48740ff8c99SAkhil Goyal /**< Type of action to be performed on the session */ 48840ff8c99SAkhil Goyal enum rte_security_session_protocol protocol; 48940ff8c99SAkhil Goyal /**< Security protocol to be configured */ 49040ff8c99SAkhil Goyal union { 49140ff8c99SAkhil Goyal struct rte_security_ipsec_xform ipsec; 49240ff8c99SAkhil Goyal struct rte_security_macsec_xform macsec; 4938b593b8cSAkhil Goyal struct rte_security_pdcp_xform pdcp; 49440ff8c99SAkhil Goyal }; 49540ff8c99SAkhil Goyal /**< Configuration parameters for security session */ 49640ff8c99SAkhil Goyal struct rte_crypto_sym_xform *crypto_xform; 49740ff8c99SAkhil Goyal /**< Security Session Crypto Transformations */ 4981a08c379SAnoob Joseph void *userdata; 4991a08c379SAnoob Joseph /**< Application specific userdata to be saved with session */ 50040ff8c99SAkhil Goyal }; 50140ff8c99SAkhil Goyal 50240ff8c99SAkhil GoyalThe configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related 50340ff8c99SAkhil Goyalconfiguration. The ``rte_security_session_action_type`` struct is used to specify whether the 50440ff8c99SAkhil Goyalsession is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol 50540ff8c99SAkhil GoyalOffload. 50640ff8c99SAkhil Goyal 50740ff8c99SAkhil Goyal.. code-block:: c 50840ff8c99SAkhil Goyal 50940ff8c99SAkhil Goyal enum rte_security_session_action_type { 51040ff8c99SAkhil Goyal RTE_SECURITY_ACTION_TYPE_NONE, 51140ff8c99SAkhil Goyal /**< No security actions */ 51240ff8c99SAkhil Goyal RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, 51340ff8c99SAkhil Goyal /**< Crypto processing for security protocol is processed inline 51440ff8c99SAkhil Goyal * during transmission */ 51540ff8c99SAkhil Goyal RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, 51640ff8c99SAkhil Goyal /**< All security protocol processing is performed inline during 51740ff8c99SAkhil Goyal * transmission */ 51840ff8c99SAkhil Goyal RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL 51940ff8c99SAkhil Goyal /**< All security protocol processing including crypto is performed 52040ff8c99SAkhil Goyal * on a lookaside accelerator */ 52140ff8c99SAkhil Goyal }; 52240ff8c99SAkhil Goyal 52340ff8c99SAkhil GoyalThe ``rte_security_session_protocol`` is defined as 52440ff8c99SAkhil Goyal 52540ff8c99SAkhil Goyal.. code-block:: c 52640ff8c99SAkhil Goyal 52740ff8c99SAkhil Goyal enum rte_security_session_protocol { 5288b593b8cSAkhil Goyal RTE_SECURITY_PROTOCOL_IPSEC = 1, 52940ff8c99SAkhil Goyal /**< IPsec Protocol */ 53040ff8c99SAkhil Goyal RTE_SECURITY_PROTOCOL_MACSEC, 53140ff8c99SAkhil Goyal /**< MACSec Protocol */ 5328b593b8cSAkhil Goyal RTE_SECURITY_PROTOCOL_PDCP, 5338b593b8cSAkhil Goyal /**< PDCP Protocol */ 53440ff8c99SAkhil Goyal }; 53540ff8c99SAkhil Goyal 5368b593b8cSAkhil GoyalCurrently the library defines configuration parameters for IPsec and PDCP only. 5378b593b8cSAkhil GoyalFor other protocols like MACSec, structures and enums are defined as place holders 5388b593b8cSAkhil Goyalwhich will be updated in the future. 53940ff8c99SAkhil Goyal 54040ff8c99SAkhil GoyalIPsec related configuration parameters are defined in ``rte_security_ipsec_xform`` 54140ff8c99SAkhil Goyal 54240ff8c99SAkhil Goyal.. code-block:: c 54340ff8c99SAkhil Goyal 54440ff8c99SAkhil Goyal struct rte_security_ipsec_xform { 54540ff8c99SAkhil Goyal uint32_t spi; 54640ff8c99SAkhil Goyal /**< SA security parameter index */ 54740ff8c99SAkhil Goyal uint32_t salt; 54840ff8c99SAkhil Goyal /**< SA salt */ 54940ff8c99SAkhil Goyal struct rte_security_ipsec_sa_options options; 55040ff8c99SAkhil Goyal /**< various SA options */ 55140ff8c99SAkhil Goyal enum rte_security_ipsec_sa_direction direction; 552*d629b7b5SJohn McNamara /**< IPsec SA Direction - Egress/Ingress */ 55340ff8c99SAkhil Goyal enum rte_security_ipsec_sa_protocol proto; 55440ff8c99SAkhil Goyal /**< IPsec SA Protocol - AH/ESP */ 55540ff8c99SAkhil Goyal enum rte_security_ipsec_sa_mode mode; 55640ff8c99SAkhil Goyal /**< IPsec SA Mode - transport/tunnel */ 55740ff8c99SAkhil Goyal struct rte_security_ipsec_tunnel_param tunnel; 55840ff8c99SAkhil Goyal /**< Tunnel parameters, NULL for transport mode */ 55940ff8c99SAkhil Goyal }; 56040ff8c99SAkhil Goyal 5618b593b8cSAkhil GoyalPDCP related configuration parameters are defined in ``rte_security_pdcp_xform`` 5628b593b8cSAkhil Goyal 5638b593b8cSAkhil Goyal.. code-block:: c 5648b593b8cSAkhil Goyal 5658b593b8cSAkhil Goyal struct rte_security_pdcp_xform { 5668b593b8cSAkhil Goyal int8_t bearer; /**< PDCP bearer ID */ 5678b593b8cSAkhil Goyal /** Enable in order delivery, this field shall be set only if 5688b593b8cSAkhil Goyal * driver/HW is capable. See RTE_SECURITY_PDCP_ORDERING_CAP. 5698b593b8cSAkhil Goyal */ 5708b593b8cSAkhil Goyal uint8_t en_ordering; 5718b593b8cSAkhil Goyal /** Notify driver/HW to detect and remove duplicate packets. 5728b593b8cSAkhil Goyal * This field should be set only when driver/hw is capable. 5738b593b8cSAkhil Goyal * See RTE_SECURITY_PDCP_DUP_DETECT_CAP. 5748b593b8cSAkhil Goyal */ 5758b593b8cSAkhil Goyal uint8_t remove_duplicates; 5768b593b8cSAkhil Goyal /** PDCP mode of operation: Control or data */ 5778b593b8cSAkhil Goyal enum rte_security_pdcp_domain domain; 5788b593b8cSAkhil Goyal /** PDCP Frame Direction 0:UL 1:DL */ 5798b593b8cSAkhil Goyal enum rte_security_pdcp_direction pkt_dir; 5808b593b8cSAkhil Goyal /** Sequence number size, 5/7/12/15/18 */ 5818b593b8cSAkhil Goyal enum rte_security_pdcp_sn_size sn_size; 5828b593b8cSAkhil Goyal /** Starting Hyper Frame Number to be used together with the SN 5838b593b8cSAkhil Goyal * from the PDCP frames 5848b593b8cSAkhil Goyal */ 5858b593b8cSAkhil Goyal uint32_t hfn; 5868b593b8cSAkhil Goyal /** HFN Threshold for key renegotiation */ 5878b593b8cSAkhil Goyal uint32_t hfn_threshold; 5888b593b8cSAkhil Goyal }; 5898b593b8cSAkhil Goyal 59040ff8c99SAkhil Goyal 59140ff8c99SAkhil GoyalSecurity API 59240ff8c99SAkhil Goyal~~~~~~~~~~~~ 59340ff8c99SAkhil Goyal 59440ff8c99SAkhil GoyalThe rte_security Library API is described in the *DPDK API Reference* document. 59540ff8c99SAkhil Goyal 59640ff8c99SAkhil GoyalFlow based Security Session 59740ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~ 59840ff8c99SAkhil Goyal 59940ff8c99SAkhil GoyalIn the case of NIC based offloads, the security session specified in the 60040ff8c99SAkhil Goyal'rte_flow_action_security' must be created on the same port as the 60140ff8c99SAkhil Goyalflow action that is being specified. 60240ff8c99SAkhil Goyal 60340ff8c99SAkhil GoyalThe ingress/egress flow attribute should match that specified in the security 60440ff8c99SAkhil Goyalsession if the security session supports the definition of the direction. 60540ff8c99SAkhil Goyal 60640ff8c99SAkhil GoyalMultiple flows can be configured to use the same security session. For 60740ff8c99SAkhil Goyalexample if the security session specifies an egress IPsec SA, then multiple 60840ff8c99SAkhil Goyalflows can be specified to that SA. In the case of an ingress IPsec SA then 60940ff8c99SAkhil Goyalit is only valid to have a single flow to map to that security session. 61040ff8c99SAkhil Goyal 61140ff8c99SAkhil Goyal.. code-block:: console 61240ff8c99SAkhil Goyal 61340ff8c99SAkhil Goyal Configuration Path 61440ff8c99SAkhil Goyal | 61540ff8c99SAkhil Goyal +--------|--------+ 61640ff8c99SAkhil Goyal | Add/Remove | 61740ff8c99SAkhil Goyal | IPsec SA | <------ Build security flow action of 61840ff8c99SAkhil Goyal | | | ipsec transform 61940ff8c99SAkhil Goyal |--------|--------| 62040ff8c99SAkhil Goyal | 62140ff8c99SAkhil Goyal +--------V--------+ 62240ff8c99SAkhil Goyal | Flow API | 62340ff8c99SAkhil Goyal +--------|--------+ 62440ff8c99SAkhil Goyal | 62540ff8c99SAkhil Goyal +--------V--------+ 62640ff8c99SAkhil Goyal | | 62740ff8c99SAkhil Goyal | NIC PMD | <------ Add/Remove SA to/from hw context 62840ff8c99SAkhil Goyal | | 62940ff8c99SAkhil Goyal +--------|--------+ 63040ff8c99SAkhil Goyal | 63140ff8c99SAkhil Goyal +--------|--------+ 63240ff8c99SAkhil Goyal | HW ACCELERATED | 63340ff8c99SAkhil Goyal | NIC | 63440ff8c99SAkhil Goyal | | 63540ff8c99SAkhil Goyal +--------|--------+ 63640ff8c99SAkhil Goyal 63740ff8c99SAkhil Goyal* Add/Delete SA flow: 63840ff8c99SAkhil Goyal To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP 63940ff8c99SAkhil Goyal using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``. 64040ff8c99SAkhil Goyal Note that any rte_flow_items may be empty, which means it is not checked. 64140ff8c99SAkhil Goyal 64240ff8c99SAkhil Goyal.. code-block:: console 64340ff8c99SAkhil Goyal 64440ff8c99SAkhil Goyal In its most basic form, IPsec flow specification is as follows: 64540ff8c99SAkhil Goyal +-------+ +----------+ +--------+ +-----+ 64640ff8c99SAkhil Goyal | Eth | -> | IP4/6 | -> | ESP | -> | END | 64740ff8c99SAkhil Goyal +-------+ +----------+ +--------+ +-----+ 64840ff8c99SAkhil Goyal 64940ff8c99SAkhil Goyal However, the API can represent, IPsec crypto offload with any encapsulation: 65040ff8c99SAkhil Goyal +-------+ +--------+ +-----+ 65140ff8c99SAkhil Goyal | Eth | -> ... -> | ESP | -> | END | 65240ff8c99SAkhil Goyal +-------+ +--------+ +-----+ 653