Skip to content

Commit 27c2654

Browse files
AntonZmanordicjm
authored andcommitted
nrf_security: CRACEN: Added data size check for AES CCM on some MCUs
Adds error reporting for the plaintext datasize over 1MB (for AES CCM) on nRF54LM20A and nRF54LV10A. Ref: NCSDK-32098 Signed-off-by: Anton Zyma <[email protected]>
1 parent 36d4807 commit 27c2654

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/include/cracen_psa_primitives.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
*/
4444
#define CRACEN_MAX_CHACHA20_KEY_SIZE (32u)
4545

46+
/*
47+
* There is a HW limitation for nRF54LM20A and nRF54LV10A:
48+
* a maximum of 1 MB of plaintext or ciphertext is supported.
49+
*/
50+
#if defined(CONFIG_SOC_NRF54LM20A) || defined(CONFIG_SOC_NRF54LV10A)
51+
#define CRACEN_MAX_CCM_DATA_SIZE (65536U * SX_BLKCIPHER_AES_BLK_SZ)
52+
#endif /* CONFIG_SOC_NRF54LM20A || CONFIG_SOC_NRF54LV10A */
53+
4654
/*
4755
* There are two key types supported for ciphers, CHACHA20 and AES,
4856
* and they both have a max key size of 32.

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/aead.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,18 @@ psa_status_t cracen_aead_set_nonce(cracen_aead_operation_t *operation, const uin
396396
#endif
397397
}
398398

399-
static void set_lengths(cracen_aead_operation_t *operation, size_t ad_length,
399+
static psa_status_t set_lengths(cracen_aead_operation_t *operation, size_t ad_length,
400400
size_t plaintext_length)
401401
{
402+
#if defined(CRACEN_MAX_CCM_DATA_SIZE)
403+
if ((operation->alg == PSA_ALG_CCM) && (plaintext_length > CRACEN_MAX_CCM_DATA_SIZE)) {
404+
return PSA_ERROR_NOT_SUPPORTED;
405+
}
406+
#endif /* CRACEN_MAX_CCM_DATA_SIZE */
407+
402408
operation->ad_length = ad_length;
403409
operation->plaintext_length = plaintext_length;
410+
return PSA_SUCCESS;
404411
}
405412

406413
psa_status_t cracen_aead_set_lengths(cracen_aead_operation_t *operation, size_t ad_length,
@@ -409,8 +416,7 @@ psa_status_t cracen_aead_set_lengths(cracen_aead_operation_t *operation, size_t
409416
#ifdef CONFIG_SOC_NRF54LM20A
410417
return PSA_ERROR_NOT_SUPPORTED;
411418
#else
412-
set_lengths(operation, ad_length, plaintext_length);
413-
return PSA_SUCCESS;
419+
return set_lengths(operation, ad_length, plaintext_length);
414420
#endif
415421
}
416422

@@ -755,7 +761,10 @@ psa_status_t cracen_aead_encrypt(const psa_key_attributes_t *attributes, const u
755761
goto error_exit;
756762
}
757763

758-
set_lengths(&operation, additional_data_length, plaintext_length);
764+
status = set_lengths(&operation, additional_data_length, plaintext_length);
765+
if (status != PSA_SUCCESS) {
766+
goto error_exit;
767+
}
759768

760769
/* Do not call the cracen_aead_update*() functions to avoid using
761770
* HW context switching (process_on_hw()) in single-part operations.
@@ -820,7 +829,10 @@ psa_status_t cracen_aead_decrypt(const psa_key_attributes_t *attributes, const u
820829
goto error_exit;
821830
}
822831

823-
set_lengths(&operation, additional_data_length, *plaintext_length);
832+
status = set_lengths(&operation, additional_data_length, *plaintext_length);
833+
if (status != PSA_SUCCESS) {
834+
goto error_exit;
835+
}
824836

825837
/* Do not call the cracen_aead_update*() functions to avoid using
826838
* HW context switching (process_on_hw()) in single-part operations.

0 commit comments

Comments
 (0)