Skip to content

Commit 5bd5fe1

Browse files
committed
nrf_security: Updated documentation for nRF Security module
- Documenting the advanced configuration section in nRF Security. - Improved dependencies on mbed TLS advanced configuration sections for improved user experience. - Fixed api inclusion of nrf_cc310_platform APIs Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Bartosz Gentkowski <[email protected]>
1 parent 9f9bd63 commit 5bd5fe1

File tree

3 files changed

+167
-53
lines changed

3 files changed

+167
-53
lines changed

crypto/doc/api.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,41 @@ nRF CC310 platform library
2222
:project: nrfxlib
2323
:members:
2424

25+
CC310 Platform - Defines
26+
========================
27+
28+
.. doxygengroup:: nrf_cc310_platform_defines
29+
:project: nrfxlib
30+
:members:
31+
32+
CC310 Platform - Initialization APIs
33+
====================================
34+
35+
.. doxygengroup:: nrf_cc310_platform_init
36+
:project: nrfxlib
37+
:members:
38+
39+
CC310 Platform - Entropy APIs
40+
=============================
41+
42+
.. doxygengroup:: nrf_cc310_platform_entropy
43+
:project: nrfxlib
44+
:members:
45+
46+
CC310 Platform - Mutex APIs
47+
===========================
48+
49+
.. doxygengroup:: nrf_cc310_platform_mutex
50+
:project: nrfxlib
51+
:members:
52+
53+
CC310 Platform - Abort APIs
54+
===========================
55+
56+
.. doxygengroup:: nrf_cc310_platform_abort
57+
:project: nrfxlib
58+
:members:
59+
2560

2661
.. _crypto_api_nrf_oberon:
2762

nrf_security/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ config MBEDTLS_ECP_FIXED_POINT_OPTIM
860860

861861
config MBEDTLS_SHA256_SMALLER
862862
bool "Use SHA256 small footprint implementation"
863-
depends on MBEDTLS_SHA256_C && NRF_SECURITY_ADVANCED
863+
depends on NRF_SECURITY_ADVANCED && (VANILLA_MBEDTLS_SHA256_C || (MBEDTLS_SHA256_C && !NRF_CRYPTO_BACKEND_COMBINATION_0))
864864
help
865865
Use a SHA-256 implementation with smaller footprint.
866866
Note, that this implementation will also have a lower performance.
@@ -872,12 +872,14 @@ config MBEDTLS_SSL_MAX_CONTENT_LEN
872872
int "SSL - Maximum buffer size"
873873
range 0 16384
874874
default 16384
875+
depends on MBEDTLS_TLS_LIBRARY
875876
help
876877
Maximum buffer size for incoming and outgoing mbed TLS I/O buffers.
877878
MBEDTLS_SSL_MAX_CONTENT_LEN setting in mbed TLS config file.
878879

879880
config MBEDTLS_SSL_CIPHERSUITES
880881
string "SSL - Cipher suites tuning"
882+
depends on MBEDTLS_TLS_LIBRARY
881883
help
882884
List of cipher suites to support in SSL/TLS.
883885
The cipher suites are given as a comma separated string, and in order of preference.

nrf_security/doc/nrf_security.rst

Lines changed: 129 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ It is possible to provide your own custom mbed TLS configuration file by deselec
4646
But if doing so, please read `User provided mbed TLS config header`_.
4747

4848

49-
Enabling backends
50-
=================
49+
nrf_security backends
50+
=====================
5151

5252
The nrf_security module supports multiple enabled backends at the same time.
53-
This is done to extend the feature set of hardware accelerated cryptography in case it is limited.
53+
This mechanism is intended to extend the available feature set of hardware accelerated cryptography.
5454
Enabling one or more backends adds more configuration options grouped into classes of cryptographic algorithms.
5555

5656
Note that configuration options added after enabling one or more backends will change based on the number of enabled backends.
@@ -61,13 +61,35 @@ The nrf_security module supports two backends:
6161
* Arm CryptoCell CC310 (in nRF52840 and nRF9160)
6262
* Standard mbed TLS
6363

