<commit_before>/*
	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 <http://www.gnu.org/licenses/>.
*/
/** @file crypto.cpp
 * @author <NAME> <<EMAIL>>
 * @date 2014
 * Crypto test functions.
 */

#include <random>
#include <secp256k1/secp256k1.h>
#include <libdevcore/Common.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Log.h>
#include <libethereum/Transaction.h>
#include <boost/test/unit_test.hpp>
#include <libdevcrypto/EC.h>
#include <libdevcrypto/ECIES.h>
#include "TestHelperCrypto.h"

using namespace std;
using namespace dev;
using namespace dev::crypto;
using namespace CryptoPP;

BOOST_AUTO_TEST_SUITE(devcrypto)

BOOST_AUTO_TEST_CASE(eckeypair_encrypt)
{
	ECKeyPair k = ECKeyPair::create();
	string message("Now is the time for all good persons to come to the aide of humanity.");
	string original = message;
	
	bytes b = asBytes(message);
	k.encrypt(b);
	assert(b != asBytes(original));
	
	bytes p = k.decrypt(&b);
	assert(p == asBytes(original));
}

BOOST_AUTO_TEST_CASE(ecies)
{
//	ECKeyPair k = ECKeyPair::create();
//
//	string message("Now is the time for all good persons to come to the aide of humanity.");
//	bytes b = bytesRef(message).toBytes();
//	ECIESEncryptor(&k).encrypt(b);<commit_msg>Export and encrypt via dev::Public. more cryptopp abstraction.<commit_after>/*
	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 <http://www.gnu.org/licenses/>.
*/
/** @file crypto.cpp
 * @author <NAME> <<EMAIL>>
 * @date 2014
 * Crypto test functions.
 */

#include <random>
#include <secp256k1/secp256k1.h>
#include <libdevcore/Common.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Log.h>
#include <libethereum/Transaction.h>
#include <boost/test/unit_test.hpp>
#include <libdevcrypto/EC.h>
//#include <libdevcrypto/ECIES.h>
#include "TestHelperCrypto.h"

using namespace std;
using namespace dev;
using namespace dev::crypto;
using namespace CryptoPP;

BOOST_AUTO_TEST_SUITE(devcrypto)

BOOST_AUTO_TEST_CASE(cryptopp_public_export_import)
{
	ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1());
	ECIES<ECP>::Encryptor e(d.GetKey());
	
	Public p = pp::exportPublicKey(e.GetKey());
	Integer x(&p[0], 32);
	Integer y(&p[32], 32);
	
	DL_PublicKey_EC<ECP> pub;
	pub.Initialize(pp::secp256k1(), ECP::Point(x,y));
	
	assert(pub == e.GetKey());
}

BOOST_AUTO_TEST_CASE(eckeypair_encrypt)
{
	ECKeyPair k = ECKeyPair::create();
	string message("Now is the time for all good persons to come to the aide of humanity.");
	string original = message;
	
	bytes b = asBytes(message);
	k.encrypt(b);
	assert(b != asBytes(original));
	
	bytes p = k.decrypt(&b);
	assert(p == asBytes(original));

	encrypt(p, k.publicKey());
	assert(p != asBytes(original));
	
	// todo: test decrypt w/Secret
}

BOOST_AUTO_TEST_CASE(ecies)
{
//	ECKeyPair k = ECKeyPair::create();
//
//	string message("Now is the time for all good persons to come to the aide of humanity.");
//	bytes b = bytesRef(message).toBytes();
//	ECIESEncryptor(&k).encrypt(b);
{'fraction_non_alphanumeric': 0.1200878691725653, 'fraction_numerical': 0.010007322431047107, 'mean_word_length': 4.739495798319328, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7334589', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1357, 'n_words': 443}