/* This Work is under GPL provided with this work. This work is based on the java implementation of the Kademlia protocol. Kademlia: Peer-to-peer routing based on the XOR metric Copyright (C) 2002 Petar Maymounkov [petar@post.harvard.edu] http://kademlia.scs.cs.nyu.edu and This work is bassed on translation from Barry Dunne to C++ Copyright (C)2003 Barry Dunne (http://www.emule-project.net) */ #ifndef cHash_h #define cHash_h unsigned getBit (const uint8_t *HASH, unsigned bit); void xor_128 (uint8_t *a,const uint8_t *b); void add_128 (uint8_t *a,const uint8_t *b); void shiftLeft (uint8_t *a, size_t bits); void setBitNumber (uint8_t *value, size_t bit, uint8_t shift); void random (uint8_t *value, size_t numBits); extern const uint8_t null[16]; extern const uint8_t eins[16]; extern const uint8_t acht[16]; class cHash { public: uint8_t hash[16]; cHash() { bzero(hash, 16); } cHash (const class cHash &b) { memcpy(hash, b.hash, 16); } cHash(const uint8_t *KEY) { memcpy(hash, KEY, 16); } void operator = (const class cHash &B) { memcpy(hash, B. hash, 16); } bool operator < (const class cHash &B) const { return 0> memcmp(hash, B.hash, 16); } bool operator > (const class cHash &B) const { return 0< memcmp(hash, B.hash, 16); } bool operator <= (const class cHash &B) const { return 0>=memcmp(hash, B.hash, 16); } bool operator >= (const class cHash &B) const { return 0<=memcmp(hash, B.hash, 16); } bool operator == (const class cHash &B) const { return 0==memcmp(hash, B.hash, 16); } bool operator != (const class cHash &B) const { return 0!=memcmp(hash, B.hash, 16); } }; #endif