From 0e2e2d24346fddf54de2e30f04d92453d34cde2a Mon Sep 17 00:00:00 2001 From: levongh Date: Mon, 19 Mar 2018 11:49:30 +0400 Subject: [PATCH] Fixed issue #48 Rebranding to nrghash --- .gitignore | 2 +- Makefile.am | 2 +- README.md | 2 +- configure.ac | 4 +- data/.gitignore | 2 +- include/Makefile.am | 2 +- include/{egihash.h => nrghash.h} | 24 +++--- {libegihash => libnrghash}/Makefile.am | 10 +-- {libegihash => libnrghash}/keccak-tiny.c | 0 .../egihash.cpp => libnrghash/nrghash.cpp | 6 +- test/.gitignore | 2 +- test/Makefile.am | 12 +-- test/{egihash_test.cpp => nrghash_test.cpp} | 73 ++++++++++--------- 13 files changed, 71 insertions(+), 70 deletions(-) rename include/{egihash.h => nrghash.h} (97%) rename {libegihash => libnrghash}/Makefile.am (71%) rename {libegihash => libnrghash}/keccak-tiny.c (100%) rename libegihash/egihash.cpp => libnrghash/nrghash.cpp (99%) rename test/{egihash_test.cpp => nrghash_test.cpp} (91%) diff --git a/.gitignore b/.gitignore index 15d5f2b..460aae6 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ *.exe *.out *.app -/egihash +/nrghash # Autotools files *.deps diff --git a/Makefile.am b/Makefile.am index f034221..bea7155 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS=libegihash include test +SUBDIRS=libnrghash include test ACLOCAL_AMFLAGS=-I m4 diff --git a/README.md b/README.md index d5e1b48..62f4ba1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# egihash +# nrghash Energi cryptocurrency hash algorithm diff --git a/configure.ac b/configure.ac index 177799d..1490884 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([egihash],[1.23.0]) +AC_INIT([nrghash],[1.23.0]) AC_PROG_CC AC_PROG_CXX @@ -36,7 +36,7 @@ CCFLAGS="$BOOST_CCFLAGS -O3 -Wall -Wextra -Werror -Wno-unused-function" AC_CONFIG_FILES(Makefile test/Makefile - libegihash/Makefile + libnrghash/Makefile include/Makefile) AC_OUTPUT diff --git a/data/.gitignore b/data/.gitignore index ec9fd6e..5efc7c3 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,3 +1,3 @@ # Dag file used for testing -/egihash.dag +/nrghash.dag diff --git a/include/Makefile.am b/include/Makefile.am index 52733fc..06174bc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,3 +1,3 @@ # These files will end up in the install include directory # For example, /usr/include -include_HEADERS = egihash.h +include_HEADERS = nrghash.h diff --git a/include/egihash.h b/include/nrghash.h similarity index 97% rename from include/egihash.h rename to include/nrghash.h index 42bb248..ea6b3f6 100644 --- a/include/egihash.h +++ b/include/nrghash.h @@ -15,7 +15,7 @@ #include #include -namespace egihash +namespace nrghash { bool test_function() noexcept; @@ -39,15 +39,15 @@ namespace egihash */ static constexpr uint32_t CALLBACK_FREQUENCY = 1024u; - /** \brief The major version of egihash + /** \brief The major version of nrghash */ static constexpr uint32_t MAJOR_VERSION = 1u; - /** \brief The revision number (middle version digit) of egihash + /** \brief The revision number (middle version digit) of nrghash */ static constexpr uint32_t REVISION = 23u; - /** \brief The minor version number of egihash + /** \brief The minor version number of nrghash */ static constexpr uint32_t MINOR_VERSION = 0u; @@ -81,11 +81,11 @@ namespace egihash */ static constexpr uint32_t EPOCH_LENGTH = 30000u; - /** \brief The width of the mix hash for egihash. + /** \brief The width of the mix hash for nrghash. */ static constexpr uint32_t MIX_BYTES = 128u; - /** \brief The size of an egihash in bytes. + /** \brief The size of an nrghash in bytes. */ static constexpr uint32_t HASH_BYTES = 64u; @@ -97,7 +97,7 @@ namespace egihash */ static constexpr uint32_t CACHE_ROUNDS = 3u; - /** \brief The number of DAG lookups to compute an egihash. + /** \brief The number of DAG lookups to compute an nrghash. */ static constexpr uint32_t ACCESSES = 64u; } @@ -126,7 +126,7 @@ namespace egihash static_assert(sizeof(node) == sizeof(uint32_t), "Invalid hash node size"); - /** \brief hash_exception indicates an error or cancellation when performing a task within egihash. + /** \brief hash_exception indicates an error or cancellation when performing a task within nrghash. * * All functions not marked noexcept may be assumed to throw hash_exception or C++ runtime exceptions. */ @@ -287,7 +287,7 @@ namespace egihash */ static constexpr h512_t empty_h512; - /** \brief result_t represents the result of an egihash. + /** \brief result_t represents the result of an nrghash. */ struct result_t { @@ -325,7 +325,7 @@ namespace egihash */ bool operator==(result_t const &) const; - /** \brief This member contains the egihash result value. + /** \brief This member contains the nrghash result value. */ h256_t value; @@ -501,9 +501,9 @@ namespace egihash ::std::shared_ptr impl; }; - /** \brief dag_t is the DAG which is used by full nodes and miners to compute egihashes. + /** \brief dag_t is the DAG which is used by full nodes and miners to compute nrghashes. * - * The DAG gives egihash it's ASIC resistance, ensuring that this hashing function is memory bound not compute bound. + * The DAG gives nrghash it's ASIC resistance, ensuring that this hashing function is memory bound not compute bound. * The DAG must be updated once per constants::EPOCH_LENGTH block numbers. * The DAG for epoch 0 is 1073739904 bytes in size and will grow linearly with each following epoch. * The DAG can take a long time to generate. It is recommended to save the DAG to disk to avoid having to regenerate it each time. diff --git a/libegihash/Makefile.am b/libnrghash/Makefile.am similarity index 71% rename from libegihash/Makefile.am rename to libnrghash/Makefile.am index 34f3416..e215034 100644 --- a/libegihash/Makefile.am +++ b/libnrghash/Makefile.am @@ -2,17 +2,17 @@ # The list of libraries we are building seperated by spaces. # The 'lib_' indicates that these build products will be installed # in the $(libdir) directory. For example /usr/lib -lib_LTLIBRARIES = libegihash.la +lib_LTLIBRARIES = libnrghash.la ####################################### # Build information for each library -# Sources for libegihash -libegihash_la_SOURCES = egihash.cpp keccak-tiny.c +# Sources for libnrghash +libnrghash_la_SOURCES = nrghash.cpp keccak-tiny.c # Linker options libTestProgram -libegihash_la_LDFLAGS = +libnrghash_la_LDFLAGS = # Compiler options. Here we are adding the include directory # to be searched for headers included in the source code. -libegihash_la_CPPFLAGS = -I$(top_srcdir)/include -D__STDC_WANT_LIB_EXT1__=1 -DUSE_SECURE_MEMZERO +libnrghash_la_CPPFLAGS = -I$(top_srcdir)/include -D__STDC_WANT_LIB_EXT1__=1 -DUSE_SECURE_MEMZERO diff --git a/libegihash/keccak-tiny.c b/libnrghash/keccak-tiny.c similarity index 100% rename from libegihash/keccak-tiny.c rename to libnrghash/keccak-tiny.c diff --git a/libegihash/egihash.cpp b/libnrghash/nrghash.cpp similarity index 99% rename from libegihash/egihash.cpp rename to libnrghash/nrghash.cpp index 70fd97b..c0ad9cc 100644 --- a/libegihash/egihash.cpp +++ b/libnrghash/nrghash.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "egihash.h" +#include "nrghash.h" extern "C" { #include "keccak-tiny.h" @@ -24,7 +24,7 @@ extern "C" namespace { - using namespace egihash; + using namespace nrghash; #pragma pack(push, 1) struct dag_file_header_t @@ -305,7 +305,7 @@ namespace } } -namespace egihash +namespace nrghash { constexpr h256_t::size_type h256_t::hash_size; diff --git a/test/.gitignore b/test/.gitignore index c1ff999..d46b86d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1 @@ -/egihash_test +/nrghash_test diff --git a/test/Makefile.am b/test/Makefile.am index 863e7d4..8f6b20c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,12 +2,12 @@ # The list of executables we are building seperated by spaces # the 'bin_' indicates that these build products will be installed # in the $(bindir) directory. For example /usr/bin -#bin_PROGRAMS=egihash_test +#bin_PROGRAMS=nrghash_test # Because a.out is only a sample program we don't want it to be installed. # The 'noinst_' prefix indicates that the following targets are not to be # installed. -noinst_PROGRAMS=egihash_test +noinst_PROGRAMS=nrghash_test ####################################### # Build information for each executable. The variable name is derived @@ -18,13 +18,13 @@ noinst_PROGRAMS=egihash_test ACLOCAL_AMFLAGS=-I ../m4 # Sources for the a.out -egihash_test_SOURCES= egihash_test.cpp +nrghash_test_SOURCES= nrghash_test.cpp # Libraries for a.out -egihash_test_LDADD = $(top_srcdir)/libegihash/libegihash.la +nrghash_test_LDADD = $(top_srcdir)/libnrghash/libnrghash.la # Linker options for a.out -egihash_test_LDFLAGS = -rpath `cd $(top_srcdir);pwd`/libegihash/.libs $(BOOST_UNIT_TEST_FRAMEWORK_LIB) +nrghash_test_LDFLAGS = -rpath `cd $(top_srcdir);pwd`/libnrghash/.libs $(BOOST_UNIT_TEST_FRAMEWORK_LIB) # Compiler options for a.out -egihash_test_CPPFLAGS = -I$(top_srcdir)/include -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN +nrghash_test_CPPFLAGS = -I$(top_srcdir)/include -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN diff --git a/test/egihash_test.cpp b/test/nrghash_test.cpp similarity index 91% rename from test/egihash_test.cpp rename to test/nrghash_test.cpp index 147bdd8..c5795f7 100644 --- a/test/egihash_test.cpp +++ b/test/nrghash_test.cpp @@ -1,12 +1,12 @@ /* ============================================================================ - Name : egihash_test.cpp + Name : nrghash_test.cpp Author : Ranjeet Devgun Version : Copyright : TODO Copyright notice Description : Uses shared library to print greeting To run the resulting executable the LD_LIBRARY_PATH must be - set to ${project_loc}/libegihash/.libs + set to ${project_loc}/libnrghash/.libs Alternatively, libtool creates a wrapper shell script in the build directory of this program which can be used to run it. Here the script will be called test. @@ -15,7 +15,7 @@ #include #include -#include "egihash.h" +#include "nrghash.h" #ifdef _WIN32 #include @@ -31,7 +31,7 @@ #include #include -#define BOOST_TEST_MODULE libegihash_unit_tests +#define BOOST_TEST_MODULE libnrghash_unit_tests #include using namespace std; @@ -43,7 +43,7 @@ namespace { bool dag_progress(::std::size_t step, ::std::size_t max, int phase) { - using namespace egihash; + using namespace nrghash; // saving output for longer running tasks like DAG generation switch (phase) @@ -129,12 +129,12 @@ BOOST_AUTO_TEST_SUITE(Keccak); BOOST_AUTO_TEST_CASE(Keccak_256) { - test_hash_func(); + test_hash_func(); } BOOST_AUTO_TEST_CASE(Keccak_512) { - test_hash_func(); + test_hash_func(); } BOOST_AUTO_TEST_SUITE_END(); @@ -145,15 +145,15 @@ BOOST_AUTO_TEST_SUITE(Egihash); BOOST_AUTO_TEST_CASE(EGIHASH_HASHIMOTO) { using namespace std; - using namespace egihash; + using namespace nrghash; - if (!boost::filesystem::exists( "data/egihash.dag" )) + if (!boost::filesystem::exists( "data/nrghash.dag" )) { - egihash::dag_t dag(0, dag_progress); - dag.save("data/egihash.dag"); + nrghash::dag_t dag(0, dag_progress); + dag.save("data/nrghash.dag"); } - dag_t d("data/egihash.dag", dag_progress); + dag_t d("data/nrghash.dag", dag_progress); string rawdata("this is a test string to be hashed"); std::vector> vExpected = { @@ -179,17 +179,17 @@ BOOST_AUTO_TEST_CASE(EGIHASH_HASHIMOTO) BOOST_AUTO_TEST_CASE(FULL_CLIENT) { - string filename_egi = string("egihash.dag"); + string filename_egi = string("nrghash.dag"); string filename_et = string("ethash_eg_seed_2_hashes.dag"); fs::path egiDagPath = fs::current_path() / "data" / filename_egi; fs::path etDagPath = fs::current_path() / "data" / filename_et; - BOOST_ASSERT(16776896 == egihash::cache_t::get_cache_size(0)); - BOOST_ASSERT(1073739904 == egihash::dag_t::get_full_size(0)); + BOOST_ASSERT(16776896 == nrghash::cache_t::get_cache_size(0)); + BOOST_ASSERT(1073739904 == nrghash::dag_t::get_full_size(0)); if ( !boost::filesystem::exists( egiDagPath ) ) { - egihash::dag_t dag(0, dag_progress); + nrghash::dag_t dag(0, dag_progress); dag.save(egiDagPath.string()); } @@ -199,17 +199,17 @@ BOOST_AUTO_TEST_CASE(FULL_CLIENT) BOOST_ASSERT(dag_ethash_if.is_open() && dag_eghash_if.is_open()); if ( dag_ethash_if.is_open() && dag_eghash_if.is_open() ) { - uint64_t egiDagSizeSkip = sizeof(egihash::constants::DAG_MAGIC_BYTES) + - sizeof(egihash::constants::MAJOR_VERSION) + - sizeof(egihash::constants::REVISION) + - sizeof(egihash::constants::MINOR_VERSION) + + uint64_t egiDagSizeSkip = sizeof(nrghash::constants::DAG_MAGIC_BYTES) + + sizeof(nrghash::constants::MAJOR_VERSION) + + sizeof(nrghash::constants::REVISION) + + sizeof(nrghash::constants::MINOR_VERSION) + sizeof(uint64_t) + // epoch sizeof(uint64_t) + // cache begin sizeof(uint64_t) + // cache_end sizeof(uint64_t) + // dag_begin sizeof(uint64_t);// dag_end - egiDagSizeSkip += egihash::cache_t::get_cache_size(0); + egiDagSizeSkip += nrghash::cache_t::get_cache_size(0); constexpr uint32_t BUFFER_SIZE = 32 * 1024 * 1024; constexpr uint32_t DATA_TO_READ = 1024; @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(FULL_CLIENT) BOOST_AUTO_TEST_CASE(seedhash_test) { - using namespace egihash; + using namespace nrghash; static constexpr char const * first100_seedhashes[] = { @@ -360,23 +360,24 @@ BOOST_AUTO_TEST_CASE(seedhash_test) BOOST_AUTO_TEST_CASE(light_hash_vs_full_hash_comparison) { using namespace std; - using namespace egihash; + using namespace nrghash; - if (!boost::filesystem::exists( "data/egihash.dag" )) + if (!boost::filesystem::exists( "data/nrghash.dag" )) { - egihash::dag_t dag(0, dag_progress); - dag.save("data/egihash.dag"); + nrghash::dag_t dag(0, dag_progress); + dag.save("data/nrghash.dag"); } - dag_t d("data/egihash.dag", dag_progress); + dag_t d("data/nrghash.dag", dag_progress); cache_t c(d.get_cache()); string rawdata("this is a test string to be hashed"); h256_t firsthash(rawdata.c_str(), rawdata.size()); + typedef int64_t __attribute__((__may_alias__)) int64_type; for (size_t i = 0; i < 1000; i++) { - uint64_t nonce = (*reinterpret_cast(&firsthash.b[0])) ^ (*reinterpret_cast(&firsthash.b[16])); + uint64_t nonce = (*reinterpret_cast(&firsthash.b[0])) ^ (*reinterpret_cast(&firsthash.b[16])); firsthash = h256_t(&firsthash.b[0], firsthash.hash_size); auto const lighthash = light::hash(c, firsthash, nonce); auto const fullhash = full::hash(d, firsthash, nonce); @@ -389,11 +390,11 @@ BOOST_AUTO_TEST_CASE(light_hash_vs_full_hash_comparison) BOOST_ASSERT(memcmp(&lighthash.value.b[0], &fullhash.value.b[0], (std::min)(lighthash.value.hash_size, fullhash.value.hash_size)) == 0); BOOST_ASSERT(memcmp(&lighthash.mixhash.b[0], &fullhash.mixhash.b[0], (std::min)(lighthash.value.hash_size, fullhash.value.hash_size)) == 0); - // checks operator== for egihash::h256_t + // checks operator== for nrghash::h256_t BOOST_ASSERT(lighthash.value == fullhash.value); BOOST_ASSERT(lighthash.mixhash == fullhash.mixhash); - // checks operator== for egihash::result_t + // checks operator== for nrghash::result_t BOOST_ASSERT(lighthash == fullhash); } @@ -404,11 +405,11 @@ BOOST_AUTO_TEST_CASE(light_hash_vs_full_hash_comparison) BOOST_AUTO_TEST_CASE(dag_cache) { using namespace std; - using namespace egihash; + using namespace nrghash; - BOOST_REQUIRE_MESSAGE(boost::filesystem::exists("data/egihash.dag"), "DAG file not generated yet. Please re-run test case."); + BOOST_REQUIRE_MESSAGE(boost::filesystem::exists("data/nrghash.dag"), "DAG file not generated yet. Please re-run test case."); - dag_t d1("data/egihash.dag", dag_progress); + dag_t d1("data/nrghash.dag", dag_progress); bool success = true; auto already_loaded = [&success](::std::size_t /*step*/, ::std::size_t /*max*/, int /*phase*/) -> bool @@ -419,7 +420,7 @@ BOOST_AUTO_TEST_CASE(dag_cache) }; // ensure we don't try to load a DAG again when it is already loaded - dag_t d2("data/egihash.dag", already_loaded); + dag_t d2("data/nrghash.dag", already_loaded); try { BOOST_REQUIRE_MESSAGE(success, "Attempt to re-load already loaded DAG - should be retrieved from DAG cache"); @@ -443,7 +444,7 @@ BOOST_AUTO_TEST_CASE(dag_cache) }; try { - dag_t d3("data/egihash.dag", not_loaded); + dag_t d3("data/nrghash.dag", not_loaded); BOOST_REQUIRE_MESSAGE(success, "Unloaded DAG was not re-loaded correctly"); } catch (hash_exception const &) @@ -459,7 +460,7 @@ BOOST_AUTO_TEST_CASE(dag_cache) BOOST_AUTO_TEST_CASE(cache_cache) { using namespace std; - using namespace egihash; + using namespace nrghash; cache_t c1(0, dag_progress);