From 958a20ce1192da6e6f83da5744b6b4303e3bb97e Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 28 Sep 2022 20:46:45 +0200 Subject: [PATCH] Fix public key size. Signed-off-by: Pol Henarejos --- src/fido/cbor_make_credential.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fido/cbor_make_credential.c b/src/fido/cbor_make_credential.c index a7fa691..44a01eb 100644 --- a/src/fido/cbor_make_credential.c +++ b/src/fido/cbor_make_credential.c @@ -289,7 +289,7 @@ int cbor_make_credential(const uint8_t *data, size_t len) { const mbedtls_ecp_curve_info *cinfo = mbedtls_ecp_curve_info_from_grp_id(ekey.grp.id); if (cinfo == NULL) CBOR_ERROR(CTAP1_ERR_OTHER); - size_t olen = 0, pkey_len = ceil((float)cinfo->bit_size/8); + size_t olen = 0; uint32_t ctr = get_sign_counter(); uint8_t cbor_buf[1024]; cbor_encoder_init(&encoder, cbor_buf, sizeof(cbor_buf), 0); @@ -301,11 +301,11 @@ int cbor_make_credential(const uint8_t *data, size_t len) { CBOR_CHECK(cbor_encode_negative_int(&mapEncoder, 1)); CBOR_CHECK(cbor_encode_uint(&mapEncoder, curve)); CBOR_CHECK(cbor_encode_negative_int(&mapEncoder, 2)); - mbedtls_mpi_write_binary(&ekey.Q.X, pkey, pkey_len); - CBOR_CHECK(cbor_encode_byte_string(&mapEncoder, pkey, pkey_len)); + mbedtls_mpi_write_binary(&ekey.Q.X, pkey, mbedtls_mpi_size(&ekey.Q.X)); + CBOR_CHECK(cbor_encode_byte_string(&mapEncoder, pkey, mbedtls_mpi_size(&ekey.Q.X))); CBOR_CHECK(cbor_encode_negative_int(&mapEncoder, 3)); - mbedtls_mpi_write_binary(&ekey.Q.Y, pkey, pkey_len); - CBOR_CHECK(cbor_encode_byte_string(&mapEncoder, pkey, pkey_len)); + mbedtls_mpi_write_binary(&ekey.Q.Y, pkey, mbedtls_mpi_size(&ekey.Q.Y)); + CBOR_CHECK(cbor_encode_byte_string(&mapEncoder, pkey, mbedtls_mpi_size(&ekey.Q.Y))); CBOR_CHECK(cbor_encoder_close_container(&encoder, &mapEncoder)); size_t rs = cbor_encoder_get_buffer_size(&encoder, cbor_buf);