Skip to content

Commit 905ad3b

Browse files
frkvbjarki-andreasen
authored andcommitted
crypto: PSA core lite calling low-level APIs for Ed25519 (pure/ph)
-This commit adds Kconfig PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS which (when enabled) calls low-level APIs for Ed25519 verify APIs without going through PSA Crypto Driver Wrappers. This gives optimized builds for NSIB, but doesn't promote reuse. -Added static assertion to ensure that ECDSA is not enabled when PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS is enabled ref: NCSDK-30323 Signed-off-by: Frank Audun Kvamtrø <[email protected]>
1 parent 965ac0a commit 905ad3b

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

subsys/nrf_security/src/core/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ config PSA_CORE_LITE
3030
not possible to use. Also note that PSA core lite is not thread-safe.
3131

3232
endchoice
33+
34+
config PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS
35+
bool "Optimized Ed25519 (only) support for NSIB usage"
36+
depends on PSA_CORE_LITE
37+
help
38+
This configuration calls low-level APIs in CRACEN for Ed25519 instead of
39+
going through PSA crypto driver wrappers APIs. This optimization limits
40+
supported algorithms for signature verification to only Pure Ed25519 and
41+
Ed25519ph.

subsys/nrf_security/src/core/lite/psa_core_lite.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#include <cracen_psa_kmu.h>
1111
#include <cracen/mem_helpers.h>
1212

13+
#if defined(CONFIG_PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS)
14+
#include "cracen_psa.h"
15+
psa_status_t silex_statuscodes_to_psa(int ret);
16+
#endif
17+
1318
#if (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)) && \
1419
defined(PSA_WANT_ECC_SECP_R1_256)
1520
const size_t pub_key_max_size = 65;
@@ -40,6 +45,16 @@ static psa_status_t get_key_buffer(
4045
return cracen_kmu_get_builtin_key(slot_number, attributes, key, key_size, key_length);
4146
}
4247

48+
/* Signature validation algorithms */
49+
50+
#if defined(CONFIG_PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS) && \
51+
(defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA))
52+
/* We don't support Ed25519 + ECDSA as the only supported verification is
53+
* Ed25519 when PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS is used
54+
*/
55+
#error PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS with ECDSA is invalid!
56+
#endif
57+
4358
#if defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) || \
4459
defined(PSA_WANT_ALG_ED25519PH)
4560

@@ -68,9 +83,15 @@ psa_status_t psa_verify_hash(
6883
return status;
6984
}
7085

86+
#if defined(CONFIG_PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS)
87+
int cracen_status = cracen_ed25519ph_verify(pub_key, hash, hash_length, signature, false);
88+
89+
return silex_statuscodes_to_psa(cracen_status);
90+
#else
7191
return psa_driver_wrapper_verify_hash(&attr, pub_key, pub_key_length,
7292
alg, hash, hash_length,
7393
signature, signature_length);
94+
#endif
7495
}
7596

7697
#endif /* PSA_WANT_ALG_ECDSA || PSA_WANT_ALG_DETERMINISTIC_ECDSA || PSA_WANT_ALG_ED25519PH */
@@ -103,10 +124,15 @@ psa_status_t psa_verify_message(
103124
if (status != PSA_SUCCESS) {
104125
return status;
105126
}
127+
#if defined(CONFIG_PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS)
128+
int cracen_status = cracen_ed25519_verify(pub_key, input, input_length, signature);
106129

130+
return silex_statuscodes_to_psa(cracen_status);
131+
#else
107132
return psa_driver_wrapper_verify_message(&attr, pub_key, pub_key_size,
108133
alg, input, input_length,
109134
signature, signature_length);
135+
#endif
110136
}
111137

112138
#endif /* PSA_WANT_ALG_ECDSA || PSA_WANT_ALG_DETERMINISTIC_ECDSA || PSA_WANT_ALG_PURE_EDDSA */
@@ -348,7 +374,6 @@ psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key_id)
348374
return status;
349375
}
350376

351-
/* Generalize to psa_driver_wrapper_destroy_key */
352377
return psa_driver_wrapper_destroy_builtin_key(&attr);
353378
}
354379

0 commit comments

Comments
 (0)