@@ -407,20 +407,6 @@ static void ec_GFp_nistp521_dbl(const EC_GROUP *group, EC_JACOBIAN *r,
407
407
// The precomputed table of base point multiples is generated by the code in
408
408
// |make_tables.go| script.
409
409
410
- // p521_get_bit returns the |i|-th bit in |in|
411
- static crypto_word_t p521_get_bit (const EC_SCALAR * in , int i ) {
412
- if (i < 0 || i >= 521 ) {
413
- return 0 ;
414
- }
415
- #if defined(OPENSSL_64_BIT )
416
- assert (sizeof (BN_ULONG ) == 8 );
417
- return (in -> words [i >> 6 ] >> (i & 63 )) & 1 ;
418
- #else
419
- assert (sizeof (BN_ULONG ) == 4 );
420
- return (in -> words [i >> 5 ] >> (i & 31 )) & 1 ;
421
- #endif
422
- }
423
-
424
410
// Constants for scalar encoding in the scalar multiplication functions.
425
411
#define P521_MUL_WSIZE (5) // window size w
426
412
// Assert the window size is 5 because the pre-computed table in |p521_table.h|
@@ -442,27 +428,6 @@ OPENSSL_STATIC_ASSERT(P521_MUL_WSIZE == 5,
442
428
#define P521_MUL_TABLE_SIZE (P521_MUL_TWO_TO_WSIZE >> 1)
443
429
#define P521_MUL_PUB_TABLE_SIZE (1 << (P521_MUL_PUB_WSIZE - 1))
444
430
445
- // Compute "regular" wNAF representation of a scalar, see
446
- // Joye, Tunstall, "Exponent Recoding and Regular Exponentiation Algorithms",
447
- // AfricaCrypt 2009, Alg 6.
448
- // It forces an odd scalar and outputs digits in
449
- // {\pm 1, \pm 3, \pm 5, \pm 7, \pm 9, ...}
450
- // i.e. signed odd digits with _no zeroes_ -- that makes it "regular".
451
- static void p521_felem_mul_scalar_rwnaf (int16_t * out , const EC_SCALAR * in ) {
452
- int16_t window , d ;
453
-
454
- window = (in -> words [0 ] & P521_MUL_WSIZE_MASK ) | 1 ;
455
- for (size_t i = 0 ; i < P521_MUL_NWINDOWS - 1 ; i ++ ) {
456
- d = (window & P521_MUL_WSIZE_MASK ) - P521_MUL_TWO_TO_WSIZE ;
457
- out [i ] = d ;
458
- window = (window - d ) >> P521_MUL_WSIZE ;
459
- for (size_t j = 1 ; j <= P521_MUL_WSIZE ; j ++ ) {
460
- window += p521_get_bit (in , (i + 1 ) * P521_MUL_WSIZE + j ) << j ;
461
- }
462
- }
463
- out [P521_MUL_NWINDOWS - 1 ] = window ;
464
- }
465
-
466
431
// p521_select_point selects the |idx|-th projective point from the given
467
432
// precomputed table and copies it to |out| in constant time.
468
433
static void p521_select_point (p521_felem out [3 ],
@@ -550,7 +515,7 @@ static void ec_GFp_nistp521_point_mul(const EC_GROUP *group, EC_JACOBIAN *r,
550
515
551
516
// Recode the scalar.
552
517
int16_t rnaf [P521_MUL_NWINDOWS ] = {0 };
553
- p521_felem_mul_scalar_rwnaf (rnaf , scalar );
518
+ scalar_rwnaf (rnaf , P521_MUL_WSIZE , scalar , 521 );
554
519
555
520
// Initialize the accumulator |res| with the table entry corresponding to
556
521
// the most significant digit of the recoded scalar (note that this digit
@@ -674,7 +639,7 @@ static void ec_GFp_nistp521_point_mul_base(const EC_GROUP *group,
674
639
int16_t rnaf [P521_MUL_NWINDOWS ] = {0 };
675
640
676
641
// Recode the scalar.
677
- p521_felem_mul_scalar_rwnaf (rnaf , scalar );
642
+ scalar_rwnaf (rnaf , P521_MUL_WSIZE , scalar , 521 );
678
643
679
644
// Process the 4 groups of digits starting from group (3) down to group (0).
680
645
for (int i = 3 ; i >= 0 ; i -- ) {
0 commit comments