Abstract out verify logic for fe_set_int
This commit is contained in:
parent
864f9db491
commit
19a2bfeeea
@ -80,6 +80,7 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST(
|
|||||||
# define secp256k1_fe_normalize_var secp256k1_fe_impl_normalize_var
|
# define secp256k1_fe_normalize_var secp256k1_fe_impl_normalize_var
|
||||||
# define secp256k1_fe_normalizes_to_zero secp256k1_fe_impl_normalizes_to_zero
|
# define secp256k1_fe_normalizes_to_zero secp256k1_fe_impl_normalizes_to_zero
|
||||||
# define secp256k1_fe_normalizes_to_zero_var secp256k1_fe_impl_normalizes_to_zero_var
|
# define secp256k1_fe_normalizes_to_zero_var secp256k1_fe_impl_normalizes_to_zero_var
|
||||||
|
# define secp256k1_fe_set_int secp256k1_fe_impl_set_int
|
||||||
#endif /* !defined(VERIFY) */
|
#endif /* !defined(VERIFY) */
|
||||||
|
|
||||||
/** Normalize a field element.
|
/** Normalize a field element.
|
||||||
@ -115,8 +116,10 @@ static int secp256k1_fe_normalizes_to_zero(const secp256k1_fe *r);
|
|||||||
*/
|
*/
|
||||||
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 (not greater than 0x7FFF), non-negative integer.
|
/** Set a field element to an integer in range [0,0x7FFF].
|
||||||
* Resulting field element is normalized; it has magnitude 0 if a == 0, and magnitude 1 otherwise.
|
*
|
||||||
|
* On input, r does not need to be initialized, a must be in [0,0x7FFF].
|
||||||
|
* On output, r represents value a, is normalized and has magnitude (a!=0).
|
||||||
*/
|
*/
|
||||||
static void secp256k1_fe_set_int(secp256k1_fe *r, int a);
|
static void secp256k1_fe_set_int(secp256k1_fe *r, int a);
|
||||||
|
|
||||||
|
@ -264,15 +264,9 @@ static int secp256k1_fe_impl_normalizes_to_zero_var(const secp256k1_fe *r) {
|
|||||||
return (z0 == 0) | (z1 == 0x3FFFFFFUL);
|
return (z0 == 0) | (z1 == 0x3FFFFFFUL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
|
SECP256K1_INLINE static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a) {
|
||||||
VERIFY_CHECK(0 <= a && a <= 0x7FFF);
|
|
||||||
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
|
|
||||||
r->magnitude = (a != 0);
|
|
||||||
r->normalized = 1;
|
|
||||||
secp256k1_fe_verify(r);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
|
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
|
||||||
|
@ -210,15 +210,9 @@ static int secp256k1_fe_impl_normalizes_to_zero_var(const secp256k1_fe *r) {
|
|||||||
return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);
|
return (z0 == 0) | (z1 == 0xFFFFFFFFFFFFFULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
|
SECP256K1_INLINE static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a) {
|
||||||
VERIFY_CHECK(0 <= a && a <= 0x7FFF);
|
|
||||||
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
|
|
||||||
r->magnitude = (a != 0);
|
|
||||||
r->normalized = 1;
|
|
||||||
secp256k1_fe_verify(r);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
|
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
|
||||||
|
@ -185,6 +185,15 @@ SECP256K1_INLINE static int secp256k1_fe_normalizes_to_zero_var(const secp256k1_
|
|||||||
secp256k1_fe_verify(r);
|
secp256k1_fe_verify(r);
|
||||||
return secp256k1_fe_impl_normalizes_to_zero_var(r);
|
return secp256k1_fe_impl_normalizes_to_zero_var(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void secp256k1_fe_impl_set_int(secp256k1_fe *r, int a);
|
||||||
|
SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
|
||||||
|
VERIFY_CHECK(0 <= a && a <= 0x7FFF);
|
||||||
|
secp256k1_fe_impl_set_int(r, a);
|
||||||
|
r->magnitude = (a != 0);
|
||||||
|
r->normalized = 1;
|
||||||
|
secp256k1_fe_verify(r);
|
||||||
|
}
|
||||||
#endif /* defined(VERIFY) */
|
#endif /* defined(VERIFY) */
|
||||||
|
|
||||||
#endif /* SECP256K1_FIELD_IMPL_H */
|
#endif /* SECP256K1_FIELD_IMPL_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user