@@ -648,7 +648,7 @@ static size_t secp256k1_strauss_scratch_size(size_t n_points) {
648648 return n_points * point_size ;
649649}
650650
651- static int secp256k1_ecmult_strauss_batch (const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n_points , size_t cb_offset ) {
651+ static int secp256k1_ecmult_strauss_batch (const secp256k1_callback * error_callback , const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n_points , size_t cb_offset ) {
652652 secp256k1_gej * points ;
653653 secp256k1_scalar * scalars ;
654654 struct secp256k1_strauss_state state ;
@@ -659,41 +659,41 @@ static int secp256k1_ecmult_strauss_batch(const secp256k1_ecmult_context *ctx, s
659659 return 1 ;
660660 }
661661
662- if (!secp256k1_scratch_allocate_frame (scratch , secp256k1_strauss_scratch_size (n_points ), STRAUSS_SCRATCH_OBJECTS )) {
662+ if (!secp256k1_scratch_allocate_frame (error_callback , scratch , secp256k1_strauss_scratch_size (n_points ), STRAUSS_SCRATCH_OBJECTS )) {
663663 return 0 ;
664664 }
665- points = (secp256k1_gej * )secp256k1_scratch_alloc (scratch , n_points * sizeof (secp256k1_gej ));
666- scalars = (secp256k1_scalar * )secp256k1_scratch_alloc (scratch , n_points * sizeof (secp256k1_scalar ));
667- state .prej = (secp256k1_gej * )secp256k1_scratch_alloc (scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_gej ));
668- state .zr = (secp256k1_fe * )secp256k1_scratch_alloc (scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_fe ));
665+ points = (secp256k1_gej * )secp256k1_scratch_alloc (error_callback , scratch , n_points * sizeof (secp256k1_gej ));
666+ scalars = (secp256k1_scalar * )secp256k1_scratch_alloc (error_callback , scratch , n_points * sizeof (secp256k1_scalar ));
667+ state .prej = (secp256k1_gej * )secp256k1_scratch_alloc (error_callback , scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_gej ));
668+ state .zr = (secp256k1_fe * )secp256k1_scratch_alloc (error_callback , scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_fe ));
669669#ifdef USE_ENDOMORPHISM
670- state .pre_a = (secp256k1_ge * )secp256k1_scratch_alloc (scratch , n_points * 2 * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_ge ));
670+ state .pre_a = (secp256k1_ge * )secp256k1_scratch_alloc (error_callback , scratch , n_points * 2 * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_ge ));
671671 state .pre_a_lam = state .pre_a + n_points * ECMULT_TABLE_SIZE (WINDOW_A );
672672#else
673- state .pre_a = (secp256k1_ge * )secp256k1_scratch_alloc (scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_ge ));
673+ state .pre_a = (secp256k1_ge * )secp256k1_scratch_alloc (error_callback , scratch , n_points * ECMULT_TABLE_SIZE (WINDOW_A ) * sizeof (secp256k1_ge ));
674674#endif
675- state .ps = (struct secp256k1_strauss_point_state * )secp256k1_scratch_alloc (scratch , n_points * sizeof (struct secp256k1_strauss_point_state ));
675+ state .ps = (struct secp256k1_strauss_point_state * )secp256k1_scratch_alloc (error_callback , scratch , n_points * sizeof (struct secp256k1_strauss_point_state ));
676676
677677 for (i = 0 ; i < n_points ; i ++ ) {
678678 secp256k1_ge point ;
679679 if (!cb (& scalars [i ], & point , i + cb_offset , cbdata )) {
680- secp256k1_scratch_deallocate_frame (scratch );
680+ secp256k1_scratch_deallocate_frame (error_callback , scratch );
681681 return 0 ;
682682 }
683683 secp256k1_gej_set_ge (& points [i ], & point );
684684 }
685685 secp256k1_ecmult_strauss_wnaf (ctx , & state , r , n_points , points , scalars , inp_g_sc );
686- secp256k1_scratch_deallocate_frame (scratch );
686+ secp256k1_scratch_deallocate_frame (error_callback , scratch );
687687 return 1 ;
688688}
689689
690690/* Wrapper for secp256k1_ecmult_multi_func interface */
691- static int secp256k1_ecmult_strauss_batch_single (const secp256k1_ecmult_context * actx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
692- return secp256k1_ecmult_strauss_batch (actx , scratch , r , inp_g_sc , cb , cbdata , n , 0 );
691+ static int secp256k1_ecmult_strauss_batch_single (const secp256k1_callback * error_callback , const secp256k1_ecmult_context * actx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
692+ return secp256k1_ecmult_strauss_batch (error_callback , actx , scratch , r , inp_g_sc , cb , cbdata , n , 0 );
693693}
694694
695- static size_t secp256k1_strauss_max_points (secp256k1_scratch * scratch ) {
696- return secp256k1_scratch_max_allocation (scratch , STRAUSS_SCRATCH_OBJECTS ) / secp256k1_strauss_scratch_size (1 );
695+ static size_t secp256k1_strauss_max_points (const secp256k1_callback * error_callback , secp256k1_scratch * scratch ) {
696+ return secp256k1_scratch_max_allocation (error_callback , scratch , STRAUSS_SCRATCH_OBJECTS ) / secp256k1_strauss_scratch_size (1 );
697697}
698698
699699/** Convert a number to WNAF notation.
@@ -985,7 +985,7 @@ static size_t secp256k1_pippenger_scratch_size(size_t n_points, int bucket_windo
985985 return (sizeof (secp256k1_gej ) << bucket_window ) + sizeof (struct secp256k1_pippenger_state ) + entries * entry_size ;
986986}
987987
988- static int secp256k1_ecmult_pippenger_batch (const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n_points , size_t cb_offset ) {
988+ static int secp256k1_ecmult_pippenger_batch (const secp256k1_callback * error_callback , const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n_points , size_t cb_offset ) {
989989 /* Use 2(n+1) with the endomorphism, n+1 without, when calculating batch
990990 * sizes. The reason for +1 is that we add the G scalar to the list of
991991 * other scalars. */
@@ -1010,15 +1010,15 @@ static int secp256k1_ecmult_pippenger_batch(const secp256k1_ecmult_context *ctx,
10101010 }
10111011
10121012 bucket_window = secp256k1_pippenger_bucket_window (n_points );
1013- if (!secp256k1_scratch_allocate_frame (scratch , secp256k1_pippenger_scratch_size (n_points , bucket_window ), PIPPENGER_SCRATCH_OBJECTS )) {
1013+ if (!secp256k1_scratch_allocate_frame (error_callback , scratch , secp256k1_pippenger_scratch_size (n_points , bucket_window ), PIPPENGER_SCRATCH_OBJECTS )) {
10141014 return 0 ;
10151015 }
1016- points = (secp256k1_ge * ) secp256k1_scratch_alloc (scratch , entries * sizeof (* points ));
1017- scalars = (secp256k1_scalar * ) secp256k1_scratch_alloc (scratch , entries * sizeof (* scalars ));
1018- state_space = (struct secp256k1_pippenger_state * ) secp256k1_scratch_alloc (scratch , sizeof (* state_space ));
1019- state_space -> ps = (struct secp256k1_pippenger_point_state * ) secp256k1_scratch_alloc (scratch , entries * sizeof (* state_space -> ps ));
1020- state_space -> wnaf_na = (int * ) secp256k1_scratch_alloc (scratch , entries * (WNAF_SIZE (bucket_window + 1 )) * sizeof (int ));
1021- buckets = (secp256k1_gej * ) secp256k1_scratch_alloc (scratch , sizeof (* buckets ) << bucket_window );
1016+ points = (secp256k1_ge * ) secp256k1_scratch_alloc (error_callback , scratch , entries * sizeof (* points ));
1017+ scalars = (secp256k1_scalar * ) secp256k1_scratch_alloc (error_callback , scratch , entries * sizeof (* scalars ));
1018+ state_space = (struct secp256k1_pippenger_state * ) secp256k1_scratch_alloc (error_callback , scratch , sizeof (* state_space ));
1019+ state_space -> ps = (struct secp256k1_pippenger_point_state * ) secp256k1_scratch_alloc (error_callback , scratch , entries * sizeof (* state_space -> ps ));
1020+ state_space -> wnaf_na = (int * ) secp256k1_scratch_alloc (error_callback , scratch , entries * (WNAF_SIZE (bucket_window + 1 )) * sizeof (int ));
1021+ buckets = (secp256k1_gej * ) secp256k1_scratch_alloc (error_callback , scratch , ( 1 << bucket_window ) * sizeof (* buckets ));
10221022
10231023 if (inp_g_sc != NULL ) {
10241024 scalars [0 ] = * inp_g_sc ;
@@ -1032,7 +1032,7 @@ static int secp256k1_ecmult_pippenger_batch(const secp256k1_ecmult_context *ctx,
10321032
10331033 while (point_idx < n_points ) {
10341034 if (!cb (& scalars [idx ], & points [idx ], point_idx + cb_offset , cbdata )) {
1035- secp256k1_scratch_deallocate_frame (scratch );
1035+ secp256k1_scratch_deallocate_frame (error_callback , scratch );
10361036 return 0 ;
10371037 }
10381038 idx ++ ;
@@ -1056,22 +1056,22 @@ static int secp256k1_ecmult_pippenger_batch(const secp256k1_ecmult_context *ctx,
10561056 for (i = 0 ; i < 1 <<bucket_window ; i ++ ) {
10571057 secp256k1_gej_clear (& buckets [i ]);
10581058 }
1059- secp256k1_scratch_deallocate_frame (scratch );
1059+ secp256k1_scratch_deallocate_frame (error_callback , scratch );
10601060 return 1 ;
10611061}
10621062
10631063/* Wrapper for secp256k1_ecmult_multi_func interface */
1064- static int secp256k1_ecmult_pippenger_batch_single (const secp256k1_ecmult_context * actx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
1065- return secp256k1_ecmult_pippenger_batch (actx , scratch , r , inp_g_sc , cb , cbdata , n , 0 );
1064+ static int secp256k1_ecmult_pippenger_batch_single (const secp256k1_callback * error_callback , const secp256k1_ecmult_context * actx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
1065+ return secp256k1_ecmult_pippenger_batch (error_callback , actx , scratch , r , inp_g_sc , cb , cbdata , n , 0 );
10661066}
10671067
10681068/**
10691069 * Returns the maximum number of points in addition to G that can be used with
10701070 * a given scratch space. The function ensures that fewer points may also be
10711071 * used.
10721072 */
1073- static size_t secp256k1_pippenger_max_points (secp256k1_scratch * scratch ) {
1074- size_t max_alloc = secp256k1_scratch_max_allocation (scratch , PIPPENGER_SCRATCH_OBJECTS );
1073+ static size_t secp256k1_pippenger_max_points (const secp256k1_callback * error_callback , secp256k1_scratch * scratch ) {
1074+ size_t max_alloc = secp256k1_scratch_max_allocation (error_callback , scratch , PIPPENGER_SCRATCH_OBJECTS );
10751075 int bucket_window ;
10761076 size_t res = 0 ;
10771077
@@ -1153,11 +1153,11 @@ static int secp256k1_ecmult_multi_batch_size_helper(size_t *n_batches, size_t *n
11531153 return 1 ;
11541154}
11551155
1156- typedef int (* secp256k1_ecmult_multi_func )(const secp256k1_ecmult_context * , secp256k1_scratch * , secp256k1_gej * , const secp256k1_scalar * , secp256k1_ecmult_multi_callback cb , void * , size_t );
1157- static int secp256k1_ecmult_multi_var (const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
1156+ typedef int (* secp256k1_ecmult_multi_func )(const secp256k1_callback * error_callback , const secp256k1_ecmult_context * , secp256k1_scratch * , secp256k1_gej * , const secp256k1_scalar * , secp256k1_ecmult_multi_callback cb , void * , size_t );
1157+ static int secp256k1_ecmult_multi_var (const secp256k1_callback * error_callback , const secp256k1_ecmult_context * ctx , secp256k1_scratch * scratch , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n ) {
11581158 size_t i ;
11591159
1160- int (* f )(const secp256k1_ecmult_context * , secp256k1_scratch * , secp256k1_gej * , const secp256k1_scalar * , secp256k1_ecmult_multi_callback cb , void * , size_t , size_t );
1160+ int (* f )(const secp256k1_callback * error_callback , const secp256k1_ecmult_context * , secp256k1_scratch * , secp256k1_gej * , const secp256k1_scalar * , secp256k1_ecmult_multi_callback cb , void * , size_t , size_t );
11611161 size_t n_batches ;
11621162 size_t n_batch_points ;
11631163
@@ -1178,13 +1178,13 @@ static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp2
11781178 * a threshold use Pippenger's algorithm. Otherwise use Strauss' algorithm.
11791179 * As a first step check if there's enough space for Pippenger's algo (which requires less space
11801180 * than Strauss' algo) and if not, use the simple algorithm. */
1181- if (!secp256k1_ecmult_multi_batch_size_helper (& n_batches , & n_batch_points , secp256k1_pippenger_max_points (scratch ), n )) {
1181+ if (!secp256k1_ecmult_multi_batch_size_helper (& n_batches , & n_batch_points , secp256k1_pippenger_max_points (error_callback , scratch ), n )) {
11821182 return secp256k1_ecmult_multi_simple_var (ctx , r , inp_g_sc , cb , cbdata , n );
11831183 }
11841184 if (n_batch_points >= ECMULT_PIPPENGER_THRESHOLD ) {
11851185 f = secp256k1_ecmult_pippenger_batch ;
11861186 } else {
1187- if (!secp256k1_ecmult_multi_batch_size_helper (& n_batches , & n_batch_points , secp256k1_strauss_max_points (scratch ), n )) {
1187+ if (!secp256k1_ecmult_multi_batch_size_helper (& n_batches , & n_batch_points , secp256k1_strauss_max_points (error_callback , scratch ), n )) {
11881188 return secp256k1_ecmult_multi_simple_var (ctx , r , inp_g_sc , cb , cbdata , n );
11891189 }
11901190 f = secp256k1_ecmult_strauss_batch ;
@@ -1193,7 +1193,7 @@ static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp2
11931193 size_t nbp = n < n_batch_points ? n : n_batch_points ;
11941194 size_t offset = n_batch_points * i ;
11951195 secp256k1_gej tmp ;
1196- if (!f (ctx , scratch , & tmp , i == 0 ? inp_g_sc : NULL , cb , cbdata , nbp , offset )) {
1196+ if (!f (error_callback , ctx , scratch , & tmp , i == 0 ? inp_g_sc : NULL , cb , cbdata , nbp , offset )) {
11971197 return 0 ;
11981198 }
11991199 secp256k1_gej_add_var (r , r , & tmp , NULL );
0 commit comments