From 07b811ebfa47c680a8b15e8631985e65c8e9e3b3 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 17 Jun 2015 11:45:36 +0200 Subject: [PATCH 1/2] basic AES tests --- libdevcrypto/AES.h | 2 + test/libdevcrypto/AES.cpp | 92 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/libdevcrypto/AES.cpp diff --git a/libdevcrypto/AES.h b/libdevcrypto/AES.h index 32d1880dc..6aaed6fad 100644 --- a/libdevcrypto/AES.h +++ b/libdevcrypto/AES.h @@ -75,6 +75,8 @@ public: /// Adjust mac interval. Next mac will be xored with value. void adjustInterval(unsigned _interval) { m_macInterval = _interval; } + + unsigned getMacInterval() { return m_macInterval;} private: AuthenticatedStream(AuthenticatedStream const&) = delete; diff --git a/test/libdevcrypto/AES.cpp b/test/libdevcrypto/AES.cpp new file mode 100644 index 000000000..5742b882e --- /dev/null +++ b/test/libdevcrypto/AES.cpp @@ -0,0 +1,92 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file MemTrie.h + * @author Christoph Jentzsch + * @date 2015 + */ + +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace dev; + +BOOST_AUTO_TEST_SUITE(AES) + +BOOST_AUTO_TEST_CASE(AesDecrypt) +{ + cout << "AesDecrypt" << endl; + bytes seed = fromHex("2dbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621"); + KeyPair kp(sha3(aesDecrypt(&seed, "test"))); + BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") == kp.address()); +} + +BOOST_AUTO_TEST_CASE(AesDecryptWrongSeed) +{ + cout << "AesDecryptWrongSeed" << endl; + bytes seed = fromHex("badaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621"); + KeyPair kp(sha3(aesDecrypt(&seed, "test"))); + BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") != kp.address()); +} + +BOOST_AUTO_TEST_CASE(AesDecryptWrongPassword) +{ + cout << "AesDecryptWrongPassword" << endl; + bytes seed = fromHex("2dbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621"); + KeyPair kp(sha3(aesDecrypt(&seed, "badtest"))); + BOOST_CHECK(Address("07746f871de684297923f933279555dda418f8a2") != kp.address()); +} + +BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeed) +{ + cout << "AesDecryptFailInvalidSeed" << endl; + bytes seed = fromHex("xdbaead416c20cfd00c2fc9f1788ff9f965a2000799c96a624767cb0e1e90d2d7191efdd92349226742fdc73d1d87e2d597536c4641098b9a89836c94f58a2ab4c525c27c4cb848b3e22ea245b2bc5c8c7beaa900b0c479253fc96fce7ffc621"); + BOOST_CHECK(bytes() == aesDecrypt(&seed, "test")); +} + +BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeedSize) +{ + cout << "AesDecryptFailInvalidSeedSize" << endl; + bytes seed = fromHex("000102030405060708090a0b0c0d0e0f"); + BOOST_CHECK(bytes() == aesDecrypt(&seed, "test")); +} + +BOOST_AUTO_TEST_CASE(AesDecryptFailInvalidSeed2) +{ + cout << "AesDecryptFailInvalidSeed2" << endl; + bytes seed = fromHex("000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"); + BOOST_CHECK(bytes() == aesDecrypt(&seed, "test")); +} +BOOST_AUTO_TEST_CASE(AuthenticatedStreamConstructor) +{ + cout << "AuthenticatedStreamConstructor" << endl; + + Secret const sec("test"); + crypto::aes::AuthenticatedStream as(crypto::aes::Encrypt, sec, 0); + BOOST_CHECK(as.getMacInterval() == 0); + as.adjustInterval(1); + BOOST_CHECK(as.getMacInterval() == 1); + crypto::aes::AuthenticatedStream as_mac(crypto::aes::Encrypt, h128(), h128(), 42); + BOOST_CHECK(as_mac.getMacInterval() == 42); +} + +BOOST_AUTO_TEST_SUITE_END() + From 83cc17f240c02eab9bf4cbf4436e6ab356c11693 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 17 Jun 2015 12:22:04 +0200 Subject: [PATCH 2/2] update file name in description --- test/libdevcrypto/AES.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libdevcrypto/AES.cpp b/test/libdevcrypto/AES.cpp index 5742b882e..071f1509c 100644 --- a/test/libdevcrypto/AES.cpp +++ b/test/libdevcrypto/AES.cpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file MemTrie.h +/** @file AES.cpp * @author Christoph Jentzsch * @date 2015 */