Skip to content

Commit

Permalink
Deterministic addresses underway (but broke AES)
Browse files Browse the repository at this point in the history
  • Loading branch information
etotheipi committed Nov 22, 2011
1 parent e4c4207 commit 5b04f82
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 114 deletions.
8 changes: 6 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* Descr: This file serves as an engine for python-based Bitcoin software.
* I forked this from my own project -- PyBtcEngine -- because I
* I needed to start including/rewriting code to use CppBlockUtils
* but did not want to break the pure-python-ness of PyBtcEngine.
* but did not want to break the pure-python methods in PyBtcEngine.
* If you are interested in in a pure-python set of bitcoin utils
* please go checkout the PyBtcEngine github project.
*
* Of course, the biggest advatage here is that you have access to
* The biggest advatage of using SWIG is that you have access to
* the blockchain through BlockObj/BlockObjRef/BlockUtils, as found
* in the CppForSWIG directory. This is available in PyBtcEngine,
* but I had to split out the modules, and I didn't have a good way
Expand All @@ -27,6 +27,10 @@
*
* ***NOTE*** This is still the Full-RAM implementation, which
* requires holding the *entire* blockchain in memory.
* This is not a problem for newer computers, which
* usually have 4GB to 16GB of RAM, and this only uses
* 1.1 GB to hold the blockchain.
*
* In the future, I plan to try to make this more
* lightweight, but I am going to forego that yet
* in favor of making a utility that works for some
Expand Down
273 changes: 224 additions & 49 deletions btcarmoryengine.py

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions cppForSwig/EncryptionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ class SecureBinaryData : public BinaryData

// These methods are definitely inherited, but SWIG needs them here if they
// are to be used from python
uint8_t const * getPtr(void) const { return BinaryData::getPtr(); }
uint8_t * getPtr(void) { return BinaryData::getPtr(); }
size_t getSize(void) const { return BinaryData::getSize(); }
uint8_t const * getPtr(void) const { return BinaryData::getPtr(); }
uint8_t * getPtr(void) { return BinaryData::getPtr(); }
size_t getSize(void) const { return BinaryData::getSize(); }
SecureBinaryData copy(void) const { return SecureBinaryData(getPtr(), getSize());}

string toHexStr(bool BE=false) const { return BinaryData::toHexStr(BE);}
string toBinStr(void) const { return BinaryData::toBinStr(); }
Expand Down
76 changes: 36 additions & 40 deletions cryptoTimings.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
################################################################################
Testing Crypto++::AES timings
################################################################################
AES Encryption with IV generation: 13299.5/sec
AES Encryption with supplied IV : 11507.8/sec
AES Decryption with supplied IV : 12124.1/sec
AES roundtrip, compare results:
Secret : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Cipher : 5c24d6bdb56621b3dc42f29d01ba0c327e410367e43cc2e4d0d713d8a83c454e
Decrypt: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Result : *** PASSED ***



################################################################################
Testing Crypto++::ECDSA timings
################################################################################
PrivateKey --> PublicKey : 753.4/sec
PrivateKey --> Signature : 755.1/sec
PublicKey --> SigVerified : 130.8/sec
PrivateKey --> NextInChain : 14974.3/sec
PublicKey --> NextInChain : 109.0/sec



################################################################################
*********************************************************************
Testing key-derivation function - timings and memory usage:
################################################################################
*********************************************************************
***KDF 1: Default params***
***KDF 2: 0.5s-1.0s timing, default mem***
***KDF 3: 0.25s-0.5s timing, 256kB max***
Testing KDF(1)
Hash Function: sha512
Mem Required : 8.0 MB
Num Iteration: 2
Hex Salt Used: 8f953b5020995b464d7d5cbfabb3e...
Pass: "This is my password " --> Key: 1446c42ec06ffecf21b5199fe14df82f (0.183717 sec)
Pass: "This is my password." --> Key: 176484a5bbfe25522151e426d3853394 (0.174887 sec)
Pass: "This is my password " --> Key: 1446c42ec06ffecf21b5199fe14df82f (0.174840 sec)
Hex Salt Used: adad20a735fa53be53a4180001ec9...
Pass: "This is my password " --> Key: 2e623cf21e74a229b97a48ab05848567 (0.173542 sec)
Pass: "This is my password." --> Key: 20570bc64cec8e34ae220108589be512 (0.172990 sec)
Pass: "This is my password " --> Key: 2e623cf21e74a229b97a48ab05848567 (0.173402 sec)
Testing KDF(2)
Hash Function: sha512
Mem Required : 32.0 MB
Num Iteration: 2
Hex Salt Used: 64a37c25c00c9bd95fc8eefd77b7f...
Pass: "This is my password " --> Key: d041597c0e0a1fddf0d69cf57ab8ef50 (0.695917 sec)
Pass: "This is my password." --> Key: c3ab637b0e72f69ecce54d9fd9c009f8 (0.702719 sec)
Pass: "This is my password " --> Key: d041597c0e0a1fddf0d69cf57ab8ef50 (0.695516 sec)
Hex Salt Used: ceca667f029ad0a10d1ef3ab0944c...
Pass: "This is my password " --> Key: 859031ea1b754907db0de9a6f63f1891 (0.747265 sec)
Pass: "This is my password." --> Key: 07f9d8a93707ca5503469c05ef8fe9d9 (0.694215 sec)
Pass: "This is my password " --> Key: 859031ea1b754907db0de9a6f63f1891 (0.688132 sec)
Testing KDF(3)
Hash Function: sha512
Mem Required : 256.0 kB
Num Iteration: 47
Hex Salt Used: c3843c1175bddfd1935d02a36244c...
Pass: "This is my password " --> Key: 7a525bbd64fdbc52497df31c8f5ec669 (0.165906 sec)
Pass: "This is my password." --> Key: 1af480216027b77b0a8eb6e4e2bf88ef (0.161794 sec)
Pass: "This is my password " --> Key: 7a525bbd64fdbc52497df31c8f5ec669 (0.165756 sec)
Num Iteration: 90
Hex Salt Used: 0a888c7586609df3daf8f7dd1e2d5...
Pass: "This is my password " --> Key: 2125ce61ddae1656f3eb7c65a2628f11 (0.299631 sec)
Pass: "This is my password." --> Key: 54538eb4bba54abdc1af93eb97001a13 (0.326200 sec)
Pass: "This is my password " --> Key: 2125ce61ddae1656f3eb7c65a2628f11 (0.347052 sec)


