mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 13:33:07 +00:00
Rename C25519.* to ECC.*
This commit is contained in:
parent
7647c8e8d1
commit
307befa892
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
#include <node/Constants.hpp>
|
#include <node/Constants.hpp>
|
||||||
#include <node/World.hpp>
|
#include <node/World.hpp>
|
||||||
#include <node/C25519.hpp>
|
#include <node/ECC.hpp>
|
||||||
#include <node/Identity.hpp>
|
#include <node/Identity.hpp>
|
||||||
#include <node/InetAddress.hpp>
|
#include <node/InetAddress.hpp>
|
||||||
#include <osdep/OSUtils.hpp>
|
#include <osdep/OSUtils.hpp>
|
||||||
@ -54,7 +54,7 @@ int main(int argc,char **argv)
|
|||||||
{
|
{
|
||||||
std::string previous,current;
|
std::string previous,current;
|
||||||
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
||||||
C25519::Pair np(C25519::generate());
|
ECC::Pair np(ECC::generate());
|
||||||
previous = std::string();
|
previous = std::string();
|
||||||
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
@ -68,10 +68,10 @@ int main(int argc,char **argv)
|
|||||||
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
|
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid" ZT_EOL_S);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
C25519::Pair previousKP;
|
ECC::Pair previousKP;
|
||||||
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
C25519::Pair currentKP;
|
ECC::Pair currentKP;
|
||||||
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ int crypto_sign(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPublic,const void *msg,unsigned int len,void *signature)
|
void ECC::sign(const ECC::Private &myPrivate,const ECC::Public &myPublic,const void *msg,unsigned int len,void *signature)
|
||||||
{
|
{
|
||||||
sc25519 sck, scs, scsk;
|
sc25519 sck, scs, scsk;
|
||||||
ge25519 ger;
|
ge25519 ger;
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Credential.hpp"
|
#include "Credential.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
@ -496,7 +496,7 @@ private:
|
|||||||
struct {
|
struct {
|
||||||
Address to;
|
Address to;
|
||||||
Address from;
|
Address from;
|
||||||
C25519::Signature signature;
|
ECC::Signature signature;
|
||||||
} _custody[ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH];
|
} _custody[ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
/****/
|
/****/
|
||||||
|
|
||||||
#include "CertificateOfMembership.hpp"
|
#include "CertificateOfMembership.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "RuntimeEnvironment.hpp"
|
#include "RuntimeEnvironment.hpp"
|
||||||
#include "Topology.hpp"
|
#include "Topology.hpp"
|
||||||
#include "Switch.hpp"
|
#include "Switch.hpp"
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "Credential.hpp"
|
#include "Credential.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ private:
|
|||||||
Address _signedBy;
|
Address _signedBy;
|
||||||
_Qualifier _qualifiers[ZT_NETWORK_COM_MAX_QUALIFIERS];
|
_Qualifier _qualifiers[ZT_NETWORK_COM_MAX_QUALIFIERS];
|
||||||
unsigned int _qualifierCount;
|
unsigned int _qualifierCount;
|
||||||
C25519::Signature _signature;
|
ECC::Signature _signature;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Credential.hpp"
|
#include "Credential.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
@ -243,7 +243,7 @@ private:
|
|||||||
uint8_t _thingValues[ZT_CERTIFICATEOFOWNERSHIP_MAX_THINGS][ZT_CERTIFICATEOFOWNERSHIP_MAX_THING_VALUE_SIZE];
|
uint8_t _thingValues[ZT_CERTIFICATEOFOWNERSHIP_MAX_THINGS][ZT_CERTIFICATEOFOWNERSHIP_MAX_THING_VALUE_SIZE];
|
||||||
Address _issuedTo;
|
Address _issuedTo;
|
||||||
Address _signedBy;
|
Address _signedBy;
|
||||||
C25519::Signature _signature;
|
ECC::Signature _signature;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -12,7 +12,7 @@ Derived from public domain code by D. J. Bernstein.
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "SHA512.hpp"
|
#include "SHA512.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Hashtable.hpp"
|
#include "Hashtable.hpp"
|
||||||
@ -2508,7 +2508,7 @@ extern "C" void ed25519_amd64_asm_sign(const unsigned char *sk,const unsigned ch
|
|||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
void C25519::agree(const C25519::Private &mine,const C25519::Public &their,void *keybuf,unsigned int keylen)
|
void ECC::agree(const ECC::Private &mine,const ECC::Public &their,void *keybuf,unsigned int keylen)
|
||||||
{
|
{
|
||||||
unsigned char rawkey[32];
|
unsigned char rawkey[32];
|
||||||
unsigned char digest[64];
|
unsigned char digest[64];
|
||||||
@ -2524,7 +2524,7 @@ void C25519::agree(const C25519::Private &mine,const C25519::Public &their,void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPublic,const void *msg,unsigned int len,void *signature)
|
void ECC::sign(const ECC::Private &myPrivate,const ECC::Public &myPublic,const void *msg,unsigned int len,void *signature)
|
||||||
{
|
{
|
||||||
unsigned char digest[64]; // we sign the first 32 bytes of SHA-512(msg)
|
unsigned char digest[64]; // we sign the first 32 bytes of SHA-512(msg)
|
||||||
SHA512(digest,msg,len);
|
SHA512(digest,msg,len);
|
||||||
@ -2580,7 +2580,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool C25519::verify(const C25519::Public &their,const void *msg,unsigned int len,const void *signature)
|
bool ECC::verify(const ECC::Public &their,const void *msg,unsigned int len,const void *signature)
|
||||||
{
|
{
|
||||||
const unsigned char *const sig = (const unsigned char *)signature;
|
const unsigned char *const sig = (const unsigned char *)signature;
|
||||||
unsigned char digest[64]; // we sign the first 32 bytes of SHA-512(msg)
|
unsigned char digest[64]; // we sign the first 32 bytes of SHA-512(msg)
|
||||||
@ -2611,14 +2611,14 @@ bool C25519::verify(const C25519::Public &their,const void *msg,unsigned int len
|
|||||||
return Utils::secureEq(sig,t2,32);
|
return Utils::secureEq(sig,t2,32);
|
||||||
}
|
}
|
||||||
|
|
||||||
void C25519::_calcPubDH(C25519::Pair &kp)
|
void ECC::_calcPubDH(ECC::Pair &kp)
|
||||||
{
|
{
|
||||||
// First 32 bytes of pub and priv are the keys for ECDH key
|
// First 32 bytes of pub and priv are the keys for ECDH key
|
||||||
// agreement. This generates the public portion from the private.
|
// agreement. This generates the public portion from the private.
|
||||||
crypto_scalarmult_base(kp.pub.data,kp.priv.data);
|
crypto_scalarmult_base(kp.pub.data,kp.priv.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void C25519::_calcPubED(C25519::Pair &kp)
|
void ECC::_calcPubED(ECC::Pair &kp)
|
||||||
{
|
{
|
||||||
unsigned char extsk[64];
|
unsigned char extsk[64];
|
||||||
sc25519 scsk;
|
sc25519 scsk;
|
@ -11,8 +11,8 @@
|
|||||||
*/
|
*/
|
||||||
/****/
|
/****/
|
||||||
|
|
||||||
#ifndef ZT_C25519_HPP
|
#ifndef ZT_ECC_HPP
|
||||||
#define ZT_C25519_HPP
|
#define ZT_ECC_HPP
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
@ -22,10 +22,7 @@ namespace ZeroTier {
|
|||||||
#define ZT_ECC_PRIVATE_KEY_SET_LEN 64
|
#define ZT_ECC_PRIVATE_KEY_SET_LEN 64
|
||||||
#define ZT_ECC_SIGNATURE_LEN 96
|
#define ZT_ECC_SIGNATURE_LEN 96
|
||||||
|
|
||||||
/**
|
class ECC
|
||||||
* A combined Curve25519 ECDH and Ed25519 signature engine
|
|
||||||
*/
|
|
||||||
class C25519
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Public { uint8_t data[ZT_ECC_PUBLIC_KEY_SET_LEN]; };
|
struct Public { uint8_t data[ZT_ECC_PUBLIC_KEY_SET_LEN]; };
|
||||||
@ -34,7 +31,7 @@ public:
|
|||||||
struct Pair { Public pub; Private priv; };
|
struct Pair { Public pub; Private priv; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a C25519 elliptic curve key pair
|
* Generate an elliptic curve key pair
|
||||||
*/
|
*/
|
||||||
static inline Pair generate()
|
static inline Pair generate()
|
||||||
{
|
{
|
@ -16,7 +16,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "SHA512.hpp"
|
#include "SHA512.hpp"
|
||||||
@ -73,7 +73,7 @@ struct _Identity_generate_cond
|
|||||||
{
|
{
|
||||||
_Identity_generate_cond() {}
|
_Identity_generate_cond() {}
|
||||||
_Identity_generate_cond(unsigned char *sb,char *gm) : digest(sb),genmem(gm) {}
|
_Identity_generate_cond(unsigned char *sb,char *gm) : digest(sb),genmem(gm) {}
|
||||||
inline bool operator()(const C25519::Pair &kp) const
|
inline bool operator()(const ECC::Pair &kp) const
|
||||||
{
|
{
|
||||||
_computeMemoryHardHash(kp.pub.data,ZT_ECC_PUBLIC_KEY_SET_LEN,digest,genmem);
|
_computeMemoryHardHash(kp.pub.data,ZT_ECC_PUBLIC_KEY_SET_LEN,digest,genmem);
|
||||||
return (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN);
|
return (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN);
|
||||||
@ -87,15 +87,15 @@ void Identity::generate()
|
|||||||
unsigned char digest[64];
|
unsigned char digest[64];
|
||||||
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
||||||
|
|
||||||
C25519::Pair kp;
|
ECC::Pair kp;
|
||||||
do {
|
do {
|
||||||
kp = C25519::generateSatisfying(_Identity_generate_cond(digest,genmem));
|
kp = ECC::generateSatisfying(_Identity_generate_cond(digest,genmem));
|
||||||
_address.setTo(digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address
|
_address.setTo(digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address
|
||||||
} while (_address.isReserved());
|
} while (_address.isReserved());
|
||||||
|
|
||||||
_publicKey = kp.pub;
|
_publicKey = kp.pub;
|
||||||
if (!_privateKey) {
|
if (!_privateKey) {
|
||||||
_privateKey = new C25519::Private();
|
_privateKey = new ECC::Private();
|
||||||
}
|
}
|
||||||
*_privateKey = kp.priv;
|
*_privateKey = kp.priv;
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ bool Identity::fromString(const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete _privateKey;
|
delete _privateKey;
|
||||||
_privateKey = (C25519::Private *)0;
|
_privateKey = (ECC::Private *)0;
|
||||||
|
|
||||||
int fno = 0;
|
int fno = 0;
|
||||||
char *saveptr = (char *)0;
|
char *saveptr = (char *)0;
|
||||||
@ -183,7 +183,7 @@ bool Identity::fromString(const char *str)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
_privateKey = new C25519::Private();
|
_privateKey = new ECC::Private();
|
||||||
if (Utils::unhex(f,_privateKey->data,ZT_ECC_PRIVATE_KEY_SET_LEN) != ZT_ECC_PRIVATE_KEY_SET_LEN) {
|
if (Utils::unhex(f,_privateKey->data,ZT_ECC_PRIVATE_KEY_SET_LEN) != ZT_ECC_PRIVATE_KEY_SET_LEN) {
|
||||||
_address.zero();
|
_address.zero();
|
||||||
return false;
|
return false;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "SHA512.hpp"
|
#include "SHA512.hpp"
|
||||||
|
|
||||||
@ -42,19 +42,19 @@ class Identity
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Identity() :
|
Identity() :
|
||||||
_privateKey((C25519::Private *)0)
|
_privateKey((ECC::Private *)0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Identity(const Identity &id) :
|
Identity(const Identity &id) :
|
||||||
_address(id._address),
|
_address(id._address),
|
||||||
_publicKey(id._publicKey),
|
_publicKey(id._publicKey),
|
||||||
_privateKey((id._privateKey) ? new C25519::Private(*(id._privateKey)) : (C25519::Private *)0)
|
_privateKey((id._privateKey) ? new ECC::Private(*(id._privateKey)) : (ECC::Private *)0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Identity(const char *str) :
|
Identity(const char *str) :
|
||||||
_privateKey((C25519::Private *)0)
|
_privateKey((ECC::Private *)0)
|
||||||
{
|
{
|
||||||
if (!fromString(str)) {
|
if (!fromString(str)) {
|
||||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
|
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
|
||||||
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
template<unsigned int C>
|
template<unsigned int C>
|
||||||
Identity(const Buffer<C> &b,unsigned int startAt = 0) :
|
Identity(const Buffer<C> &b,unsigned int startAt = 0) :
|
||||||
_privateKey((C25519::Private *)0)
|
_privateKey((ECC::Private *)0)
|
||||||
{
|
{
|
||||||
deserialize(b,startAt);
|
deserialize(b,startAt);
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public:
|
|||||||
~Identity()
|
~Identity()
|
||||||
{
|
{
|
||||||
if (_privateKey) {
|
if (_privateKey) {
|
||||||
Utils::burn(_privateKey,sizeof(C25519::Private));
|
Utils::burn(_privateKey,sizeof(ECC::Private));
|
||||||
delete _privateKey;
|
delete _privateKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,12 +82,12 @@ public:
|
|||||||
_publicKey = id._publicKey;
|
_publicKey = id._publicKey;
|
||||||
if (id._privateKey) {
|
if (id._privateKey) {
|
||||||
if (!_privateKey) {
|
if (!_privateKey) {
|
||||||
_privateKey = new C25519::Private();
|
_privateKey = new ECC::Private();
|
||||||
}
|
}
|
||||||
*_privateKey = *(id._privateKey);
|
*_privateKey = *(id._privateKey);
|
||||||
} else {
|
} else {
|
||||||
delete _privateKey;
|
delete _privateKey;
|
||||||
_privateKey = (C25519::Private *)0;
|
_privateKey = (ECC::Private *)0;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @return True if this identity contains a private key
|
* @return True if this identity contains a private key
|
||||||
*/
|
*/
|
||||||
inline bool hasPrivate() const { return (_privateKey != (C25519::Private *)0); }
|
inline bool hasPrivate() const { return (_privateKey != (ECC::Private *)0); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute a SHA384 hash of this identity's address and public key(s).
|
* Compute a SHA384 hash of this identity's address and public key(s).
|
||||||
@ -144,10 +144,10 @@ public:
|
|||||||
* @param data Data to sign
|
* @param data Data to sign
|
||||||
* @param len Length of data
|
* @param len Length of data
|
||||||
*/
|
*/
|
||||||
inline C25519::Signature sign(const void *data,unsigned int len) const
|
inline ECC::Signature sign(const void *data,unsigned int len) const
|
||||||
{
|
{
|
||||||
if (_privateKey) {
|
if (_privateKey) {
|
||||||
return C25519::sign(*_privateKey,_publicKey,data,len);
|
return ECC::sign(*_privateKey,_publicKey,data,len);
|
||||||
}
|
}
|
||||||
throw ZT_EXCEPTION_PRIVATE_KEY_REQUIRED;
|
throw ZT_EXCEPTION_PRIVATE_KEY_REQUIRED;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public:
|
|||||||
if (siglen != ZT_ECC_SIGNATURE_LEN) {
|
if (siglen != ZT_ECC_SIGNATURE_LEN) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return C25519::verify(_publicKey,data,len,signature);
|
return ECC::verify(_publicKey,data,len,signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,9 +177,9 @@ public:
|
|||||||
* @param signature Signature
|
* @param signature Signature
|
||||||
* @return True if signature validates and data integrity checks
|
* @return True if signature validates and data integrity checks
|
||||||
*/
|
*/
|
||||||
inline bool verify(const void *data,unsigned int len,const C25519::Signature &signature) const
|
inline bool verify(const void *data,unsigned int len,const ECC::Signature &signature) const
|
||||||
{
|
{
|
||||||
return C25519::verify(_publicKey,data,len,signature);
|
return ECC::verify(_publicKey,data,len,signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,7 +194,7 @@ public:
|
|||||||
inline bool agree(const Identity &id,void *const key) const
|
inline bool agree(const Identity &id,void *const key) const
|
||||||
{
|
{
|
||||||
if (_privateKey) {
|
if (_privateKey) {
|
||||||
C25519::agree(*_privateKey,id._publicKey,key,ZT_SYMMETRIC_KEY_SIZE);
|
ECC::agree(*_privateKey,id._publicKey,key,ZT_SYMMETRIC_KEY_SIZE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -242,7 +242,7 @@ public:
|
|||||||
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
|
||||||
{
|
{
|
||||||
delete _privateKey;
|
delete _privateKey;
|
||||||
_privateKey = (C25519::Private *)0;
|
_privateKey = (ECC::Private *)0;
|
||||||
|
|
||||||
unsigned int p = startAt;
|
unsigned int p = startAt;
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ public:
|
|||||||
if (privateKeyLength != ZT_ECC_PRIVATE_KEY_SET_LEN) {
|
if (privateKeyLength != ZT_ECC_PRIVATE_KEY_SET_LEN) {
|
||||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
|
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
|
||||||
}
|
}
|
||||||
_privateKey = new C25519::Private();
|
_privateKey = new ECC::Private();
|
||||||
memcpy(_privateKey->data,b.field(p,ZT_ECC_PRIVATE_KEY_SET_LEN),ZT_ECC_PRIVATE_KEY_SET_LEN);
|
memcpy(_privateKey->data,b.field(p,ZT_ECC_PRIVATE_KEY_SET_LEN),ZT_ECC_PRIVATE_KEY_SET_LEN);
|
||||||
p += ZT_ECC_PRIVATE_KEY_SET_LEN;
|
p += ZT_ECC_PRIVATE_KEY_SET_LEN;
|
||||||
}
|
}
|
||||||
@ -292,14 +292,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @return C25519 public key
|
* @return C25519 public key
|
||||||
*/
|
*/
|
||||||
inline const C25519::Public &publicKey() const { return _publicKey; }
|
inline const ECC::Public &publicKey() const { return _publicKey; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return C25519 key pair (only returns valid pair if private key is present in this Identity object)
|
* @return C25519 key pair (only returns valid pair if private key is present in this Identity object)
|
||||||
*/
|
*/
|
||||||
inline const C25519::Pair privateKeyPair() const
|
inline const ECC::Pair privateKeyPair() const
|
||||||
{
|
{
|
||||||
C25519::Pair pair;
|
ECC::Pair pair;
|
||||||
pair.pub = _publicKey;
|
pair.pub = _publicKey;
|
||||||
if (_privateKey) {
|
if (_privateKey) {
|
||||||
pair.priv = *_privateKey;
|
pair.priv = *_privateKey;
|
||||||
@ -323,8 +323,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Address _address;
|
Address _address;
|
||||||
C25519::Public _publicKey;
|
ECC::Public _publicKey;
|
||||||
C25519::Private *_privateKey;
|
ECC::Private *_privateKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include "../include/ZeroTierDebug.h"
|
#include "../include/ZeroTierDebug.h"
|
||||||
|
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
#include "Network.hpp"
|
#include "Network.hpp"
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "SharedPtr.hpp"
|
#include "SharedPtr.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
@ -813,7 +813,7 @@ void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &de
|
|||||||
outp.append((uint32_t)totalSize);
|
outp.append((uint32_t)totalSize);
|
||||||
outp.append((uint32_t)chunkIndex);
|
outp.append((uint32_t)chunkIndex);
|
||||||
|
|
||||||
C25519::Signature sig(RR->identity.sign(reinterpret_cast<const uint8_t *>(outp.data()) + sigStart,outp.size() - sigStart));
|
ECC::Signature sig(RR->identity.sign(reinterpret_cast<const uint8_t *>(outp.data()) + sigStart,outp.size() - sigStart));
|
||||||
outp.append((uint8_t)1);
|
outp.append((uint8_t)1);
|
||||||
outp.append((uint16_t)ZT_ECC_SIGNATURE_LEN);
|
outp.append((uint16_t)ZT_ECC_SIGNATURE_LEN);
|
||||||
outp.append(sig.data,ZT_ECC_SIGNATURE_LEN);
|
outp.append(sig.data,ZT_ECC_SIGNATURE_LEN);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "../include/ZeroTierOne.h"
|
#include "../include/ZeroTierOne.h"
|
||||||
#include "Credential.hpp"
|
#include "Credential.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
@ -201,7 +201,7 @@ private:
|
|||||||
Address _target;
|
Address _target;
|
||||||
Address _signedBy;
|
Address _signedBy;
|
||||||
Credential::Type _type;
|
Credential::Type _type;
|
||||||
C25519::Signature _signature;
|
ECC::Signature _signature;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Credential.hpp"
|
#include "Credential.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
#include "Address.hpp"
|
#include "Address.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
@ -207,7 +207,7 @@ private:
|
|||||||
int64_t _ts;
|
int64_t _ts;
|
||||||
Address _issuedTo;
|
Address _issuedTo;
|
||||||
Address _signedBy;
|
Address _signedBy;
|
||||||
C25519::Signature _signature;
|
ECC::Signature _signature;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "InetAddress.hpp"
|
#include "InetAddress.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "Buffer.hpp"
|
#include "Buffer.hpp"
|
||||||
#include "C25519.hpp"
|
#include "ECC.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of roots (sanity limit, okay to increase)
|
* Maximum number of roots (sanity limit, okay to increase)
|
||||||
@ -133,12 +133,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @return C25519 signature
|
* @return C25519 signature
|
||||||
*/
|
*/
|
||||||
inline const C25519::Signature &signature() const { return _signature; }
|
inline const ECC::Signature &signature() const { return _signature; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Public key that must sign next update
|
* @return Public key that must sign next update
|
||||||
*/
|
*/
|
||||||
inline const C25519::Public &updatesMustBeSignedBy() const { return _updatesMustBeSignedBy; }
|
inline const ECC::Public &updatesMustBeSignedBy() const { return _updatesMustBeSignedBy; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a world update should replace this one
|
* Check whether a world update should replace this one
|
||||||
@ -154,7 +154,7 @@ public:
|
|||||||
if ((_id == update._id)&&(_ts < update._ts)&&(_type == update._type)) {
|
if ((_id == update._id)&&(_ts < update._ts)&&(_type == update._type)) {
|
||||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
|
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
|
||||||
update.serialize(tmp,true);
|
update.serialize(tmp,true);
|
||||||
return C25519::verify(_updatesMustBeSignedBy,tmp.data(),tmp.size(),update._signature);
|
return ECC::verify(_updatesMustBeSignedBy,tmp.data(),tmp.size(),update._signature);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ public:
|
|||||||
* @param signWith Key to sign this World with (can have the same public as the next-update signing key, but doesn't have to)
|
* @param signWith Key to sign this World with (can have the same public as the next-update signing key, but doesn't have to)
|
||||||
* @return Signed World object
|
* @return Signed World object
|
||||||
*/
|
*/
|
||||||
static inline World make(World::Type t,uint64_t id,uint64_t ts,const C25519::Public &sk,const std::vector<World::Root> &roots,const C25519::Pair &signWith)
|
static inline World make(World::Type t,uint64_t id,uint64_t ts,const ECC::Public &sk,const std::vector<World::Root> &roots,const ECC::Pair &signWith)
|
||||||
{
|
{
|
||||||
World w;
|
World w;
|
||||||
w._id = id;
|
w._id = id;
|
||||||
@ -273,7 +273,7 @@ public:
|
|||||||
|
|
||||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
|
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
|
||||||
w.serialize(tmp,true);
|
w.serialize(tmp,true);
|
||||||
w._signature = C25519::sign(signWith,tmp.data(),tmp.size());
|
w._signature = ECC::sign(signWith,tmp.data(),tmp.size());
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
@ -282,8 +282,8 @@ protected:
|
|||||||
uint64_t _id;
|
uint64_t _id;
|
||||||
uint64_t _ts;
|
uint64_t _ts;
|
||||||
Type _type;
|
Type _type;
|
||||||
C25519::Public _updatesMustBeSignedBy;
|
ECC::Public _updatesMustBeSignedBy;
|
||||||
C25519::Signature _signature;
|
ECC::Signature _signature;
|
||||||
std::vector<Root> _roots;
|
std::vector<Root> _roots;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ CORE_OBJS=\
|
|||||||
node/AES.o \
|
node/AES.o \
|
||||||
node/AES_aesni.o \
|
node/AES_aesni.o \
|
||||||
node/AES_armcrypto.o \
|
node/AES_armcrypto.o \
|
||||||
node/C25519.o \
|
node/ECC.o \
|
||||||
node/Capability.o \
|
node/Capability.o \
|
||||||
node/CertificateOfMembership.o \
|
node/CertificateOfMembership.o \
|
||||||
node/CertificateOfOwnership.o \
|
node/CertificateOfOwnership.o \
|
||||||
|
10
one.cpp
10
one.cpp
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "node/C25519.hpp"
|
#include "node/ECC.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -1553,7 +1553,7 @@ static int idtool(int argc,char **argv)
|
|||||||
fprintf(stderr,"%s is not readable" ZT_EOL_S,argv[3]);
|
fprintf(stderr,"%s is not readable" ZT_EOL_S,argv[3]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
C25519::Signature signature = id.sign(inf.data(),(unsigned int)inf.length());
|
ECC::Signature signature = id.sign(inf.data(),(unsigned int)inf.length());
|
||||||
char hexbuf[1024];
|
char hexbuf[1024];
|
||||||
printf("%s",Utils::hex(signature.data,ZT_ECC_SIGNATURE_LEN,hexbuf));
|
printf("%s",Utils::hex(signature.data,ZT_ECC_SIGNATURE_LEN,hexbuf));
|
||||||
} else if (!strcmp(argv[1],"verify")) {
|
} else if (!strcmp(argv[1],"verify")) {
|
||||||
@ -1603,7 +1603,7 @@ static int idtool(int argc,char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
C25519::Pair kp(C25519::generate());
|
ECC::Pair kp(ECC::generate());
|
||||||
|
|
||||||
char idtmp[4096];
|
char idtmp[4096];
|
||||||
nlohmann::json mj;
|
nlohmann::json mj;
|
||||||
@ -1647,8 +1647,8 @@ static int idtool(int argc,char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
C25519::Pair signingKey;
|
ECC::Pair signingKey;
|
||||||
C25519::Public updatesMustBeSignedBy;
|
ECC::Public updatesMustBeSignedBy;
|
||||||
Utils::unhex(OSUtils::jsonString(mj["signingKey"],"").c_str(),signingKey.pub.data,ZT_ECC_PUBLIC_KEY_SET_LEN);
|
Utils::unhex(OSUtils::jsonString(mj["signingKey"],"").c_str(),signingKey.pub.data,ZT_ECC_PUBLIC_KEY_SET_LEN);
|
||||||
Utils::unhex(OSUtils::jsonString(mj["signingKey_SECRET"],"").c_str(),signingKey.priv.data,ZT_ECC_PRIVATE_KEY_SET_LEN);
|
Utils::unhex(OSUtils::jsonString(mj["signingKey_SECRET"],"").c_str(),signingKey.priv.data,ZT_ECC_PRIVATE_KEY_SET_LEN);
|
||||||
Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],"").c_str(),updatesMustBeSignedBy.data,ZT_ECC_PUBLIC_KEY_SET_LEN);
|
Utils::unhex(OSUtils::jsonString(mj["updatesMustBeSignedBy"],"").c_str(),updatesMustBeSignedBy.data,ZT_ECC_PUBLIC_KEY_SET_LEN);
|
||||||
|
62
selftest.cpp
62
selftest.cpp
@ -36,7 +36,7 @@
|
|||||||
#include "node/Peer.hpp"
|
#include "node/Peer.hpp"
|
||||||
#include "node/Dictionary.hpp"
|
#include "node/Dictionary.hpp"
|
||||||
#include "node/SHA512.hpp"
|
#include "node/SHA512.hpp"
|
||||||
#include "node/C25519.hpp"
|
#include "node/ECC.hpp"
|
||||||
#include "node/Poly1305.hpp"
|
#include "node/Poly1305.hpp"
|
||||||
#include "node/CertificateOfMembership.hpp"
|
#include "node/CertificateOfMembership.hpp"
|
||||||
#include "node/Node.hpp"
|
#include "node/Node.hpp"
|
||||||
@ -361,13 +361,13 @@ static int testCrypto()
|
|||||||
|
|
||||||
std::cout << "[crypto] Testing C25519 and Ed25519 against test vectors... "; std::cout.flush();
|
std::cout << "[crypto] Testing C25519 and Ed25519 against test vectors... "; std::cout.flush();
|
||||||
for(int k=0;k<ZT_NUM_C25519_TEST_VECTORS;++k) {
|
for(int k=0;k<ZT_NUM_C25519_TEST_VECTORS;++k) {
|
||||||
C25519::Pair p1,p2;
|
ECC::Pair p1,p2;
|
||||||
memcpy(p1.pub.data,C25519_TEST_VECTORS[k].pub1,ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(p1.pub.data,C25519_TEST_VECTORS[k].pub1,ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(p1.priv.data,C25519_TEST_VECTORS[k].priv1,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(p1.priv.data,C25519_TEST_VECTORS[k].priv1,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
memcpy(p2.pub.data,C25519_TEST_VECTORS[k].pub2,ZT_C25519_PUBLIC_KEY_LEN);
|
memcpy(p2.pub.data,C25519_TEST_VECTORS[k].pub2,ZT_C25519_PUBLIC_KEY_LEN);
|
||||||
memcpy(p2.priv.data,C25519_TEST_VECTORS[k].priv2,ZT_C25519_PRIVATE_KEY_LEN);
|
memcpy(p2.priv.data,C25519_TEST_VECTORS[k].priv2,ZT_C25519_PRIVATE_KEY_LEN);
|
||||||
C25519::agree(p1,p2.pub,buf1,64);
|
ECC::agree(p1,p2.pub,buf1,64);
|
||||||
C25519::agree(p2,p1.pub,buf2,64);
|
ECC::agree(p2,p1.pub,buf2,64);
|
||||||
if (memcmp(buf1,buf2,64)) {
|
if (memcmp(buf1,buf2,64)) {
|
||||||
std::cout << "FAIL (1)" << std::endl;
|
std::cout << "FAIL (1)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
@ -376,12 +376,12 @@ static int testCrypto()
|
|||||||
std::cout << "FAIL (2)" << std::endl;
|
std::cout << "FAIL (2)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
C25519::Signature sig1 = C25519::sign(p1,buf1,64);
|
ECC::Signature sig1 = ECC::sign(p1,buf1,64);
|
||||||
if (memcmp(sig1.data,C25519_TEST_VECTORS[k].agreementSignedBy1,64)) {
|
if (memcmp(sig1.data,C25519_TEST_VECTORS[k].agreementSignedBy1,64)) {
|
||||||
std::cout << "FAIL (3)" << std::endl;
|
std::cout << "FAIL (3)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
C25519::Signature sig2 = C25519::sign(p2,buf1,64);
|
ECC::Signature sig2 = ECC::sign(p2,buf1,64);
|
||||||
if (memcmp(sig2.data,C25519_TEST_VECTORS[k].agreementSignedBy2,64)) {
|
if (memcmp(sig2.data,C25519_TEST_VECTORS[k].agreementSignedBy2,64)) {
|
||||||
std::cout << "FAIL (4)" << std::endl;
|
std::cout << "FAIL (4)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
@ -394,12 +394,12 @@ static int testCrypto()
|
|||||||
memset(buf1,64,sizeof(buf1));
|
memset(buf1,64,sizeof(buf1));
|
||||||
memset(buf2,64,sizeof(buf2));
|
memset(buf2,64,sizeof(buf2));
|
||||||
memset(buf3,64,sizeof(buf3));
|
memset(buf3,64,sizeof(buf3));
|
||||||
C25519::Pair p1 = C25519::generate();
|
ECC::Pair p1 = ECC::generate();
|
||||||
C25519::Pair p2 = C25519::generate();
|
ECC::Pair p2 = ECC::generate();
|
||||||
C25519::Pair p3 = C25519::generate();
|
ECC::Pair p3 = ECC::generate();
|
||||||
C25519::agree(p1,p2.pub,buf1,64);
|
ECC::agree(p1,p2.pub,buf1,64);
|
||||||
C25519::agree(p2,p1.pub,buf2,64);
|
ECC::agree(p2,p1.pub,buf2,64);
|
||||||
C25519::agree(p3,p1.pub,buf3,64);
|
ECC::agree(p3,p1.pub,buf3,64);
|
||||||
// p1<>p2 should equal p2<>p1
|
// p1<>p2 should equal p2<>p1
|
||||||
if (memcmp(buf1,buf2,64)) {
|
if (memcmp(buf1,buf2,64)) {
|
||||||
std::cout << "FAIL (1)" << std::endl;
|
std::cout << "FAIL (1)" << std::endl;
|
||||||
@ -414,45 +414,45 @@ static int testCrypto()
|
|||||||
std::cout << "PASS" << std::endl;
|
std::cout << "PASS" << std::endl;
|
||||||
|
|
||||||
std::cout << "[crypto] Benchmarking C25519 ECC key agreement... "; std::cout.flush();
|
std::cout << "[crypto] Benchmarking C25519 ECC key agreement... "; std::cout.flush();
|
||||||
C25519::Pair bp[8];
|
ECC::Pair bp[8];
|
||||||
for(int k=0;k<8;++k)
|
for(int k=0;k<8;++k)
|
||||||
bp[k] = C25519::generate();
|
bp[k] = ECC::generate();
|
||||||
uint64_t st = OSUtils::now();
|
uint64_t st = OSUtils::now();
|
||||||
for(unsigned int k=0;k<50;++k) {
|
for(unsigned int k=0;k<50;++k) {
|
||||||
C25519::agree(bp[~k & 7],bp[k & 7].pub,buf1,64);
|
ECC::agree(bp[~k & 7],bp[k & 7].pub,buf1,64);
|
||||||
}
|
}
|
||||||
uint64_t et = OSUtils::now();
|
uint64_t et = OSUtils::now();
|
||||||
std::cout << ((double)(et - st) / 50.0) << "ms per agreement." << std::endl;
|
std::cout << ((double)(et - st) / 50.0) << "ms per agreement." << std::endl;
|
||||||
|
|
||||||
std::cout << "[crypto] Testing Ed25519 ECC signatures... "; std::cout.flush();
|
std::cout << "[crypto] Testing Ed25519 ECC signatures... "; std::cout.flush();
|
||||||
C25519::Pair didntSign = C25519::generate();
|
ECC::Pair didntSign = ECC::generate();
|
||||||
for(unsigned int i=0;i<10;++i) {
|
for(unsigned int i=0;i<10;++i) {
|
||||||
C25519::Pair p1 = C25519::generate();
|
ECC::Pair p1 = ECC::generate();
|
||||||
for(unsigned int k=0;k<sizeof(buf1);++k)
|
for(unsigned int k=0;k<sizeof(buf1);++k)
|
||||||
buf1[k] = (unsigned char)rand();
|
buf1[k] = (unsigned char)rand();
|
||||||
C25519::Signature sig = C25519::sign(p1,buf1,sizeof(buf1));
|
ECC::Signature sig = ECC::sign(p1,buf1,sizeof(buf1));
|
||||||
if (!C25519::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
if (!ECC::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
||||||
std::cout << "FAIL (1)" << std::endl;
|
std::cout << "FAIL (1)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
++buf1[17];
|
++buf1[17];
|
||||||
if (C25519::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
if (ECC::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
||||||
std::cout << "FAIL (2)" << std::endl;
|
std::cout << "FAIL (2)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
--buf1[17];
|
--buf1[17];
|
||||||
if (!C25519::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
if (!ECC::verify(p1.pub,buf1,sizeof(buf1),sig)) {
|
||||||
std::cout << "FAIL (3)" << std::endl;
|
std::cout << "FAIL (3)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (C25519::verify(didntSign.pub,buf1,sizeof(buf1),sig)) {
|
if (ECC::verify(didntSign.pub,buf1,sizeof(buf1),sig)) {
|
||||||
std::cout << "FAIL (2)" << std::endl;
|
std::cout << "FAIL (2)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(unsigned int k=0;k<64;++k) {
|
for(unsigned int k=0;k<64;++k) {
|
||||||
C25519::Signature sig2(sig);
|
ECC::Signature sig2(sig);
|
||||||
sig2.data[rand() % ZT_C25519_SIGNATURE_LEN] ^= (unsigned char)(1 << (rand() & 7));
|
sig2.data[rand() % ZT_C25519_SIGNATURE_LEN] ^= (unsigned char)(1 << (rand() & 7));
|
||||||
if (C25519::verify(p1.pub,buf1,sizeof(buf1),sig2)) {
|
if (ECC::verify(p1.pub,buf1,sizeof(buf1),sig2)) {
|
||||||
std::cout << "FAIL (5)" << std::endl;
|
std::cout << "FAIL (5)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -463,8 +463,8 @@ static int testCrypto()
|
|||||||
std::cout << "[crypto] Benchmarking Ed25519 ECC signatures... "; std::cout.flush();
|
std::cout << "[crypto] Benchmarking Ed25519 ECC signatures... "; std::cout.flush();
|
||||||
st = OSUtils::now();
|
st = OSUtils::now();
|
||||||
for(int k=0;k<1000;++k) {
|
for(int k=0;k<1000;++k) {
|
||||||
C25519::Signature sig;
|
ECC::Signature sig;
|
||||||
C25519::sign(didntSign.priv,didntSign.pub,buf1,sizeof(buf1),sig.data);
|
ECC::sign(didntSign.priv,didntSign.pub,buf1,sizeof(buf1),sig.data);
|
||||||
}
|
}
|
||||||
et = OSUtils::now();
|
et = OSUtils::now();
|
||||||
std::cout << ((double)(et - st) / 50.0) << "ms per signature." << std::endl;
|
std::cout << ((double)(et - st) / 50.0) << "ms per signature." << std::endl;
|
||||||
@ -1097,12 +1097,12 @@ int main(int argc,char **argv)
|
|||||||
// the same result.
|
// the same result.
|
||||||
/*
|
/*
|
||||||
for(int k=0;k<32;++k) {
|
for(int k=0;k<32;++k) {
|
||||||
C25519::Pair p1 = C25519::generate();
|
ECC::Pair p1 = ECC::generate();
|
||||||
C25519::Pair p2 = C25519::generate();
|
ECC::Pair p2 = ECC::generate();
|
||||||
unsigned char agg[64];
|
unsigned char agg[64];
|
||||||
C25519::agree(p1,p2.pub,agg,64);
|
ECC::agree(p1,p2.pub,agg,64);
|
||||||
C25519::Signature sig1 = C25519::sign(p1,agg,64);
|
ECC::Signature sig1 = ECC::sign(p1,agg,64);
|
||||||
C25519::Signature sig2 = C25519::sign(p2,agg,64);
|
ECC::Signature sig2 = ECC::sign(p2,agg,64);
|
||||||
printf("{{");
|
printf("{{");
|
||||||
for(int i=0;i<64;++i)
|
for(int i=0;i<64;++i)
|
||||||
printf("%s0x%.2x",((i > 0) ? "," : ""),(unsigned int)p1.pub.data[i]);
|
printf("%s0x%.2x",((i > 0) ? "," : ""),(unsigned int)p1.pub.data[i]);
|
||||||
|
@ -200,7 +200,7 @@
|
|||||||
<ClInclude Include="..\..\node\Bond.hpp" />
|
<ClInclude Include="..\..\node\Bond.hpp" />
|
||||||
<ClInclude Include="..\..\node\BondController.hpp" />
|
<ClInclude Include="..\..\node\BondController.hpp" />
|
||||||
<ClInclude Include="..\..\node\Buffer.hpp" />
|
<ClInclude Include="..\..\node\Buffer.hpp" />
|
||||||
<ClInclude Include="..\..\node\C25519.hpp" />
|
<ClInclude Include="..\..\node\ECC.hpp" />
|
||||||
<ClInclude Include="..\..\node\CertificateOfMembership.hpp" />
|
<ClInclude Include="..\..\node\CertificateOfMembership.hpp" />
|
||||||
<ClInclude Include="..\..\node\CertificateOfOwnership.hpp" />
|
<ClInclude Include="..\..\node\CertificateOfOwnership.hpp" />
|
||||||
<ClInclude Include="..\..\node\Constants.hpp" />
|
<ClInclude Include="..\..\node\Constants.hpp" />
|
||||||
|
@ -335,7 +335,7 @@
|
|||||||
<ClInclude Include="..\..\node\Buffer.hpp">
|
<ClInclude Include="..\..\node\Buffer.hpp">
|
||||||
<Filter>Header Files\node</Filter>
|
<Filter>Header Files\node</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\node\C25519.hpp">
|
<ClInclude Include="..\..\node\ECC.hpp">
|
||||||
<Filter>Header Files\node</Filter>
|
<Filter>Header Files\node</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\node\CertificateOfMembership.hpp">
|
<ClInclude Include="..\..\node\CertificateOfMembership.hpp">
|
||||||
|
@ -168,7 +168,7 @@
|
|||||||
<ClInclude Include="..\..\node\Array.hpp" />
|
<ClInclude Include="..\..\node\Array.hpp" />
|
||||||
<ClInclude Include="..\..\node\AtomicCounter.hpp" />
|
<ClInclude Include="..\..\node\AtomicCounter.hpp" />
|
||||||
<ClInclude Include="..\..\node\Buffer.hpp" />
|
<ClInclude Include="..\..\node\Buffer.hpp" />
|
||||||
<ClInclude Include="..\..\node\C25519.hpp" />
|
<ClInclude Include="..\..\node\ECC.hpp" />
|
||||||
<ClInclude Include="..\..\node\Capability.hpp" />
|
<ClInclude Include="..\..\node\Capability.hpp" />
|
||||||
<ClInclude Include="..\..\node\CertificateOfMembership.hpp" />
|
<ClInclude Include="..\..\node\CertificateOfMembership.hpp" />
|
||||||
<ClInclude Include="..\..\node\CertificateOfOwnership.hpp" />
|
<ClInclude Include="..\..\node\CertificateOfOwnership.hpp" />
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<ClInclude Include="..\..\node\Buffer.hpp">
|
<ClInclude Include="..\..\node\Buffer.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\node\C25519.hpp">
|
<ClInclude Include="..\..\node\ECC.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\node\Capability.hpp">
|
<ClInclude Include="..\..\node\Capability.hpp">
|
||||||
|
Loading…
Reference in New Issue
Block a user