ecdsa: use CtOption::into_option (#1031)

Infers types and makes these conversions less ugly
This commit is contained in:
Tony Arcieri
2025-08-04 21:51:03 -06:00
committed by GitHub
parent 18be0266f9
commit 41c53ced65
2 changed files with 12 additions and 12 deletions
+10 -11
View File
@@ -376,21 +376,20 @@ where
let z = Scalar::<C>::reduce(&bits2field::<C>(prehash)?);
let r_bytes = if recovery_id.is_x_reduced() {
Option::<C::Uint>::from(
C::Uint::decode_field_bytes(&r.to_repr()).checked_add(&C::ORDER),
)
.ok_or_else(Error::new)?
.encode_field_bytes()
C::Uint::decode_field_bytes(&r.to_repr())
.checked_add(&C::ORDER)
.into_option()
.ok_or_else(Error::new)?
.encode_field_bytes()
} else {
r.to_repr()
};
let R: ProjectivePoint<C> = Option::<AffinePoint<C>>::from(AffinePoint::<C>::decompress(
&r_bytes,
u8::from(recovery_id.is_y_odd()).into(),
))
.ok_or_else(Error::new)?
.into();
let R: ProjectivePoint<C> =
AffinePoint::<C>::decompress(&r_bytes, u8::from(recovery_id.is_y_odd()).into())
.into_option()
.ok_or_else(Error::new)?
.into();
let r_inv = *r.invert();
let u1 = -(r_inv * z);
+2 -1
View File
@@ -108,7 +108,8 @@ where
/// Initialize [`VerifyingKey`] from an [`EncodedPoint`].
pub fn from_encoded_point(public_key: &EncodedPoint<C>) -> Result<Self> {
Option::from(PublicKey::<C>::from_encoded_point(public_key))
PublicKey::<C>::from_encoded_point(public_key)
.into_option()
.map(|public_key| Self { inner: public_key })
.ok_or_else(Error::new)
}