mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-21 15:41:00 +00:00
mbedtls_ecp_write_key_ext(): Upgrade import_pair_into_psa as well
It wasn't done with the others because that code was added in a concurrent branch. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
b395e74edd
commit
84a7bfbd33
14
library/pk.c
14
library/pk.c
@ -675,10 +675,7 @@ static int import_pair_into_psa(const mbedtls_pk_context *pk,
|
|||||||
#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
|
#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
|
||||||
psa_ecc_family_t from_family = pk->ec_family;
|
psa_ecc_family_t from_family = pk->ec_family;
|
||||||
#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
|
#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
|
||||||
/* We're only reading the key, but mbedtls_ecp_write_key()
|
const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk);
|
||||||
* is missing a const annotation on its key parameter, so
|
|
||||||
* we need the non-const accessor here. */
|
|
||||||
mbedtls_ecp_keypair *ec = mbedtls_pk_ec_rw(*pk);
|
|
||||||
size_t from_bits = 0;
|
size_t from_bits = 0;
|
||||||
psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id,
|
psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id,
|
||||||
&from_bits);
|
&from_bits);
|
||||||
@ -704,12 +701,9 @@ static int import_pair_into_psa(const mbedtls_pk_context *pk,
|
|||||||
return MBEDTLS_ERR_PK_TYPE_MISMATCH;
|
return MBEDTLS_ERR_PK_TYPE_MISMATCH;
|
||||||
}
|
}
|
||||||
unsigned char key_buffer[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
|
unsigned char key_buffer[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
|
||||||
/* Make sure to pass the exact key length to
|
size_t key_length = 0;
|
||||||
* mbedtls_ecp_write_key(), because it writes Montgomery keys
|
int ret = mbedtls_ecp_write_key_ext(ec, &key_length,
|
||||||
* at the start of the buffer but Weierstrass keys at the
|
key_buffer, sizeof(key_buffer));
|
||||||
* end of the buffer. */
|
|
||||||
size_t key_length = PSA_BITS_TO_BYTES(ec->grp.nbits);
|
|
||||||
int ret = mbedtls_ecp_write_key(ec, key_buffer, key_length);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user