Skip to content

Commit 0b83b20

Browse files
Merge bitcoin-core/secp256k1#1030: doc: Fix upper bounds + cleanup in field_5x52_impl.h comment
1287786 doc: Add comment to top of field_10x26_impl.h (Elliott Jin) 58da5bd doc: Fix upper bounds + cleanup in field_5x52_impl.h comment (Elliott Jin) Pull request description: When reviewing bitcoin#816 I noticed the upper bounds in the comment at the top of `field_5x52_impl.h` were off by 1 (see `fe_verify`). This PR fixes the upper bounds and also cleans up the comment along the way. ACKs for top commit: real-or-random: ACK 1287786 Tree-SHA512: 4b7dadc92451ab1ceb5a547a3101ff37f3ffd0645490563f1f3442ea8d6219f100ed914289d22435c4172d190fa1ff52e37e4464132bb3f9bbcc338488227f7b
2 parents b39d431 + 1287786 commit 0b83b20

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/field_10x26_impl.h

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#include "field.h"
1212
#include "modinv32_impl.h"
1313

14+
/** See the comment at the top of field_5x52_impl.h for more details.
15+
*
16+
* Here, we represent field elements as 10 uint32_t's in base 2^26, least significant first,
17+
* where limbs can contain >26 bits.
18+
* A magnitude M means:
19+
* - 2*M*(2^22-1) is the max (inclusive) of the most significant limb
20+
* - 2*M*(2^26-1) is the max (inclusive) of the remaining limbs
21+
*/
22+
1423
#ifdef VERIFY
1524
static void secp256k1_fe_verify(const secp256k1_fe *a) {
1625
const uint32_t *d = a->n;

src/field_5x52_impl.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@
2222
#endif
2323

2424
/** Implements arithmetic modulo FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F,
25-
* represented as 5 uint64_t's in base 2^52. The values are allowed to contain >52 each. In particular,
26-
* each FieldElem has a 'magnitude' associated with it. Internally, a magnitude M means each element
27-
* is at most M*(2^53-1), except the most significant one, which is limited to M*(2^49-1). All operations
28-
* accept any input with magnitude at most M, and have different rules for propagating magnitude to their
29-
* output.
25+
* represented as 5 uint64_t's in base 2^52, least significant first. Note that the limbs are allowed to
26+
* contain >52 bits each.
27+
*
28+
* Each field element has a 'magnitude' associated with it. Internally, a magnitude M means:
29+
* - 2*M*(2^48-1) is the max (inclusive) of the most significant limb
30+
* - 2*M*(2^52-1) is the max (inclusive) of the remaining limbs
31+
*
32+
* Operations have different rules for propagating magnitude to their outputs. If an operation takes a
33+
* magnitude M as a parameter, that means the magnitude of input field elements can be at most M (inclusive).
34+
*
35+
* Each field element also has a 'normalized' flag. A field element is normalized if its magnitude is either
36+
* 0 or 1, and its value is already reduced modulo the order of the field.
3037
*/
3138

3239
#ifdef VERIFY

0 commit comments

Comments
 (0)