Skip to content

Commit 180faa9

Browse files
llmul on msvc
1 parent d644dda commit 180faa9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/field_10x26_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,14 @@ SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t
762762
/* [d 0 0 0 0 0 0 0 -d*R1 r9+(c<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
763763
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
764764

765-
d = c * (R0 >> 4) + t0;
765+
d = (c * (((uint64_t)R0 >> 4) << 7) >> 7) + t0; /* XXX */
766766
VERIFY_BITS(d, 56);
767767
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 d-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
768768
r[0] = d & M; d >>= 26;
769769
VERIFY_BITS(r[0], 26);
770770
VERIFY_BITS(d, 30);
771771
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1+d r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
772-
d += c * (R1 >> 4) + t1;
772+
d += (c * (((uint64_t)R1 >> 4) << 10) >> 10) + t1; /* XXX same */
773773
VERIFY_BITS(d, 53);
774774
VERIFY_CHECK(d <= 0x10000003FFFFBFULL);
775775
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 d-c*R1>>4 r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
@@ -1036,14 +1036,14 @@ SECP256K1_INLINE static void secp256k1_fe_sqr_inner(uint32_t *r, const uint32_t
10361036
/* [d 0 0 0 0 0 0 0 -d*R1 r9+(c<<22)-d*R0 r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
10371037
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 t0] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
10381038

1039-
d = c * (R0 >> 4) + t0;
1039+
d = (c * ((R0 >> 4) << 7) >> 7)+ t0; /* XXX */
10401040
VERIFY_BITS(d, 56);
10411041
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1 d-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
10421042
r[0] = d & M; d >>= 26;
10431043
VERIFY_BITS(r[0], 26);
10441044
VERIFY_BITS(d, 30);
10451045
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 t1+d r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */
1046-
d += c * (R1 >> 4) + t1;
1046+
d += (c * ((R1 >> 4) << 10) >> 10) + t1; /* XXX */
10471047
VERIFY_BITS(d, 53);
10481048
VERIFY_CHECK(d <= 0x10000003FFFFBFULL);
10491049
/* [r9+(c<<22) r8 r7 r6 r5 r4 r3 t2 d-c*R1>>4 r0-c*R0>>4] = [p18 p17 p16 p15 p14 p13 p12 p11 p10 p9 p8 p7 p6 p5 p4 p3 p2 p1 p0] */

src/scalar_8x32_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) {
265265
/** Add a*b to the number defined by (c0,c1,c2). c2 must never overflow. */
266266
#define muladd(a,b) { \
267267
uint32_t tl, th; \
268+
VERIFY_CHECK((uint64_t)a >> 32 == 0); \
269+
VERIFY_CHECK((uint64_t)b >> 32 == 0); \
268270
{ \
269271
uint64_t t = (uint64_t)a * b; \
270272
th = t >> 32; /* at most 0xFFFFFFFE */ \
@@ -280,6 +282,8 @@ static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) {
280282
/** Add a*b to the number defined by (c0,c1). c1 must never overflow. */
281283
#define muladd_fast(a,b) { \
282284
uint32_t tl, th; \
285+
VERIFY_CHECK((uint64_t)a >> 32 == 0); \
286+
VERIFY_CHECK((uint64_t)b >> 32 == 0); \
283287
{ \
284288
uint64_t t = (uint64_t)a * b; \
285289
th = t >> 32; /* at most 0xFFFFFFFE */ \
@@ -294,6 +298,8 @@ static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) {
294298
/** Add 2*a*b to the number defined by (c0,c1,c2). c2 must never overflow. */
295299
#define muladd2(a,b) { \
296300
uint32_t tl, th, th2, tl2; \
301+
VERIFY_CHECK((uint64_t)a >> 32 == 0); \
302+
VERIFY_CHECK((uint64_t)b >> 32 == 0); \
297303
{ \
298304
uint64_t t = (uint64_t)a * b; \
299305
th = t >> 32; /* at most 0xFFFFFFFE */ \

0 commit comments

Comments
 (0)