Skip to content

Commit f2fe57e

Browse files
committed
nrf_security: cracen_sw: Add support for aead with AES-CCM
Add support for AES-CCM using ECB primitives when using cracen_need_multipart_workarounds or cracen_need_ctr_size_workarounds Add AEAD to cracen_sw with AES-CCM support. Signed-off-by: Dag Erik Gjørvad <[email protected]>
1 parent 47375e9 commit f2fe57e

File tree

11 files changed

+1823
-74
lines changed

11 files changed

+1823
-74
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Security
147147
* Experimental support for KMU on the nRF54LV10A SoC.
148148
* Experimental support for compression and encryption on the nRF54LV10A SoC.
149149

150+
* Support for AES-CCM AEAD using CRACEN for the :zephyr:board:`nrf54lm20dk`.
151+
150152
* Updated:
151153

152154
* The :ref:`security_index` page with a table that lists the versions of security components implemented in the |NCS|.
@@ -665,6 +667,10 @@ Cryptography samples
665667

666668
* Added support for the ``nrf54lm20dk/nrf54lm20a/cpuapp`` board target.
667669

670+
* :ref:`crypto_aes_ccm` sample:
671+
672+
* Added support for the ``nrf54lm20dk/nrf54lm20a/cpuapp`` board target.
673+
668674
* :ref:`crypto_tls` sample:
669675

670676
* Updated sample-specific Kconfig configuration structure and documentation.

doc/nrf/security/crypto/crypto_supported_features.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,8 +4192,8 @@ The options are grouped by Series and drivers available for the device Series, a
41924192
- Supported
41934193
- Supported
41944194
- Supported
4195-
- Experimental (with exceptions, see note)
4196-
- Experimental (with exceptions, see note)
4195+
- Experimental
4196+
- Experimental
41974197
* - GCM
41984198
- :kconfig:option:`CONFIG_PSA_WANT_ALG_GCM`
41994199
- Supported
@@ -4225,18 +4225,11 @@ The options are grouped by Series and drivers available for the device Series, a
42254225
See also :ref:`ug_crypto_supported_features_aes_key_sizes`.
42264226
* CCM cipher mode:
42274227

4228-
* Multi-part encrypt and decrypt APIs are not supported.
4229-
* A maximum of 1 MB of plaintext or ciphertext is supported.
42304228

42314229
* GCM and ChaCha20-Poly1305 cipher modes:
42324230

42334231
* Multi-part encrypt and decrypt APIs are not supported.
42344232

4235-
* The following limitations apply for nRF54LV10 when using the CRACEN driver:
4236-
4237-
* CCM cipher mode:
4238-
4239-
* A maximum of 1 MB of plaintext or ciphertext is supported.
42404233

42414234
.. tab:: nrf_oberon
42424235

subsys/nrf_security/src/drivers/cracen/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ set(cracen_driver_sources)
1111
include(sxsymcrypt/sxsymcrypt.cmake)
1212
include(silexpk/silexpk.cmake)
1313
include(cracenpsa/cracenpsa.cmake)
14-
if(CONFIG_PSA_NEED_CRACEN_CTR_SIZE_WORKAROUNDS)
14+
if((CONFIG_PSA_NEED_CRACEN_CTR_SIZE_WORKAROUNDS AND
15+
(CONFIG_PSA_NEED_CRACEN_CTR_AES OR CONFIG_PSA_NEED_CRACEN_CCM_AES)) OR
16+
CONFIG_PSA_NEED_CRACEN_MULTIPART_WORKAROUNDS)
1517
include(cracen_sw/cracen_sw.cmake)
1618
endif()
1719

