Remove the assumption that n/(k+1) is a multiple of 8.

This version works, but generates the initial rows in a way that is not what we
want to specify. See #1175 for resolving this.

Co-author: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Jack Grigg
2016-08-06 02:34:07 +12:00
parent 6609813753
commit 036dcbd94a
2 changed files with 44 additions and 23 deletions

View File

@@ -38,7 +38,8 @@ protected:
unsigned char hash[WIDTH];
public:
StepRow(unsigned int n, const eh_HashState& base_state, eh_index i);
StepRow(const eh_HashState& base_state, eh_index i,
size_t hLen, size_t cBitLen, size_t cByteLen);
~StepRow() { }
template<size_t W>
@@ -75,7 +76,8 @@ class FullStepRow : public StepRow<WIDTH>
using StepRow<WIDTH>::hash;
public:
FullStepRow(unsigned int n, const eh_HashState& base_state, eh_index i);
FullStepRow(const eh_HashState& base_state, eh_index i,
size_t hLen, size_t cBitLen, size_t cByteLen);
~FullStepRow() { }
FullStepRow(const FullStepRow<WIDTH>& a) : StepRow<WIDTH> {a} { }
@@ -99,7 +101,9 @@ class TruncatedStepRow : public StepRow<WIDTH>
using StepRow<WIDTH>::hash;
public:
TruncatedStepRow(unsigned int n, const eh_HashState& base_state, eh_index i, unsigned int ilen);
TruncatedStepRow(const eh_HashState& base_state, eh_index i,
size_t hLen, size_t cBitLen, size_t cByteLen,
unsigned int ilen);
~TruncatedStepRow() { }
TruncatedStepRow(const TruncatedStepRow<WIDTH>& a) : StepRow<WIDTH> {a} { }
@@ -141,16 +145,16 @@ class Equihash
private:
BOOST_STATIC_ASSERT(K < N);
BOOST_STATIC_ASSERT(N % 8 == 0);
BOOST_STATIC_ASSERT((N/(K+1)) % 8 == 0);
BOOST_STATIC_ASSERT((N/(K+1)) + 1 < 8*sizeof(eh_index));
public:
enum { CollisionBitLength=N/(K+1) };
enum { CollisionByteLength=CollisionBitLength/8 };
enum : size_t { CollisionByteLength=(CollisionBitLength+7)/8 };
enum : size_t { HashLength=(K+1)*CollisionByteLength };
enum : size_t { FullWidth=2*CollisionByteLength+sizeof(eh_index)*(1 << (K-1)) };
enum : size_t { FinalFullWidth=2*CollisionByteLength+sizeof(eh_index)*(1 << (K)) };
enum : size_t { TruncatedWidth=max((N/8)+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K-1))) };
enum : size_t { FinalTruncatedWidth=max((N/8)+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K))) };
enum : size_t { TruncatedWidth=max(HashLength+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K-1))) };
enum : size_t { FinalTruncatedWidth=max(HashLength+sizeof(eh_trunc), 2*CollisionByteLength+sizeof(eh_trunc)*(1 << (K))) };
Equihash() { }