forked from bitcoin/bitcoin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding rapidcheck dependency, adding CKey properties
Adding rapidcheck dependency, adding CKey properties Successfully compiling bitcoin with rapidcheck dependency Adding new property file for CKey Serialization symmetry for CKey -> CBitcoinSecret -> CKey Adding crypto_gen.h - this file is meant to contain all of our crypto related generators Adding generators for CPrivKey, CPubKey, and uint256 Adding properties to make sure we can Set a CKey using begin() and end(), and property to sign a uint256, then verify with with the pubkey fixing some issues inside build files and nits introduced in some tests Fixing issue where I accidentally removed zeromq from packages.mk Fixing a few more nits Fixing one last nit
- Loading branch information
1 parent
2468292
commit 0a658bb
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package=rapidcheck | ||
|
||
$(package)_version=1.0 | ||
|
||
$(package)_download_path=https://github.com/Christewart/rapidcheck/releases/download/1.0 | ||
|
||
$(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
|
||
$(package)_sha256_hash=c228dc21ec24618bfb6afa31d622d1f4ea71168f04ee499e1ffcfc63cd5833f4 | ||
|
||
define $(package)_preprocess_cmds | ||
mkdir build | ||
endef | ||
|
||
define $(package)_config_cmds | ||
cmake -DCMAKE_INSTALL_PREFIX:PATH=$(build_prefix)/bin .. | ||
endef | ||
|
||
define $(package)_build_cmds | ||
$(MAKE) | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "key.h" | ||
#include "random.h" | ||
#include "uint256.h" | ||
#include <rapidcheck/gen/Arbitrary.h> | ||
#include <rapidcheck/Gen.h> | ||
|
||
namespace rc { | ||
|
||
/** Generator for a new CKey */ | ||
template<> | ||
struct Arbitrary<CKey> { | ||
static Gen<CKey> arbitrary() { | ||
return gen::map<int>([](int x) { | ||
CKey key; | ||
key.MakeNewKey(true); | ||
return key; | ||
}); | ||
}; | ||
}; | ||
|
||
/** Generator for a CPrivKey */ | ||
template<> | ||
struct Arbitrary<CPrivKey> { | ||
static Gen<CPrivKey> arbitrary() { | ||
return gen::map<CKey>([](CKey key) { | ||
return key.GetPrivKey(); | ||
}); | ||
}; | ||
}; | ||
|
||
/** Generator for a new CPubKey */ | ||
template<> | ||
struct Arbitrary<CPubKey> { | ||
static Gen<CPubKey> arbitrary() { | ||
return gen::map<CKey>([](CKey key) { | ||
return key.GetPubKey(); | ||
}); | ||
}; | ||
}; | ||
|
||
/** Generates a arbitrary uint256 */ | ||
template<> | ||
struct Arbitrary<uint256> { | ||
static Gen<uint256> arbitrary() { | ||
return gen::map<int>([](int x) { | ||
return GetRandHash(); | ||
}); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2012-2016 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
#include "key.h" | ||
|
||
#include "base58.h" | ||
#include "script/script.h" | ||
#include "uint256.h" | ||
#include "util.h" | ||
#include "utilstrencodings.h" | ||
#include "test/test_bitcoin.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <rapidcheck/boost_test.h> | ||
#include <rapidcheck/gen/Arbitrary.h> | ||
#include <rapidcheck/Gen.h> | ||
|
||
#include "test/gen/crypto_gen.h" | ||
/** Generator for a new CKey */ | ||
BOOST_FIXTURE_TEST_SUITE(key_properties, BasicTestingSetup) | ||
|
||
/** Check CKey uniqueness */ | ||
RC_BOOST_PROP(key_uniqueness, (CKey key1, CKey key2)) { | ||
RC_ASSERT(!(key1 == key2)); | ||
} | ||
|
||
/** Verify that a private key generates the correct public key */ | ||
RC_BOOST_PROP(key_generates_correct_pubkey, (CKey key)) { | ||
CPubKey pubKey = key.GetPubKey(); | ||
RC_ASSERT(key.VerifyPubKey(pubKey)); | ||
} | ||
|
||
/** Serialization symmetry CKey -> CBitcoinSecret -> CKey */ | ||
RC_BOOST_PROP(key_bitcoinsecret_symmetry, (CKey key)) { | ||
CBitcoinSecret secret; | ||
secret.SetKey(key); | ||
RC_ASSERT(secret.GetKey() == key); | ||
} | ||
|
||
/** Create a CKey using the 'Set' function must give us the same key */ | ||
RC_BOOST_PROP(key_set_symmetry, (CKey key)) { | ||
CKey key1; | ||
key1.Set(key.begin(), key.end(), key.IsCompressed()); | ||
RC_ASSERT(key1 == key); | ||
} | ||
|
||
/** Create a CKey, sign a piece of data, then verify it with the public key */ | ||
RC_BOOST_PROP(key_sign_symmetry, (CKey key, uint256 hash)) { | ||
std::vector<unsigned char> vchSig; | ||
key.Sign(hash,vchSig,0); | ||
CPubKey pubKey = key.GetPubKey(); | ||
RC_ASSERT(pubKey.Verify(hash,vchSig)); | ||
} | ||
BOOST_AUTO_TEST_SUITE_END() |