generate GOST R 34.10 keys with param set

This commit is contained in:
orignal 2017-03-09 18:46:28 -05:00
parent 831c835106
commit 7f71d5dbd8
2 changed files with 32 additions and 16 deletions

View file

@ -524,22 +524,10 @@ namespace crypto
EVP_PKEY * m_PrivateKey;
};
void CreateGOSTR3410RandomKeys (GOSTR3410ParamSet paramSet, uint8_t * signingPrivateKey, uint8_t * signingPublicKey);
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"); // TODO should be in one place
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);
CreateGOSTR3410RandomKeys (eGOSTR3410CryptoProA, signingPrivateKey, signingPublicKey); // A by default
}
}
}