Rename C25519.* to ECC.*
This commit is contained in:
parent
7647c8e8d1
commit
307befa892
22 changed files with 111 additions and 114 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue