Make _set_fe_int( . , 0 ) set magnitude to 0

This commit is contained in:
Tim Ruffing 2019-06-12 15:49:28 +02:00 committed by Russell O'Connor
parent 10f9bd84f4
commit d49011f54c
3 changed files with 6 additions and 5 deletions

View File

@ -14,8 +14,8 @@
* - Each field element can be normalized or not. * - Each field element can be normalized or not.
* - Each field element has a magnitude, which represents how far away * - Each field element has a magnitude, which represents how far away
* its representation is away from normalization. Normalized elements * its representation is away from normalization. Normalized elements
* always have a magnitude of 1, but a magnitude of 1 doesn't imply * always have a magnitude of 0 or 1, but a magnitude of 1 doesn't
* normality. * imply normality.
*/ */
#if defined HAVE_CONFIG_H #if defined HAVE_CONFIG_H
@ -50,7 +50,8 @@ static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r);
* without constant-time guarantee. */ * without constant-time guarantee. */
static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r); static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_fe *r);
/** Set a field element equal to a small integer. Resulting field element is normalized. */ /** Set a field element equal to a small integer. Resulting field element is normalized; it has
* magnitude 0 if a == 0, and magnitude 1 otherwise. */
static void secp256k1_fe_set_int(secp256k1_fe *r, int a); static void secp256k1_fe_set_int(secp256k1_fe *r, int a);
/** Sets a field element equal to zero, initializing all fields. */ /** Sets a field element equal to zero, initializing all fields. */

View File

@ -267,7 +267,7 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
r->n[0] = a; r->n[0] = a;
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; 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;
#ifdef VERIFY #ifdef VERIFY
r->magnitude = 1; r->magnitude = (a != 0);
r->normalized = 1; r->normalized = 1;
secp256k1_fe_verify(r); secp256k1_fe_verify(r);
#endif #endif

View File

@ -230,7 +230,7 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
r->n[0] = a; r->n[0] = a;
r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0; r->n[1] = r->n[2] = r->n[3] = r->n[4] = 0;
#ifdef VERIFY #ifdef VERIFY
r->magnitude = 1; r->magnitude = (a != 0);
r->normalized = 1; r->normalized = 1;
secp256k1_fe_verify(r); secp256k1_fe_verify(r);
#endif #endif