Fabcoin Core  0.16.2
P2P Digital Currency
AES.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include <boost/test/unit_test.hpp>
19 #include <libdevcore/Common.h>
20 #include <libdevcrypto/Common.h>
21 #include <libdevcore/SHA3.h>
22 #include <libdevcore/Log.h>
23 #include <libdevcrypto/AES.h>
25 
26 using namespace std;
27 using namespace dev;
28 using namespace dev::test;
29 
30 BOOST_AUTO_TEST_SUITE(Crypto)
31 
33 
35 {
36  cnote << "AesDecrypt";
37  bytes seed = fromHex("2dbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621");
38  KeyPair kp(sha3Secure(aesDecrypt(&seed, "test")));
39  BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") == kp.address());
40 }
41 
42 BOOST_AUTO_TEST_CASE(AesDecryptWrongSeed)
43 {
44  cnote << "AesDecryptWrongSeed";
45  bytes seed = fromHex("badaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621");
46  KeyPair kp(sha3Secure(aesDecrypt(&seed, "test")));
47  BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") != kp.address());
48 }
49 
50 BOOST_AUTO_TEST_CASE(AesDecryptWrongPassword)
51 {
52  cnote << "AesDecryptWrongPassword";
53  bytes seed = fromHex("2dbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621");
54  KeyPair kp(sha3Secure(aesDecrypt(&seed, "badtest")));
55  BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") != kp.address());
56 }
57 
58 BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeed)
59 {
60  cnote << "AesDecryptFailInvalidSeed";
61  bytes seed = fromHex("xdbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621");
62  BOOST_CHECK(bytes() == aesDecrypt(&seed, "test"));
63 }
64 
65 BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeedSize)
66 {
67  cnote << "AesDecryptFailInvalidSeedSize";
68  bytes seed = fromHex("000102030405060708090a0b0c0d0e0f");
69  BOOST_CHECK(bytes() == aesDecrypt(&seed, "test"));
70 }
71 
72 BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeed2)
73 {
74  cnote << "AesDecryptFailInvalidSeed2";
75  bytes seed = fromHex("000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f");
76  BOOST_CHECK(bytes() == aesDecrypt(&seed, "test"));
77 }
78 
80 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Simple class that represents a "key pair".
Definition: Common.h:150
BOOST_AUTO_TEST_CASE(AesDecrypt)
Definition: AES.cpp:34
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
SecureFixedHash< 32 > sha3Secure(bytesConstRef _input)
Definition: SHA3.h:41
std::hash for asio::adress
Definition: Common.h:323
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
std::vector< byte > bytes
Definition: Common.h:75
AES block cipher (Rijndael)
Address const & address() const
Retrieve the associated address of the public key.
Definition: Common.h:173
#define cnote
Definition: Log.h:303
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
bytes aesDecrypt(bytesConstRef _cipher, std::string const &_password, unsigned _rounds=2000, bytesConstRef _salt=bytesConstRef())
Definition: AES.cpp:34
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)
Definition: object.cpp:17