correct param set for GOST R 34.10 signing

pull/824/head
orignal 7 years ago
parent 439c2d445c
commit cd860bfbf8

@ -525,7 +525,7 @@ namespace data
m_Signer.reset (new i2p::crypto::EDDSA25519Signer (m_SigningPrivateKey, m_Public->GetStandardIdentity ().certificate - i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH));
break;
case SIGNING_KEY_TYPE_GOSTR3410_A_GOSTR3411:
m_Signer.reset (new i2p::crypto::GOSTR3410Signer (m_SigningPrivateKey));
m_Signer.reset (new i2p::crypto::GOSTR3410Signer (i2p::crypto::eGOSTR3410CryptoProA, m_SigningPrivateKey));
break;
default:
LogPrint (eLogError, "Identity: Signing key type ", (int)m_Public->GetSigningKeyType (), " is not supported");
@ -563,7 +563,7 @@ namespace data
i2p::crypto::CreateEDDSA25519RandomKeys (keys.m_SigningPrivateKey, signingPublicKey);
break;
case SIGNING_KEY_TYPE_GOSTR3410_A_GOSTR3411:
i2p::crypto::CreateGOSTR3410RandomKeys (keys.m_SigningPrivateKey, signingPublicKey);
i2p::crypto::CreateGOSTR3410RandomKeys (i2p::crypto::eGOSTR3410CryptoProA, keys.m_SigningPrivateKey, signingPublicKey);
break;
default:
LogPrint (eLogError, "Identity: Signing key type ", (int)type, " is not supported. Create DSA-SHA1");

@ -614,6 +614,19 @@ namespace crypto
return g_GOSTR3410Curves[paramSet];
}
void GOSTR3410Signer::Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
uint8_t digest[32];
GOSTR3411 (buf, len, digest);
BIGNUM * d = BN_bin2bn (digest, 32, nullptr);
BIGNUM * r = BN_new (), * s = BN_new ();
const auto& curve = GetGOSTR3410Curve (m_ParamSet);
curve->Sign (m_PrivateKey, d, r, s);
bn2buf (r, signature, GOSTR3410_SIGNATURE_LENGTH/2);
bn2buf (s, signature + GOSTR3410_SIGNATURE_LENGTH/2, GOSTR3410_SIGNATURE_LENGTH/2);
BN_free (d); BN_free (r); BN_free (s);
}
void CreateGOSTR3410RandomKeys (GOSTR3410ParamSet paramSet, uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
RAND_bytes (signingPrivateKey, GOSTR3410_PUBLIC_KEY_LENGTH/2);

@ -498,37 +498,22 @@ namespace crypto
{
public:
GOSTR3410Signer (const uint8_t * signingPrivateKey)
GOSTR3410Signer (GOSTR3410ParamSet paramSet, const uint8_t * signingPrivateKey):
m_ParamSet (paramSet)
{
m_PrivateKey = EVP_PKEY_new ();
EC_KEY * ecKey = EC_KEY_new ();
EVP_PKEY_assign (m_PrivateKey, NID_id_GostR3410_2001, ecKey);
EVP_PKEY_copy_parameters (m_PrivateKey, GetGostPKEY ());
EC_KEY_set_private_key (ecKey, BN_bin2bn (signingPrivateKey, GOSTR3410_PUBLIC_KEY_LENGTH/2, NULL));
m_PrivateKey = BN_bin2bn (signingPrivateKey, GOSTR3410_PUBLIC_KEY_LENGTH/2, nullptr);
}
~GOSTR3410Signer () { EVP_PKEY_free (m_PrivateKey); }
~GOSTR3410Signer () { BN_free (m_PrivateKey); }
void Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
uint8_t digest[32];
GOSTR3411 (buf, len, digest);
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new (m_PrivateKey, nullptr);
EVP_PKEY_sign_init (ctx);
size_t l = GOSTR3410_SIGNATURE_LENGTH;
EVP_PKEY_sign (ctx, signature, &l, digest, 32);
EVP_PKEY_CTX_free (ctx);
}
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
private:
EVP_PKEY * m_PrivateKey;
GOSTR3410ParamSet m_ParamSet;
BIGNUM * m_PrivateKey;
};
void CreateGOSTR3410RandomKeys (GOSTR3410ParamSet paramSet, uint8_t * signingPrivateKey, uint8_t * signingPublicKey);
inline void CreateGOSTR3410RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey)
{
CreateGOSTR3410RandomKeys (eGOSTR3410CryptoProA, signingPrivateKey, signingPublicKey); // A by default
}
}
}

Loading…
Cancel
Save