summaryrefslogtreecommitdiff
path: root/node/Identity.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-05 07:00:55 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2013-10-05 07:00:55 -0400
commit0e43e5e8f2eddd5768873350d12103f2684bedbf (patch)
treee4c49274cd6b1c717366514348ee5ba73b1b1a1c /node/Identity.cpp
parentb0187f44720fb675b99e6b6e57b660c6dfe8e464 (diff)
downloadinfinitytier-0e43e5e8f2eddd5768873350d12103f2684bedbf.tar.gz
infinitytier-0e43e5e8f2eddd5768873350d12103f2684bedbf.zip
Rest of work on new hashcash based identity scheme.
Diffstat (limited to 'node/Identity.cpp')
-rw-r--r--node/Identity.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/node/Identity.cpp b/node/Identity.cpp
index e897a42c..7ef83ade 100644
--- a/node/Identity.cpp
+++ b/node/Identity.cpp
@@ -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