X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_ameth.c;h=5089e2a21adf1184f6edebed1b3889471ba6610f;hb=25729ddc501fecd873943450dec45e15d885c20f;hp=b2d6abacb2544132d9ee9132f332144445d9d298;hpb=f8a4b31268d06d4deea274a7d3e644cf4f84e386;p=openssl-gost%2Fengine.git diff --git a/gost_ameth.c b/gost_ameth.c index b2d6aba..5089e2a 100644 --- a/gost_ameth.c +++ b/gost_ameth.c @@ -19,7 +19,7 @@ #include "gost_lcl.h" #include "e_gost_err.h" -#define PK_UNMASK_PARAM "UNMASK" +#define PK_WRAP_PARAM "LEGACY_PK_WRAP" /* * Pack bignum into byte buffer of given size, filling all leading bytes by @@ -419,6 +419,8 @@ static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk) ASN1_STRING *params = encode_gost_algor_params(pk); unsigned char *buf = NULL; int key_len = pkey_bits_gost(pk), i = 0; + /* unmasked private key */ + const char *pk_format = get_gost_engine_param(GOST_PARAM_PK_FORMAT); if (!params) { return 0; @@ -441,9 +443,7 @@ static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk) buf[key_len - 1 - i] = tmp; } - /* unmasked private key */ - const char *pk_param = get_gost_engine_param(GOST_PARAM_PK_PARAMS); - if(pk_param != NULL && strcmp(pk_param, PK_UNMASK_PARAM) == 0) { + if(pk_format != NULL && strcmp(pk_format, PK_WRAP_PARAM) == 0) { ASN1_STRING *octet = NULL; int priv_len = 0; unsigned char *priv_buf = NULL; @@ -842,6 +842,30 @@ static int mac_ctrl_gost_12(EVP_PKEY *pkey, int op, long arg1, void *arg2) return -2; } +static int mac_ctrl_magma(EVP_PKEY *pkey, int op, long arg1, void *arg2) +{ + switch (op) { + case ASN1_PKEY_CTRL_DEFAULT_MD_NID: + if (arg2) { + *(int *)arg2 = NID_magma_mac; + return 2; + } + } + return -2; +} + +static int mac_ctrl_grasshopper(EVP_PKEY *pkey, int op, long arg1, void *arg2) +{ + switch (op) { + case ASN1_PKEY_CTRL_DEFAULT_MD_NID: + if (arg2) { + *(int *)arg2 = NID_grasshopper_mac; + return 2; + } + } + return -2; +} + static int gost2001_param_encode(const EVP_PKEY *pkey, unsigned char **pder) { int nid = @@ -922,6 +946,14 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth, EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost); EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_gost_12); break; + case NID_magma_mac: + EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost); + EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_magma); + break; + case NID_grasshopper_mac: + EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost); + EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_grasshopper); + break; } return 1; }