Fix an endian-non-neutrality bug in new hashcash identity algo.

This commit is contained in:
Adam Ierymenko 2013-10-20 11:04:58 -04:00
parent 8c9b73f67b
commit 3c5c3280ff
2 changed files with 9 additions and 8 deletions

View File

@ -66,12 +66,13 @@ static inline void _computeMemoryHardHash(const void *publicKey,unsigned int pub
// Do something to genmem[] that iteratively makes every value // Do something to genmem[] that iteratively makes every value
// possibly dependent on every other value with a nontrivial // 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) { 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); s20.encrypt((char *)genmem + i,(char *)genmem + i,64);
uint64_t x = *((uint64_t *)((char *)genmem + i)); uint64_t x = Utils::ntoh(*((uint64_t *)((char *)genmem + i)));
if ((x / 7ULL) < 0x1249249249249249ULL) { if (!(x & 3)) {
s20.encrypt(&x,&x,8); // also causes PRNG state to depend on genmem[]'s state 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) for(unsigned int k=0;k<8;++k,x>>=8)
++((unsigned char *)genmem)[(uintptr_t)x % ZT_IDENTITY_GEN_MEMORY]; ++((unsigned char *)genmem)[(uintptr_t)x % ZT_IDENTITY_GEN_MEMORY];
} else { } else {

View File

@ -3,8 +3,8 @@
#ifndef _ZT_SELFTEST_CRYPTO_VECTORS_H #ifndef _ZT_SELFTEST_CRYPTO_VECTORS_H
#define _ZT_SELFTEST_CRYPTO_VECTORS_H #define _ZT_SELFTEST_CRYPTO_VECTORS_H
#define KNOWN_GOOD_IDENTITY "d83ac37b39:0:2641645e99286cba657f46c6c1556e266110177c159741bc0c45a5ed419d9d759e254c928e09275630a4c655d2e42e98394550cb14538bed3f4fdee20f1c6263:3b534f4707c160ac03432f7d5419b9a73abbe76b2f6f68e41918024c4be0cbc407db232eae79c432ee3ac2bce93d77303ac8ffcf07d5c7e9f27a8876ff84d438" #define KNOWN_GOOD_IDENTITY "70c4e2c0df:0:65317c885f0ee89e5442f6d7b8a1e46d5abc0b0384c5d5a8e39a24b26900df302f8843063bbadd030ac77637aae908bad24a7b1bd78d9e71c6a11eadfc5b3ac7:241d41bf21916813b5048eb948561c15fcda055af8927810af32aa96288505e9ce78aa2737d99dc30e413d067315122703ff315c18c71561e9d3dfd62221d3d3"
#define KNOWN_BAD_IDENTITY "d83ac37b3a:0:2641645e99286cba657f46c6c1556e266110177c159741bc0c45a5ed419d9d759e254c928e09275630a4c655d2e42e98394550cb14538bed3f4fdee20f1c6263:3b534f4707c160ac03432f7d5419b9a73abbe76b2f6f68e41918024c4be0cbc407db232eae79c432ee3ac2bce93d77303ac8ffcf07d5c7e9f27a8876ff84d438" #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 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 }; static const unsigned char s20TV0Iv[8] = { 0x28,0x8f,0xf6,0x5d,0xc4,0x2b,0x92,0xf9 };