@@ -127,6 +127,21 @@ impl PrimeCurveAffine for AffinePoint {
127127impl AffineCoordinates for AffinePoint {
128128 type FieldRepr = FieldBytes ;
129129
130+ fn from_coordinates ( x : & Self :: FieldRepr , y : & Self :: FieldRepr ) -> CtOption < Self > {
131+ let x = FieldElement :: from_bytes ( x) ;
132+ let y = FieldElement :: from_bytes ( y) ;
133+
134+ x. and_then ( |x| {
135+ y. and_then ( |y| {
136+ // Check that the point is on the curve
137+ let lhs = ( y * & y) . negate ( 1 ) ;
138+ let rhs = x * & x * & x + & CURVE_EQUATION_B ;
139+ let point = Self :: new ( x, y) ;
140+ CtOption :: new ( point, ( lhs + & rhs) . normalizes_to_zero ( ) )
141+ } )
142+ } )
143+ }
144+
130145 fn x ( & self ) -> FieldBytes {
131146 self . x . to_bytes ( )
132147 }
@@ -276,20 +291,7 @@ impl FromEncodedPoint<Secp256k1> for AffinePoint {
276291 sec1:: Coordinates :: Compressed { x, y_is_odd } => {
277292 AffinePoint :: decompress ( x, Choice :: from ( y_is_odd as u8 ) )
278293 }
279- sec1:: Coordinates :: Uncompressed { x, y } => {
280- let x = FieldElement :: from_bytes ( x) ;
281- let y = FieldElement :: from_bytes ( y) ;
282-
283- x. and_then ( |x| {
284- y. and_then ( |y| {
285- // Check that the point is on the curve
286- let lhs = ( y * & y) . negate ( 1 ) ;
287- let rhs = x * & x * & x + & CURVE_EQUATION_B ;
288- let point = Self :: new ( x, y) ;
289- CtOption :: new ( point, ( lhs + & rhs) . normalizes_to_zero ( ) )
290- } )
291- } )
292- }
294+ sec1:: Coordinates :: Uncompressed { x, y } => Self :: from_coordinates ( x, y) ,
293295 }
294296 }
295297}
0 commit comments