Skip to content

Commit 9172a0c

Browse files
committed
doc: crypto: updates to crypto samples, part 3
Updated the documentation of crypto samples. Added sample output, cross-links to recently updated docs, more details in the overview sections. Edited sample.yaml for term and style consistency. Future PRs will edit remaining crypto samples. NCSDK-33435. Follow-up to #25032 and #25157. Signed-off-by: Grzegorz Ferenc <[email protected]>
1 parent 4e54417 commit 9172a0c

File tree

38 files changed

+485
-152
lines changed

38 files changed

+485
-152
lines changed

doc/nrf/security/crypto/crypto_supported_features.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,7 @@ Based on this setting, Oberon PSA Crypto selects the most appropriate driver for
30023002
* - Configuration automatically generated based on the enabled key encapsulation algorithms. Acts as :ref:`software fallback <crypto_drivers_software_fallback>` for the other drivers.
30033003
- :kconfig:option:`CONFIG_PSA_WANT_ALG_ML_KEM`
30043004

3005+
.. _ug_crypto_supported_features_kdf_algorithms:
30053006

30063007
KDF algorithms
30073008
==============
@@ -5787,6 +5788,8 @@ Based on this setting, Oberon PSA Crypto selects the most appropriate driver for
57875788
- | :kconfig:option:`CONFIG_PSA_WANT_ALG_RSA_OAEP`
57885789
| :kconfig:option:`CONFIG_PSA_WANT_ALG_RSA_PKCS1V15_CRYPT` (does not support RSA key pair generation)
57895790
5791+
.. _ug_crypto_supported_features_ecc_curve_types:
5792+
57905793
ECC curve types
57915794
===============
57925795

samples/crypto/aes_cbc/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_GENERATE_RANDOM=y
2122
CONFIG_PSA_WANT_KEY_TYPE_AES=y
2223
CONFIG_PSA_WANT_ALG_CBC_NO_PADDING=y

samples/crypto/aes_ccm/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_GENERATE_RANDOM=y
2122
CONFIG_PSA_WANT_KEY_TYPE_AES=y
2223
CONFIG_PSA_WANT_ALG_CCM=y

samples/crypto/aes_ctr/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_GENERATE_RANDOM=y
2122
CONFIG_PSA_WANT_KEY_TYPE_AES=y
2223
CONFIG_PSA_WANT_ALG_CTR=y

samples/crypto/aes_gcm/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_GENERATE_RANDOM=y
2122
CONFIG_PSA_WANT_KEY_TYPE_AES=y
2223
CONFIG_PSA_WANT_ALG_GCM=y

samples/crypto/chachapoly/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_GENERATE_RANDOM=y
2122
CONFIG_PSA_WANT_KEY_TYPE_CHACHA20=y
2223
CONFIG_PSA_WANT_ALG_CHACHA20_POLY1305=y

samples/crypto/ecdh/prj.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_ALG_ECDH=y
2122
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y
2223
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT=y
2324
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
2425
CONFIG_PSA_WANT_ECC_SECP_R1_256=y
25-
26-
# For key generation
2726
CONFIG_PSA_WANT_GENERATE_RANDOM=y

samples/crypto/ecdsa/prj.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ CONFIG_HEAP_MEM_POOL_SIZE=8192
1313
CONFIG_CONSOLE=y
1414
CONFIG_LOG=y
1515

16-
# Enable nordic security backend and PSA APIs
16+
# Enable nRF Security backend for PSA Crypto API
1717
CONFIG_NRF_SECURITY=y
1818
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
1919

20+
# Enable cryptographic features for compilation
2021
CONFIG_PSA_WANT_ALG_ECDSA=y
2122
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y
2223
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT=y
2324
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
2425
CONFIG_PSA_WANT_ECC_SECP_R1_256=y
2526
CONFIG_PSA_WANT_ALG_SHA_256=y
26-
27-
# For key generation
2827
CONFIG_PSA_WANT_GENERATE_RANDOM=y

samples/crypto/ecjpake/README.rst

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ Crypto: EC J-PAKE
77
:local:
88
:depth: 2
99

10-
The EC J-PAKE sample demonstrates how to do password-authenticated key exchange using
11-
the elliptic curve (EC) version of the password-authenticated key exchange by
12-
juggling (J-PAKE) protocol.
10+
The EC J-PAKE sample demonstrates how to use the :ref:`PSA Crypto API <ug_psa_certified_api_overview_crypto>` to perform password-authenticated key exchange using the EC J-PAKE algorithm.
11+
The sample uses the elliptic curve (EC) version of the password-authenticated key exchange by juggling (J-PAKE) protocol with a shared password.
1312

1413
Requirements
1514
************
@@ -21,11 +20,35 @@ The sample supports the following development kits:
2120
Overview
2221
********
2322

24-
The sample performs the following operations:
23+
The sample :ref:`enables PSA Crypto API <psa_crypto_support_enable>` and configures the following Kconfig options for the cryptographic features:
2524

