Skip to content

Commit cb7e902

Browse files
VERIFY_CHECK precondition for secp256k1_fe_set_int.
1 parent b9176f6 commit cb7e902

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

src/field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ 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
53+
/** Set a field element equal to a small, non-negative integer. Resulting field element is normalized; it has
5454
* magnitude 0 if a == 0, and magnitude 1 otherwise. */
5555
static void secp256k1_fe_set_int(secp256k1_fe *r, int a);
5656

src/field_10x26_impl.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)