subsys/nrf_security/src/drivers/cracen/cracen_sw/cracen_sw.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ if(CONFIG_PSA_NEED_CRACEN_MULTIPART_WORKAROUNDS AND
4545
${CMAKE_CURRENT_LIST_DIR}/src/cracen_sw_aes_cbc.c
4646
)
4747
endif()
48+
49+
if(CONFIG_PSA_NEED_CRACEN_CTR_SIZE_WORKAROUNDS AND CONFIG_PSA_NEED_CRACEN_CCM_AES)
50+
list(APPEND cracen_driver_sources
51+
${CMAKE_CURRENT_LIST_DIR}/src/cracen_sw_aes_ccm.c
52+
)
53+
endif()
54+
55+
if(CONFIG_PSA_NEED_CRACEN_MULTIPART_WORKAROUNDS)
56+
if(CONFIG_PSA_NEED_CRACEN_CCM_AES OR CONFIG_PSA_NEED_CRACEN_GCM_AES OR CONFIG_PSA_NEED_CRACEN_CHACHA20_POLY1305)
57+
list(APPEND cracen_driver_sources
58+
${CMAKE_CURRENT_LIST_DIR}/src/cracen_sw_aead.c
59+
)
60+
endif()
61+
endif()
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/**
8+
* @file cracen_sw_aead.h
9+
*
10+
* @defgroup cracen_sw_aead Software AEAD dispatcher
11+
* @{
12+
* @brief Dispatcher layer for the software AEAD implementations.
13+
*
14+
* This module provides a common interface that dispatches to specific
15+
* software AEAD implementations (such as AES-CCM) as a workaround for
16+
* hardware limitations with multipart operations.
17+
*/
18+
19+
#ifndef CRACEN_SW_AEAD_H
20+
#define CRACEN_SW_AEAD_H
21+
22+
#include <psa/crypto.h>
23+
#include <stdbool.h>
24+
#include <stdint.h>
25+
#include "cracen_psa_primitives.h"
26+
27+
/**
28+
* @brief Set up the software AEAD encryption operation.
29+
*
30+
* @param[in,out] operation Pointer to the AEAD operation structure.
31+
* @param[in] attributes Key attributes.
32+
* @param[in] key_buffer Key material.
33+
* @param[in] key_buffer_size Size of the key material.
34+
* @param[in] alg AEAD algorithm to use.
35+
*
36+
* @retval PSA_SUCCESS Operation setup successfully.
37+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
38+
* @retval PSA_ERROR_INVALID_ARGUMENT Invalid key size.
39+
*/
40+
psa_status_t cracen_aead_encrypt_setup(cracen_aead_operation_t *operation,
41+
const psa_key_attributes_t *attributes,
42+
const uint8_t *key_buffer, size_t key_buffer_size,
43+
psa_algorithm_t alg);
44+
45+
/**
46+
* @brief Set up the software AEAD decryption operation.
47+
*
48+
* @param[in,out] operation Pointer to the AEAD operation structure.
49+
* @param[in] attributes Key attributes.
50+
* @param[in] key_buffer Key material.
51+
* @param[in] key_buffer_size Size of the key material.
52+
* @param[in] alg AEAD algorithm to use.
53+
*
54+
* @retval PSA_SUCCESS Operation setup successfully.
55+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
56+
* @retval PSA_ERROR_INVALID_ARGUMENT Invalid key size.
57+
*/
58+
psa_status_t cracen_aead_decrypt_setup(cracen_aead_operation_t *operation,
59+
const psa_key_attributes_t *attributes,
60+
const uint8_t *key_buffer, size_t key_buffer_size,
61+
psa_algorithm_t alg);
62+
63+
/**
64+
* @brief Set nonce for the software AEAD operation.
65+
*
66+
* @param[in,out] operation Pointer to the AEAD operation structure.
67+
* @param[in] nonce Nonce/IV value.
68+
* @param[in] nonce_length Length of the nonce.
69+
*
70+
* @retval PSA_SUCCESS Nonce set successfully.
71+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
72+
* @retval PSA_ERROR_INVALID_ARGUMENT Invalid nonce length.
73+
*/
74+
psa_status_t cracen_aead_set_nonce(cracen_aead_operation_t *operation, const uint8_t *nonce,
75+
size_t nonce_length);
76+
77+
/**
78+
* @brief Set lengths for the software AEAD operation.
79+
*
80+
* Some AEAD algorithms (such as CCM) require lengths to be known up-front.
81+
*
82+
* @param[in,out] operation Pointer to the AEAD operation structure.
83+
* @param[in] ad_length Length of additional data.
84+
* @param[in] plaintext_length Length of plaintext/ciphertext.
85+
*
86+
* @retval PSA_SUCCESS Lengths set successfully.
87+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
88+
*/
89+
psa_status_t cracen_aead_set_lengths(cracen_aead_operation_t *operation, size_t ad_length,
90+
size_t plaintext_length);
91+
92+
/**
93+
* @brief Update the software AEAD operation with additional data.
94+
*
95+
* @param[in,out] operation Pointer to the AEAD operation structure.
96+
* @param[in] input Additional data.
97+
* @param[in] input_length Length of additional data.
98+
*
99+
* @retval PSA_SUCCESS Additional data processed successfully.
100+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
101+
* @retval PSA_ERROR_BAD_STATE AD already finalized or operation not initialized.
102+
*/
103+
psa_status_t cracen_aead_update_ad(cracen_aead_operation_t *operation, const uint8_t *input,
104+
size_t input_length);
105+
106+
/**
107+
* @brief Update the software AEAD operation with plaintext/ciphertext.
108+
*
109+
* @param[in,out] operation Pointer to the AEAD operation structure.
110+
* @param[in] input Input data (plaintext for encrypt, ciphertext for decrypt).
111+
* @param[in] input_length Length of input data.
112+
* @param[out] output Output buffer.
113+
* @param[in] output_size Size of output buffer.
114+
* @param[out] output_length Pointer to store actual output length.
115+
*
116+
* @retval PSA_SUCCESS Data processed successfully.
117+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
118+
* @retval PSA_ERROR_BUFFER_TOO_SMALL Output buffer too small.
119+
* @retval PSA_ERROR_BAD_STATE Operation not initialized.
120+
*/
121+
psa_status_t cracen_aead_update(cracen_aead_operation_t *operation, const uint8_t *input,
122+
size_t input_length, uint8_t *output, size_t output_size,
123+
size_t *output_length);
124+
125+
/**
126+
* @brief Finish the software AEAD encryption and generate the tag.
127+
*
128+
* @param[in,out] operation Pointer to the AEAD operation structure.
129+
* @param[out] ciphertext Final ciphertext output buffer.
130+
* @param[in] ciphertext_size Size of ciphertext buffer.
131+
* @param[out] ciphertext_length Pointer to store actual ciphertext length.
132+
* @param[out] tag Tag output buffer.
133+
* @param[in] tag_size Size of tag buffer.
134+
* @param[out] tag_length Pointer to store actual tag length.
135+
*
136+
* @retval PSA_SUCCESS Encryption finished successfully; tag generated.
137+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
138+
* @retval PSA_ERROR_BUFFER_TOO_SMALL Tag buffer too small.
139+
* @retval PSA_ERROR_BAD_STATE Operation not initialized.
140+
*/
141+
psa_status_t cracen_aead_finish(cracen_aead_operation_t *operation, uint8_t *ciphertext,
142+
size_t ciphertext_size, size_t *ciphertext_length, uint8_t *tag,
143+
size_t tag_size, size_t *tag_length);
144+
145+
/**
146+
* @brief Finish the software AEAD decryption and verify the tag.
147+
*
148+
* @param[in,out] operation Pointer to the AEAD operation structure.
149+
* @param[out] plaintext Final plaintext output buffer.
150+
* @param[in] plaintext_size Size of plaintext buffer.
151+
* @param[out] plaintext_length Pointer to store actual plaintext length.
152+
* @param[in] tag Tag to verify.
153+
* @param[in] tag_length Length of the tag.
154+
*
155+
* @retval PSA_SUCCESS Decryption finished successfully; tag verified.
156+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
157+
* @retval PSA_ERROR_INVALID_SIGNATURE Tag verification failed.
158+
* @retval PSA_ERROR_BAD_STATE Operation not initialized.
159+
*/
160+
psa_status_t cracen_aead_verify(cracen_aead_operation_t *operation, uint8_t *plaintext,
161+
size_t plaintext_size, size_t *plaintext_length, const uint8_t *tag,
162+
size_t tag_length);
163+
164+
/**
165+
* @brief Abort the software AEAD operation.
166+
*
167+
* Clears the operation context and any sensitive data.
168+
*
169+
* @param[in,out] operation Pointer to the AEAD operation structure.
170+
*
171+
* @retval PSA_SUCCESS Operation aborted successfully.
172+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
173+
*/
174+
psa_status_t cracen_aead_abort(cracen_aead_operation_t *operation);
175+
176+
/**
177+
* @brief Perform a single software AEAD encryption.
178+
*
179+
* @param[in] attributes Key attributes.
180+
* @param[in] key_buffer Key material.
181+
* @param[in] key_buffer_size Size of key material.
182+
* @param[in] alg AEAD algorithm.
183+
* @param[in] nonce Nonce/IV.
184+
* @param[in] nonce_length Length of nonce.
185+
* @param[in] additional_data Additional data.
186+
* @param[in] additional_data_length Length of additional data.
187+
* @param[in] plaintext Plaintext to encrypt.
188+
* @param[in] plaintext_length Length of plaintext.
189+
* @param[out] ciphertext Output buffer for ciphertext and tag.
190+
* @param[in] ciphertext_size Size of ciphertext buffer.
191+
* @param[out] ciphertext_length Pointer to store actual output length.
192+
*
193+
* @retval PSA_SUCCESS Encryption completed successfully.
194+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
195+
* @retval PSA_ERROR_BUFFER_TOO_SMALL Output buffer too small.
196+
* @retval PSA_ERROR_INVALID_ARGUMENT Invalid parameters.
197+
*/
198+
psa_status_t cracen_aead_encrypt(const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
199+
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *nonce,
200+
size_t nonce_length, const uint8_t *additional_data,
201+
size_t additional_data_length, const uint8_t *plaintext,
202+
size_t plaintext_length, uint8_t *ciphertext,
203+
size_t ciphertext_size, size_t *ciphertext_length);
204+
205+
/**
206+
* @brief Perform a single software AEAD decryption.
207+
*
208+
* @param[in] attributes Key attributes.
209+
* @param[in] key_buffer Key material.
210+
* @param[in] key_buffer_size Size of key material.
211+
* @param[in] alg AEAD algorithm.
212+
* @param[in] nonce Nonce/IV.
213+
* @param[in] nonce_length Length of nonce.
214+
* @param[in] additional_data Additional data.
215+
* @param[in] additional_data_length Length of additional data.
216+
* @param[in] ciphertext Ciphertext and tag to decrypt.
217+
* @param[in] ciphertext_length Length of ciphertext (including tag).
218+
* @param[out] plaintext Output buffer for plaintext.
219+
* @param[in] plaintext_size Size of plaintext buffer.
220+
* @param[out] plaintext_length Pointer to store actual plaintext length.
221+
*
222+
* @retval PSA_SUCCESS Decryption and verification completed successfully.
223+
* @retval PSA_ERROR_NOT_SUPPORTED Unsupported algorithm.
224+
* @retval PSA_ERROR_INVALID_SIGNATURE Tag verification failed.
225+
* @retval PSA_ERROR_BUFFER_TOO_SMALL Output buffer too small.
226+
* @retval PSA_ERROR_INVALID_ARGUMENT Invalid parameters.
227+
*/
228+
psa_status_t cracen_aead_decrypt(const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
229+
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *nonce,
230+
size_t nonce_length, const uint8_t *additional_data,
231+
size_t additional_data_length, const uint8_t *ciphertext,
232+
size_t ciphertext_length, uint8_t *plaintext,
233+
size_t plaintext_size, size_t *plaintext_length);
234+
235+
/**
236+
* @}
237+
*/
238+
239+
#endif /* CRACEN_SW_AEAD_H */

0 commit comments

Comments
 (0)