1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright 2017,2020 NXP
9 The security library provides a framework for management and provisioning
10 of security protocol operations offloaded to hardware based devices. The
11 library defines generic APIs to create and free security sessions which can
12 support full protocol offload as well as inline crypto operation with
13 NIC or crypto devices. The framework currently only supports the IPsec, PDCP
14 and DOCSIS protocols and associated operations, other protocols will be added
20 The security library provides an additional offload capability to an existing
21 crypto device and/or ethernet device.
23 .. code-block:: console
29 +-----------+ +--------------+
30 | NIC PMD | | CRYPTO PMD |
31 +-----------+ +--------------+
35 Currently, the security library does not support the case of multi-process.
36 It will be updated in the future releases.
38 The supported offload types are explained in the sections below.
43 RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO:
44 The crypto processing for security protocol (e.g. IPsec) is processed
45 inline during receive and transmission on NIC port. The flow based
46 security action should be configured on the port.
48 Ingress Data path - The packet is decrypted in RX path and relevant
49 crypto status is set in Rx descriptors. After the successful inline
50 crypto processing the packet is presented to host as a regular Rx packet
51 however all security protocol related headers are still attached to the
52 packet. e.g. In case of IPsec, the IPsec tunnel headers (if any),
53 ESP/AH headers will remain in the packet but the received packet
54 contains the decrypted data where the encrypted data was when the packet
55 arrived. The driver Rx path check the descriptors and based on the
56 crypto status sets additional flags in the rte_mbuf.ol_flags field.
60 The underlying device may not support crypto processing for all ingress packet
61 matching to a particular flow (e.g. fragmented packets), such packets will
62 be passed as encrypted packets. It is the responsibility of application to
63 process such encrypted packets using other crypto driver instance.
65 Egress Data path - The software prepares the egress packet by adding
66 relevant security protocol headers. Only the data will not be
67 encrypted by the software. The driver will accordingly configure the
68 tx descriptors. The hardware device will encrypt the data before sending the
73 The underlying device may support post encryption TSO.
75 .. code-block:: console
86 | | Tunnel | | <------ Add tunnel header to packet
89 | | ESP | | <------ Add ESP header without trailer to packet
90 | | | | <------ Mark packet to be offloaded, add trailer
91 | +------|------+ | meta-data to mbuf
100 | NIC PMD | <------ Set hw context for inline crypto offload
105 | HW ACCELERATED | <------ Packet Encryption and
106 | NIC | Authentication happens inline
111 Inline protocol offload
112 ~~~~~~~~~~~~~~~~~~~~~~~
114 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL:
115 The crypto and protocol processing for security protocol (e.g. IPsec)
116 is processed inline during receive and transmission. The flow based
117 security action should be configured on the port.
119 Ingress Data path - The packet is decrypted in the RX path and relevant
120 crypto status is set in the Rx descriptors. After the successful inline
121 crypto processing the packet is presented to the host as a regular Rx packet
122 but all security protocol related headers are optionally removed from the
123 packet. e.g. in the case of IPsec, the IPsec tunnel headers (if any),
124 ESP/AH headers will be removed from the packet and the received packet
125 will contains the decrypted packet only. The driver Rx path checks the
126 descriptors and based on the crypto status sets additional flags in
127 ``rte_mbuf.ol_flags`` field. The driver would also set device-specific
128 metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
129 This will allow the application to identify the security processing
134 The underlying device in this case is stateful. It is expected that
135 the device shall support crypto processing for all kind of packets matching
136 to a given flow, this includes fragmented packets (post reassembly).
137 E.g. in case of IPsec the device may internally manage anti-replay etc.
138 It will provide a configuration option for anti-replay behavior i.e. to drop
139 the packets or pass them to driver with error flags set in the descriptor.
141 Egress Data path - The software will send the plain packet without any
142 security protocol headers added to the packet. The driver will configure
143 the security index and other requirement in tx descriptors.
144 The hardware device will do security processing on the packet that includes
145 adding the relevant protocol headers and encrypting the data before sending
146 the packet out. The software should make sure that the buffer
147 has required head room and tail room for any protocol header addition. The
148 software may also do early fragmentation if the resultant packet is expected
149 to cross the MTU size.
154 The underlying device will manage state information required for egress
155 processing. E.g. in case of IPsec, the seq number will be added to the
156 packet, however the device shall provide indication when the sequence number
157 is about to overflow. The underlying device may support post encryption TSO.
159 .. code-block:: console
170 | | Desc | | <------ Mark packet to be offloaded
180 | NIC PMD | <------ Set hw context for inline crypto offload
185 | HW ACCELERATED | <------ Add tunnel, ESP header etc header to
186 | NIC | packet. Packet Encryption and
187 | | Authentication happens inline.
191 Lookaside protocol offload
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~
194 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL:
195 This extends librte_cryptodev to support the programming of IPsec
196 Security Association (SA) as part of a crypto session creation including
197 the definition. In addition to standard crypto processing, as defined by
198 the cryptodev, the security protocol processing is also offloaded to the
201 Decryption: The packet is sent to the crypto device for security
202 protocol processing. The device will decrypt the packet and it will also
203 optionally remove additional security headers from the packet.
204 E.g. in case of IPsec, IPsec tunnel headers (if any), ESP/AH headers
205 will be removed from the packet and the decrypted packet may contain
210 In case of IPsec the device may internally manage anti-replay etc.
211 It will provide a configuration option for anti-replay behavior i.e. to drop
212 the packets or pass them to driver with error flags set in descriptor.
214 Encryption: The software will submit the packet to cryptodev as usual
215 for encryption, the hardware device in this case will also add the relevant
216 security protocol header along with encrypting the packet. The software
217 should make sure that the buffer has required head room and tail room
218 for any protocol header addition.
222 In the case of IPsec, the seq number will be added to the packet,
223 It shall provide an indication when the sequence number is about to
226 .. code-block:: console
234 | | SADB lookup | | <------ SA maps to cryptodev session
237 | | \--------------------\
238 | | Crypto | | | <- Crypto processing through
239 | | /----------------\ | inline crypto PMD
240 | +------|------+ | | |
241 +--------V--------+ | |
243 +--------V--------+ | | create <-- SA is added to hw
244 | L2 Stack | | | inline using existing create
245 +--------|--------+ | | session sym session APIs
247 +--------V--------+ +---|---|----V---+
248 | | | \---/ | | <--- Add tunnel, ESP header etc
249 | NIC PMD | | INLINE | | header to packet.Packet
250 | | | CRYPTO PMD | | Encryption/Decryption and
251 +--------|--------+ +----------------+ Authentication happens
261 Based on 3GPP TS 36.323 Evolved Universal Terrestrial Radio Access (E-UTRA);
262 Packet Data Convergence Protocol (PDCP) specification
266 Transmitting PDCP Entity Receiving PDCP Entity
268 | +-----------|-----------+
269 V | In order delivery and |
270 +---------|----------+ | Duplicate detection |
271 | Sequence Numbering | | (Data Plane only) |
272 +---------|----------+ +-----------|-----------+
274 +---------|----------+ +-----------|----------+
275 | Header Compression*| | Header Decompression*|
276 | (Data-Plane only) | | (Data Plane only) |
277 +---------|----------+ +-----------|----------+
279 +---------|-----------+ +-----------|----------+
280 | Integrity Protection| |Integrity Verification|
281 | (Control Plane only)| | (Control Plane only) |
282 +---------|-----------+ +-----------|----------+
283 +---------|-----------+ +----------|----------+
284 | Ciphering | | Deciphering |
285 +---------|-----------+ +----------|----------+
286 +---------|-----------+ +----------|----------+
287 | Add PDCP header | | Remove PDCP Header |
288 +---------|-----------+ +----------|----------+
290 +----------------->>----------------+
295 * Header Compression and decompression are not supported currently.
297 Just like IPsec, in case of PDCP also header addition/deletion, cipher/
298 de-cipher, integrity protection/verification is done based on the action
304 The Data Over Cable Service Interface Specification (DOCSIS) support comprises
305 the combination of encryption/decryption and CRC generation/verification, for
306 use in a DOCSIS-MAC pipeline.
314 Ethernet frame Ethernet frame
315 from core network to core network
320 +---------|----------+ +----------|---------+ |
321 | CRC generation | | CRC verification | |
322 +---------|----------+ +----------|---------+ | combined
324 +---------|----------+ +----------|---------+ |
325 | Encryption | | Decryption | |
326 +---------|----------+ +----------|---------+ |
331 DOCSIS frame DOCSIS frame
332 to Cable Modem from Cable Modem
334 The encryption/decryption is a combination of CBC and CFB modes using either AES
335 or DES algorithms as specified in the DOCSIS Security Specification (from DPDK
336 lib_rtecryptodev perspective, these are RTE_CRYPTO_CIPHER_AES_DOCSISBPI and
337 RTE_CRYPTO_CIPHER_DES_DOCSISBPI).
339 The CRC is Ethernet CRC-32 as specified in Ethernet/[ISO/IEC 8802-3].
343 * The offset and length of data for which CRC needs to be computed are
344 specified via the auth offset and length fields of the rte_crypto_sym_op.
345 * Other DOCSIS protocol functionality such as Header Checksum (HCS)
346 calculation may be added in the future.
348 Device Features and Capabilities
349 ---------------------------------
351 Device Capabilities For Security Operations
352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 The device (crypto or ethernet) capabilities which support security operations,
355 are defined by the security action type, security protocol, protocol
356 capabilities and corresponding crypto capabilities for security. For the full
357 scope of the Security capability see definition of rte_security_capability
358 structure in the *DPDK API Reference*.
362 struct rte_security_capability;
364 Each driver (crypto or ethernet) defines its own private array of capabilities
365 for the operations it supports. Below is an example of the capabilities for a
366 PMD which supports the IPsec and PDCP protocol.
370 static const struct rte_security_capability pmd_security_capabilities[] = {
371 { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */
372 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
373 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
375 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
376 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
377 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
380 .crypto_capabilities = pmd_capabilities
382 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
383 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
384 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
386 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
387 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
388 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
391 .crypto_capabilities = pmd_capabilities
393 { /* PDCP Lookaside Protocol offload Data Plane */
394 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
395 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
397 .domain = RTE_SECURITY_PDCP_MODE_DATA,
400 .crypto_capabilities = pmd_capabilities
402 { /* PDCP Lookaside Protocol offload Control */
403 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
404 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
406 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
409 .crypto_capabilities = pmd_capabilities
412 .action = RTE_SECURITY_ACTION_TYPE_NONE
415 static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
417 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
419 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
421 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
439 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
441 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
443 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
460 Below is an example of the capabilities for a PMD which supports the DOCSIS
465 static const struct rte_security_capability pmd_security_capabilities[] = {
466 { /* DOCSIS Uplink */
467 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
468 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
470 .direction = RTE_SECURITY_DOCSIS_UPLINK
472 .crypto_capabilities = pmd_capabilities
474 { /* DOCSIS Downlink */
475 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
476 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
478 .direction = RTE_SECURITY_DOCSIS_DOWNLINK
480 .crypto_capabilities = pmd_capabilities
483 .action = RTE_SECURITY_ACTION_TYPE_NONE
486 static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
487 { /* AES DOCSIS BPI */
488 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
490 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
492 .algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
508 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
511 Capabilities Discovery
512 ~~~~~~~~~~~~~~~~~~~~~~
514 Discovering the features and capabilities of a driver (crypto/ethernet)
515 is achieved through the ``rte_security_capabilities_get()`` function.
519 const struct rte_security_capability *rte_security_capabilities_get(uint16_t id);
521 This allows the user to query a specific driver and get all device
522 security capabilities. It returns an array of ``rte_security_capability`` structures
523 which contains all the capabilities for that device.
525 Security Session Create/Free
526 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
528 Security Sessions are created to store the immutable fields of a particular Security
529 Association for a particular protocol which is defined by a security session
530 configuration structure which is used in the operation processing of a packet flow.
531 Sessions are used to manage protocol specific information as well as crypto parameters.
532 Security sessions cache this immutable data in a optimal way for the underlying PMD
533 and this allows further acceleration of the offload of Crypto workloads.
535 The Security framework provides APIs to create and free sessions for crypto/ethernet
536 devices, where sessions are mempool objects. It is the application's responsibility
537 to create and manage two session mempools - one for session and other for session
538 private data. The private session data mempool object size should be able to
539 accommodate the driver's private data of security session. The application can get
540 the size of session private data using API ``rte_security_session_get_size``.
541 And the session mempool object size should be enough to accommodate
542 ``rte_security_session``.
544 Once the session mempools have been created, ``rte_security_session_create()``
545 is used to allocate and initialize a session for the required crypto/ethernet device.
547 Session APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet
548 security ops. This parameter can be retrieved using the APIs
549 ``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx``
552 Sessions already created can be updated with ``rte_security_session_update()``.
554 When a session is no longer used, the user must call ``rte_security_session_destroy()``
555 to free the driver private session data and return the memory back to the mempool.
557 For look aside protocol offload to hardware crypto device, the ``rte_crypto_op``
558 created by the application is attached to the security session by the API
559 ``rte_security_attach_session()``.
561 For Inline Crypto and Inline protocol offload, device specific defined metadata is
562 updated in the mbuf using ``rte_security_set_pkt_metadata()`` if
563 ``DEV_TX_OFFLOAD_SEC_NEED_MDATA`` is set.
565 For inline protocol offloaded ingress traffic, the application can register a
566 pointer, ``userdata`` , in the security session. When the packet is received,
567 ``rte_security_get_userdata()`` would return the userdata registered for the
568 security session which processed the packet.
572 In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
573 would be used by the driver to relay information on the security processing
574 associated with the packet. In ingress, the driver would set this in Rx
575 path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
576 similar operation. The application is expected not to modify the field
577 when it has relevant info. For ingress, this device-specific 64 bit value
578 is required to derive other information (like userdata), required for
579 identifying the security processing done on the packet.
581 Security session configuration
582 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
584 Security Session configuration structure is defined as ``rte_security_session_conf``
588 struct rte_security_session_conf {
589 enum rte_security_session_action_type action_type;
590 /**< Type of action to be performed on the session */
591 enum rte_security_session_protocol protocol;
592 /**< Security protocol to be configured */
594 struct rte_security_ipsec_xform ipsec;
595 struct rte_security_macsec_xform macsec;
596 struct rte_security_pdcp_xform pdcp;
597 struct rte_security_docsis_xform docsis;
599 /**< Configuration parameters for security session */
600 struct rte_crypto_sym_xform *crypto_xform;
601 /**< Security Session Crypto Transformations */
603 /**< Application specific userdata to be saved with session */
606 The configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related
607 configuration. The ``rte_security_session_action_type`` struct is used to specify whether the
608 session is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol
613 enum rte_security_session_action_type {
614 RTE_SECURITY_ACTION_TYPE_NONE,
615 /**< No security actions */
616 RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
617 /**< Crypto processing for security protocol is processed inline
618 * during transmission
620 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
621 /**< All security protocol processing is performed inline during
624 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
625 /**< All security protocol processing including crypto is performed
626 * on a lookaside accelerator
628 RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO
629 /**< Similar to ACTION_TYPE_NONE but crypto processing for security
630 * protocol is processed synchronously by a CPU.
634 The ``rte_security_session_protocol`` is defined as
638 enum rte_security_session_protocol {
639 RTE_SECURITY_PROTOCOL_IPSEC = 1,
640 /**< IPsec Protocol */
641 RTE_SECURITY_PROTOCOL_MACSEC,
642 /**< MACSec Protocol */
643 RTE_SECURITY_PROTOCOL_PDCP,
644 /**< PDCP Protocol */
645 RTE_SECURITY_PROTOCOL_DOCSIS,
646 /**< DOCSIS Protocol */
649 Currently the library defines configuration parameters for IPsec and PDCP only.
650 For other protocols like MACSec, structures and enums are defined as place holders
651 which will be updated in the future.
653 IPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
655 PDCP related configuration parameters are defined in ``rte_security_pdcp_xform``
657 DOCSIS related configuration parameters are defined in ``rte_security_docsis_xform``
663 The rte_security Library API is described in the *DPDK API Reference* document.
665 Flow based Security Session
666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
668 In the case of NIC based offloads, the security session specified in the
669 'rte_flow_action_security' must be created on the same port as the
670 flow action that is being specified.
672 The ingress/egress flow attribute should match that specified in the security
673 session if the security session supports the definition of the direction.
675 Multiple flows can be configured to use the same security session. For
676 example if the security session specifies an egress IPsec SA, then multiple
677 flows can be specified to that SA. In the case of an ingress IPsec SA then
678 it is only valid to have a single flow to map to that security session.
680 .. code-block:: console
686 | IPsec SA | <------ Build security flow action of
687 | | | ipsec transform
696 | NIC PMD | <------ Add/Remove SA to/from hw context
706 * Add/Delete SA flow:
707 To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
708 using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``.
709 Note that any rte_flow_items may be empty, which means it is not checked.
711 .. code-block:: console
713 In its most basic form, IPsec flow specification is as follows:
714 +-------+ +----------+ +--------+ +-----+
715 | Eth | -> | IP4/6 | -> | ESP | -> | END |
716 +-------+ +----------+ +--------+ +-----+
718 However, the API can represent, IPsec crypto offload with any encapsulation:
719 +-------+ +--------+ +-----+
720 | Eth | -> ... -> | ESP | -> | END |
721 +-------+ +--------+ +-----+