diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-20 11:04:58 -0400 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-20 11:04:58 -0400 |
commit | 3c5c3280ff9712ca25b243d8c84a4f849fe164d8 (patch) | |
tree | e497f184a3207589b76034d0e2448b3cb8ad0b6c /node | |
parent | 8c9b73f67b786d9c08ffc98cc4b0f9b7c44b7717 (diff) | |
download | infinitytier-3c5c3280ff9712ca25b243d8c84a4f849fe164d8.tar.gz infinitytier-3c5c3280ff9712ca25b243d8c84a4f849fe164d8.zip |
Fix an endian-non-neutrality bug in new hashcash identity algo.
Diffstat (limited to 'node')
-rw-r--r-- | node/Identity.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/node/Identity.cpp b/node/Identity.cpp index d50c56fe..0c7c13df 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -66,12 +66,13 @@ static inline void _computeMemoryHardHash(const void *publicKey,unsigned int pub // Do something to genmem[] that iteratively makes every value // possibly dependent on every other value with a nontrivial - // probability. + // probability. Continue to use already-initialized Salsa20 as + // a random source. for(unsigned int i=0;i<ZT_IDENTITY_GEN_MEMORY;i+=ZT_IDENTITY_GEN_MEMORY_MIX_STEP) { - s20.encrypt((char *)genmem + i,(char *)genmem + i,8); - uint64_t x = *((uint64_t *)((char *)genmem + i)); - if ((x / 7ULL) < 0x1249249249249249ULL) { - s20.encrypt(&x,&x,8); // also causes PRNG state to depend on genmem[]'s state + s20.encrypt((char *)genmem + i,(char *)genmem + i,64); + uint64_t x = Utils::ntoh(*((uint64_t *)((char *)genmem + i))); + if (!(x & 3)) { + s20.encrypt((char *)genmem + i,(char *)genmem + i,64); // also makes future salsa20 state content-dependent for(unsigned int k=0;k<8;++k,x>>=8) ++((unsigned char *)genmem)[(uintptr_t)x % ZT_IDENTITY_GEN_MEMORY]; } else { @@ -135,7 +136,7 @@ bool Identity::locallyValidate() const unsigned char addrb[5]; _address.copyTo(addrb,5); - + return ( (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN)&& (digest[59] == addrb[0])&& |