Skip to content

Commit 2888640

Browse files
VERIFY_CHECK precondition for secp256k1_fe_set_int.
1 parent d49011f commit 2888640

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/field.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r);
5050
* without constant-time guarantee. */
5151
static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r);
5252

53-
/** Set a field element equal to a small integer. Resulting field element is normalized; it has
54-
* magnitude 0 if a == 0, and magnitude 1 otherwise. */
53+
/** Set a field element equal to a small (not greater than 0x7FFF), non-negative integer.
54+
* Resulting field element is normalized; it has magnitude 0 if a == 0, and magnitude 1 otherwise.
55+
*/
5556
static void secp256k1_fe_set_int(secp256k1_fe *r, int a);
5657

5758
/** Sets a field element equal to zero, initializing all fields. */

src/field_10x26_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r) {
264264
}
265265

266266
SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
267+
VERIFY_CHECK(0 <= a && a <= 0x7FFF);
267268
r->n[0] = a;
268269
r->n[1] = r->n[2] = r->n[3] = r->n[4] = r->n[5] = r->n[6] = r->n[7] = r->n[8] = r->n[9] = 0;
269270
#ifdef VERIFY

src/field_5x52_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r) {
227227
}
228228

229229
SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
230+
VERIFY_CHECK(0 <= a && a <= 0x7FFF);
230231
r->n[0] = a;
231232
r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0;
232233
#ifdef VERIFY

0 commit comments

Comments
 (0)