Fix loading and saving Montgomery keys.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2023-08-24 16:01:39 +02:00
parent 7376817724
commit 1d3232df36
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
2 changed files with 2 additions and 2 deletions

View file

@ -102,7 +102,7 @@ int cmd_decrypt_asym() {
free(kdata);
return SW_DATA_INVALID();
}
r = mbedtls_mpi_read_binary(&ctx.ctx.mbed_ecdh.d, kdata + 1, key_size - 1);
r = mbedtls_ecp_read_key(gid, (mbedtls_ecdsa_context *)&ctx.ctx.mbed_ecdh, kdata + 1, key_size - 1);
mbedtls_platform_zeroize(kdata, key_size);
free(kdata);
if (r != 0) {

View file

@ -502,7 +502,7 @@ int store_keys(void *key_ctx, int type, uint8_t key_id) {
mbedtls_ecdsa_context *ecdsa = (mbedtls_ecdsa_context *) key_ctx;
key_size = mbedtls_mpi_size(&ecdsa->d);
kdata[0] = ecdsa->grp.id & 0xff;
mbedtls_mpi_write_binary(&ecdsa->d, kdata + 1, key_size);
mbedtls_ecp_write_key(ecdsa, kdata + 1, key_size);
key_size++;
}
else if (type & HSM_KEY_AES) {