From c74d09a7cda32e6ab39111d5bf023d4854770505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 29 Apr 2015 14:14:08 +0200 Subject: [PATCH 1/3] Optimize Keccak implementation and remove Crypto++ dependency --- CMakeLists.txt | 4 - cryptopp/CMakeLists.txt | 13 --- src/benchmark/benchmark.cpp | 11 +-- src/libethash/CMakeLists.txt | 14 +-- src/libethash/internal.c | 29 +++--- src/libethash/keccak.cpp | 116 ++++++++++++++++++++++++ src/libethash/keccak.h | 23 +++++ src/libethash/sha3.c | 151 -------------------------------- src/libethash/sha3.h | 31 ------- src/libethash/sha3_cryptopp.cpp | 37 -------- src/libethash/sha3_cryptopp.h | 19 ---- test/c/test.cpp | 13 +-- 12 files changed, 157 insertions(+), 304 deletions(-) delete mode 100644 cryptopp/CMakeLists.txt create mode 100644 src/libethash/keccak.cpp create mode 100644 src/libethash/keccak.h delete mode 100644 src/libethash/sha3.c delete mode 100644 src/libethash/sha3.h delete mode 100644 src/libethash/sha3_cryptopp.cpp delete mode 100644 src/libethash/sha3_cryptopp.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ea8c1849..f90195d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,6 @@ project(ethash) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") set(ETHHASH_LIBS ethash) -if (WIN32 AND WANT_CRYPTOPP) - add_subdirectory(cryptopp) -endif() - add_subdirectory(src/libethash) # bin2h.cmake doesn't work if (NOT OpenCL_FOUND) diff --git a/cryptopp/CMakeLists.txt b/cryptopp/CMakeLists.txt deleted file mode 100644 index 6f428053..00000000 --- a/cryptopp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(LIBRARY cryptopp) - -include_directories(../../cryptopp) - -# todo, subset -file(GLOB HEADERS "../../cryptopp/*.h") -file(GLOB SOURCE "../../cryptopp/*.cpp") - -add_library(${LIBRARY} ${HEADERS} ${SOURCE}) - -set(CRYPTOPP_INCLUDE_DIRS "../.." "../../../" PARENT_SCOPE) -set(CRYPTOPP_LIBRARIES ${LIBRARY} PARENT_SCOPE) -set(CRYPTOPP_FOUND TRUE PARENT_SCOPE) diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 1a648edf..839795e0 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -29,14 +29,7 @@ #endif #include #include - -#ifdef WITH_CRYPTOPP -#include -#include - -#else -#include "libethash/sha3.h" -#endif // WITH_CRYPTOPP +#include #undef min #undef max @@ -135,7 +128,7 @@ extern "C" int main(void) auto time = std::chrono::duration_cast(high_resolution_clock::now() - startTime).count(); ethash_h256_t cache_hash; - SHA3_256(&cache_hash, (uint8_t const*)cache_mem, params.cache_size); + keccak256(&cache_hash, (uint8_t const*)cache_mem, params.cache_size); debugf("ethash_mkcache: %ums, sha3: %s\n", (unsigned)((time*1000)/CLOCKS_PER_SEC), bytesToHexString(&cache_hash, sizeof(cache_hash)).data()); // print a couple of test hashes diff --git a/src/libethash/CMakeLists.txt b/src/libethash/CMakeLists.txt index 4875dcf7..778dd30e 100644 --- a/src/libethash/CMakeLists.txt +++ b/src/libethash/CMakeLists.txt @@ -8,9 +8,11 @@ set(CMAKE_BUILD_TYPE Release) if (NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() set(FILES util.h + keccak.h keccak.cpp io.c internal.c ethash.h @@ -25,18 +27,6 @@ else() list(APPEND FILES io_posix.c) endif() -if (NOT CRYPTOPP_FOUND) - find_package(CryptoPP 5.6.2) -endif() - -if (CRYPTOPP_FOUND) - add_definitions(-DWITH_CRYPTOPP) - include_directories( ${CRYPTOPP_INCLUDE_DIRS} ) - list(APPEND FILES sha3_cryptopp.cpp sha3_cryptopp.h) -else() - list(APPEND FILES sha3.c sha3.h) -endif() - add_library(${LIBRARY} ${FILES}) if (CRYPTOPP_FOUND) diff --git a/src/libethash/internal.c b/src/libethash/internal.c index 02967913..b69c9643 100644 --- a/src/libethash/internal.c +++ b/src/libethash/internal.c @@ -32,14 +32,7 @@ #include "internal.h" #include "data_sizes.h" #include "io.h" - -#ifdef WITH_CRYPTOPP - -#include "sha3_cryptopp.h" - -#else -#include "sha3.h" -#endif // WITH_CRYPTOPP +#include "keccak.h" uint64_t ethash_get_datasize(uint32_t const block_number) { @@ -67,10 +60,10 @@ bool static ethash_compute_cache_nodes( } uint32_t const num_nodes = (uint32_t) (params->cache_size / sizeof(node)); - SHA3_512(nodes[0].bytes, (uint8_t*)seed, 32); + keccak512(nodes[0].bytes, (uint8_t*)seed, 32); for (unsigned i = 1; i != num_nodes; ++i) { - SHA3_512(nodes[i].bytes, nodes[i - 1].bytes, 64); + keccak512(nodes[i].bytes, nodes[i - 1].bytes, 64); } for (unsigned j = 0; j != ETHASH_CACHE_ROUNDS; j++) { @@ -81,7 +74,7 @@ bool static ethash_compute_cache_nodes( for (unsigned w = 0; w != NODE_WORDS; ++w) { data.words[w] ^= nodes[idx].words[w]; } - SHA3_512(nodes[i].bytes, data.bytes, sizeof(data)); + keccak512(nodes[i].bytes, data.bytes, sizeof(data)); } } @@ -133,7 +126,7 @@ void ethash_calculate_dag_item( node const* init = &cache_nodes[node_index % num_parent_nodes]; memcpy(ret, init, sizeof(node)); ret->words[0] ^= node_index; - SHA3_512(ret->bytes, ret->bytes, sizeof(node)); + keccak512(ret->bytes, ret->bytes, sizeof(node)); #if defined(_M_X64) && ENABLE_SSE __m128i const fnv_prime = _mm_set1_epi32(FNV_PRIME); __m128i xmm0 = ret->xmm[0]; @@ -171,7 +164,7 @@ void ethash_calculate_dag_item( } #endif } - SHA3_512(ret->bytes, ret->bytes, sizeof(node)); + keccak512(ret->bytes, ret->bytes, sizeof(node)); } bool ethash_compute_full_data( @@ -213,7 +206,7 @@ static bool ethash_hash( fix_endian64(s_mix[0].double_words[4], nonce); // compute sha3-512 hash and replicate across mix - SHA3_512(s_mix->bytes, s_mix->bytes, 40); + keccak512(s_mix->bytes, s_mix->bytes, 40); fix_endian_arr32(s_mix[0].words, 16); node* const mix = s_mix + 1; @@ -279,7 +272,7 @@ static bool ethash_hash( fix_endian_arr32(mix->words, MIX_WORDS / 4); memcpy(&ret->mix_hash, mix->bytes, 32); // final Keccak hash - SHA3_256(&ret->result, s_mix->bytes, 64 + 32); // Keccak-256(s + compressed_mix) + keccak256(&ret->result, s_mix->bytes, 64 + 32); // Keccak-256(s + compressed_mix) return true; } @@ -294,9 +287,9 @@ void ethash_quick_hash( memcpy(buf, header_hash, 32); fix_endian64_same(nonce); memcpy(&(buf[32]), &nonce, 8); - SHA3_512(buf, buf, 40); + keccak512(buf, buf, 40); memcpy(&(buf[64]), mix_hash, 32); - SHA3_256(return_hash, buf, 64 + 32); + keccak256(return_hash, buf, 64 + 32); } void ethash_get_seedhash(ethash_h256_t* seedhash, const uint32_t block_number) @@ -304,7 +297,7 @@ void ethash_get_seedhash(ethash_h256_t* seedhash, const uint32_t block_number) ethash_h256_reset(seedhash); const uint32_t epochs = block_number / ETHASH_EPOCH_LENGTH; for (uint32_t i = 0; i < epochs; ++i) - SHA3_256(seedhash, (uint8_t*)seedhash, 32); + keccak256(seedhash, (uint8_t*)seedhash, 32); } int ethash_quick_check_difficulty( diff --git a/src/libethash/keccak.cpp b/src/libethash/keccak.cpp new file mode 100644 index 00000000..29c0c351 --- /dev/null +++ b/src/libethash/keccak.cpp @@ -0,0 +1,116 @@ +#include "keccak.h" + +#include + +namespace +{ + uint8_t const rho[] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 }; + uint8_t const pi[] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 }; + uint64_t const RC[] = { 1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, + 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, + 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, + 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, + 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, + 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; + + inline uint64_t rot(uint64_t x, uint64_t s) { return x << s | x >> (64 - s); } + + #define REPEAT6(e) e e e e e e + #define REPEAT24(e) REPEAT6(e e e e) + #define REPEAT5(e) e e e e e + #define FOR5(v, s, e) v = 0; REPEAT5(e; v += s;) + + /// Keccak-f[1600] + inline void keccakf1600(uint64_t* a) noexcept + { + uint64_t b[5] = {0}; + uint64_t t = 0; + uint8_t x, y; + + for (size_t i = 0; i < 24; ++i) + { + // Round[1600](a,RC): + // theta step: + FOR5(x, 1, + b[x] = 0; + FOR5(y, 5, + b[x] ^= a[x + y]; )) + FOR5(x, 1, + FOR5(y, 5, + a[y + x] ^= b[(x + 4) % 5] ^ rot(b[(x + 1) % 5], 1); )) + + // rho and pi steps + t = a[1]; + x = 0; + REPEAT24(b[0] = a[pi[x]]; + a[pi[x]] = rot(t, rho[x]); + t = b[0]; + x++; ) + // chi step + FOR5(y, + 5, + FOR5(x, 1, + b[x] = a[y + x];) + FOR5(x, 1, + a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) + // iota step + a[0] ^= RC[i]; + } + } + + inline void xorin(uint64_t* dst, const uint64_t* src, size_t size) + { + for (size_t i = 0; i < size; ++i) + dst[i] ^= src[i]; + } + + inline void keccak(uint64_t* out, size_t outSize, const uint64_t* data, size_t size) + { + static const size_t stateSize = 200; + const auto r = stateSize - (2 * outSize); // 256: 136, 512: 72 + uint64_t a[stateSize / 8] = {0}; + // Absorb input. + while (size >= r) + { + xorin(a, data, r / 8); + keccakf1600(a); + data += r / 8; + size -= r; + } + // Xor in the DS and pad frame. + a[size / 8] ^= 0x01; // 0x01: Keccak, 0x06: SHA3 + a[(r - 1) / 8] ^= 0x8000000000000000; + // Xor in the last block. + xorin(a, data, size / 8); + keccakf1600(a); + std::memcpy(out, a, outSize); // TODO: How about using out as a state + } +} + +extern "C" +{ + +void keccak256(ethash_h256_t* out, uint8_t const* data, size_t size) +{ + // FIXME: What with unaligned memory? + keccak((uint64_t*)out, 32, (uint64_t*)data, size); +} + +void keccak512(uint8_t* out, uint8_t const* data, size_t size) +{ + keccak((uint64_t*)out, 64, (uint64_t*)data, size); +} + +void keccak256_96(ethash_h256_t* out, uint8_t const* data) +{ + keccak((uint64_t*)out, 32, (uint64_t*)data, 96 / 8); +} + +void keccak512_40(uint8_t* out, uint8_t const* data) +{ + keccak((uint64_t*)out, 64, (uint64_t*)data, 40 / 8); +} + +} // extern "C" diff --git a/src/libethash/keccak.h b/src/libethash/keccak.h new file mode 100644 index 00000000..16890b04 --- /dev/null +++ b/src/libethash/keccak.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +struct ethash_h256; +typedef struct ethash_h256 ethash_h256_t; + +#ifdef __cplusplus +extern "C" { +#endif + +void keccak256(ethash_h256_t* out, uint8_t const* data, size_t size); + +void keccak512(uint8_t* out, uint8_t const* data, size_t size); + +void keccak256_96(ethash_h256_t* out, uint8_t const* data); + +void keccak512_40(uint8_t* out, uint8_t const* data); + +#ifdef __cplusplus +} +#endif diff --git a/src/libethash/sha3.c b/src/libethash/sha3.c deleted file mode 100644 index e72fe101..00000000 --- a/src/libethash/sha3.c +++ /dev/null @@ -1,151 +0,0 @@ -/** libkeccak-tiny -* -* A single-file implementation of SHA-3 and SHAKE. -* -* Implementor: David Leon Gil -* License: CC0, attribution kindly requested. Blame taken too, -* but not liability. -*/ -#include "sha3.h" - -#include -#include -#include -#include - -/******** The Keccak-f[1600] permutation ********/ - -/*** Constants. ***/ -static const uint8_t rho[24] = \ - { 1, 3, 6, 10, 15, 21, - 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, - 62, 18, 39, 61, 20, 44}; -static const uint8_t pi[24] = \ - {10, 7, 11, 17, 18, 3, - 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, - 20, 14, 22, 9, 6, 1}; -static const uint64_t RC[24] = \ - {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, - 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, - 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, - 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, - 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, - 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; - -/*** Helper macros to unroll the permutation. ***/ -#define rol(x, s) (((x) << s) | ((x) >> (64 - s))) -#define REPEAT6(e) e e e e e e -#define REPEAT24(e) REPEAT6(e e e e) -#define REPEAT5(e) e e e e e -#define FOR5(v, s, e) \ - v = 0; \ - REPEAT5(e; v += s;) - -/*** Keccak-f[1600] ***/ -static inline void keccakf(void* state) { - uint64_t* a = (uint64_t*)state; - uint64_t b[5] = {0}; - uint64_t t = 0; - uint8_t x, y; - - for (int i = 0; i < 24; i++) { - // Theta - FOR5(x, 1, - b[x] = 0; - FOR5(y, 5, - b[x] ^= a[x + y]; )) - FOR5(x, 1, - FOR5(y, 5, - a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) - // Rho and pi - t = a[1]; - x = 0; - REPEAT24(b[0] = a[pi[x]]; - a[pi[x]] = rol(t, rho[x]); - t = b[0]; - x++; ) - // Chi - FOR5(y, - 5, - FOR5(x, 1, - b[x] = a[y + x];) - FOR5(x, 1, - a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) - // Iota - a[0] ^= RC[i]; - } -} - -/******** The FIPS202-defined functions. ********/ - -/*** Some helper macros. ***/ - -#define _(S) do { S } while (0) -#define FOR(i, ST, L, S) \ - _(for (size_t i = 0; i < L; i += ST) { S; }) -#define mkapply_ds(NAME, S) \ - static inline void NAME(uint8_t* dst, \ - const uint8_t* src, \ - size_t len) { \ - FOR(i, 1, len, S); \ - } -#define mkapply_sd(NAME, S) \ - static inline void NAME(const uint8_t* src, \ - uint8_t* dst, \ - size_t len) { \ - FOR(i, 1, len, S); \ - } - -mkapply_ds(xorin, dst[i] ^= src[i]) // xorin -mkapply_sd(setout, dst[i] = src[i]) // setout - -#define P keccakf -#define Plen 200 - -// Fold P*F over the full blocks of an input. -#define foldP(I, L, F) \ - while (L >= rate) { \ - F(a, I, rate); \ - P(a); \ - I += rate; \ - L -= rate; \ - } - -/** The sponge-based hash construction. **/ -static inline int hash(uint8_t* out, size_t outlen, - const uint8_t* in, size_t inlen, - size_t rate, uint8_t delim) { - if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) { - return -1; - } - uint8_t a[Plen] = {0}; - // Absorb input. - foldP(in, inlen, xorin); - // Xor in the DS and pad frame. - a[inlen] ^= delim; - a[rate - 1] ^= 0x80; - // Xor in the last block. - xorin(a, in, inlen); - // Apply P - P(a); - // Squeeze output. - foldP(out, outlen, setout); - setout(a, out, outlen); - memset(a, 0, 200); - return 0; -} - -#define defsha3(bits) \ - int sha3_##bits(uint8_t* out, size_t outlen, \ - const uint8_t* in, size_t inlen) { \ - if (outlen > (bits/8)) { \ - return -1; \ - } \ - return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ - } - -/*** FIPS202 SHA3 FOFs ***/ -defsha3(256) -defsha3(512) diff --git a/src/libethash/sha3.h b/src/libethash/sha3.h deleted file mode 100644 index a3800629..00000000 --- a/src/libethash/sha3.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "compiler.h" -#include -#include - -struct ethash_h256; - -#define decsha3(bits) \ - int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t); - -decsha3(256) -decsha3(512) - -static inline void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size) -{ - sha3_256((uint8_t*)ret, 32, data, size); -} - -static inline void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size) -{ - sha3_512(ret, 64, data, size); -} - -#ifdef __cplusplus -} -#endif diff --git a/src/libethash/sha3_cryptopp.cpp b/src/libethash/sha3_cryptopp.cpp deleted file mode 100644 index 2a7c0266..00000000 --- a/src/libethash/sha3_cryptopp.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - This file is part of ethash. - - ethash 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. - - ethash 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 ethash. If not, see . -*/ - -/** @file sha3.cpp -* @author Tim Hughes -* @date 2015 -*/ -#include -#include - -extern "C" { -struct ethash_h256; -typedef struct ethash_h256 ethash_h256_t; -void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size) -{ - CryptoPP::SHA3_256().CalculateDigest((uint8_t*)ret, data, size); -} - -void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size) -{ - CryptoPP::SHA3_512().CalculateDigest(ret, data, size); -} -} diff --git a/src/libethash/sha3_cryptopp.h b/src/libethash/sha3_cryptopp.h deleted file mode 100644 index cc81f285..00000000 --- a/src/libethash/sha3_cryptopp.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "compiler.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct ethash_h256; -typedef struct ethash_h256 ethash_h256_t; - -void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size); -void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size); - -#ifdef __cplusplus -} -#endif diff --git a/test/c/test.cpp b/test/c/test.cpp index 9eb0e90c..02524fdc 100644 --- a/test/c/test.cpp +++ b/test/c/test.cpp @@ -3,14 +3,7 @@ #include #include #include - -#ifdef WITH_CRYPTOPP - -#include - -#else -#include -#endif // WITH_CRYPTOPP +#include #define BOOST_TEST_MODULE Daggerhashimoto #define BOOST_TEST_MAIN @@ -59,7 +52,7 @@ BOOST_AUTO_TEST_CASE(SHA256_check) { ethash_h256_t input; ethash_h256_t out; memcpy(&input, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", 32); - SHA3_256(&out, (uint8_t*)&input, 32); + keccak256(&out, (uint8_t*)&input, 32); const std::string expected = "2b5ddf6f4d21c23de216f44d5e4bdc68e044b71897837ea74c83908be7037cd7", actual = bytesToHexString((uint8_t*)&out, 32); @@ -71,7 +64,7 @@ BOOST_AUTO_TEST_CASE(SHA256_check) { BOOST_AUTO_TEST_CASE(SHA512_check) { uint8_t input[64], out[64]; memcpy(input, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", 64); - SHA3_512(out, input, 64); + keccak512(out, input, 64); const std::string expected = "0be8a1d334b4655fe58c6b38789f984bb13225684e86b20517a55ab2386c7b61c306f25e0627c60064cecd6d80cd67a82b3890bd1289b7ceb473aad56a359405", actual = bytesToHexString(out, 64); From 5b288002d7ca5f80c3f455c0de31499e6a823b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 29 Apr 2015 16:12:45 +0200 Subject: [PATCH 2/3] Python extension & MSVC fixes --- MANIFEST.in | 6 +++--- setup.py | 6 +++--- src/libethash/keccak.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 74e73c8b..941cdb45 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,8 +1,8 @@ include setup.py -# C sources +# C/C++ sources include src/libethash/internal.c -include src/libethash/sha3.c +include src/libethash/keccak.cpp include src/libethash/util.c include src/python/core.c @@ -13,5 +13,5 @@ include src/libethash/endian.h include src/libethash/ethash.h include src/libethash/fnv.h include src/libethash/internal.h -include src/libethash/sha3.h +include src/libethash/keccak.h include src/libethash/util.h diff --git a/setup.py b/setup.py index bfe95596..3ff937e9 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ 'src/python/core.c', 'src/libethash/io.c', 'src/libethash/internal.c', - 'src/libethash/sha3.c'] + 'src/libethash/keccak.cpp'] if os.name == 'nt': sources += [ 'src/libethash/util.c', @@ -25,13 +25,13 @@ 'src/libethash/io.h', 'src/libethash/fnv.h', 'src/libethash/internal.h', - 'src/libethash/sha3.h', + 'src/libethash/keccak.h', 'src/libethash/util.h', ] pyethash = Extension('pyethash', sources=sources, depends=depends, - extra_compile_args=["-Isrc/", "-std=gnu99", "-Wall"]) + extra_compile_args=["-Isrc/", "-std=gnu99", "-std=c++11", "-Wall"]) setup( name='pyethash', diff --git a/src/libethash/keccak.cpp b/src/libethash/keccak.cpp index 29c0c351..2f43bf21 100644 --- a/src/libethash/keccak.cpp +++ b/src/libethash/keccak.cpp @@ -23,7 +23,7 @@ namespace #define FOR5(v, s, e) v = 0; REPEAT5(e; v += s;) /// Keccak-f[1600] - inline void keccakf1600(uint64_t* a) noexcept + inline void keccakf1600(uint64_t* a) { uint64_t b[5] = {0}; uint64_t t = 0; From 1f1f24963e9084d0b0aeae99e03e03635148efcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 29 Apr 2015 16:30:31 +0200 Subject: [PATCH 3/3] State initial implementation of Keccak by @coruus. --- src/libethash/keccak.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libethash/keccak.cpp b/src/libethash/keccak.cpp index 2f43bf21..0f052308 100644 --- a/src/libethash/keccak.cpp +++ b/src/libethash/keccak.cpp @@ -1,3 +1,8 @@ + +/* + Core Keccack implementation devided from https://github.com/coruus/keccak-tiny by David Leon Gil +*/ + #include "keccak.h" #include