|
10 | 10 | #include <cracen_psa_kmu.h> |
11 | 11 | #include <cracen/mem_helpers.h> |
12 | 12 |
|
| 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 | + |
13 | 18 | #if (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)) && \ |
14 | 19 | defined(PSA_WANT_ECC_SECP_R1_256) |
15 | 20 | const size_t pub_key_max_size = 65; |
@@ -40,6 +45,16 @@ static psa_status_t get_key_buffer( |
40 | 45 | return cracen_kmu_get_builtin_key(slot_number, attributes, key, key_size, key_length); |
41 | 46 | } |
42 | 47 |
|
| 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 | + |
43 | 58 | #if defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) || \ |
44 | 59 | defined(PSA_WANT_ALG_ED25519PH) |
45 | 60 |
|
@@ -68,9 +83,15 @@ psa_status_t psa_verify_hash( |
68 | 83 | return status; |
69 | 84 | } |
70 | 85 |
|
| 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 |
71 | 91 | return psa_driver_wrapper_verify_hash(&attr, pub_key, pub_key_length, |
72 | 92 | alg, hash, hash_length, |
73 | 93 | signature, signature_length); |
| 94 | +#endif |
74 | 95 | } |
75 | 96 |
|
76 | 97 | #endif /* PSA_WANT_ALG_ECDSA || PSA_WANT_ALG_DETERMINISTIC_ECDSA || PSA_WANT_ALG_ED25519PH */ |
@@ -103,10 +124,15 @@ psa_status_t psa_verify_message( |
103 | 124 | if (status != PSA_SUCCESS) { |
104 | 125 | return status; |
105 | 126 | } |
| 127 | +#if defined(CONFIG_PSA_CORE_LITE_NSIB_ED25519_OPTIMIZATIONS) |
| 128 | + int cracen_status = cracen_ed25519_verify(pub_key, input, input_length, signature); |
106 | 129 |
|
| 130 | + return silex_statuscodes_to_psa(cracen_status); |
| 131 | +#else |
107 | 132 | return psa_driver_wrapper_verify_message(&attr, pub_key, pub_key_size, |
108 | 133 | alg, input, input_length, |
109 | 134 | signature, signature_length); |
| 135 | +#endif |
110 | 136 | } |
111 | 137 |
|
112 | 138 | #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) |
348 | 374 | return status; |
349 | 375 | } |
350 | 376 |
|
351 | | - /* Generalize to psa_driver_wrapper_destroy_key */ |
352 | 377 | return psa_driver_wrapper_destroy_builtin_key(&attr); |
353 | 378 | } |
354 | 379 |
|
|
0 commit comments