Rename C25519.* to ECC.*

This commit is contained in:
Adam Ierymenko 2024-09-15 17:34:01 -04:00
parent 7647c8e8d1
commit 307befa892
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
22 changed files with 111 additions and 114 deletions

View file

@ -21,7 +21,7 @@
#include "Constants.hpp"
#include "Credential.hpp"
#include "Address.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Utils.hpp"
#include "Buffer.hpp"
#include "Identity.hpp"
@ -496,7 +496,7 @@ private:
struct {
Address to;
Address from;
C25519::Signature signature;
ECC::Signature signature;
} _custody[ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH];
};

View file

@ -12,7 +12,7 @@
/****/
#include "CertificateOfMembership.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "RuntimeEnvironment.hpp"
#include "Topology.hpp"
#include "Switch.hpp"

View file

@ -25,7 +25,7 @@
#include "Credential.hpp"
#include "Buffer.hpp"
#include "Address.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Identity.hpp"
#include "Utils.hpp"
@ -310,7 +310,7 @@ private:
Address _signedBy;
_Qualifier _qualifiers[ZT_NETWORK_COM_MAX_QUALIFIERS];
unsigned int _qualifierCount;
C25519::Signature _signature;
ECC::Signature _signature;
};
} // namespace ZeroTier

View file

@ -21,7 +21,7 @@
#include "Constants.hpp"
#include "Credential.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Address.hpp"
#include "Identity.hpp"
#include "Buffer.hpp"
@ -243,7 +243,7 @@ private:
uint8_t _thingValues[ZT_CERTIFICATEOFOWNERSHIP_MAX_THINGS][ZT_CERTIFICATEOFOWNERSHIP_MAX_THING_VALUE_SIZE];
Address _issuedTo;
Address _signedBy;
C25519::Signature _signature;
ECC::Signature _signature;
};
} // namespace ZeroTier

View file

@ -12,7 +12,7 @@ Derived from public domain code by D. J. Bernstein.
#include <string.h>
#include "Constants.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "SHA512.hpp"
#include "Buffer.hpp"
#include "Hashtable.hpp"
@ -2508,7 +2508,7 @@ extern "C" void ed25519_amd64_asm_sign(const unsigned char *sk,const unsigned ch
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 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)
SHA512(digest,msg,len);
@ -2580,7 +2580,7 @@ void C25519::sign(const C25519::Private &myPrivate,const C25519::Public &myPubli
#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;
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);
}
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
// agreement. This generates the public portion from the private.
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];
sc25519 scsk;

View file

