@@ -214,19 +214,41 @@ typedef int (*secp256k1_nonce_function)(
214214#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
215215#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
216216
217- /** A built-in constant secp256k1 context object with static storage duration.
217+ /** A built-in constant secp256k1 context object with static storage duration, to be
218+ * used in conjunction with secp256k1_selftest.
218219 *
219220 * This context object is *not* "initialized for signing", i.e., it cannot be used
220221 * for certain functions that operate on secret keys, e.g., signing and public key
221222 * generation. See secp256k1_context_create if you need a context object initialized
222223 * for signing.
224+ *
225+ * It is highly recommended to call secp256k1_selftest before using this context.
223226 */
224227SECP256K1_API extern const secp256k1_context * secp256k1_context_static ;
225228
226229/** Deprecated alias for secp256k1_context_no_precomp. */
227230SECP256K1_API extern const secp256k1_context * secp256k1_context_no_precomp
228231SECP256K1_DEPRECATED ("Use secp256k1_context_static instead" );
229232
233+ /** Perform basic self tests (to be used in conjunction with secp256k1_context_static)
234+ *
235+ * This function performs self tests that detect some serious usage errors and
236+ * similar conditions, e.g., when the library is compiled for the wrong endianness.
237+ * This is a last resort measure to be used in production. The performed tests are
238+ * very rudimentary and are not intended as a replacement for running the test
239+ * binaries.
240+ *
241+ * It is highly recommended to call this before using secp256k1_context_static.
242+ * It is not necessary to call this function before using a context created with
243+ * secp256k1_context_create (or secp256k1_context_preallocated_create), which will
244+ * take care of performing the self tests.
245+ *
246+ * If the tests fail, this function will call the default error handler to abort the
247+ * program (see secp256k1_context_set_error_callback).
248+ */
249+ SECP256K1_API void secp256k1_selftest (void );
250+
251+
230252/** Create a secp256k1 context object (in dynamically allocated memory).
231253 *
232254 * This function uses malloc to allocate memory. It is guaranteed that malloc is
0 commit comments