diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-09-17 16:49:16 -0400 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-09-17 16:49:16 -0400 |
commit | 5ccc91a7c3c0c41a2b4e5e7d4ccc279b71ab8641 (patch) | |
tree | cfa2177d7a3aa7b7cb242173d567d955857dbbc4 /node | |
parent | 157aba5c3f86d1e385e01a415f081891a0fa12f5 (diff) | |
download | infinitytier-5ccc91a7c3c0c41a2b4e5e7d4ccc279b71ab8641.tar.gz infinitytier-5ccc91a7c3c0c41a2b4e5e7d4ccc279b71ab8641.zip |
Prescient endian-ness fix in deriveAddress.
Diffstat (limited to 'node')
-rw-r--r-- | node/Identity.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/node/Identity.cpp b/node/Identity.cpp index 161ec659..93d5024b 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -30,6 +30,7 @@ #include <string.h> #include <stdint.h> +#include "Constants.hpp" #include "Identity.hpp" #include "SHA512.hpp" #include "Salsa20.hpp" @@ -160,7 +161,31 @@ Address Identity::deriveAddress(const void *keyBytes,unsigned int keyLen) uint64_t nonce = 0; for(unsigned int r=0;r<ZT_IDENTITY_DERIVEADDRESS_ROUNDS;++r) { nonce = Utils::crc64(nonce,ram,ZT_IDENTITY_DERIVEADDRESS_MEMORY); +#if __BYTE_ORDER == __BIG_ENDIAN + nonce = ( // swap to little endian -- this was written for a LE system + ((nonce & 0x00000000000000FFULL) << 56) | + ((nonce & 0x000000000000FF00ULL) << 40) | + ((nonce & 0x0000000000FF0000ULL) << 24) | + ((nonce & 0x00000000FF000000ULL) << 8) | + ((nonce & 0x000000FF00000000ULL) >> 8) | + ((nonce & 0x0000FF0000000000ULL) >> 24) | + ((nonce & 0x00FF000000000000ULL) >> 40) | + ((nonce & 0xFF00000000000000ULL) >> 56) + ); +#endif Salsa20 s20(salsaKey,256,&nonce); +#if __BYTE_ORDER == __BIG_ENDIAN + nonce = ( // swap back to big endian + ((nonce & 0x00000000000000FFULL) << 56) | + ((nonce & 0x000000000000FF00ULL) << 40) | + ((nonce & 0x0000000000FF0000ULL) << 24) | + ((nonce & 0x00000000FF000000ULL) << 8) | + ((nonce & 0x000000FF00000000ULL) >> 8) | + ((nonce & 0x0000FF0000000000ULL) >> 24) | + ((nonce & 0x00FF000000000000ULL) >> 40) | + ((nonce & 0xFF00000000000000ULL) >> 56) + ); +#endif s20.encrypt(ram,ram,ZT_IDENTITY_DERIVEADDRESS_MEMORY); } |