@ -11,8 +11,8 @@
*/
/****/
#ifndef ZT_C25519_HPP
#define ZT_C25519_HPP
#ifndef ZT_ECC_HPP
#define ZT_ECC_HPP
#include "Utils.hpp"
@ -22,10 +22,7 @@ namespace ZeroTier {
#define ZT_ECC_PRIVATE_KEY_SET_LEN 64
#define ZT_ECC_SIGNATURE_LEN 96
/**
* A combined Curve25519 ECDH and Ed25519 signature engine
*/
class C25519
class ECC
{
public:
struct Public { uint8_t data[ZT_ECC_PUBLIC_KEY_SET_LEN]; };
@ -34,7 +31,7 @@ public:
struct Pair { Public pub; Private priv; };
/**
* Generate a C25519 elliptic curve key pair
* Generate an elliptic curve key pair
*/
static inline Pair generate()
{

View file

@ -16,7 +16,7 @@
#include <string.h>
#include <stdint.h>
#include "C25519.hpp"
#include "ECC.hpp"
#include "Constants.hpp"
#include "Identity.hpp"
#include "SHA512.hpp"
@ -73,7 +73,7 @@ struct _Identity_generate_cond
{
_Identity_generate_cond() {}
_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);
return (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN);
@ -87,15 +87,15 @@ void Identity::generate()
unsigned char digest[64];
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
C25519::Pair kp;
ECC::Pair kp;
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
} while (_address.isReserved());
_publicKey = kp.pub;
if (!_privateKey) {
_privateKey = new C25519::Private();
_privateKey = new ECC::Private();
}
*_privateKey = kp.priv;
@ -157,7 +157,7 @@ bool Identity::fromString(const char *str)
}
delete _privateKey;
_privateKey = (C25519::Private *)0;
_privateKey = (ECC::Private *)0;
int fno = 0;
char *saveptr = (char *)0;
@ -183,7 +183,7 @@ bool Identity::fromString(const char *str)
}
break;
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) {
_address.zero();
return false;

View file

@ -20,7 +20,7 @@
#include "Constants.hpp"
#include "Utils.hpp"
#include "Address.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Buffer.hpp"
#include "SHA512.hpp"
@ -42,19 +42,19 @@ class Identity
{
public:
Identity() :
_privateKey((C25519::Private *)0)
_privateKey((ECC::Private *)0)
{
}
Identity(const Identity &id) :
_address(id._address),
_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) :
_privateKey((C25519::Private *)0)
_privateKey((ECC::Private *)0)
{
if (!fromString(str)) {
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
@ -63,7 +63,7 @@ public:
template<unsigned int C>
Identity(const Buffer<C> &b,unsigned int startAt = 0) :
_privateKey((C25519::Private *)0)
_privateKey((ECC::Private *)0)
{
deserialize(b,startAt);
}
@ -71,7 +71,7 @@ public:
~Identity()
{
if (_privateKey) {
Utils::burn(_privateKey,sizeof(C25519::Private));
Utils::burn(_privateKey,sizeof(ECC::Private));
delete _privateKey;
}
}
@ -82,12 +82,12 @@ public:
_publicKey = id._publicKey;
if (id._privateKey) {
if (!_privateKey) {
_privateKey = new C25519::Private();
_privateKey = new ECC::Private();
}
*_privateKey = *(id._privateKey);
} else {
delete _privateKey;
_privateKey = (C25519::Private *)0;
_privateKey = (ECC::Private *)0;
}
return *this;
}
@ -109,7 +109,7 @@ public:
/**
* @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).
@ -144,10 +144,10 @@ public:
* @param data Data to sign
* @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) {
return C25519::sign(*_privateKey,_publicKey,data,len);
return ECC::sign(*_privateKey,_publicKey,data,len);
}
throw ZT_EXCEPTION_PRIVATE_KEY_REQUIRED;
}
@ -166,7 +166,7 @@ public:
if (siglen != ZT_ECC_SIGNATURE_LEN) {
return false;
}
return C25519::verify(_publicKey,data,len,signature);
return ECC::verify(_publicKey,data,len,signature);
}
/**
@ -177,9 +177,9 @@ public:
* @param signature Signature
* @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
{
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 false;
@ -242,7 +242,7 @@ public:
inline unsigned int deserialize(const Buffer<C> &b,unsigned int startAt = 0)
{
delete _privateKey;
_privateKey = (C25519::Private *)0;
_privateKey = (ECC::Private *)0;
unsigned int p = startAt;
@ -261,7 +261,7 @@ public:
if (privateKeyLength != ZT_ECC_PRIVATE_KEY_SET_LEN) {
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);
p += ZT_ECC_PRIVATE_KEY_SET_LEN;
}
@ -292,14 +292,14 @@ public:
/**
* @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)
*/
inline const C25519::Pair privateKeyPair() const
inline const ECC::Pair privateKeyPair() const
{
C25519::Pair pair;
ECC::Pair pair;
pair.pub = _publicKey;
if (_privateKey) {
pair.priv = *_privateKey;
@ -323,8 +323,8 @@ public:
private:
Address _address;
C25519::Public _publicKey;
C25519::Private *_privateKey;
ECC::Public _publicKey;
ECC::Private *_privateKey;
};
} // namespace ZeroTier

View file

@ -18,7 +18,7 @@
#include "../include/ZeroTierDebug.h"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Constants.hpp"
#include "../version.h"
#include "Network.hpp"

View file

@ -19,7 +19,7 @@
#include "../version.h"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Constants.hpp"
#include "SharedPtr.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)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((uint16_t)ZT_ECC_SIGNATURE_LEN);
outp.append(sig.data,ZT_ECC_SIGNATURE_LEN);

View file

@ -23,7 +23,7 @@
#include "../include/ZeroTierOne.h"
#include "Credential.hpp"
#include "Address.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Utils.hpp"
#include "Buffer.hpp"
#include "Identity.hpp"
@ -201,7 +201,7 @@ private:
Address _target;
Address _signedBy;
Credential::Type _type;
C25519::Signature _signature;
ECC::Signature _signature;
};
} // namespace ZeroTier

View file

@ -21,7 +21,7 @@
#include "Constants.hpp"
#include "Credential.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
#include "Address.hpp"
#include "Identity.hpp"
#include "Buffer.hpp"
@ -207,7 +207,7 @@ private:
int64_t _ts;
Address _issuedTo;
Address _signedBy;
C25519::Signature _signature;
ECC::Signature _signature;
};
} // namespace ZeroTier

View file

@ -21,7 +21,7 @@
#include "InetAddress.hpp"
#include "Identity.hpp"
#include "Buffer.hpp"
#include "C25519.hpp"
#include "ECC.hpp"
/**
* Maximum number of roots (sanity limit, okay to increase)
@ -133,12 +133,12 @@ public:
/**
* @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
*/
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
@ -154,7 +154,7 @@ public:
if ((_id == update._id)&&(_ts < update._ts)&&(_type == update._type)) {
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
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;
}
@ -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)
* @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;
w._id = id;
@ -273,7 +273,7 @@ public:
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> tmp;
w.serialize(tmp,true);
w._signature = C25519::sign(signWith,tmp.data(),tmp.size());
w._signature = ECC::sign(signWith,tmp.data(),tmp.size());
return w;
}
@ -282,8 +282,8 @@ protected:
uint64_t _id;
uint64_t _ts;
Type _type;
C25519::Public _updatesMustBeSignedBy;
C25519::Signature _signature;
ECC::Public _updatesMustBeSignedBy;
ECC::Signature _signature;
std::vector<Root> _roots;
};