File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 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);
150150 */
151151static int secp256k1_fe_is_odd (const secp256k1_fe * a );
152152
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+ */
154159static int secp256k1_fe_equal (const secp256k1_fe * a , const secp256k1_fe * b );
155160
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+ */
157165static int secp256k1_fe_equal_var (const secp256k1_fe * a , const secp256k1_fe * b );
158166
159167/** Compare two field elements. Requires both inputs to be normalized */
Original file line number Diff line number Diff line change 2020
2121SECP256K1_INLINE static int secp256k1_fe_equal (const secp256k1_fe * a , const secp256k1_fe * b ) {
2222 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
2329 secp256k1_fe_negate (& na , a , 1 );
2430 secp256k1_fe_add (& na , b );
2531 return secp256k1_fe_normalizes_to_zero (& na );
2632}
2733
2834SECP256K1_INLINE static int secp256k1_fe_equal_var (const secp256k1_fe * a , const secp256k1_fe * b ) {
2935 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
3042 secp256k1_fe_negate (& na , a , 1 );
3143 secp256k1_fe_add (& na , b );
3244 return secp256k1_fe_normalizes_to_zero_var (& na );
You can’t perform that action at this time.
0 commit comments