|
@@ -37,29 +37,29 @@ void identityV0ProofOfWorkFrankenhash(const void *const publicKey, unsigned int
|
|
|
// Initialize genmem[] using Salsa20 in a CBC-like configuration since
|
|
|
// ordinary Salsa20 is randomly seek-able. This is good for a cipher
|
|
|
// but is not what we want for sequential memory-hardness.
|
|
|
- Utils::zero<ZT_V0_IDENTITY_GEN_MEMORY>(genmem);
|
|
|
- Salsa20 s20(digest, (char *) digest + 32);
|
|
|
- s20.crypt20((char *) genmem, (char *) genmem, 64);
|
|
|
- for (unsigned long i = 64;i < ZT_V0_IDENTITY_GEN_MEMORY;i += 64) {
|
|
|
+ Utils::zero< ZT_V0_IDENTITY_GEN_MEMORY >(genmem);
|
|
|
+ Salsa20 s20(digest, (char *)digest + 32);
|
|
|
+ s20.crypt20((char *)genmem, (char *)genmem, 64);
|
|
|
+ for (unsigned long i = 64; i < ZT_V0_IDENTITY_GEN_MEMORY; i += 64) {
|
|
|
unsigned long k = i - 64;
|
|
|
- *((uint64_t * )((char *) genmem + i)) = *((uint64_t * )((char *) genmem + k));
|
|
|
- *((uint64_t * )((char *) genmem + i + 8)) = *((uint64_t * )((char *) genmem + k + 8));
|
|
|
- *((uint64_t * )((char *) genmem + i + 16)) = *((uint64_t * )((char *) genmem + k + 16));
|
|
|
- *((uint64_t * )((char *) genmem + i + 24)) = *((uint64_t * )((char *) genmem + k + 24));
|
|
|
- *((uint64_t * )((char *) genmem + i + 32)) = *((uint64_t * )((char *) genmem + k + 32));
|
|
|
- *((uint64_t * )((char *) genmem + i + 40)) = *((uint64_t * )((char *) genmem + k + 40));
|
|
|
- *((uint64_t * )((char *) genmem + i + 48)) = *((uint64_t * )((char *) genmem + k + 48));
|
|
|
- *((uint64_t * )((char *) genmem + i + 56)) = *((uint64_t * )((char *) genmem + k + 56));
|
|
|
- s20.crypt20((char *) genmem + i, (char *) genmem + i, 64);
|
|
|
+ *((uint64_t *)((char *)genmem + i)) = *((uint64_t *)((char *)genmem + k));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 8)) = *((uint64_t *)((char *)genmem + k + 8));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 16)) = *((uint64_t *)((char *)genmem + k + 16));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 24)) = *((uint64_t *)((char *)genmem + k + 24));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 32)) = *((uint64_t *)((char *)genmem + k + 32));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 40)) = *((uint64_t *)((char *)genmem + k + 40));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 48)) = *((uint64_t *)((char *)genmem + k + 48));
|
|
|
+ *((uint64_t *)((char *)genmem + i + 56)) = *((uint64_t *)((char *)genmem + k + 56));
|
|
|
+ s20.crypt20((char *)genmem + i, (char *)genmem + i, 64);
|
|
|
}
|
|
|
|
|
|
// Render final digest using genmem as a lookup table
|
|
|
- for (unsigned long i = 0;i < (ZT_V0_IDENTITY_GEN_MEMORY / sizeof(uint64_t));) {
|
|
|
- unsigned long idx1 = (unsigned long) (Utils::ntoh(((uint64_t *) genmem)[i++]) % (64 / sizeof(uint64_t))); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
- unsigned long idx2 = (unsigned long) (Utils::ntoh(((uint64_t *) genmem)[i++]) % (ZT_V0_IDENTITY_GEN_MEMORY / sizeof(uint64_t))); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
- uint64_t tmp = ((uint64_t *) genmem)[idx2];
|
|
|
- ((uint64_t *) genmem)[idx2] = ((uint64_t *) digest)[idx1];
|
|
|
- ((uint64_t *) digest)[idx1] = tmp;
|
|
|
+ for (unsigned long i = 0; i < (ZT_V0_IDENTITY_GEN_MEMORY / sizeof(uint64_t));) {
|
|
|
+ unsigned long idx1 = (unsigned long)(Utils::ntoh(((uint64_t *)genmem)[i++]) % (64 / sizeof(uint64_t))); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
+ unsigned long idx2 = (unsigned long)(Utils::ntoh(((uint64_t *)genmem)[i++]) % (ZT_V0_IDENTITY_GEN_MEMORY / sizeof(uint64_t))); // NOLINT(hicpp-use-auto,modernize-use-auto)
|
|
|
+ uint64_t tmp = ((uint64_t *)genmem)[idx2];
|
|
|
+ ((uint64_t *)genmem)[idx2] = ((uint64_t *)digest)[idx1];
|
|
|
+ ((uint64_t *)digest)[idx1] = tmp;
|
|
|
s20.crypt20(digest, digest, 64);
|
|
|
}
|
|
|
}
|
|
@@ -86,7 +86,9 @@ struct p_CompareLittleEndian
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
ZT_INLINE bool operator()(const uint64_t a,const uint64_t b) const noexcept { return Utils::swapBytes(a) < Utils::swapBytes(b); }
|
|
|
#else
|
|
|
- ZT_INLINE bool operator()(const uint64_t a,const uint64_t b) const noexcept { return a < b; }
|
|
|
+ ZT_INLINE bool operator()(const uint64_t a, const uint64_t b) const noexcept
|
|
|
+ { return a < b; }
|
|
|
+
|
|
|
#endif
|
|
|
};
|
|
|
|
|
@@ -100,7 +102,7 @@ bool identityV1ProofOfWorkCriteria(const void *in, const unsigned int len)
|
|
|
// executing all branches and then selecting the answer, which means this
|
|
|
// construction should require a GPU to do ~3X the work of a CPU per iteration.
|
|
|
SHA512(w, in, len);
|
|
|
- for (unsigned int i = 8, j = 0;i < (ZT_IDENTITY_V1_POW_MEMORY_SIZE / 8);) {
|
|
|
+ for (unsigned int i = 8, j = 0; i < (ZT_IDENTITY_V1_POW_MEMORY_SIZE / 8);) {
|
|
|
uint64_t *const ww = w + i;
|
|
|
const uint64_t *const wp = w + j;
|
|
|
i += 8;
|
|
@@ -159,7 +161,8 @@ bool Identity::generate(const Type t)
|
|
|
delete[] genmem;
|
|
|
m_fp.address = address; // address comes from PoW hash for type 0 identities
|
|
|
m_computeHash();
|
|
|
- } break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
case P384: {
|
|
|
for (;;) {
|
|
@@ -185,7 +188,8 @@ bool Identity::generate(const Type t)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- } break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
default:
|
|
|
return false;
|
|
@@ -201,7 +205,7 @@ bool Identity::locallyValidate() const noexcept
|
|
|
switch (m_type) {
|
|
|
case C25519: {
|
|
|
uint8_t digest[64];
|
|
|
- char *const genmem = (char *) malloc(ZT_V0_IDENTITY_GEN_MEMORY);
|
|
|
+ char *const genmem = (char *)malloc(ZT_V0_IDENTITY_GEN_MEMORY);
|
|
|
if (!genmem)
|
|
|
return false;
|
|
|
identityV0ProofOfWorkFrankenhash(m_pub, ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, digest, genmem);
|
|
@@ -225,14 +229,13 @@ void Identity::hashWithPrivate(uint8_t h[ZT_FINGERPRINT_HASH_SIZE]) const
|
|
|
switch (m_type) {
|
|
|
case C25519:
|
|
|
SHA384(h, m_pub, ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, m_priv, ZT_C25519_COMBINED_PRIVATE_KEY_SIZE);
|
|
|
- break;
|
|
|
+ return;
|
|
|
case P384:
|
|
|
SHA384(h, m_pub, sizeof(m_pub), m_priv, sizeof(m_priv));
|
|
|
- break;
|
|
|
+ return;
|
|
|
}
|
|
|
- return;
|
|
|
}
|
|
|
- Utils::zero<48>(h);
|
|
|
+ Utils::zero< ZT_FINGERPRINT_HASH_SIZE >(h);
|
|
|
}
|
|
|
|
|
|
unsigned int Identity::sign(const void *data, unsigned int len, void *sig, unsigned int siglen) const
|
|
@@ -250,7 +253,7 @@ unsigned int Identity::sign(const void *data, unsigned int len, void *sig, unsig
|
|
|
static_assert(ZT_ECC384_SIGNATURE_HASH_SIZE == ZT_SHA384_DIGEST_SIZE, "weird!");
|
|
|
uint8_t h[ZT_ECC384_SIGNATURE_HASH_SIZE];
|
|
|
SHA384(h, data, len, m_pub, ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE);
|
|
|
- ECC384ECDSASign(m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE, h, (uint8_t *) sig);
|
|
|
+ ECC384ECDSASign(m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE, h, (uint8_t *)sig);
|
|
|
return ZT_ECC384_SIGNATURE_SIZE;
|
|
|
}
|
|
|
}
|
|
@@ -267,7 +270,7 @@ bool Identity::verify(const void *data, unsigned int len, const void *sig, unsig
|
|
|
if (siglen == ZT_ECC384_SIGNATURE_SIZE) {
|
|
|
uint8_t h[ZT_ECC384_SIGNATURE_HASH_SIZE];
|
|
|
SHA384(h, data, len, m_pub, ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE);
|
|
|
- return ECC384ECDSAVerify(m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, h, (const uint8_t *) sig);
|
|
|
+ return ECC384ECDSAVerify(m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, h, (const uint8_t *)sig);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -276,37 +279,25 @@ bool Identity::verify(const void *data, unsigned int len, const void *sig, unsig
|
|
|
|
|
|
bool Identity::agree(const Identity &id, uint8_t key[ZT_SYMMETRIC_KEY_SIZE]) const
|
|
|
{
|
|
|
- uint8_t rawkey[128];
|
|
|
- uint8_t h[64];
|
|
|
- if (m_hasPrivate) {
|
|
|
- if (m_type == C25519) {
|
|
|
- if ((id.m_type == C25519) || (id.m_type == P384)) {
|
|
|
- // If we are a C25519 key we can agree with another C25519 key or with only the
|
|
|
- // C25519 portion of a type 1 P-384 key.
|
|
|
- C25519::agree(m_priv, id.m_pub, rawkey);
|
|
|
- SHA512(h, rawkey, ZT_C25519_ECDH_SHARED_SECRET_SIZE);
|
|
|
- Utils::copy<ZT_SYMMETRIC_KEY_SIZE>(key, h);
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else if (m_type == P384) {
|
|
|
- if (id.m_type == P384) {
|
|
|
- // For another P384 identity we execute DH agreement with BOTH keys and then
|
|
|
- // hash the results together. For those (cough FIPS cough) who only consider
|
|
|
- // P384 to be kosher, the C25519 secret can be considered a "salt"
|
|
|
- // or something. For those who don't trust P384 this means the privacy of
|
|
|
- // your traffic is also protected by C25519.
|
|
|
- C25519::agree(m_priv, id.m_pub, rawkey);
|
|
|
- ECC384ECDH(id.m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE, rawkey + ZT_C25519_ECDH_SHARED_SECRET_SIZE);
|
|
|
- SHA384(h, rawkey, ZT_C25519_ECDH_SHARED_SECRET_SIZE + ZT_ECC384_SHARED_SECRET_SIZE);
|
|
|
- Utils::copy<ZT_SYMMETRIC_KEY_SIZE>(key, h);
|
|
|
- return true;
|
|
|
- } else if (id.m_type == C25519) {
|
|
|
- // If the other identity is a C25519 identity we can agree using only that type.
|
|
|
- C25519::agree(m_priv, id.m_pub, rawkey);
|
|
|
- SHA512(h, rawkey, ZT_C25519_ECDH_SHARED_SECRET_SIZE);
|
|
|
- Utils::copy<ZT_SYMMETRIC_KEY_SIZE>(key, h);
|
|
|
- return true;
|
|
|
- }
|
|
|
+ uint8_t rawkey[128], h[64];
|
|
|
+ if (likely(m_hasPrivate)) {
|
|
|
+ if ((m_type == C25519) || (id.m_type == C25519)) {
|
|
|
+ // If we are a C25519 key we can agree with another C25519 key or with only the
|
|
|
+ // C25519 portion of a type 1 P-384 key.
|
|
|
+ C25519::agree(m_priv, id.m_pub, rawkey);
|
|
|
+ SHA512(h, rawkey, ZT_C25519_ECDH_SHARED_SECRET_SIZE);
|
|
|
+ Utils::copy< ZT_SYMMETRIC_KEY_SIZE >(key, h);
|
|
|
+ return true;
|
|
|
+ } else if ((m_type == P384) && (id.m_type == P384)) {
|
|
|
+ // For another P384 identity we execute DH agreement with BOTH keys and then
|
|
|
+ // hash the results together. For those (cough FIPS cough) who only consider
|
|
|
+ // P384 to be kosher, the C25519 secret can be considered a "salt"
|
|
|
+ // or something. For those who don't trust P384 this means the privacy of
|
|
|
+ // your traffic is also protected by C25519.
|
|
|
+ C25519::agree(m_priv, id.m_pub, rawkey);
|
|
|
+ ECC384ECDH(id.m_pub + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE, m_priv + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE, rawkey + ZT_C25519_ECDH_SHARED_SECRET_SIZE);
|
|
|
+ SHA384(key, rawkey, ZT_C25519_ECDH_SHARED_SECRET_SIZE + ZT_ECC384_SHARED_SECRET_SIZE);
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
@@ -330,22 +321,22 @@ char *Identity::toString(bool includePrivate, char buf[ZT_IDENTITY_STRING_BUFFER
|
|
|
Utils::hex(m_priv, ZT_C25519_COMBINED_PRIVATE_KEY_SIZE, p);
|
|
|
p += ZT_C25519_COMBINED_PRIVATE_KEY_SIZE * 2;
|
|
|
}
|
|
|
- *p = (char) 0;
|
|
|
+ *p = (char)0;
|
|
|
return buf;
|
|
|
}
|
|
|
case P384: {
|
|
|
*(p++) = '1';
|
|
|
*(p++) = ':';
|
|
|
- int el = Utils::b32e(m_pub, sizeof(m_pub), p, (int) (ZT_IDENTITY_STRING_BUFFER_LENGTH - (uintptr_t) (p - buf)));
|
|
|
+ int el = Utils::b32e(m_pub, sizeof(m_pub), p, (int)(ZT_IDENTITY_STRING_BUFFER_LENGTH - (uintptr_t)(p - buf)));
|
|
|
if (el <= 0) return nullptr;
|
|
|
p += el;
|
|
|
if ((m_hasPrivate) && (includePrivate)) {
|
|
|
*(p++) = ':';
|
|
|
- el = Utils::b32e(m_priv, sizeof(m_priv), p, (int) (ZT_IDENTITY_STRING_BUFFER_LENGTH - (uintptr_t) (p - buf)));
|
|
|
+ el = Utils::b32e(m_priv, sizeof(m_priv), p, (int)(ZT_IDENTITY_STRING_BUFFER_LENGTH - (uintptr_t)(p - buf)));
|
|
|
if (el <= 0) return nullptr;
|
|
|
p += el;
|
|
|
}
|
|
|
- *p = (char) 0;
|
|
|
+ *p = (char)0;
|
|
|
return buf;
|
|
|
}
|
|
|
}
|
|
@@ -362,7 +353,7 @@ bool Identity::fromString(const char *str)
|
|
|
|
|
|
int fno = 0;
|
|
|
char *saveptr = nullptr;
|
|
|
- for (char *f = Utils::stok(tmp, ":", &saveptr);((f) && (fno < 4));f = Utils::stok(nullptr, ":", &saveptr)) {
|
|
|
+ for (char *f = Utils::stok(tmp, ":", &saveptr); ((f) && (fno < 4)); f = Utils::stok(nullptr, ":", &saveptr)) {
|
|
|
switch (fno++) {
|
|
|
|
|
|
case 0:
|
|
@@ -437,11 +428,11 @@ int Identity::marshal(uint8_t data[ZT_IDENTITY_MARSHAL_SIZE_MAX], const bool inc
|
|
|
switch (m_type) {
|
|
|
|
|
|
case C25519:
|
|
|
- data[ZT_ADDRESS_LENGTH] = (uint8_t) C25519;
|
|
|
- Utils::copy<ZT_C25519_COMBINED_PUBLIC_KEY_SIZE>(data + ZT_ADDRESS_LENGTH + 1, m_pub);
|
|
|
+ data[ZT_ADDRESS_LENGTH] = (uint8_t)C25519;
|
|
|
+ Utils::copy< ZT_C25519_COMBINED_PUBLIC_KEY_SIZE >(data + ZT_ADDRESS_LENGTH + 1, m_pub);
|
|
|
if ((includePrivate) && (m_hasPrivate)) {
|
|
|
data[ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE] = ZT_C25519_COMBINED_PRIVATE_KEY_SIZE;
|
|
|
- Utils::copy<ZT_C25519_COMBINED_PRIVATE_KEY_SIZE>(data + ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1, m_priv);
|
|
|
+ Utils::copy< ZT_C25519_COMBINED_PRIVATE_KEY_SIZE >(data + ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1, m_priv);
|
|
|
return ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1 + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE;
|
|
|
} else {
|
|
|
data[ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE] = 0;
|
|
@@ -449,11 +440,11 @@ int Identity::marshal(uint8_t data[ZT_IDENTITY_MARSHAL_SIZE_MAX], const bool inc
|
|
|
}
|
|
|
|
|
|
case P384:
|
|
|
- data[ZT_ADDRESS_LENGTH] = (uint8_t) P384;
|
|
|
- Utils::copy<ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE>(data + ZT_ADDRESS_LENGTH + 1, m_pub);
|
|
|
+ data[ZT_ADDRESS_LENGTH] = (uint8_t)P384;
|
|
|
+ Utils::copy< ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE >(data + ZT_ADDRESS_LENGTH + 1, m_pub);
|
|
|
if ((includePrivate) && (m_hasPrivate)) {
|
|
|
data[ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE] = ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE;
|
|
|
- Utils::copy<ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE>(data + ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1, m_priv);
|
|
|
+ Utils::copy< ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE >(data + ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1, m_priv);
|
|
|
return ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1 + ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE;
|
|
|
} else {
|
|
|
data[ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE] = 0;
|
|
@@ -473,13 +464,13 @@ int Identity::unmarshal(const uint8_t *data, const int len) noexcept
|
|
|
m_fp.address = Address(data);
|
|
|
|
|
|
unsigned int privlen;
|
|
|
- switch ((m_type = (Type) data[ZT_ADDRESS_LENGTH])) {
|
|
|
+ switch ((m_type = (Type)data[ZT_ADDRESS_LENGTH])) {
|
|
|
|
|
|
case C25519:
|
|
|
if (len < (ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1))
|
|
|
return -1;
|
|
|
|
|
|
- Utils::copy<ZT_C25519_COMBINED_PUBLIC_KEY_SIZE>(m_pub, data + ZT_ADDRESS_LENGTH + 1);
|
|
|
+ Utils::copy< ZT_C25519_COMBINED_PUBLIC_KEY_SIZE >(m_pub, data + ZT_ADDRESS_LENGTH + 1);
|
|
|
m_computeHash();
|
|
|
|
|
|
privlen = data[ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE];
|
|
@@ -487,7 +478,7 @@ int Identity::unmarshal(const uint8_t *data, const int len) noexcept
|
|
|
if (len < (ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1 + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE))
|
|
|
return -1;
|
|
|
m_hasPrivate = true;
|
|
|
- Utils::copy<ZT_C25519_COMBINED_PRIVATE_KEY_SIZE>(m_priv, data + ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1);
|
|
|
+ Utils::copy< ZT_C25519_COMBINED_PRIVATE_KEY_SIZE >(m_priv, data + ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1);
|
|
|
return ZT_ADDRESS_LENGTH + 1 + ZT_C25519_COMBINED_PUBLIC_KEY_SIZE + 1 + ZT_C25519_COMBINED_PRIVATE_KEY_SIZE;
|
|
|
} else if (privlen == 0) {
|
|
|
m_hasPrivate = false;
|
|
@@ -499,7 +490,7 @@ int Identity::unmarshal(const uint8_t *data, const int len) noexcept
|
|
|
if (len < (ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1))
|
|
|
return -1;
|
|
|
|
|
|
- Utils::copy<ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE>(m_pub, data + ZT_ADDRESS_LENGTH + 1);
|
|
|
+ Utils::copy< ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE >(m_pub, data + ZT_ADDRESS_LENGTH + 1);
|
|
|
m_computeHash(); // this sets the address for P384
|
|
|
if (Address(m_fp.hash) != m_fp.address) // this sanity check is possible with V1 identities
|
|
|
return -1;
|
|
@@ -509,7 +500,7 @@ int Identity::unmarshal(const uint8_t *data, const int len) noexcept
|
|
|
if (len < (ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1 + ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE))
|
|
|
return -1;
|
|
|
m_hasPrivate = true;
|
|
|
- Utils::copy<ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE>(&m_priv, data + ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1);
|
|
|
+ Utils::copy< ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE >(&m_priv, data + ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1);
|
|
|
return ZT_ADDRESS_LENGTH + 1 + ZT_IDENTITY_P384_COMPOUND_PUBLIC_KEY_SIZE + 1 + ZT_IDENTITY_P384_COMPOUND_PRIVATE_KEY_SIZE;
|
|
|
} else if (privlen == 0) {
|
|
|
m_hasPrivate = false;
|
|
@@ -547,7 +538,7 @@ ZT_Identity *ZT_Identity_new(enum ZT_IdentityType type)
|
|
|
return nullptr;
|
|
|
try {
|
|
|
ZeroTier::Identity *const id = new ZeroTier::Identity();
|
|
|
- id->generate((ZeroTier::Identity::Type) type);
|
|
|
+ id->generate((ZeroTier::Identity::Type)type);
|
|
|
return reinterpret_cast<ZT_Identity *>(id);
|
|
|
} catch (...) {
|
|
|
return nullptr;
|
|
@@ -596,8 +587,8 @@ int ZT_Identity_verify(const ZT_Identity *id, const void *data, unsigned int len
|
|
|
enum ZT_IdentityType ZT_Identity_type(const ZT_Identity *id)
|
|
|
{
|
|
|
if (!id)
|
|
|
- return (ZT_IdentityType) 0;
|
|
|
- return (enum ZT_IdentityType) reinterpret_cast<const ZeroTier::Identity *>(id)->type();
|
|
|
+ return (ZT_IdentityType)0;
|
|
|
+ return (enum ZT_IdentityType)reinterpret_cast<const ZeroTier::Identity *>(id)->type();
|
|
|
}
|
|
|
|
|
|
char *ZT_Identity_toString(const ZT_Identity *id, char *buf, int capacity, int includePrivate)
|