Skip to content

Commit 57d4b0d

Browse files
Increase precision of g1 and g2.
This allows us to shift by 256+128 = 384 bits, which is a multiple of the limb size of the scalar representation. This also happens to be the most precision possible for g2 that still fits into a 256-bit value.
1 parent d7838ba commit 57d4b0d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/scalar_impl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar *r1, secp256k1_scalar
294294
* Cryptography on Sensor Networks Using the MSP430X Microcontroller" (Gouvea, Oliveira, Lopez),
295295
* Section 4.3 (here we use a somewhat higher-precision estimate):
296296
* d = a1*b2 - b1*a2
297-
* g1 = round((2^272)*b2/d)
298-
* g2 = round((2^272)*b1/d)
297+
* g1 = round((2^384)*b2/d)
298+
* g2 = round((2^384)*(-b1)/d)
299299
*
300300
* (Note that 'd' is also equal to the curve order here because [a1,b1] and [a2,b2] are found
301301
* as outputs of the Extended Euclidean Algorithm on inputs 'order' and 'lambda').
@@ -318,18 +318,18 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar *r1, secp256k1_scalar
318318
0x8A280AC5UL, 0x0774346DUL, 0xD765CDA8UL, 0x3DB1562CUL
319319
);
320320
static const secp256k1_scalar g1 = SECP256K1_SCALAR_CONST(
321-
0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00003086UL,
322-
0xD221A7D4UL, 0x6BCDE86CUL, 0x90E49284UL, 0xEB153DABUL
321+
0x3086D221UL, 0xA7D46BCDUL, 0xE86C90E4UL, 0x9284EB15UL,
322+
0x3DAA8A14UL, 0x71E8CA7FUL, 0xE893209AUL, 0x45DBB031UL
323323
);
324324
static const secp256k1_scalar g2 = SECP256K1_SCALAR_CONST(
325-
0x00000000UL, 0x00000000UL, 0x00000000UL, 0x0000E443UL,
326-
0x7ED6010EUL, 0x88286F54UL, 0x7FA90ABFUL, 0xE4C42212UL
325+
0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C4UL,
326+
0x221208ACUL, 0x9DF506C6UL, 0x1571B4AEUL, 0x8AC47F71UL
327327
);
328328
VERIFY_CHECK(r1 != a);
329329
VERIFY_CHECK(r2 != a);
330330
/* these _var calls are constant time since the shift amount is constant */
331-
secp256k1_scalar_mul_shift_var(&c1, a, &g1, 272);
332-
secp256k1_scalar_mul_shift_var(&c2, a, &g2, 272);
331+
secp256k1_scalar_mul_shift_var(&c1, a, &g1, 384);
332+
secp256k1_scalar_mul_shift_var(&c2, a, &g2, 384);
333333
secp256k1_scalar_mul(&c1, &c1, &minus_b1);
334334
secp256k1_scalar_mul(&c2, &c2, &minus_b2);
335335
secp256k1_scalar_add(r2, &c1, &c2);

0 commit comments

Comments
 (0)