*********************************************************************
Testing Crypto++::AES timings
*********************************************************************
AES Encryption with IV generation: 15317.2/sec
AES Encryption with supplied IV : 16316.4/sec
AES Decryption with supplied IV : 9497.4/sec
AES roundtrip, compare results:
Secret : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Cipher : 5c24d6bdb56621b3dc42f29d01ba0c327e410367e43cc2e4d0d713d8a83c454e
Decrypt: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Result : *** PASSED ***

*********************************************************************
Testing Crypto++::ECDSA timings
*********************************************************************
PrivateKey --> PublicKey : 595.3/sec
PubPrivPair--> CheckMatch : 205.6/sec
PrivateKey --> Signature : 870.7/sec
PublicKey --> SigVerified : 129.9/sec
PrivateKey --> NextInChain : 16479.3/sec
PublicKey --> NextInChain : 110.8/sec
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions swigPbeEngine.py

This file was deleted.

31 changes: 29 additions & 2 deletions unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
Test_BasicUtils = True
Test_PyBlockUtils = True
Test_CppBlockUtils = True
Test_AddressSimple = True
Test_SimpleAddress = True
Test_EncryptedAddress = False
Test_MultiSigTx = True
Test_TxSimpleCreate = True
Test_SelectCoins = True
Test_CryptoTiming = True


Expand Down Expand Up @@ -159,7 +161,7 @@ def printpassorfail(abool):

################################################################################
################################################################################
if Test_AddressSimple:
if Test_SimpleAddress:

# Execute the tests with Satoshi's public key from the Bitcoin specification page
satoshiPubKeyHex = '04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284'
Expand Down Expand Up @@ -216,6 +218,23 @@ def printpassorfail(abool):
txoutA.binScript = '\x76\xa9\x14' + AddrA.getAddr160() + '\x88\xac'


################################################################################
################################################################################
if Test_EncryptedAddress:
# Create an address to user for all subsequent tests
privKey = SecureBinaryData(hex_to_binary('aa'*32))
pubKey = CryptoECDSA().ComputePublicKey(privKey)
addr20 = pubKey.getHash160()

# We pretend that we plugged some passphrases through a KDF
fakeKdfOutput1 = SecureBinaryData( hex_to_binary('11'*32) )
fakeKdfOutput2 = SecureBinaryData( hex_to_binary('22'*32) )

testAddr = PyBtcAddress().createFromPlainKeyData(addr20, privKey)
testAddr = PyBtcAddress().createFromPlainKeyData(addr20, privKey, pubKey)
testAddr = PyBtcAddress().createFromPlainKeyData(addr20, privKey, pubKey, skipCheck=True)
testAddr = PyBtcAddress().createFromPlainKeyData(addr20, privKey, skipPubCompute=True)


################################################################################
################################################################################
Expand Down Expand Up @@ -427,6 +446,14 @@ def printpassorfail(abool):
print ' PrivateKey --> PublicKey'.ljust(36),
print ': %0.1f/sec' % (nTest/(end-start))

# Check keypair match
start = time.time()
for i in range(nTest):
match = CryptoECDSA().CheckPubPrivKeyMatch(privKey, pubKey)
end = time.time()
print ' PubPrivPair--> CheckMatch'.ljust(36),
print ': %0.1f/sec' % (nTest/(end-start))

# Test signing speed
msg = SecureBinaryData( hex_to_binary('ff'*32) )
sig = SecureBinaryData()
Expand Down

0 comments on commit 5b04f82

Please sign in to comment.