|
91 | 91 | C::Point: WeierstrassPoint + Group + FromCompressed<Coordinate<C>>,
|
92 | 92 | Coordinate<C>: IntMod,
|
93 | 93 | {
|
94 |
| - pub fn new(point: <C as IntrinsicCurve>::Point) -> Self { |
95 |
| - Self { point } |
| 94 | + /// Convert an [`AffinePoint`] into a [`PublicKey`]. |
| 95 | + /// In addition, for `Coordinate<C>` implementing `IntMod`, this function will assert that the |
| 96 | + /// affine coordinates of `point` are both in canonical form. |
| 97 | + pub fn from_affine(point: AffinePoint<C>) -> Result<Self> { |
| 98 | + // Internally this calls `is_eq` on `x` and `y` coordinates, which will assert `x, y` are |
| 99 | + // reduced. |
| 100 | + if point.is_identity() { |
| 101 | + Err(Error::new()) |
| 102 | + } else { |
| 103 | + Ok(Self { point }) |
| 104 | + } |
96 | 105 | }
|
97 | 106 |
|
98 | 107 | pub fn from_sec1_bytes(bytes: &[u8]) -> Result<Self>
|
@@ -188,7 +197,7 @@ where
|
188 | 197 | }
|
189 | 198 |
|
190 | 199 | pub fn from_affine(point: <C as IntrinsicCurve>::Point) -> Result<Self> {
|
191 |
| - let public_key = PublicKey::<C>::new(point); |
| 200 | + let public_key = PublicKey::<C>::from_affine(point)?; |
192 | 201 | Ok(Self::new(public_key))
|
193 | 202 | }
|
194 | 203 |
|
@@ -453,9 +462,9 @@ where
|
453 | 462 | let u2 = s.div_unsafe(&r);
|
454 | 463 | let NEG_G = C::Point::NEG_GENERATOR;
|
455 | 464 | let point = <C as IntrinsicCurve>::msm(&[neg_u1, u2], &[NEG_G, R]);
|
456 |
| - let public_key = PublicKey { point }; |
| 465 | + let vk = VerifyingKey::from_affine(point)?; |
457 | 466 |
|
458 |
| - Ok(VerifyingKey { inner: public_key }) |
| 467 | + Ok(vk) |
459 | 468 | }
|
460 | 469 | }
|
461 | 470 |
|
|
0 commit comments