Merge magnitude/normalized fields, move/improve comments
Also split secp256k1_fe_verify into a generic and an implementation specific part.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#ifndef SECP256K1_FIELD_IMPL_H
|
||||
#define SECP256K1_FIELD_IMPL_H
|
||||
|
||||
#include "field.h"
|
||||
#include "util.h"
|
||||
|
||||
#if defined(SECP256K1_WIDEMUL_INT128)
|
||||
@@ -131,4 +132,21 @@ static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a) {
|
||||
return secp256k1_fe_equal(&t1, a);
|
||||
}
|
||||
|
||||
#ifndef VERIFY
|
||||
static void secp256k1_fe_verify(const secp256k1_fe *a) { (void)a; }
|
||||
#else
|
||||
static void secp256k1_fe_impl_verify(const secp256k1_fe *a);
|
||||
static void secp256k1_fe_verify(const secp256k1_fe *a) {
|
||||
/* Magnitude between 0 and 32. */
|
||||
int r = (a->magnitude >= 0) & (a->magnitude <= 32);
|
||||
/* Normalized is 0 or 1. */
|
||||
r &= (a->normalized == 0) | (a->normalized == 1);
|
||||
/* If normalized, magnitude must be 0 or 1. */
|
||||
if (a->normalized) r &= (a->magnitude <= 1);
|
||||
VERIFY_CHECK(r == 1);
|
||||
/* Invoke implementation-specific checks. */
|
||||
secp256k1_fe_impl_verify(a);
|
||||
}
|
||||
#endif /* defined(VERIFY) */
|
||||
|
||||
#endif /* SECP256K1_FIELD_IMPL_H */
|
||||
|
||||
Reference in New Issue
Block a user