From bad043729f44d0c64986657a333da097eba2f9e7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sun, 20 Oct 2013 15:31:32 -0400 Subject: Yet another revision of this algo... yeesh... and update to supernode IDs. I think I am gonna go with this one. Seems memory-hard enough to me. I am probably procrastinating by obsessing over it. --- node/Identity.cpp | 58 ++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'node/Identity.cpp') diff --git a/node/Identity.cpp b/node/Identity.cpp index 0c7c13df..a180c2ba 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -39,16 +39,8 @@ // These can't be changed without a new identity type. They define the // parameters of the hashcash hashing/searching algorithm. -// Hashcash halting criteria #define ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN 7 - -// Amount of memory for memory-hardness -#define ZT_IDENTITY_GEN_MEMORY 8388608 - -// Step distance for mixing genmem[] -#define ZT_IDENTITY_GEN_MEMORY_MIX_STEP 1024 - -// Rounds used for Salsa20 step +#define ZT_IDENTITY_GEN_MEMORY 4194304 #define ZT_IDENTITY_GEN_SALSA20_ROUNDS 20 namespace ZeroTier { @@ -56,37 +48,37 @@ namespace ZeroTier { // A memory-hard composition of SHA-512 and Salsa20 for hashcash hashing static inline void _computeMemoryHardHash(const void *publicKey,unsigned int publicKeyBytes,void *digest,void *genmem) { - // Hash publicKey[] to obtain Salsa20 key + // Digest publicKey[] to obtain initial digest SHA512::hash(digest,publicKey,publicKeyBytes); - // Generate genmem[] bytes of Salsa20 key stream + // Initialize genmem[] using Salsa20 in a CBC-like configuration since + // ordinary Salsa20 is randomly seekable. This is good for a cipher + // but is not what we want for sequential memory-harndess. memset(genmem,0,ZT_IDENTITY_GEN_MEMORY); Salsa20 s20(digest,256,(char *)digest + 32,ZT_IDENTITY_GEN_SALSA20_ROUNDS); - s20.encrypt(genmem,genmem,ZT_IDENTITY_GEN_MEMORY); - - // Do something to genmem[] that iteratively makes every value - // possibly dependent on every other value with a nontrivial - // probability. Continue to use already-initialized Salsa20 as - // a random source. - for(unsigned int i=0;i>=8) - ++((unsigned char *)genmem)[(uintptr_t)x % ZT_IDENTITY_GEN_MEMORY]; - } else { - for(unsigned int k=0;k<8;++k,x>>=8) - --((unsigned char *)genmem)[(uintptr_t)x % ZT_IDENTITY_GEN_MEMORY]; - } } - // Mix in publicKey[] again, ensuring all entropy is used - for(unsigned int i=0;i