diff --git a/math/src/elliptic_curve/edwards/point.rs b/math/src/elliptic_curve/edwards/point.rs index b2c1becec..5cae60909 100644 --- a/math/src/elliptic_curve/edwards/point.rs +++ b/math/src/elliptic_curve/edwards/point.rs @@ -136,10 +136,11 @@ impl IsGroup for EdwardsProjectivePoint { let den_s2 = &one - &dx1x2y1y2; // SAFETY: The creation of the result point is safe because the inputs are always points that belong to the curve. // We are using that den_s1 and den_s2 aren't zero. - // See Theorem 3.3 from https://eprint.iacr.org/2007/286.pdf. - let point = Self::new([&num_s1 / &den_s1, &num_s2 / &den_s2, one]); + // See Theorem 3.3 from https://eprint.iacr.org/2007/286.pdf. + let x_coord = (&num_s1 / &den_s1).unwrap(); + let y_coord = (&num_s2 / &den_s2).unwrap(); + let point = Self::new([x_coord, y_coord, one]); point.unwrap() - } /// Returns the additive inverse of the projective point `p` diff --git a/math/src/elliptic_curve/short_weierstrass/point.rs b/math/src/elliptic_curve/short_weierstrass/point.rs index 4bbb38ddf..8e6a7d927 100644 --- a/math/src/elliptic_curve/short_weierstrass/point.rs +++ b/math/src/elliptic_curve/short_weierstrass/point.rs @@ -348,7 +348,8 @@ where } if z == FieldElement::zero() { - let point = Self::new([x, y, z]); + let point = Self::new([x, y, z]) + .map_err(|_| DeserializationError::FieldFromBytesError)?; if point.is_neutral_element() { Ok(point) } else { @@ -358,11 +359,10 @@ where &(&y / &z).unwrap_unchecked() }) == FieldElement::zero() { - Ok(Self::new([x, y, z])) + Self::new([x, y, z]).map_err(|_| DeserializationError::FieldFromBytesError) } else { Err(DeserializationError::FieldFromBytesError) } - } PointFormat::Uncompressed => { if bytes.len() % 2 != 0 {