|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project |
|
|
|
* Copyright (c) 2013-2021, The PurpleI2P Project |
|
|
|
* |
|
|
|
* |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* |
|
|
|
* |
|
|
@ -21,7 +21,7 @@ namespace crypto |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
virtual ~CryptoKeyEncryptor () {}; |
|
|
|
virtual ~CryptoKeyEncryptor () {}; |
|
|
|
virtual void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding) = 0; // 222 bytes data, 512/514 bytes encrypted
|
|
|
|
virtual void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding) = 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class CryptoKeyDecryptor |
|
|
|
class CryptoKeyDecryptor |
|
|
@ -29,7 +29,7 @@ namespace crypto |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
virtual ~CryptoKeyDecryptor () {}; |
|
|
|
virtual ~CryptoKeyDecryptor () {}; |
|
|
|
virtual bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, bool zeroPadding) = 0; // 512/514 bytes encrypted, 222 bytes data
|
|
|
|
virtual bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) = 0; |
|
|
|
virtual size_t GetPublicKeyLen () const = 0; // we need it to set key in LS2
|
|
|
|
virtual size_t GetPublicKeyLen () const = 0; // we need it to set key in LS2
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -39,7 +39,7 @@ namespace crypto |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
ElGamalEncryptor (const uint8_t * pub); |
|
|
|
ElGamalEncryptor (const uint8_t * pub); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding) override; // 222 bytes data, 512/514 bytes encrypted
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -51,8 +51,8 @@ namespace crypto |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
ElGamalDecryptor (const uint8_t * priv); |
|
|
|
ElGamalDecryptor (const uint8_t * priv); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, bool zeroPadding); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) override; // 514 bytes encrypted, 222 bytes data
|
|
|
|
size_t GetPublicKeyLen () const { return 256; }; |
|
|
|
size_t GetPublicKeyLen () const override { return 256; }; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -67,7 +67,7 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESP256Encryptor (const uint8_t * pub); |
|
|
|
ECIESP256Encryptor (const uint8_t * pub); |
|
|
|
~ECIESP256Encryptor (); |
|
|
|
~ECIESP256Encryptor (); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding) override; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -82,8 +82,8 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESP256Decryptor (const uint8_t * priv); |
|
|
|
ECIESP256Decryptor (const uint8_t * priv); |
|
|
|
~ECIESP256Decryptor (); |
|
|
|
~ECIESP256Decryptor (); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, bool zeroPadding); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) override; |
|
|
|
size_t GetPublicKeyLen () const { return 64; }; |
|
|
|
size_t GetPublicKeyLen () const override { return 64; }; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -101,7 +101,7 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESGOSTR3410Encryptor (const uint8_t * pub); |
|
|
|
ECIESGOSTR3410Encryptor (const uint8_t * pub); |
|
|
|
~ECIESGOSTR3410Encryptor (); |
|
|
|
~ECIESGOSTR3410Encryptor (); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding); |
|
|
|
void Encrypt (const uint8_t * data, uint8_t * encrypted, BN_CTX * ctx, bool zeroPadding) override; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -115,8 +115,8 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESGOSTR3410Decryptor (const uint8_t * priv); |
|
|
|
ECIESGOSTR3410Decryptor (const uint8_t * priv); |
|
|
|
~ECIESGOSTR3410Decryptor (); |
|
|
|
~ECIESGOSTR3410Decryptor (); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx, bool zeroPadding); |
|
|
|
bool Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) override; |
|
|
|
size_t GetPublicKeyLen () const { return 64; }; |
|
|
|
size_t GetPublicKeyLen () const override { return 64; }; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
@ -133,7 +133,7 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESX25519AEADRatchetEncryptor (const uint8_t * pub); |
|
|
|
ECIESX25519AEADRatchetEncryptor (const uint8_t * pub); |
|
|
|
~ECIESX25519AEADRatchetEncryptor () {}; |
|
|
|
~ECIESX25519AEADRatchetEncryptor () {}; |
|
|
|
void Encrypt (const uint8_t *, uint8_t * pub, BN_CTX *, bool); |
|
|
|
void Encrypt (const uint8_t *, uint8_t * pub, BN_CTX *, bool) override; |
|
|
|
// copies m_PublicKey to pub
|
|
|
|
// copies m_PublicKey to pub
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
@ -147,9 +147,9 @@ namespace crypto |
|
|
|
|
|
|
|
|
|
|
|
ECIESX25519AEADRatchetDecryptor (const uint8_t * priv, bool calculatePublic = false); |
|
|
|
ECIESX25519AEADRatchetDecryptor (const uint8_t * priv, bool calculatePublic = false); |
|
|
|
~ECIESX25519AEADRatchetDecryptor () {}; |
|
|
|
~ECIESX25519AEADRatchetDecryptor () {}; |
|
|
|
bool Decrypt (const uint8_t * epub, uint8_t * sharedSecret, BN_CTX * ctx, bool zeroPadding); |
|
|
|
bool Decrypt (const uint8_t * epub, uint8_t * sharedSecret, BN_CTX * ctx) override; |
|
|
|
// agree with static and return in sharedSecret (32 bytes)
|
|
|
|
// agree with static and return in sharedSecret (32 bytes)
|
|
|
|
size_t GetPublicKeyLen () const { return 32; }; |
|
|
|
size_t GetPublicKeyLen () const override { return 32; }; |
|
|
|
const uint8_t * GetPubicKey () const { return m_StaticKeys.GetPublicKey (); }; |
|
|
|
const uint8_t * GetPubicKey () const { return m_StaticKeys.GetPublicKey (); }; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|