Skip to content

Commit ebad841

Browse files
gmaxwellsipa
authored andcommitted
Check correctness of lambda split without -DVERIFY
The VERIFY macro turns on various paranoid consistency checks, but the complete functionality should still be tested without it. This also adds a couple of static test points for extremely small split inputs/outputs. The existing bounds vectors already check extremely large outputs.
1 parent fe7fc1f commit ebad841

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/tests.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3635,12 +3635,17 @@ void run_ecmult_gen_blind(void) {
36353635
#ifdef USE_ENDOMORPHISM
36363636
/***** ENDOMORPHISH TESTS *****/
36373637
void test_scalar_split(const secp256k1_scalar* full) {
3638-
secp256k1_scalar s1, slam;
3638+
secp256k1_scalar s, s1, slam;
36393639
const unsigned char zero[32] = {0};
36403640
unsigned char tmp[32];
36413641

36423642
secp256k1_scalar_split_lambda(&s1, &slam, full);
36433643

3644+
/* check slam*lambda + s1 == full */
3645+
secp256k1_scalar_mul(&s, &secp256k1_const_lambda, &slam);
3646+
secp256k1_scalar_add(&s, &s, &s1);
3647+
CHECK(secp256k1_scalar_eq(&s, full));
3648+
36443649
/* check that both are <= 128 bits in size */
36453650
if (secp256k1_scalar_is_high(&s1)) {
36463651
secp256k1_scalar_negate(&s1, &s1);
@@ -3658,6 +3663,15 @@ void test_scalar_split(const secp256k1_scalar* full) {
36583663

36593664
void run_endomorphism_tests(void) {
36603665
unsigned i;
3666+
static secp256k1_scalar s;
3667+
test_scalar_split(&secp256k1_scalar_zero);
3668+
test_scalar_split(&secp256k1_scalar_one);
3669+
secp256k1_scalar_negate(&s,&secp256k1_scalar_one);
3670+
test_scalar_split(&s);
3671+
test_scalar_split(&secp256k1_const_lambda);
3672+
secp256k1_scalar_add(&s, &secp256k1_const_lambda, &secp256k1_scalar_one);
3673+
test_scalar_split(&s);
3674+
36613675
for (i = 0; i < 100U * count; ++i) {
36623676
secp256k1_scalar full;
36633677
random_scalar_order_test(&full);

0 commit comments

Comments
 (0)