@@ -335,81 +335,82 @@ void run_scratch_tests(void) {
335
335
int32_t ecount = 0 ;
336
336
size_t checkpoint ;
337
337
size_t checkpoint_2 ;
338
- secp256k1_context * none = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
339
338
secp256k1_scratch_space * scratch ;
340
339
secp256k1_scratch_space local_scratch ;
341
340
341
+ ctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
342
+
342
343
/* Test public API */
343
- secp256k1_context_set_illegal_callback (none , counting_illegal_callback_fn , & ecount );
344
- secp256k1_context_set_error_callback (none , counting_illegal_callback_fn , & ecount );
344
+ secp256k1_context_set_illegal_callback (ctx , counting_illegal_callback_fn , & ecount );
345
+ secp256k1_context_set_error_callback (ctx , counting_illegal_callback_fn , & ecount );
345
346
346
- scratch = secp256k1_scratch_space_create (none , 1000 );
347
+ scratch = secp256k1_scratch_space_create (ctx , 1000 );
347
348
CHECK (scratch != NULL );
348
349
CHECK (ecount == 0 );
349
350
350
351
/* Test internal API */
351
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 0 ) == 1000 );
352
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 1 ) == 1000 - (ALIGNMENT - 1 ));
352
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 0 ) == 1000 );
353
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 1 ) == 1000 - (ALIGNMENT - 1 ));
353
354
CHECK (scratch -> alloc_size == 0 );
354
355
CHECK (scratch -> alloc_size % ALIGNMENT == 0 );
355
356
356
357
/* Allocating 500 bytes succeeds */
357
- checkpoint = secp256k1_scratch_checkpoint (& none -> error_callback , scratch );
358
- CHECK (secp256k1_scratch_alloc (& none -> error_callback , scratch , 500 ) != NULL );
359
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 0 ) == 1000 - adj_alloc );
360
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 1 ) == 1000 - adj_alloc - (ALIGNMENT - 1 ));
358
+ checkpoint = secp256k1_scratch_checkpoint (& ctx -> error_callback , scratch );
359
+ CHECK (secp256k1_scratch_alloc (& ctx -> error_callback , scratch , 500 ) != NULL );
360
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 0 ) == 1000 - adj_alloc );
361
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 1 ) == 1000 - adj_alloc - (ALIGNMENT - 1 ));
361
362
CHECK (scratch -> alloc_size != 0 );
362
363
CHECK (scratch -> alloc_size % ALIGNMENT == 0 );
363
364
364
365
/* Allocating another 501 bytes fails */
365
- CHECK (secp256k1_scratch_alloc (& none -> error_callback , scratch , 501 ) == NULL );
366
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 0 ) == 1000 - adj_alloc );
367
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 1 ) == 1000 - adj_alloc - (ALIGNMENT - 1 ));
366
+ CHECK (secp256k1_scratch_alloc (& ctx -> error_callback , scratch , 501 ) == NULL );
367
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 0 ) == 1000 - adj_alloc );
368
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 1 ) == 1000 - adj_alloc - (ALIGNMENT - 1 ));
368
369
CHECK (scratch -> alloc_size != 0 );
369
370
CHECK (scratch -> alloc_size % ALIGNMENT == 0 );
370
371
371
372
/* ...but it succeeds once we apply the checkpoint to undo it */
372
- secp256k1_scratch_apply_checkpoint (& none -> error_callback , scratch , checkpoint );
373
+ secp256k1_scratch_apply_checkpoint (& ctx -> error_callback , scratch , checkpoint );
373
374
CHECK (scratch -> alloc_size == 0 );
374
- CHECK (secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 0 ) == 1000 );
375
- CHECK (secp256k1_scratch_alloc (& none -> error_callback , scratch , 500 ) != NULL );
375
+ CHECK (secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 0 ) == 1000 );
376
+ CHECK (secp256k1_scratch_alloc (& ctx -> error_callback , scratch , 500 ) != NULL );
376
377
CHECK (scratch -> alloc_size != 0 );
377
378
378
379
/* try to apply a bad checkpoint */
379
- checkpoint_2 = secp256k1_scratch_checkpoint (& none -> error_callback , scratch );
380
- secp256k1_scratch_apply_checkpoint (& none -> error_callback , scratch , checkpoint );
380
+ checkpoint_2 = secp256k1_scratch_checkpoint (& ctx -> error_callback , scratch );
381
+ secp256k1_scratch_apply_checkpoint (& ctx -> error_callback , scratch , checkpoint );
381
382
CHECK (ecount == 0 );
382
- secp256k1_scratch_apply_checkpoint (& none -> error_callback , scratch , checkpoint_2 ); /* checkpoint_2 is after checkpoint */
383
+ secp256k1_scratch_apply_checkpoint (& ctx -> error_callback , scratch , checkpoint_2 ); /* checkpoint_2 is after checkpoint */
383
384
CHECK (ecount == 1 );
384
- secp256k1_scratch_apply_checkpoint (& none -> error_callback , scratch , (size_t ) -1 ); /* this is just wildly invalid */
385
+ secp256k1_scratch_apply_checkpoint (& ctx -> error_callback , scratch , (size_t ) -1 ); /* this is just wildly invalid */
385
386
CHECK (ecount == 2 );
386
387
387
388
/* try to use badly initialized scratch space */
388
- secp256k1_scratch_space_destroy (none , scratch );
389
+ secp256k1_scratch_space_destroy (ctx , scratch );
389
390
memset (& local_scratch , 0 , sizeof (local_scratch ));
390
391
scratch = & local_scratch ;
391
- CHECK (!secp256k1_scratch_max_allocation (& none -> error_callback , scratch , 0 ));
392
+ CHECK (!secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , 0 ));
392
393
CHECK (ecount == 3 );
393
- CHECK (secp256k1_scratch_alloc (& none -> error_callback , scratch , 500 ) == NULL );
394
+ CHECK (secp256k1_scratch_alloc (& ctx -> error_callback , scratch , 500 ) == NULL );
394
395
CHECK (ecount == 4 );
395
- secp256k1_scratch_space_destroy (none , scratch );
396
+ secp256k1_scratch_space_destroy (ctx , scratch );
396
397
CHECK (ecount == 5 );
397
398
398
399
/* Test that large integers do not wrap around in a bad way */
399
- scratch = secp256k1_scratch_space_create (none , 1000 );
400
+ scratch = secp256k1_scratch_space_create (ctx , 1000 );
400
401
/* Try max allocation with a large number of objects. Only makes sense if
401
402
* ALIGNMENT is greater than 1 because otherwise the objects take no extra
402
403
* space. */
403
- CHECK (ALIGNMENT <= 1 || !secp256k1_scratch_max_allocation (& none -> error_callback , scratch , (SIZE_MAX / (ALIGNMENT - 1 )) + 1 ));
404
+ CHECK (ALIGNMENT <= 1 || !secp256k1_scratch_max_allocation (& ctx -> error_callback , scratch , (SIZE_MAX / (ALIGNMENT - 1 )) + 1 ));
404
405
/* Try allocating SIZE_MAX to test wrap around which only happens if
405
406
* ALIGNMENT > 1, otherwise it returns NULL anyway because the scratch
406
407
* space is too small. */
407
- CHECK (secp256k1_scratch_alloc (& none -> error_callback , scratch , SIZE_MAX ) == NULL );
408
- secp256k1_scratch_space_destroy (none , scratch );
408
+ CHECK (secp256k1_scratch_alloc (& ctx -> error_callback , scratch , SIZE_MAX ) == NULL );
409
+ secp256k1_scratch_space_destroy (ctx , scratch );
409
410
410
411
/* cleanup */
411
- secp256k1_scratch_space_destroy (none , NULL ); /* no-op */
412
- secp256k1_context_destroy (none );
412
+ secp256k1_scratch_space_destroy (ctx , NULL ); /* no-op */
413
+ secp256k1_context_destroy (ctx );
413
414
}
414
415
415
416
@@ -680,7 +681,6 @@ void run_rfc6979_hmac_sha256_tests(void) {
680
681
681
682
void run_tagged_sha256_tests (void ) {
682
683
int ecount = 0 ;
683
- secp256k1_context * none = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
684
684
unsigned char tag [32 ] = { 0 };
685
685
unsigned char msg [32 ] = { 0 };
686
686
unsigned char hash32 [32 ];
@@ -691,23 +691,22 @@ void run_tagged_sha256_tests(void) {
691
691
0xE2 , 0x76 , 0x55 , 0x9A , 0x3B , 0xDE , 0x55 , 0xB3
692
692
};
693
693
694
- secp256k1_context_set_illegal_callback (none , counting_illegal_callback_fn , & ecount );
694
+ secp256k1_context_set_illegal_callback (ctx , counting_illegal_callback_fn , & ecount );
695
695
696
696
/* API test */
697
- CHECK (secp256k1_tagged_sha256 (none , hash32 , tag , sizeof (tag ), msg , sizeof (msg )) == 1 );
698
- CHECK (secp256k1_tagged_sha256 (none , NULL , tag , sizeof (tag ), msg , sizeof (msg )) == 0 );
697
+ CHECK (secp256k1_tagged_sha256 (ctx , hash32 , tag , sizeof (tag ), msg , sizeof (msg )) == 1 );
698
+ CHECK (secp256k1_tagged_sha256 (ctx , NULL , tag , sizeof (tag ), msg , sizeof (msg )) == 0 );
699
699
CHECK (ecount == 1 );
700
- CHECK (secp256k1_tagged_sha256 (none , hash32 , NULL , 0 , msg , sizeof (msg )) == 0 );
700
+ CHECK (secp256k1_tagged_sha256 (ctx , hash32 , NULL , 0 , msg , sizeof (msg )) == 0 );
701
701
CHECK (ecount == 2 );
702
- CHECK (secp256k1_tagged_sha256 (none , hash32 , tag , sizeof (tag ), NULL , 0 ) == 0 );
702
+ CHECK (secp256k1_tagged_sha256 (ctx , hash32 , tag , sizeof (tag ), NULL , 0 ) == 0 );
703
703
CHECK (ecount == 3 );
704
704
705
705
/* Static test vector */
706
706
memcpy (tag , "tag" , 3 );
707
707
memcpy (msg , "msg" , 3 );
708
- CHECK (secp256k1_tagged_sha256 (none , hash32 , tag , 3 , msg , 3 ) == 1 );
708
+ CHECK (secp256k1_tagged_sha256 (ctx , hash32 , tag , 3 , msg , 3 ) == 1 );
709
709
CHECK (secp256k1_memcmp_var (hash32 , hash_expected , sizeof (hash32 )) == 0 );
710
- secp256k1_context_destroy (none );
711
710
}
712
711
713
712
/***** RANDOM TESTS *****/
@@ -7366,7 +7365,7 @@ int main(int argc, char **argv) {
7366
7365
run_context_tests (1 );
7367
7366
run_scratch_tests ();
7368
7367
7369
- ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
7368
+ ctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
7370
7369
/* Randomize the context only with probability 15/16
7371
7370
to make sure we test without context randomization from time to time.
7372
7371
TODO Reconsider this when recalibrating the tests. */
0 commit comments