26-
1. Initializes the Platform Security Architecture (PSA) API.
27-
#. Goes through the steps for J-PAKE on server and client sides.
28-
#. Verifies that the derived keys are the same.
25+
* :kconfig:option:`CONFIG_PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY` - Used to enable support for ECC public key types from among the supported cryptographic operations for :ref:`ug_crypto_supported_features_key_types`.
26+
* :kconfig:option:`CONFIG_PSA_WANT_ALG_JPAKE` - Used to enable support for the J-PAKE key agreement algorithm from among the supported cryptographic operations for :ref:`ug_crypto_supported_features_pake_algorithms`.
27+
* :kconfig:option:`CONFIG_PSA_WANT_ALG_SHA_256` - Used to enable support for the SHA-256 hash algorithm from among the supported cryptographic operations for :ref:`ug_crypto_supported_features_hash_algorithms`.
28+
29+
.. include:: /samples/crypto/aes_cbc/README.rst
30+
:start-after: crypto_sample_overview_driver_selection_start
31+
:end-before: crypto_sample_overview_driver_selection_end
32+
33+
Once built and run, the sample performs the following operations:
34+
35+
1. Initialization:
36+
37+
a. The PSA Crypto API is initialized using :c:func:`psa_crypto_init`.
38+
#. A password key is imported using :c:func:`psa_import_key` with the ``PSA_KEY_TYPE_PASSWORD`` type.
39+
The key is configured with usage flags for key derivation.
40+
41+
#. EC J-PAKE key exchange:
42+
43+
a. PAKE operations are set up for both client and server using :c:func:`psa_pake_setup`.
44+
#. Key exchange rounds are performed using :c:func:`psa_pake_output` and :c:func:`psa_pake_input`.
45+
This includes key sharing, zero-knowledge public values, and zero-knowledge proofs.
46+
#. Shared secrets are derived using :c:func:`psa_pake_get_shared_key` and key derivation functions.
47+
#. The derived secrets are compared to verify that both parties obtained the same shared secret.
48+
49+
#. Cleanup:
50+
51+
a. The password key is removed from the PSA crypto keystore using :c:func:`psa_destroy_key`.
2952

3053
Building and running
3154
********************
@@ -37,8 +60,30 @@ Building and running
3760
Testing
3861
=======
3962

40-
After programming the sample to your development kit, complete the following steps to test it:
63+
.. include:: /samples/crypto/aes_cbc/README.rst
64+
:start-after: crypto_sample_testing_start
65+
:end-before: crypto_sample_testing_end
66+
67+
.. code-block:: text
4168
42-
1. |connect_terminal|
43-
#. Compile and program the application.
44-
#. Observe the logs from the application using a terminal emulator.
69+
*** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
70+
*** Using Zephyr OS v4.1.99-1612683d4010 ***
71+
[00:00:00.251,159] <inf> ecjpake: Starting EC J-PAKE example...
72+
[00:00:00.251,190] <inf> ecjpake: Importing password key...
73+
[00:00:00.251,342] <inf> ecjpake: Password key imported successfully!
74+
[00:00:00.251,373] <inf> ecjpake: Performing EC J-PAKE key exchange rounds...
75+
[00:00:00.251,708] <inf> ecjpake: EC J-PAKE key exchange completed successfully!
76+
[00:00:00.251,739] <inf> ecjpake: Deriving shared secrets...
77+
[00:00:00.251,770] <inf> ecjpake: Shared secrets derived successfully!
78+
[00:00:00.251,800] <inf> ecjpake: ---- server_secret (len: 32): ----
79+
[00:00:00.251,831] <inf> ecjpake: Content:
80+
c3 1e 5b 35 97 25 ee a3 ef ba 66 c3 f9 81 37 2a |..[5.%.. ..f...7*
81+
76 9d a9 cb 1c 49 4f 6d ef b8 a2 aa 11 2c fc bd |v....IOm .....,..
82+
[00:00:00.251,861] <inf> ecjpake: ---- server_secret end ----
83+
[00:00:00.251,892] <inf> ecjpake: ---- client_secret (len: 32): ----
84+
[00:00:00.251,922] <inf> ecjpake: Content:
85+
c3 1e 5b 35 97 25 ee a3 ef ba 66 c3 f9 81 37 2a |..[5.%.. ..f...7*
86+
76 9d a9 cb 1c 49 4f 6d ef b8 a2 aa 11 2c fc bd |v....IOm .....,..
87+
[00:00:00.251,953] <inf> ecjpake: ---- client_secret end ----
88+
[00:00:00.251,984] <inf> ecjpake: Shared secrets match successfully!
89+
[00:00:00.252,014] <inf> ecjpake: Example finished successfully!

samples/crypto/ecjpake/sample.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
sample:
2-
description: This app provides an example of EC J-PAKE
3-
name: EC J-PAKE example
2+
description: |
3+
This sample demonstrates EC J-PAKE key exchange using the EC J-PAKE algorithm.
4+
name: EC J-PAKE sample
45
tests:
56
sample.ecjpake.oberon:
67
sysbuild: true

0 commit comments

Comments
 (0)