Skip to content

Commit ba698f8

Browse files
committed
Merge bitcoin#539: Assorted minor corrections
52ab96f clean dependendies in field_*_impl.h (Russell O'Connor) deff5ed Correct math typos in field_*.h (Russell O'Connor) 4efb3f8 Add check that restrict pointers don't alias with all parameters. (Russell O'Connor) Pull request description: * add more checks for restrict pointers. * correct math typos. * refine dependencies on "num.h" Tree-SHA512: c368f577927db2ace3e7f46850cb2fdf9d7d169b698a9697767e1f82e9e7091f2b2fea0f7cf173048eb4c1bb56824c884fa849c04c595ee97766c01f346a54ec
2 parents 949e85b + 52ab96f commit ba698f8

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

src/field_10x26.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <stdint.h>
1111

1212
typedef struct {
13-
/* X = sum(i=0..9, elem[i]*2^26) mod n */
13+
/* X = sum(i=0..9, n[i]*2^(i*26)) mod p
14+
* where p = 2^256 - 0x1000003D1
15+
*/
1416
uint32_t n[10];
1517
#ifdef VERIFY
1618
int magnitude;

src/field_10x26_impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define SECP256K1_FIELD_REPR_IMPL_H
99

1010
#include "util.h"
11-
#include "num.h"
1211
#include "field.h"
1312

1413
#ifdef VERIFY
@@ -486,7 +485,8 @@ SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t
486485
VERIFY_BITS(b[9], 26);
487486

488487
/** [... a b c] is a shorthand for ... + a<<52 + b<<26 + c<<0 mod n.
489-
* px is a shorthand for sum(a[i]*b[x-i], i=0..x).
488+
* for 0 <= x <= 9, px is a shorthand for sum(a[i]*b[x-i], i=0..x).
489+
* for 9 <= x <= 18, px is a shorthand for sum(a[i]*b[x-i], i=(x-9)..9)
490490
* Note that [x 0 0 0 0 0 0 0 0 0 0] = [x*R1 x*R0].
491491
*/
492492

@@ -1069,6 +1069,7 @@ static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp2
10691069
secp256k1_fe_verify(a);
10701070
secp256k1_fe_verify(b);
10711071
VERIFY_CHECK(r != b);
1072+
VERIFY_CHECK(a != b);
10721073
#endif
10731074
secp256k1_fe_mul_inner(r->n, a->n, b->n);
10741075
#ifdef VERIFY

src/field_5x52.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <stdint.h>
1111

1212
typedef struct {
13-
/* X = sum(i=0..4, elem[i]*2^52) mod n */
13+
/* X = sum(i=0..4, n[i]*2^(i*52)) mod p
14+
* where p = 2^256 - 0x1000003D1
15+
*/
1416
uint64_t n[5];
1517
#ifdef VERIFY
1618
int magnitude;

src/field_5x52_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#endif
1313

1414
#include "util.h"
15-
#include "num.h"
1615
#include "field.h"
1716

1817
#if defined(USE_ASM_X86_64)
@@ -422,6 +421,7 @@ static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp2
422421
secp256k1_fe_verify(a);
423422
secp256k1_fe_verify(b);
424423
VERIFY_CHECK(r != b);
424+
VERIFY_CHECK(a != b);
425425
#endif
426426
secp256k1_fe_mul_inner(r->n, a->n, b->n);
427427
#ifdef VERIFY

src/field_5x52_int128_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t
3232
VERIFY_BITS(b[3], 56);
3333
VERIFY_BITS(b[4], 52);
3434
VERIFY_CHECK(r != b);
35+
VERIFY_CHECK(a != b);
3536

3637
/* [... a b c] is a shorthand for ... + a<<104 + b<<52 + c<<0 mod n.
37-
* px is a shorthand for sum(a[i]*b[x-i], i=0..x).
38+
* for 0 <= x <= 4, px is a shorthand for sum(a[i]*b[x-i], i=0..x).
39+
* for 4 <= x <= 8, px is a shorthand for sum(a[i]*b[x-i], i=(x-4)..4)
3840
* Note that [x 0 0 0 0 0] = [x*R].
3941
*/
4042

src/field_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#endif
1313

1414
#include "util.h"
15+
#include "num.h"
1516

1617
#if defined(USE_FIELD_10X26)
1718
#include "field_10x26_impl.h"

0 commit comments

Comments
 (0)