64+
65+
Arm CryptoCell CC310 backend
66+
----------------------------
67+
68+
The Arm CryptoCell CC310 backend is a library which provides hardware accelerated cryptography using the CC310 hardware.
69+
70+
The Arm CryptoCell CC310 backend is only available on the following devices:
71+
72+
* nRF52840
73+
* nRF9160
74+
75+
6476
Enabling the Arm CryptoCell CC310 backend
6577
-----------------------------------------
6678

6779
To enable the Arm CryptoCell CC310 backend, set the :option:`CONFIG_CC310_BACKEND` Kconfig variable to true.
6880

6981
.. note:: This backend is only available in nRF52840 and nRF9160.
7082

83+
84+
Standard mbed TLS backend
85+
-------------------------
86+
87+
The standard `mbed TLS backend <https://tls.mbed.org/>`_ is a software-only library provided by Arm.
88+
89+
The standard mbed TLS backend can be used on nRF devices that do not feature the CC310 hardware.
90+
Alternatively, it can be used on CC310 enabled devices to add support for features not available in the `Arm CryptoCell CC310 backend`_, for example AES-256 or ECC Brainpool curves.
91+
92+
7193
Enabling the standard mbed TLS backend
7294
--------------------------------------
7395

@@ -77,24 +99,10 @@ To enable the standard mbed TLS backend, set the :option:`CONFIG_MBEDTLS_VANILLA
7799
Using the nrf_cc310_mbedcrypto as backend
78100
-----------------------------------------
79101

80-
To use the :ref:`nrf_cc310_mbedcrypto_readme` as a backend, it must be initialized using the standard mbed TLS APIs for platform abstraction:
102+
To use the :ref:`nrf_cc310_mbedcrypto_readme` as a backend, the CC310 hardware must first be initialized.
81103

82-
.. code-block:: c
83-
:caption: Initializing the nrf_cc310_mbedcrypto backend
84-
85-
static mbedtls_platform_context platform_context = {0};
86-
int ret;
87-
ret = mbedtls_platform_set_calloc_free(alloc_fn, free_fn);
88-
if (ret != 0) {
89-
/* Failed to set the alternative calloc/free */
90-
return ret;
91-
}
92-
93-
ret = mbedtls_platform_setup(&platform_context);
94-
if (ret != 0) {
95-
/* Failed to initialize nrf_cc310_mbedcrypto platform */
96-
return ret,
97-
}
104+
The CC310 is initialized in :ref:`nrf:lib_hw_cc310` and is controlled with the :option:`nrf:CONFIG_HW_CC310` Kconfig variable.
105+
This variable default value is `y` when the CC310 is available.
98106

99107

100108
mbed TLS glue layer
@@ -241,7 +249,7 @@ AES cipher mode support can be configured according to the following table:
241249
+--------------+----------------+---------------------------------------------+
242250
| XTS | Standard only | :option:`CONFIG_MBEDTLS_CIPHER_MODE_XTS` |
243251
+--------------+----------------+---------------------------------------------+
244-
| CMAC | | :option:`CONFIG_MBEDTLS_CMAC_C` |
252+
| CMAC | | :option:`CONFIG_MBEDTLS_CMAC_C` |
245253
+--------------+----------------+---------------------------------------------+
246254

247255
.. note::
@@ -652,57 +660,126 @@ See the :ref:`nrf_cc310_mbedcrypto_readme` documentation for details.
652660
Advanced configuration section
653661
------------------------------
654662

655-
The Advanced Configuration section i Kconfig can be used to fine tune the build
656-
of the standard mbed TLS library.
663+
The advanced configuration section in Kconfig can be used to fine-tune the build of the `standard mbed TLS backend`_ library.
664+
For example, the options available in the advanced configuration section can help to reduce the memory usage and flash footprint of the library.
657665

658-
This provides the possibility of reducing the footprint and memory usage of the
659-
nRF Security module.
666+
Actual size reductions depend on the option being adjusted.
667+
They also depend on whether `standard mbed TLS backend`_ is the only backend enabled, or whether the `mbed TLS glue layer`_ is used as well.
660668

661-
Before adjusting the default settings, please refer to https://tls.mbed.org/kb/how-to/reduce-mbedtls-memory-and-storage-footprint.
669+
Before modifying the default settings, see `this article <https://tls.mbed.org/kb/how-to/reduce-mbedtls-memory-and-storage-footprint>`_.
662670

