Skip to content

Commit

Permalink
Merge dashpay#539: Assorted minor corrections
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gmaxwell committed Feb 21, 2019
2 parents 949e85b + 52ab96f commit ba698f8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/field_10x26.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <stdint.h>

typedef struct {
/* X = sum(i=0..9, elem[i]*2^26) mod n */
/* X = sum(i=0..9, n[i]*2^(i*26)) mod p
* where p = 2^256 - 0x1000003D1
*/
uint32_t n[10];
#ifdef VERIFY
int magnitude;
Expand Down
5 changes: 3 additions & 2 deletions src/field_10x26_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define SECP256K1_FIELD_REPR_IMPL_H

#include "util.h"
#include "num.h"
#include "field.h"

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

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

Expand Down Expand Up @@ -1069,6 +1069,7 @@ static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp2
secp256k1_fe_verify(a);
secp256k1_fe_verify(b);
VERIFY_CHECK(r != b);
VERIFY_CHECK(a != b);
#endif
secp256k1_fe_mul_inner(r->n, a->n, b->n);
#ifdef VERIFY
Expand Down
4 changes: 3 additions & 1 deletion src/field_5x52.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <stdint.h>

typedef struct {
/* X = sum(i=0..4, elem[i]*2^52) mod n */
/* X = sum(i=0..4, n[i]*2^(i*52)) mod p
* where p = 2^256 - 0x1000003D1
*/
uint64_t n[5];
#ifdef VERIFY
int magnitude;
Expand Down
2 changes: 1 addition & 1 deletion src/field_5x52_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#endif

#include "util.h"
#include "num.h"
#include "field.h"

#if defined(USE_ASM_X86_64)
Expand Down Expand Up @@ -422,6 +421,7 @@ static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp2
secp256k1_fe_verify(a);
secp256k1_fe_verify(b);
VERIFY_CHECK(r != b);
VERIFY_CHECK(a != b);
#endif
secp256k1_fe_mul_inner(r->n, a->n, b->n);
#ifdef VERIFY
Expand Down
4 changes: 3 additions & 1 deletion src/field_5x52_int128_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t
VERIFY_BITS(b[3], 56);
VERIFY_BITS(b[4], 52);
VERIFY_CHECK(r != b);
VERIFY_CHECK(a != b);

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

Expand Down
1 change: 1 addition & 0 deletions src/field_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif

#include "util.h"
#include "num.h"

#if defined(USE_FIELD_10X26)
#include "field_10x26_impl.h"
Expand Down

0 comments on commit ba698f8

Please sign in to comment.