|
|
@ -8,6 +8,7 @@ |
|
|
|
#include <atomic> |
|
|
|
#include <atomic> |
|
|
|
#include "Base.h" |
|
|
|
#include "Base.h" |
|
|
|
#include "Signature.h" |
|
|
|
#include "Signature.h" |
|
|
|
|
|
|
|
#include "CryptoKey.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace i2p |
|
|
|
namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
@ -52,7 +53,7 @@ namespace data |
|
|
|
const size_t DEFAULT_IDENTITY_SIZE = sizeof (Identity); // 387 bytes
|
|
|
|
const size_t DEFAULT_IDENTITY_SIZE = sizeof (Identity); // 387 bytes
|
|
|
|
|
|
|
|
|
|
|
|
const uint16_t CRYPTO_KEY_TYPE_ELGAMAL = 0; |
|
|
|
const uint16_t CRYPTO_KEY_TYPE_ELGAMAL = 0; |
|
|
|
const uint16_t CRYPTO_KEY_TYPE_ECICS_P256_SHA256_AES256CBC = 65280; // TODO: change to actual code
|
|
|
|
const uint16_t CRYPTO_KEY_TYPE_ECIES_P256_SHA256_AES256CBC = 65280; // TODO: change to actual code
|
|
|
|
|
|
|
|
|
|
|
|
const uint16_t SIGNING_KEY_TYPE_DSA_SHA1 = 0; |
|
|
|
const uint16_t SIGNING_KEY_TYPE_DSA_SHA1 = 0; |
|
|
|
const uint16_t SIGNING_KEY_TYPE_ECDSA_SHA256_P256 = 1; |
|
|
|
const uint16_t SIGNING_KEY_TYPE_ECDSA_SHA256_P256 = 1; |
|
|
@ -88,11 +89,12 @@ namespace data |
|
|
|
size_t ToBuffer (uint8_t * buf, size_t len) const; |
|
|
|
size_t ToBuffer (uint8_t * buf, size_t len) const; |
|
|
|
size_t FromBase64(const std::string& s); |
|
|
|
size_t FromBase64(const std::string& s); |
|
|
|
std::string ToBase64 () const; |
|
|
|
std::string ToBase64 () const; |
|
|
|
const Identity& GetStandardIdentity () const { return m_StandardIdentity; }; |
|
|
|
const Identity& GetStandardIdentity () const { return m_StandardIdentity; }; |
|
|
|
|
|
|
|
|
|
|
|
const IdentHash& GetIdentHash () const { return m_IdentHash; }; |
|
|
|
const IdentHash& GetIdentHash () const { return m_IdentHash; }; |
|
|
|
const uint8_t * GetEncryptionPublicKey () const { return m_StandardIdentity.publicKey; }; |
|
|
|
const uint8_t * GetEncryptionPublicKey () const { return m_StandardIdentity.publicKey; }; |
|
|
|
uint8_t * GetEncryptionPublicKeyBuffer () { return m_StandardIdentity.publicKey; }; |
|
|
|
uint8_t * GetEncryptionPublicKeyBuffer () { return m_StandardIdentity.publicKey; }; |
|
|
|
|
|
|
|
std::shared_ptr<i2p::crypto::CryptoKeyEncryptor> CreateEncryptor (const uint8_t * key) const; |
|
|
|
size_t GetFullLen () const { return m_ExtendedLen + DEFAULT_IDENTITY_SIZE; }; |
|
|
|
size_t GetFullLen () const { return m_ExtendedLen + DEFAULT_IDENTITY_SIZE; }; |
|
|
|
size_t GetSigningPublicKeyLen () const; |
|
|
|
size_t GetSigningPublicKeyLen () const; |
|
|
|
size_t GetSigningPrivateKeyLen () const; |
|
|
|
size_t GetSigningPrivateKeyLen () const; |
|
|
@ -136,7 +138,7 @@ namespace data |
|
|
|
const uint8_t * GetPrivateKey () const { return m_PrivateKey; }; |
|
|
|
const uint8_t * GetPrivateKey () const { return m_PrivateKey; }; |
|
|
|
const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; }; |
|
|
|
const uint8_t * GetSigningPrivateKey () const { return m_SigningPrivateKey; }; |
|
|
|
uint8_t * GetPadding(); |
|
|
|
uint8_t * GetPadding(); |
|
|
|
void RecalculateIdentHash(uint8_t * buf=nullptr) { m_Public->RecalculateIdentHash(buf); } |
|
|
|
void RecalculateIdentHash(uint8_t * buf=nullptr) { m_Public->RecalculateIdentHash(buf); } |
|
|
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const; |
|
|
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const; |
|
|
|
|
|
|
|
|
|
|
|
size_t GetFullLen () const { return m_Public->GetFullLen () + 256 + m_Public->GetSigningPrivateKeyLen (); }; |
|
|
|
size_t GetFullLen () const { return m_Public->GetFullLen () + 256 + m_Public->GetSigningPrivateKeyLen (); }; |
|
|
@ -146,6 +148,8 @@ namespace data |
|
|
|
size_t FromBase64(const std::string& s); |
|
|
|
size_t FromBase64(const std::string& s); |
|
|
|
std::string ToBase64 () const; |
|
|
|
std::string ToBase64 () const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> CreateDecryptor (const uint8_t * key) const; |
|
|
|
|
|
|
|
|
|
|
|
static PrivateKeys CreateRandomKeys (SigningKeyType type = SIGNING_KEY_TYPE_DSA_SHA1, CryptoKeyType cryptoType = CRYPTO_KEY_TYPE_ELGAMAL); |
|
|
|
static PrivateKeys CreateRandomKeys (SigningKeyType type = SIGNING_KEY_TYPE_DSA_SHA1, CryptoKeyType cryptoType = CRYPTO_KEY_TYPE_ELGAMAL); |
|
|
|
static void GenerateCryptoKeyPair (CryptoKeyType type, uint8_t * priv, uint8_t * pub); // priv and pub are 256 bytes long
|
|
|
|
static void GenerateCryptoKeyPair (CryptoKeyType type, uint8_t * priv, uint8_t * pub); // priv and pub are 256 bytes long
|
|
|
|
|
|
|
|
|
|
|
@ -187,7 +191,8 @@ namespace data |
|
|
|
virtual ~RoutingDestination () {}; |
|
|
|
virtual ~RoutingDestination () {}; |
|
|
|
|
|
|
|
|
|
|
|
virtual std::shared_ptr<const IdentityEx> GetIdentity () const = 0; |
|
|
|
virtual std::shared_ptr<const IdentityEx> GetIdentity () const = 0; |
|
|
|
virtual const uint8_t * GetEncryptionPublicKey () const = 0; |
|
|
|
virtual const uint8_t * GetEncryptionPublicKey () const = 0; // deprecated
|
|
|
|
|
|
|
|
virtual void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx) = 0; // encrypt data for
|
|
|
|
virtual bool IsDestination () const = 0; // for garlic
|
|
|
|
virtual bool IsDestination () const = 0; // for garlic
|
|
|
|
|
|
|
|
|
|
|
|
const IdentHash& GetIdentHash () const { return GetIdentity ()->GetIdentHash (); }; |
|
|
|
const IdentHash& GetIdentHash () const { return GetIdentity ()->GetIdentHash (); }; |
|
|
|