@@ -92,12 +92,26 @@ static void secp256k1_gej_verify(const secp256k1_gej *a) {
9292 (void )a ;
9393}
9494
95+ /* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */
9596static void secp256k1_ge_set_gej_zinv (secp256k1_ge * r , const secp256k1_gej * a , const secp256k1_fe * zi ) {
9697 secp256k1_fe zi2 ;
9798 secp256k1_fe zi3 ;
98- /* Do not call secp256k1_ge_verify, as we do not require a->z to be initialized. */
99- secp256k1_fe_verify (& a -> x );
100- secp256k1_fe_verify (& a -> y );
99+ secp256k1_gej_verify (a );
100+ secp256k1_fe_verify (zi );
101+ VERIFY_CHECK (!a -> infinity );
102+ secp256k1_fe_sqr (& zi2 , zi );
103+ secp256k1_fe_mul (& zi3 , & zi2 , zi );
104+ secp256k1_fe_mul (& r -> x , & a -> x , & zi2 );
105+ secp256k1_fe_mul (& r -> y , & a -> y , & zi3 );
106+ r -> infinity = a -> infinity ;
107+ secp256k1_ge_verify (r );
108+ }
109+
110+ /* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */
111+ static void secp256k1_ge_set_ge_zinv (secp256k1_ge * r , const secp256k1_ge * a , const secp256k1_fe * zi ) {
112+ secp256k1_fe zi2 ;
113+ secp256k1_fe zi3 ;
114+ secp256k1_ge_verify (a );
101115 secp256k1_fe_verify (zi );
102116 VERIFY_CHECK (!a -> infinity );
103117 secp256k1_fe_sqr (& zi2 , zi );
@@ -222,17 +236,13 @@ static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const se
222236
223237 /* Work our way backwards, using the z-ratios to scale the x/y values. */
224238 while (i > 0 ) {
225- secp256k1_gej tmpa ;
226239 if (i != len - 1 ) {
227240 secp256k1_fe_verify (& zr [i ]);
228241 secp256k1_fe_mul (& zs , & zs , & zr [i ]);
229242 }
230243 i -- ;
231244 secp256k1_ge_verify (& a [i ]);
232- tmpa .x = a [i ].x ;
233- tmpa .y = a [i ].y ;
234- tmpa .infinity = 0 ;
235- secp256k1_ge_set_gej_zinv (& a [i ], & tmpa , & zs );
245+ secp256k1_ge_set_ge_zinv (& a [i ], & a [i ], & zs );
236246 }
237247 }
238248}
0 commit comments