Skip to content

Commit 166d9eb

Browse files
Vge0rgenordicjm
authored andcommitted
nrf_security: Guard IKG function with key type
The IKG in Cracen only supports one asymmetric key type, the SECP256R1. This guards the function call to the IKG with the relevant configuration. This is important because the PSA signing APIs can be used with algorithms like EDDSA which have lower footprint so it can reduce the flash usage when ECDSA is not needed. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 5cdbae0 commit 166d9eb

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,15 @@ static psa_status_t export_ecc_public_key_from_keypair(const psa_key_attributes_
637637
if (key_buffer_size != sizeof(ikg_opaque_key)) {
638638
return PSA_ERROR_INVALID_ARGUMENT;
639639
}
640-
priv_key =
641-
si_sig_fetch_ikprivkey(sx_curve, ((ikg_opaque_key *)key_buffer)->owner_id);
642-
data[0] = SI_ECC_PUBKEY_UNCOMPRESSED;
643-
pub_key.key.eckey.qx = &data[1];
644-
pub_key.key.eckey.qy = &data[1 + sx_pk_curve_opsize(sx_curve)];
640+
641+
if (IS_ENABLED(PSA_NEED_CRACEN_ECDSA_SECP_R1_256)) {
642+
priv_key = si_sig_fetch_ikprivkey(sx_curve, *key_buffer);
643+
data[0] = SI_ECC_PUBKEY_UNCOMPRESSED;
644+
pub_key.key.eckey.qx = &data[1];
645+
pub_key.key.eckey.qy = &data[1 + sx_pk_curve_opsize(sx_curve)];
646+
} else {
647+
return PSA_ERROR_NOT_SUPPORTED;
648+
}
645649
} else {
646650

647651
switch (psa_curve) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@ static int cracen_signature_prepare_ec_prvkey(struct si_sig_privkey *privkey, ch
100100
return status;
101101
}
102102

103+
/* IKG supports one SECP256_R1 key */
103104
if (PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes)) ==
104105
PSA_KEY_LOCATION_CRACEN) {
105106
if (key_buffer_size != sizeof(ikg_opaque_key)) {
106107
return SX_ERR_INVALID_ARG;
107108
}
108-
*privkey =
109-
si_sig_fetch_ikprivkey(*sicurve, ((ikg_opaque_key *)key_buffer)->owner_id);
110109

111-
return status;
110+
if (IS_ENABLED(PSA_NEED_CRACEN_ECDSA_SECP_R1_256)) {
111+
*privkey = si_sig_fetch_ikprivkey(*sicurve, *key_buffer);
112+
return status;
113+
} else {
114+
return SX_ERR_INCOMPATIBLE_HW;
115+
}
112116
}
113117

114118
if (key_buffer_size != PSA_BITS_TO_BYTES(psa_get_key_bits(attributes))) {

0 commit comments

Comments
 (0)