summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-20 11:04:58 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-20 11:04:58 -0400
commit3c5c3280ff9712ca25b243d8c84a4f849fe164d8 (patch)
treee497f184a3207589b76034d0e2448b3cb8ad0b6c
parent8c9b73f67b786d9c08ffc98cc4b0f9b7c44b7717 (diff)
downloadinfinitytier-3c5c3280ff9712ca25b243d8c84a4f849fe164d8.tar.gz
infinitytier-3c5c3280ff9712ca25b243d8c84a4f849fe164d8.zip
Fix an endian-non-neutrality bug in new hashcash identity algo.
-rw-r--r--node/Identity.cpp13
-rw-r--r--selftest-crypto-vectors.hpp4
2 files changed, 9 insertions, 8 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])&&
diff --git a/selftest-crypto-vectors.hpp b/selftest-crypto-vectors.hpp
index 8e07e36a..d828d224 100644
--- a/selftest-crypto-vectors.hpp
+++ b/selftest-crypto-vectors.hpp
@@ -3,8 +3,8 @@
#ifndef _ZT_SELFTEST_CRYPTO_VECTORS_H
#define _ZT_SELFTEST_CRYPTO_VECTORS_H
-#define KNOWN_GOOD_IDENTITY "d83ac37b39:0:2641645e99286cba657f46c6c1556e266110177c159741bc0c45a5ed419d9d759e254c928e09275630a4c655d2e42e98394550cb14538bed3f4fdee20f1c6263:3b534f4707c160ac03432f7d5419b9a73abbe76b2f6f68e41918024c4be0cbc407db232eae79c432ee3ac2bce93d77303ac8ffcf07d5c7e9f27a8876ff84d438"
-#define KNOWN_BAD_IDENTITY "d83ac37b3a:0:2641645e99286cba657f46c6c1556e266110177c159741bc0c45a5ed419d9d759e254c928e09275630a4c655d2e42e98394550cb14538bed3f4fdee20f1c6263:3b534f4707c160ac03432f7d5419b9a73abbe76b2f6f68e41918024c4be0cbc407db232eae79c432ee3ac2bce93d77303ac8ffcf07d5c7e9f27a8876ff84d438"
+#define KNOWN_GOOD_IDENTITY "70c4e2c0df:0:65317c885f0ee89e5442f6d7b8a1e46d5abc0b0384c5d5a8e39a24b26900df302f8843063bbadd030ac77637aae908bad24a7b1bd78d9e71c6a11eadfc5b3ac7:241d41bf21916813b5048eb948561c15fcda055af8927810af32aa96288505e9ce78aa2737d99dc30e413d067315122703ff315c18c71561e9d3dfd62221d3d3"
+#define KNOWN_BAD_IDENTITY "71c4e2c0df:0:65317c885f0ee89e5442f6d7b8a1e46d5abc0b0384c5d5a8e39a24b26900df302f8843063bbadd030ac77637aae908bad24a7b1bd78d9e71c6a11eadfc5b3ac7:241d41bf21916813b5048eb948561c15fcda055af8927810af32aa96288505e9ce78aa2737d99dc30e413d067315122703ff315c18c71561e9d3dfd62221d3d3"
static const unsigned char s20TV0Key[32] = { 0x0f,0x62,0xb5,0x08,0x5b,0xae,0x01,0x54,0xa7,0xfa,0x4d,0xa0,0xf3,0x46,0x99,0xec,0x3f,0x92,0xe5,0x38,0x8b,0xde,0x31,0x84,0xd7,0x2a,0x7d,0xd0,0x23,0x76,0xc9,0x1c };
static const unsigned char s20TV0Iv[8] = { 0x28,0x8f,0xf6,0x5d,0xc4,0x2b,0x92,0xf9 };