aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Timoshkov <dmitry@baikal.ru>2020-11-27 17:19:59 +0300
committerDmitry Belyavskiy <beldmit@gmail.com>2020-11-28 19:57:04 +0300
commit46ebb505e1b2ade87bef52b389ecdebdd2049af4 (patch)
treeba7caf54391c24fdb1e63baae13bc334b9876690
parent09490070b7ce29a510759f0f058a65e97be089c2 (diff)
downloadgost-engine-46ebb505e1b2ade87bef52b389ecdebdd2049af4.zip
gost-engine-46ebb505e1b2ade87bef52b389ecdebdd2049af4.tar.gz
gost-engine-46ebb505e1b2ade87bef52b389ecdebdd2049af4.tar.bz2
Add explicit support for NID_id_GostR3410_2001DH (GOST R 34.10-2001 DH)
(cherry picked from commit e1afd2a137a0a4cab89260202fdc1828263d098d)
-rw-r--r--gost_ameth.c8
-rw-r--r--gost_ec_keyx.c2
-rw-r--r--gost_eng.c9
-rw-r--r--gost_pmeth.c4
4 files changed, 22 insertions, 1 deletions
diff --git a/gost_ameth.c b/gost_ameth.c
index f13b4ed..253b009 100644
--- a/gost_ameth.c
+++ b/gost_ameth.c
@@ -43,6 +43,7 @@ static int pkey_bits_gost(const EVP_PKEY *pk)
switch (EVP_PKEY_base_id(pk)) {
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
case NID_id_GostR3410_2012_256:
return 256;
case NID_id_GostR3410_2012_512:
@@ -87,6 +88,7 @@ static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key)
}
break;
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr));
gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet);
break;
@@ -127,6 +129,7 @@ static int gost_decode_nid_params(EVP_PKEY *pkey, int pkey_nid, int param_nid)
case NID_id_GostR3410_2012_256:
case NID_id_GostR3410_2012_512:
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
if (!key_ptr) {
key_ptr = EC_KEY_new();
if (!EVP_PKEY_assign(pkey, pkey_nid, key_ptr)) {
@@ -186,6 +189,7 @@ static int gost_set_priv_key(EVP_PKEY *pkey, BIGNUM *priv)
case NID_id_GostR3410_2012_512:
case NID_id_GostR3410_2012_256:
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
{
EC_KEY *ec = EVP_PKEY_get0(pkey);
if (!ec) {
@@ -210,6 +214,7 @@ BIGNUM *gost_get0_priv_key(const EVP_PKEY *pkey)
case NID_id_GostR3410_2012_512:
case NID_id_GostR3410_2012_256:
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
{
EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey);
if (ec)
@@ -236,6 +241,7 @@ static int pkey_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
md_nid = NID_id_GostR3411_2012_256;
break;
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
case NID_id_GostR3410_94:
md_nid = NID_id_GostR3411_94;
break;
@@ -821,6 +827,7 @@ static int pkey_size_gost(const EVP_PKEY *pk)
switch (EVP_PKEY_base_id(pk)) {
case NID_id_GostR3410_94:
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
case NID_id_GostR3410_2012_256:
return 64;
case NID_id_GostR3410_2012_512:
@@ -915,6 +922,7 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth,
return 0;
switch (nid) {
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
EVP_PKEY_asn1_set_free(*ameth, pkey_free_gost_ec);
EVP_PKEY_asn1_set_private(*ameth,
priv_decode_gost, priv_encode_gost,
diff --git a/gost_ec_keyx.c b/gost_ec_keyx.c
index dd52a74..9680393 100644
--- a/gost_ec_keyx.c
+++ b/gost_ec_keyx.c
@@ -248,7 +248,7 @@ static int pkey_GOST_ECcp_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out,
EVP_PKEY *pubk = EVP_PKEY_CTX_get0_pkey(pctx);
struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(pctx);
int pkey_nid = EVP_PKEY_base_id(pubk);
- ASN1_OBJECT *crypt_params_obj = (pkey_nid == NID_id_GostR3410_2001) ?
+ ASN1_OBJECT *crypt_params_obj = (pkey_nid == NID_id_GostR3410_2001 || pkey_nid == NID_id_GostR3410_2001DH) ?
OBJ_nid2obj(NID_id_Gost28147_89_CryptoPro_A_ParamSet) :
OBJ_nid2obj(NID_id_tc26_gost_28147_param_Z);
const struct gost_cipher_info *param =
diff --git a/gost_eng.c b/gost_eng.c
index 8257072..7faf0bc 100644
--- a/gost_eng.c
+++ b/gost_eng.c
@@ -39,6 +39,7 @@ static int gost_pkey_asn1_meths(ENGINE* e, EVP_PKEY_ASN1_METHOD** ameth,
const int** nids, int nid);
static EVP_PKEY_METHOD* pmeth_GostR3410_2001 = NULL,
+ * pmeth_GostR3410_2001DH = NULL,
* pmeth_GostR3410_2012_256 = NULL,
* pmeth_GostR3410_2012_512 = NULL,
* pmeth_Gost28147_MAC = NULL, * pmeth_Gost28147_MAC_12 = NULL,
@@ -46,6 +47,7 @@ static EVP_PKEY_METHOD* pmeth_GostR3410_2001 = NULL,
* pmeth_magma_mac_acpkm = NULL, * pmeth_grasshopper_mac_acpkm = NULL;
static EVP_PKEY_ASN1_METHOD* ameth_GostR3410_2001 = NULL,
+ * ameth_GostR3410_2001DH = NULL,
* ameth_GostR3410_2012_256 = NULL,
* ameth_GostR3410_2012_512 = NULL,
* ameth_Gost28147_MAC = NULL, * ameth_Gost28147_MAC_12 = NULL,
@@ -176,6 +178,13 @@ static struct gost_meth_minfo {
"GOST R 34.10-2001",
},
{
+ NID_id_GostR3410_2001DH,
+ &pmeth_GostR3410_2001DH,
+ &ameth_GostR3410_2001DH,
+ "GOST2001 DH",
+ "GOST R 34.10-2001 DH",
+ },
+ {
NID_id_Gost28147_89_MAC,
&pmeth_Gost28147_MAC,
&ameth_Gost28147_MAC,
diff --git a/gost_pmeth.c b/gost_pmeth.c
index 3f60210..b990d1a 100644
--- a/gost_pmeth.c
+++ b/gost_pmeth.c
@@ -39,6 +39,7 @@ static int pkey_gost_init(EVP_PKEY_CTX *ctx)
if (pkey && EVP_PKEY_get0(pkey)) {
switch (EVP_PKEY_base_id(pkey)) {
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
case NID_id_GostR3410_2012_256:
case NID_id_GostR3410_2012_512:
{
@@ -107,6 +108,7 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
switch (EVP_MD_type((const EVP_MD *)p2)) {
case NID_id_GostR3411_94:
if (pkey_nid == NID_id_GostR3410_2001
+ || pkey_nid == NID_id_GostR3410_2001DH
|| pkey_nid == NID_id_GostR3410_94) {
pctx->md = (EVP_MD *)p2;
return 1;
@@ -458,6 +460,7 @@ static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
switch (EVP_PKEY_base_id(pkey)) {
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
case NID_id_GostR3410_2012_256:
order = 64;
break;
@@ -1015,6 +1018,7 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
switch (id) {
case NID_id_GostR3410_2001:
+ case NID_id_GostR3410_2001DH:
EVP_PKEY_meth_set_ctrl(*pmeth,
pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);