Remove GOST R 34.10 / 34.11 support.
This crate only ever generates Ed25519 destinations, but Identity.cpp's CreateVerifier runs
on identities parsed from arbitrary remote peers -- so Gost.cpp's hand-rolled curve
arithmetic and Streebog hashes were attacker-reachable code for a capability we never use.
The ECIES-GOST encryptor/decryptor in CryptoKey.* was already dead even within upstream:
nothing outside CryptoKey.{h,cpp} referenced it.
Every switch this touches already had a default: arm logging "signing key type is not
supported" -- the same graceful path upstream uses for RSA -- so a GOST identity is now
rejected rather than mishandled. Peers or destinations declaring signing key type 9 or 10
become unusable; those are vanishingly rare on the live network.
update-vendor.sh deletes libi2pd/Gost.{cpp,h} outright, which is why they are absent here.
That also retires 0003-awslc-gost-curve-compat.patch.
diff --git a/libi2pd/CryptoKey.cpp b/libi2pd/CryptoKey.cpp
index 1a448ed..0c77a51 100644
@@ -8,7 +8,6 @@
#include <string.h>
#include "Log.h"
-#include "Gost.h"
#include "CryptoKey.h"
namespace i2p
@@ -96,63 +95,6 @@ namespace crypto
EC_GROUP_free (curve);
}
- ECIESGOSTR3410Encryptor::ECIESGOSTR3410Encryptor (const uint8_t * pub)
- {
- auto& curve = GetGOSTR3410Curve (eGOSTR3410CryptoProA);
- m_PublicKey = EC_POINT_new (curve->GetGroup ());
- BIGNUM * x = BN_bin2bn (pub, 32, nullptr);
- BIGNUM * y = BN_bin2bn (pub + 32, 32, nullptr);
- if (!EC_POINT_set_affine_coordinates (curve->GetGroup (), m_PublicKey, x, y, nullptr))
- LogPrint (eLogError, "ECICS GOST R 34.10 invalid public key");
- BN_free (x); BN_free (y);
- }
-
- ECIESGOSTR3410Encryptor::~ECIESGOSTR3410Encryptor ()
- {
- if (m_PublicKey) EC_POINT_free (m_PublicKey);
- }
-
- void ECIESGOSTR3410Encryptor::Encrypt (const uint8_t * data, uint8_t * encrypted)
- {
- if (m_PublicKey)
- ECIESEncrypt (GetGOSTR3410Curve (eGOSTR3410CryptoProA)->GetGroup (), m_PublicKey, data, encrypted);
- }
-
- ECIESGOSTR3410Decryptor::ECIESGOSTR3410Decryptor (const uint8_t * priv)
- {
- m_PrivateKey = BN_bin2bn (priv, 32, nullptr);
- }
-
- ECIESGOSTR3410Decryptor::~ECIESGOSTR3410Decryptor ()
- {
- if (m_PrivateKey) BN_free (m_PrivateKey);
- }
-
- bool ECIESGOSTR3410Decryptor::Decrypt (const uint8_t * encrypted, uint8_t * data)
- {
- if (m_PrivateKey)
- return ECIESDecrypt (GetGOSTR3410Curve (eGOSTR3410CryptoProA)->GetGroup (), m_PrivateKey, encrypted, data);
- return false;
- }
-
-
- void CreateECIESGOSTR3410RandomKeys (uint8_t * priv, uint8_t * pub)
- {
- auto& curve = GetGOSTR3410Curve (eGOSTR3410CryptoProA);
- EC_POINT * p = nullptr;
- BIGNUM * key = nullptr;
- GenerateECIESKeyPair (curve->GetGroup (), key, p);
- bn2buf (key, priv, 32);
- RAND_bytes (priv + 32, 224);
- BN_free (key);
- BIGNUM * x = BN_new (), * y = BN_new ();
- EC_POINT_get_affine_coordinates (curve->GetGroup (), p, x, y, NULL);
- bn2buf (x, pub, 32);
- bn2buf (y, pub + 32, 32);
- RAND_bytes (pub + 64, 192);
- EC_POINT_free (p);
- BN_free (x); BN_free (y);
- }
ECIESX25519AEADRatchetEncryptor::ECIESX25519AEADRatchetEncryptor (const uint8_t * pub)
{
diff --git a/libi2pd/CryptoKey.h b/libi2pd/CryptoKey.h
index 099bdd5..6a01f14 100644
@@ -94,37 +94,6 @@ namespace crypto
void CreateECIESP256RandomKeys (uint8_t * priv, uint8_t * pub);
-// ECIES GOST R 34.10
-
- class ECIESGOSTR3410Encryptor: public CryptoKeyEncryptor
- {
- public:
-
- ECIESGOSTR3410Encryptor (const uint8_t * pub);
- ~ECIESGOSTR3410Encryptor ();
- void Encrypt (const uint8_t * data, uint8_t * encrypted) override;
-
- private:
-
- EC_POINT * m_PublicKey;
- };
-
-
- class ECIESGOSTR3410Decryptor: public CryptoKeyDecryptor
- {
- public:
-
- ECIESGOSTR3410Decryptor (const uint8_t * priv);
- ~ECIESGOSTR3410Decryptor ();
- bool Decrypt (const uint8_t * encrypted, uint8_t * data) override;
- size_t GetPublicKeyLen () const override { return 64; };
-
- private:
-
- BIGNUM * m_PrivateKey;
- };
-
- void CreateECIESGOSTR3410RandomKeys (uint8_t * priv, uint8_t * pub);
// ECIES-X25519-AEAD-Ratchet
diff --git a/libi2pd/Identity.cpp b/libi2pd/Identity.cpp
index becd443..cbb7783 100644
@@ -124,21 +124,6 @@ namespace data
memcpy (m_StandardIdentity.signingKey + padding, signingKey, i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH);
break;
}
- case SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256:
- {
- // 256
- size_t padding = 128 - i2p::crypto::GOSTR3410_256_PUBLIC_KEY_LENGTH; // 64 = 128 - 64
- RAND_bytes (m_StandardIdentity.signingKey, padding);
- memcpy (m_StandardIdentity.signingKey + padding, signingKey, i2p::crypto::GOSTR3410_256_PUBLIC_KEY_LENGTH);
- break;
- }
- case SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512:
- {
- // 512
- // no padding, key length is 128
- memcpy (m_StandardIdentity.signingKey, signingKey, i2p::crypto::GOSTR3410_512_PUBLIC_KEY_LENGTH);
- break;
- }
default:
LogPrint (eLogError, "Identity: Signing key type ", (int)type, " is not supported");
}
@@ -405,10 +390,6 @@ namespace data
return new i2p::crypto::ECDSAP521Verifier ();
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
return new i2p::crypto::EDDSA25519Verifier ();
- case SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256:
- return new i2p::crypto::GOSTR3410_256_Verifier (i2p::crypto::eGOSTR3410CryptoProA);
- case SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512:
- return new i2p::crypto::GOSTR3410_512_Verifier (i2p::crypto::eGOSTR3410TC26A512);
case SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519:
return new i2p::crypto::RedDSA25519Verifier ();
case SIGNING_KEY_TYPE_RSA_SHA256_2048:
@@ -698,12 +679,6 @@ namespace data
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
return new i2p::crypto::EDDSA25519Signer (priv, nullptr);
break;
- case SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256:
- return new i2p::crypto::GOSTR3410_256_Signer (i2p::crypto::eGOSTR3410CryptoProA, priv);
- break;
- case SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512:
- return new i2p::crypto::GOSTR3410_512_Signer (i2p::crypto::eGOSTR3410TC26A512, priv);
- break;
case SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519:
return new i2p::crypto::RedDSA25519Signer (priv);
break;
@@ -807,12 +782,6 @@ namespace data
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
i2p::crypto::CreateEDDSA25519RandomKeys (priv, pub);
break;
- case SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256:
- i2p::crypto::CreateGOSTR3410RandomKeys (i2p::crypto::eGOSTR3410CryptoProA, priv, pub);
- break;
- case SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512:
- i2p::crypto::CreateGOSTR3410RandomKeys (i2p::crypto::eGOSTR3410TC26A512, priv, pub);
- break;
case SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519:
i2p::crypto::CreateRedDSA25519RandomKeys (priv, pub);
break;
diff --git a/libi2pd/Signature.h b/libi2pd/Signature.h
index fe609fb..79b36f1 100644
@@ -17,7 +17,6 @@
#include <openssl/evp.h>
#include "Crypto.h"
#include "Ed25519.h"
-#include "Gost.h"
namespace i2p
{
@@ -450,130 +449,6 @@ namespace crypto
}
- // ГОСТ Р 34.11
- struct GOSTR3411_256_Hash
- {
- static void CalculateHash (const uint8_t * buf, size_t len, uint8_t * digest)
- {
- GOSTR3411_2012_256 (buf, len, digest);
- }
-
- enum { hashLen = 32 };
- };
-
- struct GOSTR3411_512_Hash
- {
- static void CalculateHash (const uint8_t * buf, size_t len, uint8_t * digest)
- {
- GOSTR3411_2012_512 (buf, len, digest);
- }
-
- enum { hashLen = 64 };
- };
-
- // ГОСТ Р 34.10
- const size_t GOSTR3410_256_PUBLIC_KEY_LENGTH = 64;
- const size_t GOSTR3410_512_PUBLIC_KEY_LENGTH = 128;
-
- template<typename Hash>
- class GOSTR3410Verifier: public Verifier
- {
- public:
-
- enum { keyLen = Hash::hashLen };
-
- GOSTR3410Verifier (GOSTR3410ParamSet paramSet):
- m_ParamSet (paramSet), m_PublicKey (nullptr)
- {
- }
-
- void SetPublicKey (const uint8_t * signingKey)
- {
- BIGNUM * x = BN_bin2bn (signingKey, GetPublicKeyLen ()/2, NULL);
- BIGNUM * y = BN_bin2bn (signingKey + GetPublicKeyLen ()/2, GetPublicKeyLen ()/2, NULL);
- m_PublicKey = GetGOSTR3410Curve (m_ParamSet)->CreatePoint (x, y);
- BN_free (x); BN_free (y);
- }
- ~GOSTR3410Verifier ()
- {
- if (m_PublicKey) EC_POINT_free (m_PublicKey);
- }
-
- bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const
- {
- uint8_t digest[Hash::hashLen];
- Hash::CalculateHash (buf, len, digest);
- BIGNUM * d = BN_bin2bn (digest, Hash::hashLen, nullptr);
- BIGNUM * r = BN_bin2bn (signature, GetSignatureLen ()/2, NULL);
- BIGNUM * s = BN_bin2bn (signature + GetSignatureLen ()/2, GetSignatureLen ()/2, NULL);
- bool ret = GetGOSTR3410Curve (m_ParamSet)->Verify (m_PublicKey, d, r, s);
- BN_free (d); BN_free (r); BN_free (s);
- return ret;
- }
-
- size_t GetPublicKeyLen () const { return keyLen*2; }
- size_t GetSignatureLen () const { return keyLen*2; }
-
- private:
-
- GOSTR3410ParamSet m_ParamSet;
- EC_POINT * m_PublicKey;
- };
-
- template<typename Hash>
- class GOSTR3410Signer: public Signer
- {
- public:
-
- enum { keyLen = Hash::hashLen };
-
- GOSTR3410Signer (GOSTR3410ParamSet paramSet, const uint8_t * signingPrivateKey):
- m_ParamSet (paramSet)
- {
- m_PrivateKey = BN_bin2bn (signingPrivateKey, keyLen, nullptr);
- }
- ~GOSTR3410Signer () { BN_free (m_PrivateKey); }
-
- void Sign (const uint8_t * buf, int len, uint8_t * signature) const
- {
- uint8_t digest[Hash::hashLen];
- Hash::CalculateHash (buf, len, digest);
- BIGNUM * d = BN_bin2bn (digest, Hash::hashLen, nullptr);
- BIGNUM * r = BN_new (), * s = BN_new ();
- GetGOSTR3410Curve (m_ParamSet)->Sign (m_PrivateKey, d, r, s);
- bn2buf (r, signature, keyLen);
- bn2buf (s, signature + keyLen, keyLen);
- BN_free (d); BN_free (r); BN_free (s);
- }
-
- private:
-
- GOSTR3410ParamSet m_ParamSet;
- BIGNUM * m_PrivateKey;
- };
-
- inline void CreateGOSTR3410RandomKeys (GOSTR3410ParamSet paramSet, uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
- {
- const auto& curve = GetGOSTR3410Curve (paramSet);
- auto keyLen = curve->GetKeyLen ();
- RAND_bytes (signingPrivateKey, keyLen);
- BIGNUM * priv = BN_bin2bn (signingPrivateKey, keyLen, nullptr);
-
- auto pub = curve->MulP (priv);
- BN_free (priv);
- BIGNUM * x = BN_new (), * y = BN_new ();
- curve->GetXY (pub, x, y);
- EC_POINT_free (pub);
- bn2buf (x, signingPublicKey, keyLen);
- bn2buf (y, signingPublicKey + keyLen, keyLen);
- BN_free (x); BN_free (y);
- }
-
- typedef GOSTR3410Verifier<GOSTR3411_256_Hash> GOSTR3410_256_Verifier;
- typedef GOSTR3410Signer<GOSTR3411_256_Hash> GOSTR3410_256_Signer;
- typedef GOSTR3410Verifier<GOSTR3411_512_Hash> GOSTR3410_512_Verifier;
- typedef GOSTR3410Signer<GOSTR3411_512_Hash> GOSTR3410_512_Signer;
-
// RedDSA
typedef EDDSA25519Verifier RedDSA25519Verifier;
class RedDSA25519Signer: public Signer