Skip to content

Commit b17a7df

Browse files
Make _set_fe_int( . , 0 ) set magnitude to 0
1 parent 4949658 commit b17a7df

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/field.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* - Each field element can be normalized or not.
1515
* - Each field element has a magnitude, which represents how far away
1616
* its representation is away from normalization. Normalized elements
17-
* always have a magnitude of 1, but a magnitude of 1 doesn't imply
18-
* normality.
17+
* always have a magnitude of 0 or 1, but a magnitude of 1 doesn't
18+
* imply normality.
1919
*/
2020

2121
#if defined HAVE_CONFIG_H
@@ -51,7 +51,8 @@ static int secp256k1_fe_normalizes_to_zero(secp256k1_fe *r);
5151
* implementation may optionally normalize the input, but this should not be relied upon. */
5252
static int secp256k1_fe_normalizes_to_zero_var(secp256k1_fe *r);
5353

54-
/** Set a field element equal to a small integer. Resulting field element is normalized. */
54+
/** Set a field element equal to a small integer. Resulting field element is normalized; it has
55+
* magnitude 0 if a == 0, and magnitude 1 otherwise. */
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
266266
r->n[0] = a;
267267
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;
268268
#ifdef VERIFY
269-
r->magnitude = 1;
269+
r->magnitude = (a != 0);
270270
r->normalized = 1;
271271
secp256k1_fe_verify(r);
272272
#endif

src/field_5x52_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
229229
r->n[0] = a;
230230
r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0;
231231
#ifdef VERIFY
232-
r->magnitude = 1;
232+
r->magnitude = (a != 0);
233233
r->normalized = 1;
234234
secp256k1_fe_verify(r);
235235
#endif

0 commit comments

Comments
 (0)