Skip to content

Commit ecc8446

Browse files
committed
batch_interface: add batch_context_verify function
added batch_context_verify to the schnorrsig module
1 parent f4db5d1 commit ecc8446

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

include/secp256k1_schnorrsig.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(
175175
const secp256k1_xonly_pubkey *pubkey
176176
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5);
177177

178+
/** Verify the set of schnorr signatures or tweaked pubkeys present in the secp256k1_batch_context.
179+
*
180+
* Returns: 1: correct schnorrsigs/tweaks
181+
* 0: incorrect schnorrsigs/tweaks
182+
*
183+
* In particular, returns 1 if the batch context is empty or NULL.
184+
*
185+
* Args: ctx: a secp256k1 context object (can be initialized for none).
186+
* batch_ctx: a secp256k1 batch context object that contains a
187+
* set of schnorrsigs/tweaks.
188+
*/
189+
SECP256K1_API int secp256k1_batch_context_verify(
190+
const secp256k1_context *ctx,
191+
secp256k1_batch_context *batch_ctx
192+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
178193

179194
#ifdef __cplusplus
180195
}

src/modules/schnorrsig/Makefile.am.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ noinst_HEADERS += src/modules/schnorrsig/main_impl.h
33
noinst_HEADERS += src/modules/schnorrsig/tests_impl.h
44
noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h
55
noinst_HEADERS += src/modules/schnorrsig/bench_impl.h
6+
noinst_HEADERS += src/modules/schnorrsig/batch_add_impl.h
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef SECP256K1_BATCH_ADD_IMPL_H
2+
#define SECP256K1_BATCH_ADD_IMPL_H
3+
4+
#include "../../batch_impl.h"
5+
6+
/** Batch verifies the schnorrsig/tweaks present in the batch context object.
7+
* If the batch context is empty,
8+
*
9+
* calls secp256k1_ecmult_strauss_batch on a scratch space filled with 2n points
10+
* and 2n scalars, where n = no of terms (user input in secp256k1_batch_context_create)
11+
*
12+
* Fails if:
13+
* 0 != -(s1 + a2*s2 + ... + au*su)G
14+
* + R1 + a2*R2 + ... + au*Ru + e1*P1 + (a2*e2)P2 + ... + (au*eu)Pu.
15+
*/
16+
int secp256k1_batch_verify(const secp256k1_callback* error_callback, secp256k1_batch_context* batch_ctx) {
17+
secp256k1_gej resj;
18+
19+
if(batch_ctx != NULL && batch_ctx->scalars != NULL && batch_ctx->points != NULL) {
20+
batch_ctx->result = secp256k1_ecmult_strauss_batch(error_callback, batch_ctx->data, &resj, batch_ctx->scalars, batch_ctx->points, &batch_ctx->sc_g, NULL, NULL, batch_ctx->len, 0) && secp256k1_gej_is_infinity(&resj);
21+
22+
return batch_ctx->result;
23+
}
24+
25+
return 0;
26+
}
27+
28+
#endif

src/modules/schnorrsig/main_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../../../include/secp256k1.h"
1111
#include "../../../include/secp256k1_schnorrsig.h"
1212
#include "../../hash.h"
13+
#include "batch_add_impl.h"
1314

1415

1516

@@ -266,4 +267,9 @@ int secp256k1_schnorrsig_verify(const secp256k1_context* ctx, const unsigned cha
266267
secp256k1_fe_equal_var(&rx, &r.x);
267268
}
268269

270+
int secp256k1_batch_context_verify(const secp256k1_context *ctx, secp256k1_batch_context *batch_ctx) {
271+
VERIFY_CHECK(ctx != NULL);
272+
return secp256k1_batch_verify(&ctx->error_callback, batch_ctx);
273+
}
274+
269275
#endif

0 commit comments

Comments
 (0)