Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
key.h File Reference
#include <pubkey.h>
#include <script/keyorigin.h>
#include <serialize.h>
#include <support/allocators/secure.h>
#include <uint256.h>
#include <optional>
#include <stdexcept>
#include <utility>
#include <vector>
Include dependency graph for key.h:

Go to the source code of this file.

Classes

class  CKey
 An encapsulated private key. More...
struct  CExtKey
class  KeyPair
 KeyPair. More...
class  ECC_Context
 RAII class initializing and deinitializing global state for elliptic curve support. More...

Typedefs

typedef struct secp256k1_context_struct secp256k1_context
 Unless explicitly stated all pointer arguments must not be NULL.
typedef std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
 CPrivKey is a serialized private key, with all parameters included (SIZE bytes).
using ECDHSecret = std::array<std::byte, ECDH_SECRET_SIZE>

Functions

CKey GenerateRandomKey (bool compressed=true) noexcept
std::optional< std::pair< CExtKey, KeyOriginInfo > > DeriveExtKey (const CExtKey &ext_key, const std::vector< uint32_t > &path)
bool ECC_InitSanityCheck ()
 Check that required EC support is available at runtime.
secp256k1_context * GetSecp256k1SignContext ()
 Access the secp256k1 context used for signing and MuSig2 nonce generation.

Variables

constexpr size_t ECDH_SECRET_SIZE = CSHA256::OUTPUT_SIZE
 Size of ECDH shared secrets.

Typedef Documentation

◆ CPrivKey

typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey

CPrivKey is a serialized private key, with all parameters included (SIZE bytes).

Definition at line 28 of file key.h.

◆ ECDHSecret

using ECDHSecret = std::array<std::byte, ECDH_SECRET_SIZE>

Definition at line 34 of file key.h.

◆ secp256k1_context

Unless explicitly stated all pointer arguments must not be NULL.

The following rules specify the order of arguments in API calls:

  1. Context pointers go first, followed by output arguments, combined output/input arguments, and finally input-only arguments.
  2. Array lengths always immediately follow the argument whose length they describe, even if this violates rule 1.
  3. Within the OUT/OUTIN/IN groups, pointers to data that is typically generated later go first. This means: signatures, public nonces, secret nonces, messages, public keys, secret keys, tweaks.
  4. Arguments that are not data pointers go last, from more complex to less complex: function pointers, algorithm names, messages, void pointers, counts, flags, booleans.
  5. Opaque data pointers follow the function pointer they are to be passed to. Opaque data structure that holds context information

The primary purpose of context objects is to store randomization data for enhanced protection against side-channel leakage. This protection is only effective if the context is randomized after its creation. See secp256k1_context_create for creation of contexts and secp256k1_context_randomize for randomization.

A secondary purpose of context objects is to store pointers to callback functions that the library will call when certain error states arise. See secp256k1_context_set_error_callback as well as secp256k1_context_set_illegal_callback for details. Future library versions may use context objects for additional purposes.

A constructed context can safely be used from multiple threads simultaneously, but API calls that take a non-const pointer to a context need exclusive access to it. In particular this is the case for secp256k1_context_destroy, secp256k1_context_preallocated_destroy, and secp256k1_context_randomize.

Regarding randomization, either do it once at creation time (in which case you do not need any locking for the other calls), or use a read-write lock.

Definition at line 22 of file key.h.

Function Documentation

◆ DeriveExtKey()

std::optional< std::pair< CExtKey, KeyOriginInfo > > DeriveExtKey ( const CExtKey & ext_key,
const std::vector< uint32_t > & path )

Get extended key and origin info for a given path

Parameters
[in]ext_keyThe extended private key to derive from
[in]pathThe BIP 32 path
Returns
the resulting extended private key and origin info

Definition at line 369 of file key.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ECC_InitSanityCheck()

bool ECC_InitSanityCheck ( )

Check that required EC support is available at runtime.

Definition at line 456 of file key.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateRandomKey()

CKey GenerateRandomKey ( bool compressed = true)
noexcept

Definition at line 354 of file key.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSecp256k1SignContext()

secp256k1_context * GetSecp256k1SignContext ( )

Access the secp256k1 context used for signing and MuSig2 nonce generation.

Definition at line 462 of file key.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ECDH_SECRET_SIZE

size_t ECDH_SECRET_SIZE = CSHA256::OUTPUT_SIZE
inlineconstexpr

Size of ECDH shared secrets.

Definition at line 31 of file key.h.