Skip to content

Commit

Permalink
batch_interface: add batch_context_verify function
Browse files Browse the repository at this point in the history
added batch_context_verify to the schnorrsig module
  • Loading branch information
siv2r committed May 21, 2022
1 parent f4db5d1 commit ecc8446
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/secp256k1_schnorrsig.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(
const secp256k1_xonly_pubkey *pubkey
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5);

/** Verify the set of schnorr signatures or tweaked pubkeys present in the secp256k1_batch_context.
*
* Returns: 1: correct schnorrsigs/tweaks
* 0: incorrect schnorrsigs/tweaks
*
* In particular, returns 1 if the batch context is empty or NULL.
*
* Args: ctx: a secp256k1 context object (can be initialized for none).
* batch_ctx: a secp256k1 batch context object that contains a
* set of schnorrsigs/tweaks.
*/
SECP256K1_API int secp256k1_batch_context_verify(
const secp256k1_context *ctx,
secp256k1_batch_context *batch_ctx
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/schnorrsig/Makefile.am.include
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ noinst_HEADERS += src/modules/schnorrsig/main_impl.h
noinst_HEADERS += src/modules/schnorrsig/tests_impl.h
noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h
noinst_HEADERS += src/modules/schnorrsig/bench_impl.h
noinst_HEADERS += src/modules/schnorrsig/batch_add_impl.h
28 changes: 28 additions & 0 deletions src/modules/schnorrsig/batch_add_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef SECP256K1_BATCH_ADD_IMPL_H
#define SECP256K1_BATCH_ADD_IMPL_H

#include "../../batch_impl.h"

/** Batch verifies the schnorrsig/tweaks present in the batch context object.
* If the batch context is empty,
*
* calls secp256k1_ecmult_strauss_batch on a scratch space filled with 2n points
* and 2n scalars, where n = no of terms (user input in secp256k1_batch_context_create)
*
* Fails if:
* 0 != -(s1 + a2*s2 + ... + au*su)G
* + R1 + a2*R2 + ... + au*Ru + e1*P1 + (a2*e2)P2 + ... + (au*eu)Pu.
*/
int secp256k1_batch_verify(const secp256k1_callback* error_callback, secp256k1_batch_context* batch_ctx) {
secp256k1_gej resj;

if(batch_ctx != NULL && batch_ctx->scalars != NULL && batch_ctx->points != NULL) {
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);

return batch_ctx->result;
}

return 0;
}

#endif
6 changes: 6 additions & 0 deletions src/modules/schnorrsig/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../../../include/secp256k1.h"
#include "../../../include/secp256k1_schnorrsig.h"
#include "../../hash.h"
#include "batch_add_impl.h"



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

int secp256k1_batch_context_verify(const secp256k1_context *ctx, secp256k1_batch_context *batch_ctx) {
VERIFY_CHECK(ctx != NULL);
return secp256k1_batch_verify(&ctx->error_callback, batch_ctx);
}

#endif

0 comments on commit ecc8446

Please sign in to comment.