@@ -56,6 +56,14 @@ struct secp256k1_context_struct {
56
56
secp256k1_callback error_callback ;
57
57
};
58
58
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
+
59
67
secp256k1_context * secp256k1_context_create (unsigned int flags ) {
60
68
secp256k1_context * ret = (secp256k1_context * )checked_malloc (& default_error_callback , sizeof (secp256k1_context ));
61
69
ret -> illegal_callback = default_illegal_callback ;
@@ -91,6 +99,7 @@ secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
91
99
}
92
100
93
101
void secp256k1_context_destroy (secp256k1_context * ctx ) {
102
+ CHECK (ctx != secp256k1_context_no_precomp );
94
103
if (ctx != NULL ) {
95
104
secp256k1_ecmult_context_clear (& ctx -> ecmult_ctx );
96
105
secp256k1_ecmult_gen_context_clear (& ctx -> ecmult_gen_ctx );
@@ -100,6 +109,7 @@ void secp256k1_context_destroy(secp256k1_context* ctx) {
100
109
}
101
110
102
111
void secp256k1_context_set_illegal_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
112
+ CHECK (ctx != secp256k1_context_no_precomp );
103
113
if (fun == NULL ) {
104
114
fun = default_illegal_callback_fn ;
105
115
}
@@ -108,6 +118,7 @@ void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(
108
118
}
109
119
110
120
void secp256k1_context_set_error_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
121
+ CHECK (ctx != secp256k1_context_no_precomp );
111
122
if (fun == NULL ) {
112
123
fun = default_error_callback_fn ;
113
124
}
@@ -559,6 +570,7 @@ int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey
559
570
560
571
int secp256k1_context_randomize (secp256k1_context * ctx , const unsigned char * seed32 ) {
561
572
VERIFY_CHECK (ctx != NULL );
573
+ CHECK (ctx != secp256k1_context_no_precomp );
562
574
ARG_CHECK (secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx ));
563
575
secp256k1_ecmult_gen_blind (& ctx -> ecmult_gen_ctx , seed32 );
564
576
return 1 ;
0 commit comments