@@ -436,23 +436,6 @@ void scalar_test(void) {
436
436
CHECK (secp256k1_num_eq (& rnum , & r2num ));
437
437
}
438
438
439
- {
440
- /* Test that multipying the scalars is equal to multiplying their numbers modulo the order. */
441
- secp256k1_scalar_t r ;
442
- secp256k1_num_t r2num ;
443
- secp256k1_num_t rnum ;
444
- secp256k1_num_mul (& rnum , & snum , & s2num );
445
- secp256k1_num_mod (& rnum , & order );
446
- secp256k1_scalar_mul (& r , & s , & s2 );
447
- secp256k1_scalar_get_num (& r2num , & r );
448
- CHECK (secp256k1_num_eq (& rnum , & r2num ));
449
- /* The result can only be zero if at least one of the factors was zero. */
450
- CHECK (secp256k1_scalar_is_zero (& r ) == (secp256k1_scalar_is_zero (& s ) || secp256k1_scalar_is_zero (& s2 )));
451
- /* The results can only be equal to one of the factors if that factor was zero, or the other factor was one. */
452
- CHECK (secp256k1_num_eq (& rnum , & snum ) == (secp256k1_scalar_is_zero (& s ) || secp256k1_scalar_is_one (& s2 )));
453
- CHECK (secp256k1_num_eq (& rnum , & s2num ) == (secp256k1_scalar_is_zero (& s2 ) || secp256k1_scalar_is_one (& s )));
454
- }
455
-
456
439
{
457
440
secp256k1_scalar_t neg ;
458
441
secp256k1_num_t negnum ;
@@ -479,24 +462,6 @@ void scalar_test(void) {
479
462
CHECK (secp256k1_scalar_is_zero (& neg ));
480
463
}
481
464
482
- {
483
- /* Test secp256k1_scalar_mul_shift_var. */
484
- secp256k1_scalar_t r ;
485
- secp256k1_num_t one ;
486
- secp256k1_num_t rnum ;
487
- secp256k1_num_t rnum2 ;
488
- unsigned char cone [1 ] = {0x01 };
489
- unsigned int shift = 256 + (secp256k1_rand32 () % 257 );
490
- secp256k1_scalar_mul_shift_var (& r , & s1 , & s2 , shift );
491
- secp256k1_num_mul (& rnum , & s1num , & s2num );
492
- secp256k1_num_shift (& rnum , shift - 1 );
493
- secp256k1_num_set_bin (& one , cone , 1 );
494
- secp256k1_num_add (& rnum , & rnum , & one );
495
- secp256k1_num_shift (& rnum , 1 );
496
- secp256k1_scalar_get_num (& rnum2 , & r );
497
- CHECK (secp256k1_num_eq (& rnum , & rnum2 ));
498
- }
499
-
500
465
{
501
466
/* test secp256k1_scalar_shr_int */
502
467
secp256k1_scalar_t r ;
@@ -1725,23 +1690,25 @@ void run_ecmult_gen_blind(void) {
1725
1690
/***** ENDOMORPHISH TESTS *****/
1726
1691
void test_scalar_split (void ) {
1727
1692
secp256k1_scalar_t full ;
1728
- secp256k1_scalar_t s1 , slam ;
1729
- const unsigned char zero [32 ] = {0 };
1730
- unsigned char tmp [32 ];
1693
+ secp256k1_scalar_t s1 , slam , tmp ;
1694
+ secp256k1_scalar_t lambda = SECP256K1_SCALAR_CONST (
1695
+ 0x5363ad4c , 0xc05c30e0 , 0xa5261c02 , 0x8812645a ,
1696
+ 0x122e22ea , 0x20816678 , 0xdf02967c , 0x1b23bd72
1697
+ );
1731
1698
1732
1699
random_scalar_order_test (& full );
1733
1700
secp256k1_scalar_split_lambda (& s1 , & slam , & full );
1734
1701
1702
+ /* check that they are a lambda decomposition */
1703
+ secp256k1_scalar_mul (& tmp , & lambda , & slam );
1704
+ secp256k1_scalar_add (& tmp , & tmp , & s1 );
1705
+ CHECK (secp256k1_scalar_eq (& tmp , & full ));
1706
+
1735
1707
/* check that both are <= 128 bits in size */
1736
1708
if (secp256k1_scalar_is_high (& s1 ))
1737
1709
secp256k1_scalar_negate (& s1 , & s1 );
1738
1710
if (secp256k1_scalar_is_high (& slam ))
1739
1711
secp256k1_scalar_negate (& slam , & slam );
1740
-
1741
- secp256k1_scalar_get_b32 (tmp , & s1 );
1742
- CHECK (memcmp (zero , tmp , 16 ) == 0 );
1743
- secp256k1_scalar_get_b32 (tmp , & slam );
1744
- CHECK (memcmp (zero , tmp , 16 ) == 0 );
1745
1712
}
1746
1713
1747
1714
void run_endomorphism_tests (void ) {
0 commit comments