Rest of work on new hashcash based identity scheme.

This commit is contained in:
Adam Ierymenko 2013-10-05 07:00:55 -04:00
parent b0187f4472
commit 0e43e5e8f2
6 changed files with 41 additions and 177 deletions

View file

@ -36,6 +36,8 @@
#include "Salsa20.hpp"
#include "Utils.hpp"
#define ZT_IDENTITY_SHA_BYTE1_MASK 0xf8
namespace ZeroTier {
/*
@ -51,7 +53,7 @@ struct _Identity_generate_cond
{
SHA512::hash(sha512buf,kp.pub.data,kp.pub.size());
if ((!sha512buf[0])&&(!(sha512buf[1] & 0xf0)))
if ((!sha512buf[0])&&(!(sha512buf[1] & ZT_IDENTITY_SHA_BYTE1_MASK)))
return true;
return false;
@ -76,9 +78,20 @@ void Identity::generate()
*_privateKey = kp.priv;
}
bool Identity::locallyValidate(bool doAddressDerivationCheck) const
bool Identity::locallyValidate() const
{
return true;
char sha512buf[64];
char addrb[5];
_address.copyTo(addrb,5);
SHA512::hash(sha512buf,_publicKey.data,_publicKey.size());
return (
(!sha512buf[0])&&
(!(sha512buf[1] & ZT_IDENTITY_SHA_BYTE1_MASK))&&
(sha512buf[59] == addrb[0])&&
(sha512buf[60] == addrb[1])&&
(sha512buf[61] == addrb[2])&&
(sha512buf[62] == addrb[3])&&
(sha512buf[63] == addrb[4]));
}
std::string Identity::toString(bool includePrivate) const