From f8a09df5c0d8861a7e1b383eab9e71f7c98244e1 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 16 Feb 2017 21:45:12 -0500 Subject: [PATCH] generate GOST R 34.10 keys pair --- Signature.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Signature.h b/Signature.h index f0b51050..19fa565b 100644 --- a/Signature.h +++ b/Signature.h @@ -490,6 +490,24 @@ namespace crypto EVP_PKEY * m_PrivateKey; }; + + inline void CreateGOSTR3410RandomKeys (uint8_t * signingPrivateKey, uint8_t * signingPublicKey) + { + auto ctx = EVP_PKEY_CTX_new_id(NID_id_GostR3410_2001, nullptr); + EVP_PKEY_keygen_init (ctx); + EVP_PKEY_CTX_ctrl_str (ctx, "paramset", "A"); + EVP_PKEY* pkey = nullptr; + EVP_PKEY_keygen (ctx, &pkey); + const EC_KEY* ecKey = (const EC_KEY*) EVP_PKEY_get0(pkey); + bn2buf (EC_KEY_get0_private_key (ecKey), signingPrivateKey, GOSTR3410_PUBLIC_KEY_LENGTH/2); + BIGNUM * x = BN_new(), * y = BN_new(); + EC_POINT_get_affine_coordinates_GFp (EC_KEY_get0_group(ecKey), EC_KEY_get0_public_key (ecKey), x, y, NULL); + bn2buf (x, signingPublicKey, GOSTR3410_PUBLIC_KEY_LENGTH/2); + bn2buf (y, signingPublicKey + GOSTR3410_PUBLIC_KEY_LENGTH/2, GOSTR3410_PUBLIC_KEY_LENGTH/2); + BN_free (x); BN_free (y); + EVP_PKEY_CTX_free (ctx); + EVP_PKEY_free (pkey); + } } }