Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751* Args: ctx: pointer to a context object752* In/Out: seckey: pointer to the 32-byte secret key to be negated. If the753* secret key is invalid according to754* secp256k1_ec_seckey_verify, this function returns 0 and755* seckey will be set to some unspecified value.756*/757SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(758const secp256k1_context *ctx,759unsigned char *seckey760) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);762/** Negates a public key in place.763*764* Returns: 1 always765* Args: ctx: pointer to a context object766* In/Out: pubkey: pointer to the public key to be negated.767*/768SECP256K1_API int secp256k1_ec_pubkey_negate(769const secp256k1_context *ctx,770secp256k1_pubkey *pubkey771) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);773/** Tweak a secret key by adding tweak to it.774*775* Returns: 0 if the arguments are invalid or the resulting secret key would be776* invalid (only when the tweak is the negation of the secret key). 1777* otherwise.778* Args: ctx: pointer to a context object.779* In/Out: seckey: pointer to a 32-byte secret key. If the secret key is780* invalid according to secp256k1_ec_seckey_verify, this781* function returns 0. seckey will be set to some unspecified782* value if this function returns 0.783* In: tweak32: pointer to a 32-byte tweak, which must be valid according to784* secp256k1_ec_seckey_verify or 32 zero bytes. For uniformly785* random 32-byte tweaks, the chance of being invalid is786* negligible (around 1 in 2^128).787*/788SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_add(789const secp256k1_context *ctx,790unsigned char *seckey,791const unsigned char *tweak32792) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);794/** Tweak a public key by adding tweak times the generator to it.795*796* Returns: 0 if the arguments are invalid or the resulting public key would be797* invalid (only when the tweak is the negation of the corresponding798* secret key). 1 otherwise.799* Args: ctx: pointer to a context object.800* In/Out: pubkey: pointer to a public key object. pubkey will be set to an801* invalid value if this function returns 0.802* In: tweak32: pointer to a 32-byte tweak, which must be valid according to803* secp256k1_ec_seckey_verify or 32 zero bytes. For uniformly804* random 32-byte tweaks, the chance of being invalid is805* negligible (around 1 in 2^128).806*/807SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(808const secp256k1_context *ctx,809secp256k1_pubkey *pubkey,810const unsigned char *tweak32811) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);813/** Tweak a secret key by multiplying it by a tweak.814*815* Returns: 0 if the arguments are invalid. 1 otherwise.816* Args: ctx: pointer to a context object.817* In/Out: seckey: pointer to a 32-byte secret key. If the secret key is818* invalid according to secp256k1_ec_seckey_verify, this819* function returns 0. seckey will be set to some unspecified820* value if this function returns 0.821* In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to822* secp256k1_ec_seckey_verify, this function returns 0. For823* uniformly random 32-byte arrays the chance of being invalid824* is negligible (around 1 in 2^128).825*/826SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_mul(827const secp256k1_context *ctx,828unsigned char *seckey,829const unsigned char *tweak32830) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);832/** Tweak a public key by multiplying it by a tweak value.833*834* Returns: 0 if the arguments are invalid. 1 otherwise.835* Args: ctx: pointer to a context object.836* In/Out: pubkey: pointer to a public key object. pubkey will be set to an837* invalid value if this function returns 0.838* In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according to839* secp256k1_ec_seckey_verify, this function returns 0. For840* uniformly random 32-byte arrays the chance of being invalid841* is negligible (around 1 in 2^128).842*/843SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(844const secp256k1_context *ctx,845secp256k1_pubkey *pubkey,846const unsigned char *tweak32847) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);849/** Randomizes the context to provide enhanced protection against side-channel leakage.850*851* Returns: 1: randomization successful852* 0: error853* Args: ctx: pointer to a context object (not secp256k1_context_static).854* In: seed32: pointer to a 32-byte random seed (NULL resets to initial state).855*856* While secp256k1 code is written and tested to be constant-time no matter what857* secret values are, it is possible that a compiler may output code which is not,858* and also that the CPU may not emit the same radio frequencies or draw the same859* amount of power for all values. Randomization of the context shields against860* side-channel observations which aim to exploit secret-dependent behaviour in861* certain computations which involve secret keys.862*863* It is highly recommended to call this function on contexts returned from864* secp256k1_context_create or secp256k1_context_clone (or from the corresponding865* functions in secp256k1_preallocated.h) before using these contexts to call API866* functions that perform computations involving secret keys, e.g., signing and867* public key generation. It is possible to call this function more than once on868* the same context, and doing so before every few computations involving secret869* keys is recommended as a defense-in-depth measure. Randomization of the static870* context secp256k1_context_static is not supported.871*872* Currently, the random seed is mainly used for blinding multiplications of a873* secret scalar with the elliptic curve base point. Multiplications of this874* kind are performed by exactly those API functions which are documented to875* require a context that is not secp256k1_context_static. As a rule of thumb,876* these are all functions which take a secret key (or a keypair) as an input.877* A notable exception to that rule is the ECDH module, which relies on a different878* kind of elliptic curve point multiplication and thus does not benefit from879* enhanced protection against side-channel leakage currently.880*/881SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(882secp256k1_context *ctx,883const unsigned char *seed32884) SECP256K1_ARG_NONNULL(1);886/** Add a number of public keys together.887*888* Returns: 1: the sum of the public keys is valid.889* 0: the sum of the public keys is not valid.890* Args: ctx: pointer to a context object.891* Out: out: pointer to a public key object for placing the resulting public key.892* In: ins: pointer to array of pointers to public keys.893* n: the number of public keys to add together (must be at least 1).894*/895SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(896const secp256k1_context *ctx,897secp256k1_pubkey *out,898const secp256k1_pubkey * const *ins,899size_t n900) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);902/** Compute a tagged hash as defined in BIP-340.903*904* This is useful for creating a message hash and achieving domain separation905* through an application-specific tag. This function returns906* SHA256(SHA256(tag)||SHA256(tag)||msg). Therefore, tagged hash907* implementations optimized for a specific tag can precompute the SHA256 state908* after hashing the tag hashes.909*910* Returns: 1 always.911* Args: ctx: pointer to a context object912* Out: hash32: pointer to a 32-byte array to store the resulting hash913* In: tag: pointer to an array containing the tag914* taglen: length of the tag array915* msg: pointer to an array containing the message916* msglen: length of the message array917*/918SECP256K1_API int secp256k1_tagged_sha256(919const secp256k1_context *ctx,920unsigned char *hash32,921const unsigned char *tag,922size_t taglen,923const unsigned char *msg,924size_t msglen925) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5);927#ifdef __cplusplus928}929#endif931#endif /* SECP256K1_H */
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.