@@ -1084,6 +1084,33 @@ static size_t secp256k1_pippenger_max_points(secp256k1_scratch *scratch) {
10841084 return res ;
10851085}
10861086
1087+ /* Computes ecmult_multi by simply multiplying and adding each point. Does not
1088+ * require a scratch space */
1089+ static int secp256k1_ecmult_multi_simple_var (const secp256k1_ecmult_context * ctx , secp256k1_gej * r , const secp256k1_scalar * inp_g_sc , secp256k1_ecmult_multi_callback cb , void * cbdata , size_t n_points ) {
1090+ size_t point_idx ;
1091+ secp256k1_scalar szero ;
1092+ secp256k1_gej tmpj ;
1093+
1094+ secp256k1_scalar_set_int (& szero , 0 );
1095+ secp256k1_gej_set_infinity (r );
1096+ secp256k1_gej_set_infinity (& tmpj );
1097+ /* r = inp_g_sc*G */
1098+ secp256k1_ecmult (ctx , r , & tmpj , & szero , inp_g_sc );
1099+ for (point_idx = 0 ; point_idx < n_points ; point_idx ++ ) {
1100+ secp256k1_ge point ;
1101+ secp256k1_gej pointj ;
1102+ secp256k1_scalar scalar ;
1103+ if (!cb (& scalar , & point , point_idx , cbdata )) {
1104+ return 0 ;
1105+ }
1106+ /* r += scalar*point */
1107+ secp256k1_gej_set_ge (& pointj , & point );
1108+ secp256k1_ecmult (ctx , & tmpj , & pointj , & scalar , NULL );
1109+ secp256k1_gej_add_var (r , r , & tmpj , NULL );
1110+ }
1111+ return 1 ;
1112+ }
1113+
10871114typedef int (* secp256k1_ecmult_multi_func )(const secp256k1_ecmult_context * , secp256k1_scratch * , secp256k1_gej * , const secp256k1_scalar * , secp256k1_ecmult_multi_callback cb , void * , size_t );
10881115static 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 ) {
10891116 size_t i ;
@@ -1102,6 +1129,9 @@ static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp2
11021129 secp256k1_ecmult (ctx , r , r , & szero , inp_g_sc );
11031130 return 1 ;
11041131 }
1132+ if (scratch == NULL ) {
1133+ return secp256k1_ecmult_multi_simple_var (ctx , r , inp_g_sc , cb , cbdata , n );
1134+ }
11051135
11061136 max_points = secp256k1_pippenger_max_points (scratch );
11071137 if (max_points == 0 ) {
0 commit comments