Changeset View
Changeset View
Standalone View
Standalone View
src/key.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017 The Zcash developers | |||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_KEY_H | #ifndef BITCOIN_KEY_H | ||||
#define BITCOIN_KEY_H | #define BITCOIN_KEY_H | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <support/allocators/secure.h> | #include <support/allocators/secure.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <stdexcept> | #include <stdexcept> | ||||
#include <vector> | #include <vector> | ||||
/** | /** | ||||
* secp256k1: | |||||
* const unsigned int PRIVATE_KEY_SIZE = 279; | |||||
* const unsigned int PUBLIC_KEY_SIZE = 65; | |||||
* const unsigned int SIGNATURE_SIZE = 72; | |||||
* | |||||
* see www.keylength.com | |||||
* script supports up to 75 for single byte push | |||||
*/ | |||||
/** | |||||
* 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 | ||||
* bytes) | * (PRIVATE_KEY_SIZE bytes) | ||||
*/ | */ | ||||
typedef std::vector<uint8_t, secure_allocator<uint8_t>> CPrivKey; | typedef std::vector<uint8_t, secure_allocator<uint8_t>> CPrivKey; | ||||
/** An encapsulated secp256k1 private key. */ | /** An encapsulated secp256k1 private key. */ | ||||
class CKey { | class CKey { | ||||
public: | |||||
/** | |||||
* secp256k1: | |||||
*/ | |||||
static const unsigned int PRIVATE_KEY_SIZE = 279; | |||||
static const unsigned int COMPRESSED_PRIVATE_KEY_SIZE = 214; | |||||
/** | |||||
* see www.keylength.com | |||||
* script supports up to 75 for single byte push | |||||
*/ | |||||
static_assert( | |||||
PRIVATE_KEY_SIZE >= COMPRESSED_PRIVATE_KEY_SIZE, | |||||
"COMPRESSED_PRIVATE_KEY_SIZE is larger than PRIVATE_KEY_SIZE"); | |||||
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) | ||||
//! compressed. | //! compressed. | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |