Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

key.cpp File Reference
#include <key.h>
#include <arith_uint256.h>
#include <crypto/common.h>
#include <crypto/hmac_sha512.h>
#include <random.h>
#include <secp256k1.h>
#include <secp256k1_recovery.h>
+ Include dependency graph for key.cpp:

Go to the source code of this file.

Functions

static int ec_privkey_import_der (const secp256k1_context *ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen)
 These functions are taken from the libsecp256k1 distribution and are very ugly. More...
 
static int ec_privkey_export_der (const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed)
 This serializes to a DER encoding of the ECPrivateKey type from section C.4 of SEC 1 http://www.secg.org/sec1-v2.pdf. More...
 
bool ECC_InitSanityCheck ()
 Check that required EC support is available at runtime. More...
 
void ECC_Start ()
 Initialize the elliptic curve support. More...
 
void ECC_Stop ()
 Deinitialize the elliptic curve support. More...
 

Variables

static secp256k1_contextsecp256k1_context_sign = nullptr
 

Function Documentation

◆ ec_privkey_export_der()

static int ec_privkey_export_der ( const secp256k1_context ctx,
unsigned char *  privkey,
size_t *  privkeylen,
const unsigned char *  key32,
int  compressed 
)
static

This serializes to a DER encoding of the ECPrivateKey type from section C.4 of SEC 1 http://www.secg.org/sec1-v2.pdf.

The optional parameters and publicKey fields are included.

privkey must point to an output buffer of length at least CKey::PRIVATE_KEY_SIZE bytes. privkeylen must initially be set to the size of the privkey buffer. Upon return it will be set to the number of bytes used in the buffer. key32 must point to a 32-byte raw private key.

Definition at line 92 of file key.cpp.

References CKey::COMPRESSED_PRIVATE_KEY_SIZE, CPubKey::COMPRESSED_PUBLIC_KEY_SIZE, ctx, memcpy(), CKey::PRIVATE_KEY_SIZE, CPubKey::PUBLIC_KEY_SIZE, SECP256K1_EC_COMPRESSED, secp256k1_ec_pubkey_create(), secp256k1_ec_pubkey_serialize(), and SECP256K1_EC_UNCOMPRESSED.

Referenced by CKey::GetPrivKey(), test_ecdsa_edge_cases(), and test_ecdsa_end_to_end().

◆ ec_privkey_import_der()

static int ec_privkey_import_der ( const secp256k1_context ctx,
unsigned char *  out32,
const unsigned char *  privkey,
size_t  privkeylen 
)
static

These functions are taken from the libsecp256k1 distribution and are very ugly.

This parses a format loosely based on a DER encoding of the ECPrivateKey type from section C.4 of SEC 1 http://www.secg.org/sec1-v2.pdf, with the following caveats:

  • The octet-length of the SEQUENCE must be encoded as 1 or 2 octets. It is not required to be encoded as one octet if it is less than 256, as DER would require.
  • The octet-length of the SEQUENCE must not be greater than the remaining length of the key encoding, but need not match it (i.e. the encoding may contain junk after the encoded SEQUENCE).
  • The privateKey OCTET STRING is zero-filled on the left to 32 octets.
  • Anything after the encoding of the privateKey OCTET STRING is ignored, whether or not it is validly encoded DER.

out32 must point to an output buffer of length at least 32 bytes.

Definition at line 35 of file key.cpp.

References ctx, memcpy(), and secp256k1_ec_seckey_verify().

Referenced by CKey::Load(), and test_ecdsa_end_to_end().

◆ ECC_InitSanityCheck()

bool ECC_InitSanityCheck ( void  )

Check that required EC support is available at runtime.

Definition at line 316 of file key.cpp.

References CKey::GetPubKey(), CKey::MakeNewKey(), and CKey::VerifyPubKey().

Referenced by InitSanityCheck().

◆ ECC_Start()

void ECC_Start ( void  )

Initialize the elliptic curve support.

May not be called twice without calling ECC_Stop first.

Definition at line 323 of file key.cpp.

References ctx, GetRandBytes(), secp256k1_context_create(), secp256k1_context_randomize(), secp256k1_context_sign, and SECP256K1_CONTEXT_SIGN.

Referenced by AppInitSanityChecks(), main(), and Secp256k1Init::Secp256k1Init().

◆ ECC_Stop()

void ECC_Stop ( void  )

Deinitialize the elliptic curve support.

No-op if ECC_Start wasn't called first.

Definition at line 340 of file key.cpp.

References ctx, secp256k1_context_destroy(), and secp256k1_context_sign.

Referenced by main(), Shutdown(), and Secp256k1Init::~Secp256k1Init().

Variable Documentation

◆ secp256k1_context_sign

secp256k1_context* secp256k1_context_sign = nullptr
static
Released under the MIT license