12
12
#include < secp256k1_batch.h>
13
13
#include < secp256k1_schnorrsig_batch.h>
14
14
15
+ class Batch {
16
+ private:
17
+ secp256k1_batch* m_batch;
18
+ public:
19
+ Batch (secp256k1_batch* batch) : m_batch(batch) {}
20
+ secp256k1_batch* get () const { return m_batch; }
21
+ };
22
+
15
23
BatchSchnorrVerifier::BatchSchnorrVerifier () {
16
24
unsigned char rnd[16 ];
17
25
GetRandBytes (rnd);
@@ -20,26 +28,29 @@ BatchSchnorrVerifier::BatchSchnorrVerifier() {
20
28
// still efficient.
21
29
const size_t max_batch_size{106 };
22
30
secp256k1_batch* batch{secp256k1_batch_create (secp256k1_context_static, max_batch_size, rnd)};
23
- m_batch = batch;
31
+ m_batch = new Batch ( batch) ;
24
32
}
25
33
26
34
BatchSchnorrVerifier::~BatchSchnorrVerifier () {
27
- (void )secp256k1_batch_destroy (secp256k1_context_static, m_batch);
35
+ if (m_batch) {
36
+ (void )secp256k1_batch_destroy (secp256k1_context_static, m_batch->get ());
37
+ delete m_batch;
38
+ }
28
39
}
29
40
30
41
bool BatchSchnorrVerifier::Add (const Span<const unsigned char > sig, const XOnlyPubKey& pubkey, const uint256& sighash) {
31
42
LOCK (m_batch_mutex);
32
- if (secp256k1_batch_usable (secp256k1_context_static, m_batch) == 0 ) {
43
+ if (secp256k1_batch_usable (secp256k1_context_static, m_batch-> get () ) == 0 ) {
33
44
LogPrintf (" ERROR: BatchSchnorrVerifier m_batch unusable\n " );
34
45
return false ;
35
46
}
36
47
37
48
secp256k1_xonly_pubkey pubkey_parsed;
38
49
if (!secp256k1_xonly_pubkey_parse (secp256k1_context_static, &pubkey_parsed, pubkey.data ())) return false ;
39
- return secp256k1_batch_add_schnorrsig (secp256k1_context_static, m_batch, sig.data (), sighash.begin (), 32 , &pubkey_parsed);
50
+ return secp256k1_batch_add_schnorrsig (secp256k1_context_static, m_batch-> get () , sig.data (), sighash.begin (), 32 , &pubkey_parsed);
40
51
}
41
52
42
53
bool BatchSchnorrVerifier::Verify () {
43
54
LOCK (m_batch_mutex);
44
- return secp256k1_batch_verify (secp256k1_context_static, m_batch);
55
+ return secp256k1_batch_verify (secp256k1_context_static, m_batch-> get () );
45
56
}
0 commit comments