|
| 1 | +.. _ug_crypto_architecture: |
| 2 | + |
| 3 | +Cryptographic architecture overview |
| 4 | +################################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The cryptographic subsystem in the |NCS| is based on the `PSA Certified Crypto API`_ standard (PSA Crypto API), which is one of the `PSA Certified APIs <Embedded and IoT Security Specifications and Implementations_>`_. |
| 11 | +The PSA Crypto API is a cryptographic standard that offers a unified interface for cryptographic operations across different hardware platforms. |
| 12 | + |
| 13 | +PSA Crypto API architecture |
| 14 | +*************************** |
| 15 | + |
| 16 | +The following figure shows the general architecture of PSA Crypto: |
| 17 | + |
| 18 | +.. figure:: ../images/psa_crypto_api_arch.svg |
| 19 | + :alt: PSA Crypto standard architecture |
| 20 | + :align: center |
| 21 | + |
| 22 | + PSA Crypto standard architecture |
| 23 | + |
| 24 | +In this figure: |
| 25 | + |
| 26 | +* Application calls the PSA Crypto implementation through the PSA Crypto API. |
| 27 | +* The PSA Crypto API implementation is an abstraction layer that manages cryptographic operations, key handling, and driver coordination. |
| 28 | + The implementations can be different, but they should all conform to the PSA Crypto specification. |
| 29 | +* Crypto driver is a specialized component that implements specific cryptographic algorithms or provides access to hardware accelerators. |
| 30 | +* Storage integration provides persistent and secure storage capabilities through standardized PSA Secure Storage APIs. |
| 31 | + It implements storage interfaces that allow the PSA Crypto implementation to securely store and retrieve keys, ensuring proper protection of sensitive material throughout its lifecycle. |
| 32 | + |
| 33 | +.. _ug_crypto_architecture_interaction_flow: |
| 34 | + |
| 35 | +Component interaction flow |
| 36 | +========================== |
| 37 | + |
| 38 | +When an application makes a call to the PSA Crypto API, the following interaction flow occurs between the architecture components: |
| 39 | + |
| 40 | +1. The application or protocol stack initiates a cryptographic operation by calling a function in the PSA Crypto API, such as ``psa_cipher_encrypt()`` or ``psa_sign_message()``. |
| 41 | +2. The PSA Crypto implementation receives the request and performs initial parameter validation to ensure the request is properly formatted and contains valid parameters. |
| 42 | +3. Based on the specific operation requested, the implementation selects the most appropriate crypto driver. |
| 43 | + Hardware drivers are typically prioritized when available, with software drivers serving as fallbacks. |
| 44 | +4. If the operation involves cryptographic keys, the implementation coordinates with the storage integration to securely retrieve the necessary key material. |
| 45 | + Keys are handled using `Key Identifiers`_ to maintain security and prevent direct exposure of key material to the application. |
| 46 | +5. The implementation delegates the actual cryptographic processing to the selected crypto driver. |
| 47 | + The driver performs the requested operation using either hardware acceleration or software algorithms. |
| 48 | +6. The driver returns the operation result to the PSA Crypto implementation, which performs any necessary post-processing and validation. |
| 49 | +7. The implementation returns the final result to the application through the PSA Crypto API, completing the cryptographic operation. |
| 50 | + |
| 51 | +.. _ug_crypto_architecture_implementation_standards: |
| 52 | + |
| 53 | +Implementations in the |NCS| |
| 54 | +**************************** |
| 55 | + |
| 56 | +The |NCS| follows the PSA Crypto standard through two major API implementations: Oberon PSA Crypto and TF-M Crypto Service. |
| 57 | +They are designed for use without and with Trusted Firmware-M (TF-M), respectively, and have different security requirements. |
| 58 | +Both are based on the `sdk-oberon-psa-crypto`_ library, which offers a lightweight PSA Crypto API implementation optimized for resource-constrained microcontrollers. |
| 59 | + |
| 60 | +.. figure:: ../images/psa_crypto_api_overview.svg |
| 61 | + :alt: PSA Crypto API implementations in the |NCS| |
| 62 | + :align: center |
| 63 | + |
| 64 | + PSA Crypto API implementations in the |NCS| |
| 65 | + |
| 66 | +.. _ug_crypto_architecture_implementation_standards_oberon: |
| 67 | + |
| 68 | +Oberon PSA Crypto implementation |
| 69 | +================================ |
| 70 | + |
| 71 | +The Oberon PSA Crypto implementation provides a direct PSA Crypto API interface for applications that do not require Trusted Firmware-M (TF-M). |
| 72 | +The Oberon PSA Crypto is a library that serves as the central component managing cryptographic operations and driver selection. |
| 73 | + |
| 74 | +.. figure:: ../images/psa_crypto_api_oberon.svg |
| 75 | + :alt: Oberon PSA Crypto implementation |
| 76 | + :align: center |
| 77 | + |
| 78 | + Oberon PSA Crypto implementation |
| 79 | + |
| 80 | +The Oberon PSA Crypto acts as the implementation provider, directly exposing the PSA Crypto API to applications. |
| 81 | +Each driver can implement support for different subsets of cryptographic algorithms, providing software support for algorithms that hardware cannot support. |
| 82 | + |
| 83 | +The following figure shows the driver library selection through the driver wrapper, one of the internal modules of Oberon PSA Crypto: |
| 84 | + |
| 85 | +.. figure:: ../images/psa_certified_api_lib_selection.svg |
| 86 | + :alt: Oberon PSA Crypto driver library selection |
| 87 | + :align: center |
| 88 | + |
| 89 | + Oberon PSA Crypto driver library selection |
| 90 | + |
| 91 | +This implementation standard is suitable for applications that prioritize simplicity and do not require the additional security isolation provided by TF-M. |
| 92 | +It offers direct access to cryptographic functionality with minimal overhead, making it ideal for resource-constrained applications. |
| 93 | + |
| 94 | +Storage integration for the Oberon PSA Crypto implementation |
| 95 | +------------------------------------------------------------ |
| 96 | + |
| 97 | +When using the Oberon PSA Crypto implementation, persistent keys from the PSA Crypto API can be stored in the |NCS| using one of the following storage mechanisms: |
| 98 | + |
| 99 | +* Zephyr's :ref:`Secure storage <zephyr:secure_storage>` subsystem - Zephyr-specific implementation of the functions defined in the `PSA Certified Secure Storage API`_. |
| 100 | +* |NCS|'s :ref:`trusted_storage_readme` library - which provides features like integrity, confidentiality, and authenticity of the stored data without using the TF-M Platform Root of Trust (PRoT). |
| 101 | + |
| 102 | +For more information about the storage integration for the Oberon PSA Crypto implementation, see :ref:`trusted_storage_in_ncs`. |
| 103 | + |
| 104 | +.. _ug_crypto_architecture_implementation_standards_tfm: |
| 105 | + |
| 106 | +TF-M Crypto Service implementation |
| 107 | +================================== |
| 108 | + |
| 109 | +The TF-M Crypto Service implementation provides PSA Crypto API access through Trusted Firmware-M for applications that require enhanced security through hardware-enforced separation. |
| 110 | + |
| 111 | +.. figure:: ../images/psa_crypto_api_tfm.svg |
| 112 | + :alt: TF-M Crypto Service implementation |
| 113 | + :align: center |
| 114 | + |
| 115 | + TF-M Crypto Service implementation |
| 116 | + |
| 117 | +This implementation leverages TF-M's Secure Processing Environment (SPE) to isolate cryptographic operations from the Non-Secure Processing Environment (NSPE). |
| 118 | +TF-M is built on top of TrustZone technology and isolates the PSA Crypto API as non-secure callable calls into a secure processing environment. |
| 119 | + |
| 120 | +.. figure:: ../images/tfm_psa_crypto_api_nspe_spe.svg |
| 121 | + :alt: TF-M Crypto Service implementation in the NSPE and SPE |
| 122 | + :align: center |
| 123 | + |
| 124 | + TF-M Crypto Service implementation in the NSPE and SPE |
| 125 | + |
| 126 | +In this architecture, TF-M implements the secure cryptographic service using the existing Oberon PSA Core and its associated drivers within the secure environment. |
| 127 | +Cryptographic keys are stored and isolated in the SPE, ensuring they are not accessible by the application running in the NSPE. |
| 128 | +The same cryptographic drivers (nrf_cc3xx, nrf_oberon, and CRACEN) are available within the secure environment, providing consistent cryptographic capabilities. |
| 129 | +Additionally, TF-M integrates key storage using its internal mechanisms, offering secure key management through :ref:`Internal Trusted Storage <ug_tfm_services_its>` and :ref:`Protected Storage <tfm_partition_ps>`. |
| 130 | + |
| 131 | +This implementation standard is mandatory for applications requiring PSA Certified security levels and provides the highest level of security through hardware-enforced isolation. |
| 132 | +It ensures that cryptographic operations and key material remain protected even if the non-secure application is compromised. |
| 133 | + |
| 134 | +Storage integration for the TF-M Crypto Service implementation |
| 135 | +-------------------------------------------------------------- |
| 136 | + |
| 137 | +When using the TF-M Crypto Service implementation, keys from the PSA Crypto API are stored in the |NCS| using both of the following storage mechanisms: |
| 138 | + |
| 139 | +* Internal Trusted Storage (ITS) - One of :ref:`ug_tfm_architecture_rot_services_platform` that provides secure storage within the Trusted Firmware-M environment. |
| 140 | + ITS is the only storage for persistent keys in the TF-M Crypto Service implementation. |
| 141 | +* Protected Storage (PS) - One of :ref:`ug_tfm_architecture_rot_services_application` that provides secure storage within the Trusted Firmware-M environment. |
| 142 | + |
| 143 | +For more information about the storage integration for the TF-M Crypto Service implementation, see :ref:`ug_psa_certified_api_overview_secstorage` and :ref:`ug_tfm_services`. |
0 commit comments