Skip to content

Commit 332b401

Browse files
joerchanrlubos
authored andcommitted
samples: crypto: Add PBKDF2 sample
Add sample to demonstrate PBKDF2 use-case. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 778876a commit 332b401

11 files changed

+364
-0
lines changed

samples/crypto/pbkdf2/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2023 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
project(pbkdf2)
12+
13+
target_sources(app PRIVATE
14+
src/main.c)

samples/crypto/pbkdf2/README.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. _crypto_pbkdf2:
2+
3+
Crypto: PBKDF2
4+
##############
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Password Based Key Derivation Function (PBKDF2) sample shows how to derive keys with the PBKDF2 algorithm, using a sample password salt, and iteration count.
11+
The underlying pseudorandom function (PRF) used in this sample is HMAC with SHA-256.
12+
13+
Requirements
14+
************
15+
16+
The sample supports the following development kits:
17+
18+
.. table-from-sample-yaml::
19+
20+
.. include:: /includes/tfm.txt
21+
22+
Overview
23+
********
24+
25+
The sample performs the following operations:
26+
27+
1. Initialization of the Platform Security Architecture (PSA) API.
28+
29+
#. Key derivation:
30+
31+
a. Imports the input password into the PSA crypto keystore.
32+
#. Derives the output key.
33+
34+
#. Cleanup:
35+
36+
a. The input password is removed from the PSA crypto keystore.
37+
38+
Building and running
39+
********************
40+
41+
.. |sample path| replace:: :file:`samples/crypto/pbkdf2`
42+
43+
.. include:: /includes/build_and_run_ns.txt
44+
45+
Testing
46+
=======
47+
48+
After programming the sample to your development kit, complete the following steps to test it:
49+
50+
1. |connect_terminal|
51+
#. Compile and program the application.
52+
#. Observe the logs from the application using a terminal emulator.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable both oberon driver and hardware crypto accelerator
2+
# Key derivation is only supported in software driver but is using chained
3+
# driver to accelerate sub-operations.
4+
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
5+
CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable both oberon driver and hardware crypto accelerator
2+
# Key derivation is only supported in software driver but is using chained
3+
# driver to accelerate sub-operations.
4+
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
5+
CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_TFM_PROFILE_TYPE_NOT_SET=y
2+
3+
# Using hardware crypto accelerator
4+
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Enable both oberon driver and hardware crypto accelerator
2+
# Key derivation is only supported in software driver but is using chained
3+
# driver to accelerate sub-operations.
4+
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
5+
CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_TFM_PROFILE_TYPE_NOT_SET=y
2+
3+
# Using hardware crypto accelerator
4+
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* Disable uart1 in nonsecure since it is used by the TFM secure app. */
8+
&uart1 {
9+
status = "disabled";
10+
};

samples/crypto/pbkdf2/prj.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The Zephyr CMSIS emulation assumes that ticks are ms, currently
2+
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
3+
4+
CONFIG_MAIN_STACK_SIZE=4096
5+
CONFIG_HEAP_MEM_POOL_SIZE=4096
6+
7+
# Enable logging
8+
CONFIG_CONSOLE=y
9+
CONFIG_LOG=y
10+
11+
# Enable nordic security backend and PSA APIs
12+
CONFIG_NRF_SECURITY=y
13+
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
14+
15+
CONFIG_MBEDTLS_ENABLE_HEAP=y
16+
CONFIG_MBEDTLS_HEAP_SIZE=8192
17+
18+
CONFIG_PSA_WANT_ALG_SHA_256=y
19+
CONFIG_PSA_WANT_ALG_HMAC=y
20+
CONFIG_PSA_WANT_ALG_PBKDF2_HMAC=y

samples/crypto/pbkdf2/sample.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sample:
2+
description: HMAC key derivation function example
3+
name: PBKDF2 example
4+
tests:
5+
sample.pbkdf2:
6+
tags: introduction psa cc3xx
7+
platform_allow: >
8+
nrf5340dk_nrf5340_cpuapp
9+
nrf9160dk_nrf9160 nrf52840dk_nrf52840
10+
harness: console
11+
harness_config:
12+
type: multi_line
13+
regex:
14+
- ".*Example finished successfully!.*"
15+
integration_platforms:
16+
- nrf5340dk_nrf5340_cpuapp
17+
- nrf9160dk_nrf9160
18+
- nrf52840dk_nrf52840

0 commit comments

Comments
 (0)