77#ifndef  SECP256K1_FIELD_H 
88#define  SECP256K1_FIELD_H 
99
10- /** Field element module. 
11-  * 
12-  *  Field elements can be represented in several ways, but code accessing 
13-  *  it (and implementations) need to take certain properties into account: 
14-  *  - Each field element can be normalized or not. 
15-  *  - Each field element has a magnitude, which represents how far away 
16-  *    its representation is away from normalization. Normalized elements 
17-  *    always have a magnitude of 0 or 1, but a magnitude of 1 doesn't 
18-  *    imply normality. 
19-  */ 
20- 
2110#include  "util.h" 
2211
12+ /* This file defines the generic interface for working with secp256k1_fe 
13+  * objects, which represent field elements (integers modulo 2^256 - 2^32 - 977). 
14+  * 
15+  * The actual definition of the secp256k1_fe type depends on the chosen field 
16+  * implementation; see the field_5x52.h and field_10x26.h files for details. 
17+  * 
18+  * All secp256k1_fe objects have implicit properties that determine what 
19+  * operations are permitted on it. These are purely a function of what 
20+  * secp256k1_fe_ operations are applied on it, generally (implicitly) fixed at 
21+  * compile time, and do not depend on the chosen field implementation. Despite 
22+  * that, what these properties actually entail for the field representation 
23+  * values depends on the chosen field implementation. These properties are: 
24+  * - magnitude: an integer in [0,32] 
25+  * - normalized: 0 or 1; normalized=1 implies magnitude <= 1. 
26+  * 
27+  * In VERIFY mode, they are materialized explicitly as fields in the struct, 
28+  * allowing run-time verification of these properties. In that case, the field 
29+  * implementation also provides a secp256k1_fe_verify routine to verify that 
30+  * these fields match the run-time value and perform internal consistency 
31+  * checks. */ 
32+ #ifdef  VERIFY 
33+ #  define  SECP256K1_FE_VERIFY_FIELDS  \
34+     int magnitude; \
35+     int normalized;
36+ #else 
37+ #  define  SECP256K1_FE_VERIFY_FIELDS 
38+ #endif 
39+ 
2340#if  defined(SECP256K1_WIDEMUL_INT128 )
2441#include  "field_5x52.h" 
2542#elif  defined(SECP256K1_WIDEMUL_INT64 )
@@ -34,6 +51,12 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST(
3451    0x9cf04975ul , 0x12f58995ul , 0xc1396c28ul , 0x719501eeul 
3552);
3653
54+ #ifndef  VERIFY 
55+ /* In non-VERIFY mode, we #define the fe operations to be identical to their 
56+  * internal field implementation, to avoid the potential overhead of a 
57+  * function call (even though presumably inlinable). */ 
58+ #endif  /* !defined(VERIFY) */ 
59+ 
3760/** Normalize a field element. This brings the field element to a canonical representation, reduces 
3861 *  its magnitude to 1, and reduces it modulo field size `p`. 
3962 */ 
0 commit comments