@@ -75,6 +75,15 @@ static const secp256k1_context secp256k1_context_static_ = {
75
75
const secp256k1_context * secp256k1_context_static = & secp256k1_context_static_ ;
76
76
const secp256k1_context * secp256k1_context_no_precomp = & secp256k1_context_static_ ;
77
77
78
+ /* Helper function that determines if a context is proper, i.e., is not the static context or a copy thereof.
79
+ *
80
+ * This is intended for "context" functions such as secp256k1_context_clone. Function which need specific
81
+ * features of a context should still check for these features directly. For example, a function that needs
82
+ * ecmult_gen should directly check for the existence of the ecmult_gen context. */
83
+ static int secp256k1_context_is_proper (const secp256k1_context * ctx ) {
84
+ return secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx );
85
+ }
86
+
78
87
void secp256k1_selftest (void ) {
79
88
if (!secp256k1_selftest_passes ()) {
80
89
secp256k1_callback_call (& default_error_callback , "self test failed" );
@@ -171,6 +180,9 @@ void secp256k1_context_destroy(secp256k1_context* ctx) {
171
180
}
172
181
173
182
void secp256k1_context_set_illegal_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
183
+ /* We compare pointers instead of checking secp256k1_context_is_proper() here
184
+ because setting callbacks is allowed on *copies* of the static context:
185
+ it's harmless and makes testing easier. */
174
186
ARG_CHECK_NO_RETURN (ctx != secp256k1_context_static );
175
187
if (fun == NULL ) {
176
188
fun = secp256k1_default_illegal_callback_fn ;
@@ -180,6 +192,9 @@ void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(
180
192
}
181
193
182
194
void secp256k1_context_set_error_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
195
+ /* We compare pointers instead of checking secp256k1_context_is_proper() here
196
+ because setting callbacks is allowed on *copies* of the static context:
197
+ it's harmless and makes testing easier. */
183
198
ARG_CHECK_NO_RETURN (ctx != secp256k1_context_static );
184
199
if (fun == NULL ) {
185
200
fun = secp256k1_default_error_callback_fn ;
0 commit comments