@@ -1084,6 +1084,33 @@ static size_t secp256k1_pippenger_max_points(secp256k1_scratch *scratch) {
1084
1084
return res ;
1085
1085
}
1086
1086
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
+
1087
1114
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 );
1088
1115
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 ) {
1089
1116
size_t i ;
@@ -1102,6 +1129,9 @@ static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp2
1102
1129
secp256k1_ecmult (ctx , r , r , & szero , inp_g_sc );
1103
1130
return 1 ;
1104
1131
}
1132
+ if (scratch == NULL ) {
1133
+ return secp256k1_ecmult_multi_simple_var (ctx , r , inp_g_sc , cb , cbdata , n );
1134
+ }
1105
1135
1106
1136
max_points = secp256k1_pippenger_max_points (scratch );
1107
1137
if (max_points == 0 ) {
0 commit comments