Skip to content

Commit 19191b2

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Use builtin functions for RSA
-This gives priority to the builtin implementation for RSA. It prevents the PSA drivers to do RSA operations with the only exception the key genration. Ref: NCSDK-13753 Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 1a2e798 commit 19191b2

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

nrf_security/configs/nrf-config.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ extern "C" {
9090
#define MBEDTLS_OID_C
9191
#define MBEDTLS_PKCS1_V21
9292
#define MBEDTLS_MD_C
93+
#ifndef MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR
94+
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR
95+
#endif
96+
#ifndef MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS
97+
#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS
98+
#endif
99+
#endif
100+
101+
#if defined(PSA_WANT_ALG_RSA) || \
102+
defined(PSA_WANT_ALG_RSA_OAEP) || \
103+
defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT) || \
104+
defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) || \
105+
defined(PSA_WANT_ALG_RSA_PSS)
106+
107+
#if defined(PSA_WANT_ALG_SHA_1)
108+
#define MBEDTLS_PSA_BUILTIN_ALG_SHA_1
109+
#endif
110+
93111
#endif
94112

95113
#if defined(PSA_WANT_ALG_SHA_1)

nrf_security/src/psa_crypto_driver_wrappers.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,20 @@ psa_status_t psa_driver_wrapper_sign_hash(
280280
* cycle through all known transparent accelerators */
281281
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
282282
#if defined(PSA_CRYPTO_DRIVER_CC3XX)
283+
/* Do not call the cc3xx_sign_hash for RSA keys since it still in early development */
284+
if(PSA_KEY_TYPE_IS_RSA(attributes->core.type)){
285+
return( psa_sign_hash_builtin( attributes,
286+
key_buffer,
287+
key_buffer_size,
288+
alg,
289+
hash,
290+
hash_length,
291+
signature,
292+
signature_size,
293+
signature_length ) );
294+
295+
}
296+
283297
status = cc3xx_sign_hash( attributes,
284298
key_buffer,
285299
key_buffer_size,
@@ -393,6 +407,17 @@ psa_status_t psa_driver_wrapper_verify_hash(
393407
* cycle through all known transparent accelerators */
394408
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
395409
#if defined(PSA_CRYPTO_DRIVER_CC3XX)
410+
/* Do not call the cc3xx_verify_hash for RSA keys since it still in early development */
411+
if(PSA_KEY_TYPE_IS_RSA(attributes->core.type)){
412+
return( psa_verify_hash_builtin( attributes,
413+
key_buffer,
414+
key_buffer_size,
415+
alg,
416+
hash,
417+
hash_length,
418+
signature,
419+
signature_length ) );
420+
}
396421

397422
status = cc3xx_verify_hash( attributes,
398423
key_buffer,
@@ -725,6 +750,15 @@ psa_status_t psa_driver_wrapper_import_key(
725750
case PSA_KEY_LOCATION_LOCAL_STORAGE:
726751
/* Key is stored in the slot in export representation, so
727752
* cycle through all known transparent accelerators */
753+
754+
/* RSA are not fully supported yet in the PSA drivers. This is a workaround
755+
* to make sure that only the builtin solution is being used. */
756+
if(PSA_KEY_TYPE_IS_RSA(attributes->core.type)){
757+
return( psa_import_key_into_slot( attributes,
758+
data, data_length,
759+
key_buffer, key_buffer_size,
760+
key_buffer_length, bits ) );
761+
}
728762
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
729763
#if defined(PSA_CRYPTO_DRIVER_TEST)
730764
status = mbedtls_test_transparent_import_key(
@@ -874,6 +908,17 @@ psa_status_t psa_driver_wrapper_export_public_key(
874908
case PSA_KEY_LOCATION_LOCAL_STORAGE:
875909
/* Key is stored in the slot in export representation, so
876910
* cycle through all known transparent accelerators */
911+
912+
/* RSA are not fully supported yet in the PSA drivers. This is a workaround
913+
* to make sure that only the builtin solution is being used. */
914+
if(PSA_KEY_TYPE_IS_RSA(attributes->core.type)){
915+
return( psa_export_public_key_internal( attributes,
916+
key_buffer,
917+
key_buffer_size,
918+
data,
919+
data_size,
920+
data_length ) );
921+
}
877922
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
878923
#if defined(PSA_CRYPTO_DRIVER_CC3XX)
879924
status = cc3xx_export_public_key(

0 commit comments

Comments
 (0)