Skip to content

Commit

Permalink
ecdsa: fixup public key deserialization for ecc
Browse files Browse the repository at this point in the history
`<C as Curve>::Uint` represents the field elements, not their serialized
size. This what `<C as Curve>::FieldBytesSize` is intended to be.

This is consistent for all the curves implemented here, but this breaks
the deserialization of NistP521 curve points.
  • Loading branch information
baloo committed Jan 23, 2025
1 parent 12b25dd commit c3502a2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/asymmetric/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -53,7 +54,9 @@ impl PublicKey {
C: PrimeCurve + CurveAlgorithm + PointCompression,
FieldBytesSize<C>: 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::<C>::USIZE * 2
{
return None;
}

Expand Down

0 comments on commit c3502a2

Please sign in to comment.