Changeset View
Changeset View
Standalone View
Standalone View
src/key.h
Show All 25 Lines | |||||
/** | /** | ||||
* secure_allocator is defined in allocators.h | * secure_allocator is defined in allocators.h | ||||
* CPrivKey is a serialized private key, with all parameters included (279 | * CPrivKey is a serialized private key, with all parameters included (279 | ||||
* bytes) | * bytes) | ||||
*/ | */ | ||||
typedef std::vector<uint8_t, secure_allocator<uint8_t>> CPrivKey; | typedef std::vector<uint8_t, secure_allocator<uint8_t>> CPrivKey; | ||||
/** An encapsulated private key. */ | /** An encapsulated secp256k1 private key. */ | ||||
class CKey { | class CKey { | ||||
private: | private: | ||||
//! Whether this private key is valid. We check for correctness when | //! Whether this private key is valid. We check for correctness when | ||||
//! modifying the key data, so fValid should always correspond to the actual | //! modifying the key data, so fValid should always correspond to the actual | ||||
//! state. | //! state. | ||||
bool fValid; | bool fValid; | ||||
//! Whether the public key corresponding to this private key is (to be) | //! Whether the public key corresponding to this private key is (to be) | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Compute the public key from a private key. | * Compute the public key from a private key. | ||||
* This is expensive. | * This is expensive. | ||||
*/ | */ | ||||
CPubKey GetPubKey() const; | CPubKey GetPubKey() const; | ||||
/** | /** | ||||
* Create a DER-serialized signature. | * Create a DER-serialized ECDSA signature. | ||||
* The test_case parameter tweaks the deterministic nonce. | * The test_case parameter tweaks the deterministic nonce. | ||||
*/ | */ | ||||
bool Sign(const uint256 &hash, std::vector<uint8_t> &vchSig, | bool SignECDSA(const uint256 &hash, std::vector<uint8_t> &vchSig, | ||||
uint32_t test_case = 0) const; | uint32_t test_case = 0) const; | ||||
/** | /** | ||||
* Create a compact signature (65 bytes), which allows reconstructing the | * Create a compact ECDSA signature (65 bytes), which allows reconstructing | ||||
* used public key. | * the used public key. | ||||
* The format is one header byte, followed by two times 32 bytes for the | * The format is one header byte, followed by two times 32 bytes for the | ||||
* serialized r and s values. | * serialized r and s values. | ||||
* The header byte: 0x1B = first key with even y, 0x1C = first key with odd | * The header byte: 0x1B = first key with even y, 0x1C = first key with odd | ||||
* y, | * y, | ||||
* 0x1D = second key with even y, 0x1E = second key with | * 0x1D = second key with even y, 0x1E = second key with | ||||
* odd y, | * odd y, | ||||
* add 0x04 for compressed keys. | * add 0x04 for compressed keys. | ||||
*/ | */ | ||||
bool SignCompact(const uint256 &hash, std::vector<uint8_t> &vchSig) const; | bool SignCompact(const uint256 &hash, std::vector<uint8_t> &vchSig) const; | ||||
//! Derive BIP32 child key. | //! Derive BIP32 child key. | ||||
bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, | bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, | ||||
const ChainCode &cc) const; | const ChainCode &cc) const; | ||||
/** | /** | ||||
* Verify thoroughly whether a private key and a public key match. | * Verify thoroughly whether a private key and a public key match. | ||||
* This is done using a different mechanism than just regenerating it. | * This is done using a different mechanism than just regenerating it. | ||||
* (An ECDSA signature is created then verified.) | |||||
*/ | */ | ||||
bool VerifyPubKey(const CPubKey &vchPubKey) const; | bool VerifyPubKey(const CPubKey &vchPubKey) const; | ||||
//! Load private key and check that public key matches. | //! Load private key and check that public key matches. | ||||
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck); | bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck); | ||||
}; | }; | ||||
struct CExtKey { | struct CExtKey { | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |