Skip to content

Commit ed7c084

Browse files
committed
add static context object which has no capabilities
1 parent 1e6f1f5 commit ed7c084

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

include/secp256k1.h

+7
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ typedef int (*secp256k1_nonce_function)(
179179
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
180180
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
181181

182+
/** A simple secp256k1 context object with no precomputed tables. These are useful for
183+
* type serialization/parsing functions which require a context object to maintain
184+
* API consistency, but currently do not require expensive precomputations or dynamic
185+
* allocations.
186+
*/
187+
SECP256K1_API extern const secp256k1_context *secp256k1_context_no_precomp;
188+
182189
/** Create a secp256k1 context object.
183190
*
184191
* Returns: a newly created context object.

src/secp256k1.c

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ struct secp256k1_context_struct {
5656
secp256k1_callback error_callback;
5757
};
5858

59+
static const secp256k1_context secp256k1_context_no_precomp_ = {
60+
{ 0 },
61+
{ 0 },
62+
{ default_illegal_callback_fn, 0 },
63+
{ default_error_callback_fn, 0 }
64+
};
65+
const secp256k1_context *secp256k1_context_no_precomp = &secp256k1_context_no_precomp_;
66+
5967
secp256k1_context* secp256k1_context_create(unsigned int flags) {
6068
secp256k1_context* ret = (secp256k1_context*)checked_malloc(&default_error_callback, sizeof(secp256k1_context));
6169
ret->illegal_callback = default_illegal_callback;

src/tests.c

+1
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,7 @@ void run_ec_pubkey_parse_test(void) {
35993599
ecount = 0;
36003600
VG_UNDEF(&pubkey, sizeof(pubkey));
36013601
CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 65) == 1);
3602+
CHECK(secp256k1_ec_pubkey_parse(secp256k1_context_no_precomp, &pubkey, pubkeyc, 65) == 1);
36023603
VG_CHECK(&pubkey, sizeof(pubkey));
36033604
CHECK(ecount == 0);
36043605
VG_UNDEF(&ge, sizeof(ge));

0 commit comments

Comments
 (0)