mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
decryptor for ECIES-X25519-AEAD-Ratchet
This commit is contained in:
parent
9ed58e5186
commit
553d59c32b
@ -1,6 +1,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Gost.h"
|
#include "Gost.h"
|
||||||
|
#include "Elligator.h"
|
||||||
#include "CryptoKey.h"
|
#include "CryptoKey.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
@ -146,6 +147,22 @@ namespace crypto
|
|||||||
BN_free (x); BN_free (y);
|
BN_free (x); BN_free (y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ECIESX25519AEADRatchetDecryptor::Decrypt (const uint8_t * epub, uint8_t * keyMaterial, BN_CTX * ctx, bool zeroPadding)
|
||||||
|
{
|
||||||
|
uint8_t key[32];
|
||||||
|
if (!GetElligator ()->Decode (epub, key)) return false;
|
||||||
|
m_StaticKeys.Agree (key, keyMaterial);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateECIESX25519AEADRatchetRandomKeys (uint8_t * priv, uint8_t * pub)
|
||||||
|
{
|
||||||
|
X25519Keys k;
|
||||||
|
k.GenerateKeys ();
|
||||||
|
k.GetPrivateKey (priv);
|
||||||
|
memcpy (pub, k.GetPublicKey (), 32);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +116,25 @@ namespace crypto
|
|||||||
};
|
};
|
||||||
|
|
||||||
void CreateECIESGOSTR3410RandomKeys (uint8_t * priv, uint8_t * pub);
|
void CreateECIESGOSTR3410RandomKeys (uint8_t * priv, uint8_t * pub);
|
||||||
|
|
||||||
|
// ECIES-X25519-AEAD-Ratchet
|
||||||
|
|
||||||
|
class ECIESX25519AEADRatchetDecryptor: public CryptoKeyDecryptor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ECIESX25519AEADRatchetDecryptor (const uint8_t * priv): m_StaticKeys (priv, nullptr) {};
|
||||||
|
~ECIESX25519AEADRatchetDecryptor () {};
|
||||||
|
bool Decrypt (const uint8_t * epub, uint8_t * keyMaterial, BN_CTX * ctx, bool zeroPadding);
|
||||||
|
// take elligator encoded ephemeral pub (32 bytes), agree with static and return in keyMaterial (32 bytes)
|
||||||
|
size_t GetPublicKeyLen () const { return 32; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
X25519Keys m_StaticKeys;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CreateECIESX25519AEADRatchetRandomKeys (uint8_t * priv, uint8_t * pub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,6 +674,9 @@ namespace data
|
|||||||
case CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC:
|
case CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC:
|
||||||
return std::make_shared<i2p::crypto::ECIESGOSTR3410Decryptor>(key);
|
return std::make_shared<i2p::crypto::ECIESGOSTR3410Decryptor>(key);
|
||||||
break;
|
break;
|
||||||
|
case CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RARCHET:
|
||||||
|
return std::make_shared<i2p::crypto::ECIESX25519AEADRatchetDecryptor>(key);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogError, "Identity: Unknown crypto key type ", (int)cryptoType);
|
LogPrint (eLogError, "Identity: Unknown crypto key type ", (int)cryptoType);
|
||||||
};
|
};
|
||||||
@ -750,6 +753,9 @@ namespace data
|
|||||||
case CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC:
|
case CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC:
|
||||||
i2p::crypto::CreateECIESGOSTR3410RandomKeys (priv, pub);
|
i2p::crypto::CreateECIESGOSTR3410RandomKeys (priv, pub);
|
||||||
break;
|
break;
|
||||||
|
case CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RARCHET:
|
||||||
|
i2p::crypto::CreateECIESX25519AEADRatchetRandomKeys (priv, pub);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogError, "Identity: Crypto key type ", (int)type, " is not supported");
|
LogPrint (eLogError, "Identity: Crypto key type ", (int)type, " is not supported");
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ namespace data
|
|||||||
|
|
||||||
const uint16_t CRYPTO_KEY_TYPE_ELGAMAL = 0;
|
const uint16_t CRYPTO_KEY_TYPE_ELGAMAL = 0;
|
||||||
const uint16_t CRYPTO_KEY_TYPE_ECIES_P256_SHA256_AES256CBC = 1;
|
const uint16_t CRYPTO_KEY_TYPE_ECIES_P256_SHA256_AES256CBC = 1;
|
||||||
|
const uint16_t CRYPTO_KEY_TYPE_ECIES_X25519_AEAD_RARCHET = 4;
|
||||||
const uint16_t CRYPTO_KEY_TYPE_ECIES_P256_SHA256_AES256CBC_TEST = 65280; // TODO: remove later
|
const uint16_t CRYPTO_KEY_TYPE_ECIES_P256_SHA256_AES256CBC_TEST = 65280; // TODO: remove later
|
||||||
const uint16_t CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC = 65281; // TODO: use GOST R 34.11 instead SHA256 and GOST 28147-89 instead AES
|
const uint16_t CRYPTO_KEY_TYPE_ECIES_GOSTR3410_CRYPTO_PRO_A_SHA256_AES256CBC = 65281; // TODO: use GOST R 34.11 instead SHA256 and GOST 28147-89 instead AES
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user