Skip to content

Commit 809d688

Browse files
roconnor-blockstreamFabcien
authored andcommitted
[SECP256K1] Increase precision of g1 and g2
Summary: ``` 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. ``` Partial backport 2/11 of secp256k1 [[bitcoin-core/secp256k1#830 | PR830]]: bitcoin-core/secp256k1@76ed922 Test Plan: ninja check-secp256k1 Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8038
1 parent e4fa96f commit 809d688

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
@@ -303,8 +303,8 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar *r1, secp256k1_scalar
303303
* Cryptography on Sensor Networks Using the MSP430X Microcontroller" (Gouvea, Oliveira, Lopez),
304304
* Section 4.3 (here we use a somewhat higher-precision estimate):
305305
* d = a1*b2 - b1*a2
306-
* g1 = round((2^272)*b2/d)
307-
* g2 = round((2^272)*b1/d)
306+
* g1 = round((2^384)*b2/d)
307+
* g2 = round((2^384)*(-b1)/d)
308308
*
309309
* (Note that 'd' is also equal to the curve order here because [a1,b1] and [a2,b2] are found
310310
* as outputs of the Extended Euclidean Algorithm on inputs 'order' and 'lambda').
@@ -327,18 +327,18 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar *r1, secp256k1_scalar
327327
0x8A280AC5UL, 0x0774346DUL, 0xD765CDA8UL, 0x3DB1562CUL
328328
);
329329
static const secp256k1_scalar g1 = SECP256K1_SCALAR_CONST(
330-
0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00003086UL,
331-
0xD221A7D4UL, 0x6BCDE86CUL, 0x90E49284UL, 0xEB153DABUL
330+
0x3086D221UL, 0xA7D46BCDUL, 0xE86C90E4UL, 0x9284EB15UL,
331+
0x3DAA8A14UL, 0x71E8CA7FUL, 0xE893209AUL, 0x45DBB031UL
332332
);
333333
static const secp256k1_scalar g2 = SECP256K1_SCALAR_CONST(
334-
0x00000000UL, 0x00000000UL, 0x00000000UL, 0x0000E443UL,
335-
0x7ED6010EUL, 0x88286F54UL, 0x7FA90ABFUL, 0xE4C42212UL
334+
0xE4437ED6UL, 0x010E8828UL, 0x6F547FA9UL, 0x0ABFE4C4UL,
335+
0x221208ACUL, 0x9DF506C6UL, 0x1571B4AEUL, 0x8AC47F71UL
336336
);
337337
VERIFY_CHECK(r1 != a);
338338
VERIFY_CHECK(r2 != a);
339339
/* these _var calls are constant time since the shift amount is constant */
340-
secp256k1_scalar_mul_shift_var(&c1, a, &g1, 272);
341-
secp256k1_scalar_mul_shift_var(&c2, a, &g2, 272);
340+
secp256k1_scalar_mul_shift_var(&c1, a, &g1, 384);
341+
secp256k1_scalar_mul_shift_var(&c2, a, &g2, 384);
342342
secp256k1_scalar_mul(&c1, &c1, &minus_b1);
343343
secp256k1_scalar_mul(&c2, &c2, &minus_b2);
344344
secp256k1_scalar_add(r2, &c1, &c2);

0 commit comments

Comments
 (0)