@@ -71,11 +71,13 @@ static int secp256k1_modinv64_mul_cmp_62(const secp256k1_modinv64_signed62 *a, i
71
71
return 0 ;
72
72
}
73
73
74
- /* Check if the determinant of t is equal to 1 << n. */
75
- static int secp256k1_modinv64_det_check_pow2 (const secp256k1_modinv64_trans2x2 * t , unsigned int n ) {
74
+ /* Check if the determinant of t is equal to 1 << n. If abs, check if |det t| == 1 << n. */
75
+ static int secp256k1_modinv64_det_check_pow2 (const secp256k1_modinv64_trans2x2 * t , unsigned int n , int abs ) {
76
76
secp256k1_int128 a ;
77
77
secp256k1_i128_det (& a , t -> u , t -> v , t -> q , t -> r );
78
- return secp256k1_i128_check_pow2 (& a , n , 1 );
78
+ if (secp256k1_i128_check_pow2 (& a , n , 1 )) return 1 ;
79
+ if (abs && secp256k1_i128_check_pow2 (& a , n , -1 )) return 1 ;
80
+ return 0 ;
79
81
}
80
82
#endif
81
83
@@ -218,7 +220,7 @@ static int64_t secp256k1_modinv64_divsteps_59(int64_t zeta, uint64_t f0, uint64_
218
220
* aggregate of 59 of them will have determinant 2^59. Multiplying with the initial
219
221
* 8*identity (which has determinant 2^6) means the overall outputs has determinant
220
222
* 2^65. */
221
- VERIFY_CHECK (secp256k1_modinv64_det_check_pow2 (t , 65 ));
223
+ VERIFY_CHECK (secp256k1_modinv64_det_check_pow2 (t , 65 , 0 ));
222
224
#endif
223
225
return zeta ;
224
226
}
@@ -301,7 +303,7 @@ static int64_t secp256k1_modinv64_divsteps_62_var(int64_t eta, uint64_t f0, uint
301
303
* does not change the gcd of f and g, apart from adding a power-of-2 factor to it (which
302
304
* will be divided out again). As each divstep's individual matrix has determinant 2, the
303
305
* aggregate of 62 of them will have determinant 2^62. */
304
- VERIFY_CHECK (secp256k1_modinv64_det_check_pow2 (t , 62 ));
306
+ VERIFY_CHECK (secp256k1_modinv64_det_check_pow2 (t , 62 , 0 ));
305
307
#endif
306
308
return eta ;
307
309
}
0 commit comments