File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -150,10 +150,18 @@ static int secp256k1_fe_is_zero(const secp256k1_fe *a);
150
150
*/
151
151
static int secp256k1_fe_is_odd (const secp256k1_fe * a );
152
152
153
- /** Compare two field elements. Requires magnitude-1 inputs. */
153
+ /** Determine whether two field elements are equal.
154
+ *
155
+ * On input, a and b must be valid field elements with magnitudes not exceeding
156
+ * 1 and 31, respectively.
157
+ * Returns a = b (mod p).
158
+ */
154
159
static int secp256k1_fe_equal (const secp256k1_fe * a , const secp256k1_fe * b );
155
160
156
- /** Same as secp256k1_fe_equal, but may be variable time. */
161
+ /** Determine whether two field elements are equal, without constant-time guarantee.
162
+ *
163
+ * Identical in behavior to secp256k1_fe_equal, but not constant time in either a or b.
164
+ */
157
165
static int secp256k1_fe_equal_var (const secp256k1_fe * a , const secp256k1_fe * b );
158
166
159
167
/** Compare two field elements. Requires both inputs to be normalized */
Original file line number Diff line number Diff line change 20
20
21
21
SECP256K1_INLINE static int secp256k1_fe_equal (const secp256k1_fe * a , const secp256k1_fe * b ) {
22
22
secp256k1_fe na ;
23
+ #ifdef VERIFY
24
+ secp256k1_fe_verify (a );
25
+ secp256k1_fe_verify (b );
26
+ VERIFY_CHECK (a -> magnitude <= 1 );
27
+ VERIFY_CHECK (b -> magnitude <= 31 );
28
+ #endif
23
29
secp256k1_fe_negate (& na , a , 1 );
24
30
secp256k1_fe_add (& na , b );
25
31
return secp256k1_fe_normalizes_to_zero (& na );
26
32
}
27
33
28
34
SECP256K1_INLINE static int secp256k1_fe_equal_var (const secp256k1_fe * a , const secp256k1_fe * b ) {
29
35
secp256k1_fe na ;
36
+ #ifdef VERIFY
37
+ secp256k1_fe_verify (a );
38
+ secp256k1_fe_verify (b );
39
+ VERIFY_CHECK (a -> magnitude <= 1 );
40
+ VERIFY_CHECK (b -> magnitude <= 31 );
41
+ #endif
30
42
secp256k1_fe_negate (& na , a , 1 );
31
43
secp256k1_fe_add (& na , b );
32
44
return secp256k1_fe_normalizes_to_zero_var (& na );
You can’t perform that action at this time.
0 commit comments