663671
.. note::
664-
The settings available in `Advanced configuration section`_ are not validated.
665-
Thus special care must be taken when adjusting those settings.
672+
The settings available in the advanced configuration section are not validated.
673+
Adjust these settings with caution.
666674

667675

668676
Multiple Precision Integers (MPI) / Bignum calculation
669677
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
670678

671-
The :option:`CONFIG_MBEDTLS_MPI_WINDOW_SIZE` Kconfig variable controls the window size
672-
used in mbed TLS.
673-
Reducing this value to reduce memory usage. Note that reducing this this value
674-
might have an impact on the performance.
679+
The :option:`CONFIG_MBEDTLS_MPI_WINDOW_SIZE` Kconfig variable controls the window size used in mbed TLS for MPI calculations.
680+
Reduce this value to reduce memory usage. Note that reducing this this value may have an impact on the performance.
681+
682+
The :option:`CONFIG_MBEDTLS_MPI_MAX_SIZE` Kconfig variable controls the maximum size of MPIs that can be used for calculation.
683+
Reduce this value only if you are sure that the system will not need larger sizes.
684+
685+
686+
+------------------------------------------------+---------+-------+------+
687+
| Option | Default | Min | Max |
688+
+================================================+=========+=======+======+
689+
| :option:`CONFIG_MBEDTLS_MPI_WINDOW_SIZE` | 6 | 1 | 6 |
690+
+------------------------------------------------+---------+-------+------+
691+
| :option:`CONFIG_MBEDTLS_MPI_MAX_SIZE` | 1024 | 0 | 1024 |
692+
+------------------------------------------------+---------+-------+------+
693+
675694

676-
The :option:`CONFIG_MBEDTLS_MPI_MAX_SIZE` Kconfig variable controls the maximum size of
677-
MPIs that can be used for calculation.
678-
Only reduce this value if it is ensured that the system won't need larger numbers.
695+
Elliptic Curves
696+
~~~~~~~~~~~~~~~
697+
698+
The :option:`CONFIG_MBEDTLS_ECP_MAX_BITS` Kconfig variable controls the largest elliptic curve supported in the library.
699+
700+
If the curves that are used are smaller than 521 bits, then this option can be reduced in order to save memory.
701+
See `ECC curves configurations`_ for information on how to select the curves to use.
702+
For example, if `NIST secp384r1` is the only curve enabled, then :option:`CONFIG_MBEDTLS_ECP_MAX_BITS` can be reduced to 384 bits.
703+
704+
The :option:`CONFIG_MBEDTLS_ECP_WINDOW_SIZE` Kconfig variable controls the window size used for elliptic curve multiplication.
705+
This value can be reduced down to 2 to reduce memory usage.
706+
Keep in mind that reducing the value impacts the performance of the system.
707+
708+
The :option:`CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM` Kconfig variable controls ECP fixed point optimizations.
709+
If disabled, the system uses less memory, but performance of the system is reduced.
710+
711+
712+
+------------------------------------------------+---------+-------+-----+
713+
| Option | Default | Min | Max |
714+
+================================================+=========+=======+=====+
715+
| :option:`CONFIG_MBEDTLS_ECP_MAX_BITS` | 521 | 0 | 521 |
716+
+------------------------------------------------+---------+-------+-----+
717+
| :option:`CONFIG_MBEDTLS_ECP_WINDOW_SIZE` | 6 | 2 | 6 |
718+
+------------------------------------------------+---------+-------+-----+
719+
| :option:`CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM` | `y` | `n` | `y` |
720+
+------------------------------------------------+---------+-------+-----+
721+
722+
723+
SHA-256
724+
~~~~~~~
725+
726+
The :option:`CONFIG_MBEDTLS_SHA256_SMALLER` Kconfig variable can be used to select a SHA-256 implementation with smaller footprint.
727+
Such configuration reduces SHA-256 calculation performance.
728+
729+
For example, on a Cortex-M4, the size of :cpp:func:`mbedtls_sha256_process()` is reduced from ~2 KB to ~0.5 KB, however it also performs around 30% slower.
730+
731+
+------------------------------------------------+---------+-------+-----+
732+
| Option | Default | Min | Max |
733+
+================================================+=========+=======+=====+
734+
| :option:`CONFIG_MBEDTLS_SHA256_SMALLER` | `n` | `n` | `y` |
735+
+------------------------------------------------+---------+-------+-----+
736+
737+
738+
SSL Configurations
739+
~~~~~~~~~~~~~~~~~~
740+
741+
The :option:`CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN` Kconfig variable can be used to specify the maximum size for incoming and outgoing mbed TLS I/O buffers.
742+
The default value is 16384 as specified in RFC5246, however if both sides are under your control, this value can safely be reduced under the following conditions:
743+
744+
* Both sides support the max_fragment_length SSL extension, RFC8449.
745+
The max_fragment_length allows for buffer reduction to less than 1 KB.
746+
* Knowledge of the maximum size that will ever be sent in a single SSL/TLS frame.
747+
748+
If one of those conditions is met, the buffer size can safely be reduced to a more appropriate value for memory constrained devices.
749+
750+
The :option:`CONFIG_MBEDTLS_SSL_CIPHERSUITES` Kconfig variable is a custom list of cipher suites to support in SSL/TLS.
751+
The cipher suites are provided as a comma-separated string, in order of preference.
752+
This list can only be used for restricting cipher suites available in the system.
753+
754+
755+
+------------------------------------------------+---------+-----------+-------+-------+
756+
| Option | Type | Default | Min | Max |
757+
+================================================+=========+===========+=======+=======+
758+
| :option:`CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN` | Integer | 16384 | 0 | 16384 |
759+
+------------------------------------------------+---------+-----------+-------+-------+
760+
| :option:`CONFIG_MBEDTLS_SSL_CIPHERSUITES` | String | `<empty>` | | |
761+
+------------------------------------------------+---------+-----------+-------+-------+
762+
763+
.. note::
764+
The string in :option:`CONFIG_MBEDTLS_SSL_CIPHERSUITES` should not be quoted.
679765

