From c3502a26bc51b85219e8b49eba2e39fd950b8fd2 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Sun, 14 Jul 2024 19:09:42 -0700 Subject: [PATCH] ecdsa: fixup public key deserialization for ecc `::Uint` represents the field elements, not their serialized size. This what `::FieldBytesSize` is intended to be. This is consistent for all the curves implemented here, but this breaks the deserialization of NistP521 curve points. --- src/asymmetric/public_key.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/asymmetric/public_key.rs b/src/asymmetric/public_key.rs index 09ab0175..2a45576c 100644 --- a/src/asymmetric/public_key.rs +++ b/src/asymmetric/public_key.rs @@ -2,8 +2,9 @@ use crate::{asymmetric, ecdsa::algorithm::CurveAlgorithm, ed25519}; use ::ecdsa::elliptic_curve::{ - bigint::Integer, generic_array::GenericArray, point::PointCompression, sec1, FieldBytesSize, - PrimeCurve, + generic_array::{typenum::Unsigned, GenericArray}, + point::PointCompression, + sec1, FieldBytesSize, PrimeCurve, }; use num_traits::FromPrimitive; use rsa::{BigUint, RsaPublicKey}; @@ -53,7 +54,9 @@ impl PublicKey { C: PrimeCurve + CurveAlgorithm + PointCompression, FieldBytesSize: sec1::ModulusSize, { - if self.algorithm != C::asymmetric_algorithm() || self.bytes.len() != C::Uint::BYTES * 2 { + if self.algorithm != C::asymmetric_algorithm() + || self.bytes.len() != FieldBytesSize::::USIZE * 2 + { return None; }