680766

681-
User provided mbed TLS config header
767+
User-provided mbed TLS config header
682768
------------------------------------
683769

684-
The :ref:`nrf_security_readme` provides a Kconfig interface to control
685-
compilation and linking of mbed TLS and the :ref:`nrf_cc310_mbedcrypto_readme`
686-
library.
770+
The :ref:`nrf_security_readme` provides a Kconfig interface to control compilation and linking of mbed TLS and the :ref:`nrf_cc310_mbedcrypto_readme` library.
687771

688-
The Kconfig interface and build system ensures that the configuration of
689-
:ref:`nrf_security_readme` is valid and working, and ensures that depencies
690-
between different cryptographic APIs are met.
772+
The Kconfig interface and build system ensures that the configuration of :ref:`nrf_security_readme` is valid and working, and ensures that dependencies between different cryptographic APIs are met.
691773

692-
It is therefore highly recommended to let the build system generate the mbed TLS
693-
configuration header.
774+
It is therefore highly recommended to let the build system generate the mbed TLS configuration header.
694775

695-
However, for special use-case that can not be achieved using the Kconfig
696-
configuration tool, it is possible to provide a custom mbed TLS configuration
697-
header. When doing so, care must be taken to ensure a working system.
776+
However, for special use cases that cannot be achieved using the Kconfig configuration tool, it is possible to provide a custom mbed TLS configuration header.
777+
When doing so, make sure that the system is working.
698778

699-
It it therefore advised to use Kconfig and the build system to create a mbed TLS
700-
configuration header as a starting point, and then tweak this file to include
701-
settings not available i Kconfig.
779+
It is therefore advised to use Kconfig and the build system to create an mbed TLS configuration header as a starting point, and then tweak this file to include settings that are not available in Kconfig.
702780

703781
.. note::
704-
When providing a custom mbed TLS configuration header, it is important that
705-
the following criterea is still met:
782+
When providing a custom mbed TLS configuration header, it is important that the following criteria are still met:
706783

707784
* Entropy length of 144, i.e. ``#define MBEDTLS_ENTROPY_MAX_GATHER 144``
708785
* Force SHA256

0 commit comments

Comments
 (0)