1 /**********************************************************************
3 * Copyright (c) 2005-2006 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Implementation of RFC 4490/4491 ASN1 method *
8 * Requires OpenSSL 0.9.9 for compilation *
9 **********************************************************************/
10 #include <openssl/engine.h>
11 #include <openssl/evp.h>
12 #include <openssl/asn1.h>
14 #include "gost_params.h"
16 #include "e_gost_err.h"
18 int gost94_nid_by_params(DSA *p)
20 R3410_params *gost_params;
22 for (gost_params = R3410_paramset;gost_params->q!=NULL; gost_params++)
24 BN_dec2bn(&q,gost_params->q);
28 return gost_params->nid;
35 static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key)
37 ASN1_STRING *params = ASN1_STRING_new();
38 GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new();
39 int pkey_param_nid = NID_undef;
40 int cipher_param_nid = NID_undef;
43 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
44 ERR_R_MALLOC_FAILURE);
45 ASN1_STRING_free(params);
49 switch (EVP_PKEY_base_id(key))
51 case NID_id_GostR3410_2001_cc:
52 pkey_param_nid = NID_id_GostR3410_2001_ParamSet_cc;
53 cipher_param_nid = NID_id_Gost28147_89_cc;
55 case NID_id_GostR3410_94_cc:
56 pkey_param_nid = NID_id_GostR3410_94_CryptoPro_A_ParamSet;
57 cipher_param_nid = NID_id_Gost28147_89_cc;
59 case NID_id_GostR3410_2001:
60 pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)key)));
61 cipher_param_nid = get_encryption_params(NULL)->nid;
63 case NID_id_GostR3410_94:
64 pkey_param_nid = (int) gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)key));
65 if (pkey_param_nid == NID_undef)
67 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
68 GOST_R_INVALID_GOST94_PARMSET);
69 ASN1_STRING_free(params);
73 cipher_param_nid = get_encryption_params(NULL)->nid;
76 gkp->key_params = OBJ_nid2obj(pkey_param_nid);
77 gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet);
78 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid);*/
79 params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data);
80 if (params->length <=0 )
82 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
83 ERR_R_MALLOC_FAILURE);
84 ASN1_STRING_free(params);
88 params ->type = V_ASN1_SEQUENCE;
90 GOST_KEY_PARAMS_free(gkp);
94 /* Parses GOST algorithm parameters from X509_ALGOR and
95 * modifies pkey setting NID and parameters
97 static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)
99 ASN1_OBJECT *palg_obj =NULL;
100 int ptype = V_ASN1_UNDEF;
101 int pkey_nid = NID_undef,param_nid = NID_undef;
103 ASN1_STRING *pval = NULL;
104 const unsigned char *p;
105 GOST_KEY_PARAMS *gkp = NULL;
107 X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);
109 if (ptype != V_ASN1_SEQUENCE)
111 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
112 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
116 pkey_nid = OBJ_obj2nid(palg_obj);
118 gkp = d2i_GOST_KEY_PARAMS(NULL,&p,pval->length);
121 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
122 GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
125 param_nid = OBJ_obj2nid(gkp->key_params);
126 GOST_KEY_PARAMS_free(gkp);
127 EVP_PKEY_set_type(pkey,pkey_nid);
130 case NID_id_GostR3410_94:
131 case NID_id_GostR3410_94_cc:
133 DSA *dsa= EVP_PKEY_get0(pkey);
137 if (!EVP_PKEY_assign(pkey,pkey_nid,dsa)) return 0;
139 if (!fill_GOST94_params(dsa,param_nid)) return 0;
142 case NID_id_GostR3410_2001:
143 case NID_id_GostR3410_2001_cc:
145 EC_KEY *ec = EVP_PKEY_get0(pkey);
149 if (!EVP_PKEY_assign(pkey,pkey_nid,ec)) return 0;
151 if (!fill_GOST2001_params(ec,param_nid)) return 0;
158 static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv)
160 switch (EVP_PKEY_base_id(pkey))
162 case NID_id_GostR3410_94:
163 case NID_id_GostR3410_94_cc:
165 DSA *dsa = EVP_PKEY_get0(pkey);
169 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
171 dsa->priv_key = BN_dup(priv);
172 if (!EVP_PKEY_missing_parameters(pkey))
173 gost94_compute_public(dsa);
176 case NID_id_GostR3410_2001:
177 case NID_id_GostR3410_2001_cc:
179 EC_KEY *ec = EVP_PKEY_get0(pkey);
183 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
185 if (!EC_KEY_set_private_key(ec,priv)) return 0;
186 if (!EVP_PKEY_missing_parameters(pkey))
187 gost2001_compute_public(ec);
193 BIGNUM* gost_get_priv_key(const EVP_PKEY *pkey)
195 switch (EVP_PKEY_base_id(pkey))
197 case NID_id_GostR3410_94:
198 case NID_id_GostR3410_94_cc:
200 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pkey);
205 if (!dsa->priv_key) return NULL;
206 return BN_dup(dsa->priv_key);
209 case NID_id_GostR3410_2001:
210 case NID_id_GostR3410_2001_cc:
212 EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey);
218 if (!(priv=EC_KEY_get0_private_key(ec))) return NULL;
226 static int pkey_ctrl_gost(EVP_PKEY *pkey, int op,
227 long arg1, void *arg2)
231 case ASN1_PKEY_CTRL_PKCS7_SIGN:
234 X509_ALGOR *alg1 = NULL, *alg2 = NULL;
235 int nid = EVP_PKEY_base_id(pkey);
236 PKCS7_SIGNER_INFO_get0_algs((PKCS7_SIGNER_INFO*)arg2,
238 X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_id_GostR3411_94),
240 if (nid == NID_undef)
244 X509_ALGOR_set0(alg2, OBJ_nid2obj(nid), V_ASN1_NULL, 0);
247 case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
251 ASN1_STRING * params = encode_gost_algor_params(pkey);
256 PKCS7_RECIP_INFO_get0_alg((PKCS7_RECIP_INFO*)arg2, &alg);
257 X509_ALGOR_set0(alg, OBJ_nid2obj(pkey->type),
258 V_ASN1_SEQUENCE, params);
261 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
262 *(int *)arg2 = NID_id_GostR3411_94;
268 /*----------------------- free functions * ------------------------------*/
269 static void pkey_free_gost94(EVP_PKEY *key)
273 DSA_free(key->pkey.dsa);
277 static void pkey_free_gost01(EVP_PKEY *key)
281 EC_KEY_free(key->pkey.ec);
285 /* ------------------ private key functions -----------------------------*/
286 static int priv_decode_gost( EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
288 const unsigned char *pkey_buf = NULL,*p=NULL;
292 X509_ALGOR *palg =NULL;
293 ASN1_OBJECT *palg_obj = NULL;
294 ASN1_INTEGER *priv_key=NULL;
296 if (!PKCS8_pkey_get0(&palg_obj,&pkey_buf,&priv_len,&palg,p8inf))
299 if (!decode_gost_algor_params(pk,palg))
303 if (V_ASN1_OCTET_STRING == *p)
305 /* New format - Little endian octet string */
306 unsigned char rev_buf[32];
308 ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL,&p,priv_len);
309 if (!s||s->length !=32)
311 GOSTerr(GOST_F_PRIV_DECODE_GOST_94,
317 rev_buf[31-i]=s->data[i];
320 pk_num = getbnfrombuf(rev_buf,32);
324 priv_key=d2i_ASN1_INTEGER(NULL,&p,priv_len);
325 if (!priv_key || !(pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)))
327 GOSTerr(GOST_F_PRIV_DECODE_GOST_94,
333 ret= gost_set_priv_key(pk,pk_num);
338 /* ----------------------------------------------------------------------*/
339 static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk)
341 ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
342 ASN1_STRING *params = encode_gost_algor_params(pk);
343 unsigned char *priv_buf = NULL;
347 ASN1_INTEGER *asn1key=NULL;
352 key = gost_get_priv_key(pk);
353 asn1key = BN_to_ASN1_INTEGER(key,NULL);
355 priv_len = i2d_ASN1_INTEGER(asn1key,&priv_buf);
356 ASN1_INTEGER_free(asn1key);
357 return PKCS8_pkey_set0(p8,algobj,0,V_ASN1_SEQUENCE,params,
361 static int priv_print_gost (BIO *out,const EVP_PKEY *pkey, int indent,
365 if (!BIO_indent(out,indent,128)) return 0;
366 key = gost_get_priv_key(pkey);
373 /* ---------------------------------------------------------------------*/
374 static int param_missing_gost94(const EVP_PKEY *pk)
376 const DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
378 if (!dsa->q) return 1;
382 static int param_missing_gost01(const EVP_PKEY *pk)
384 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
386 if (!EC_KEY_get0_group(ec)) return 1;
390 static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from)
392 const DSA *dfrom = EVP_PKEY_get0((EVP_PKEY *)from);
393 DSA *dto = EVP_PKEY_get0(to);
394 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
396 GOSTerr(GOST_F_PARAM_COPY_GOST94,
397 GOST_R_INCOMPATIBLE_ALGORITHMS);
402 GOSTerr(GOST_F_PARAM_COPY_GOST94,
403 GOST_R_KEY_PARAMETERS_MISSING);
409 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),dto);
411 #define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);
412 COPYBIGNUM(dto,dfrom,p)
413 COPYBIGNUM(dto,dfrom,q)
414 COPYBIGNUM(dto,dfrom,g)
417 gost94_compute_public(dto);
420 static int param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
422 EC_KEY *eto = EVP_PKEY_get0(to);
423 const EC_KEY *efrom = EVP_PKEY_get0((EVP_PKEY *)from);
424 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
426 GOSTerr(GOST_F_PARAM_COPY_GOST01,
427 GOST_R_INCOMPATIBLE_ALGORITHMS);
432 GOSTerr(GOST_F_PARAM_COPY_GOST94,
433 GOST_R_KEY_PARAMETERS_MISSING);
439 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),eto);
441 EC_KEY_set_group(eto,EC_GROUP_dup(EC_KEY_get0_group(efrom)));
442 if (EC_KEY_get0_private_key(eto))
444 gost2001_compute_public(eto);
449 static int param_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
451 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
452 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
453 if (!BN_cmp(da->q,db->q)) return 1;
457 static int param_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b)
459 if (EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)a)))==
460 EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)b))))
468 /* ---------- Public key functions * --------------------------------------*/
469 static int pub_decode_gost94(EVP_PKEY *pk, X509_PUBKEY *pub)
471 X509_ALGOR *palg = NULL;
472 const unsigned char *pubkey_buf = NULL;
473 unsigned char *databuf;
474 ASN1_OBJECT *palgobj = NULL;
477 ASN1_OCTET_STRING *octet= NULL;
479 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
480 &palg, pub)) return 0;
481 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
482 if (!decode_gost_algor_params(pk,palg)) return 0;
483 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
486 GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
489 databuf = OPENSSL_malloc(octet->length);
490 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
492 databuf[j]=octet->data[i];
494 dsa = EVP_PKEY_get0(pk);
495 dsa->pub_key=BN_bin2bn(databuf,octet->length,NULL);
496 ASN1_OCTET_STRING_free(octet);
497 OPENSSL_free(databuf);
502 static int pub_encode_gost94(X509_PUBKEY *pub,const EVP_PKEY *pk)
504 ASN1_OBJECT *algobj = NULL;
505 ASN1_OCTET_STRING *octet = NULL;
507 unsigned char *buf=NULL,*databuf,*sptr;
508 int i,j,data_len,ret=0;
510 int ptype = V_ASN1_UNDEF;
511 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
512 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
513 if (pk->save_parameters)
515 ASN1_STRING *params = encode_gost_algor_params(pk);
517 ptype = V_ASN1_SEQUENCE;
519 data_len = BN_num_bytes(dsa->pub_key);
520 databuf = OPENSSL_malloc(data_len);
521 BN_bn2bin(dsa->pub_key,databuf);
522 octet = ASN1_OCTET_STRING_new();
523 ASN1_STRING_set(octet,NULL,data_len);
524 sptr = ASN1_STRING_data(octet);
525 for (i=0,j=data_len-1; i< data_len;i++,j--)
529 OPENSSL_free(databuf);
530 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
531 ASN1_BIT_STRING_free(octet);
532 if (ret <0) return 0;
533 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
536 static int pub_decode_gost01(EVP_PKEY *pk,X509_PUBKEY *pub)
538 X509_ALGOR *palg = NULL;
539 const unsigned char *pubkey_buf = NULL;
540 unsigned char *databuf;
541 ASN1_OBJECT *palgobj = NULL;
545 ASN1_OCTET_STRING *octet= NULL;
546 const EC_GROUP *group;
548 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
549 &palg, pub)) return 0;
550 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
551 if (!decode_gost_algor_params(pk,palg)) return 0;
552 group = EC_KEY_get0_group(EVP_PKEY_get0(pk));
553 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
556 GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
559 databuf = OPENSSL_malloc(octet->length);
560 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
562 databuf[j]=octet->data[i];
564 if (EVP_PKEY_base_id(pk) == NID_id_GostR3410_2001_cc)
566 X= getbnfrombuf(databuf,octet->length/2);
567 Y= getbnfrombuf(databuf+(octet->length/2),octet->length/2);
571 Y= getbnfrombuf(databuf,octet->length/2);
572 X= getbnfrombuf(databuf+(octet->length/2),octet->length/2);
574 OPENSSL_free(databuf);
575 pub_key = EC_POINT_new(group);
576 if (!EC_POINT_set_affine_coordinates_GFp(group
579 GOSTerr(GOST_F_PUB_DECODE_GOST01,
585 if (!EC_KEY_set_public_key(EVP_PKEY_get0(pk),pub_key))
587 GOSTerr(GOST_F_PUB_DECODE_GOST01,
591 /*EC_POINT_free(pub_key);*/
596 static int pub_encode_gost01(X509_PUBKEY *pub,const EVP_PKEY *pk)
598 ASN1_OBJECT *algobj = NULL;
599 ASN1_OCTET_STRING *octet = NULL;
601 unsigned char *buf=NULL,*databuf,*sptr;
602 int i,j,data_len,ret=0;
603 const EC_POINT *pub_key;
605 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
606 int ptype = V_ASN1_UNDEF;
608 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
609 if (pk->save_parameters)
611 ASN1_STRING *params = encode_gost_algor_params(pk);
613 ptype = V_ASN1_SEQUENCE;
616 EC_GROUP_get_order(EC_KEY_get0_group(ec),order,NULL);
617 pub_key=EC_KEY_get0_public_key(ec);
620 GOSTerr(GOST_F_PUB_ENCODE_GOST01,
621 GOST_R_PUBLIC_KEY_UNDEFINED);
626 EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
628 data_len = 2*BN_num_bytes(order);
630 databuf = OPENSSL_malloc(data_len);
631 memset(databuf,0,data_len);
632 if (EVP_PKEY_base_id(pk) == NID_id_GostR3410_2001_cc)
634 store_bignum(X,databuf,data_len/2);
635 store_bignum(Y,databuf+data_len/2,data_len/2);
639 store_bignum(X,databuf+data_len/2,data_len/2);
640 store_bignum(Y,databuf,data_len/2);
644 octet = ASN1_OCTET_STRING_new();
645 ASN1_STRING_set(octet,NULL,data_len);
646 sptr=ASN1_STRING_data(octet);
647 for (i=0,j=data_len-1;i<data_len;i++,j--)
651 OPENSSL_free(databuf);
652 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
653 ASN1_BIT_STRING_free(octet);
654 if (ret <0) return 0;
655 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
658 static int pub_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
660 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
661 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
662 if (da && db && da->pub_key && db->pub_key
663 && !BN_cmp(da->pub_key,db->pub_key))
670 static int pub_cmp_gost01(const EVP_PKEY *a,const EVP_PKEY *b)
672 const EC_KEY *ea = EVP_PKEY_get0((EVP_PKEY *)a);
673 const EC_KEY *eb = EVP_PKEY_get0((EVP_PKEY *)b);
674 const EC_POINT *ka,*kb;
676 if (!ea || !eb) return 0;
677 ka = EC_KEY_get0_public_key(ea);
678 kb = EC_KEY_get0_public_key(eb);
679 if (!ka || !kb) return 0;
680 ret = (0==EC_POINT_cmp(EC_KEY_get0_group(ea),ka,kb,NULL)) ;
684 static int pub_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
688 if (!BIO_indent(out,indent,128)) return 0;
689 key = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key;
695 static int pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
701 static int pkey_size_gost(const EVP_PKEY *pk)
706 static int pkey_bits_gost(const EVP_PKEY *pk)
710 /*------------------------ ASN1 METHOD for GOST MAC -------------------*/
711 static void mackey_free_gost(EVP_PKEY *pk)
714 OPENSSL_free(pk->pkey.ptr);
717 static int priv_decode_mac(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
719 X509_ALGOR *palg = NULL;
721 ASN1_OBJECT *palg_obj = NULL;
722 ASN1_OCTET_STRING *s=NULL;
723 const unsigned char *pkey_buf = NULL, *p = NULL;
724 unsigned char *keybuf=NULL;
725 if (!PKCS8_pkey_get0(&palg_obj,&pkey_buf,&priv_len,&palg,p8inf))
730 if (V_ASN1_OCTET_STRING != *p)
732 GOSTerr(GOST_F_PRIV_DECODE_MAC,
733 GOST_R_DECODE_ERROR);
736 s = d2i_ASN1_OCTET_STRING(NULL,&p,priv_len);
737 if (!s || s->length!=32)
739 GOSTerr(GOST_F_PRIV_DECODE_MAC,
740 GOST_R_DECODE_ERROR);
743 keybuf = OPENSSL_malloc(32);
744 memcpy(keybuf,s->data,32);
745 EVP_PKEY_assign(pk,EVP_PKEY_base_id(pk),keybuf);
750 static int priv_encode_mac(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk)
752 ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
753 ASN1_STRING *key = ASN1_STRING_new();
754 unsigned char *priv_buf=NULL, *data = EVP_PKEY_get0((EVP_PKEY *)pk);
757 ASN1_STRING_set(key, data, 32);
758 priv_len = i2d_ASN1_OCTET_STRING(key,&priv_buf);
759 ASN1_STRING_free(key);
760 return PKCS8_pkey_set0(p8,algobj,0,V_ASN1_NULL,NULL,priv_buf,priv_len);
763 static int priv_print_mac(BIO *out,const EVP_PKEY *pkey, int indent,
766 unsigned char *data = EVP_PKEY_get0((EVP_PKEY *)pkey);
768 if (!BIO_indent(out, indent,128)) return 0;
769 for (i=0; i<32;i++) {
770 BIO_printf(out,"%02x",data[i]);
774 static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
778 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
779 *(int *)arg2 = NID_id_Gost28147_89_MAC;
784 /* ----------------------------------------------------------------------*/
785 int register_ameth_gost (int nid, EVP_PKEY_ASN1_METHOD **ameth, const char* pemstr, const char* info)
787 *ameth = EVP_PKEY_asn1_new(nid,
788 ASN1_PKEY_SIGPARAM_NULL, pemstr, info);
789 if (!*ameth) return 0;
792 case NID_id_GostR3410_94_cc:
793 case NID_id_GostR3410_94:
794 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost94);
795 EVP_PKEY_asn1_set_private (*ameth,
796 priv_decode_gost, priv_encode_gost,
799 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
800 param_missing_gost94, param_copy_gost94,
801 param_cmp_gost94,0 );
802 EVP_PKEY_asn1_set_public (*ameth,
803 pub_decode_gost94, pub_encode_gost94,
804 pub_cmp_gost94, pub_print_gost94,
805 pkey_size_gost, pkey_bits_gost);
807 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
809 case NID_id_GostR3410_2001_cc:
810 case NID_id_GostR3410_2001:
811 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost01);
812 EVP_PKEY_asn1_set_private (*ameth,
813 priv_decode_gost, priv_encode_gost,
816 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
817 param_missing_gost01, param_copy_gost01,
818 param_cmp_gost01, 0);
819 EVP_PKEY_asn1_set_public (*ameth,
820 pub_decode_gost01, pub_encode_gost01,
821 pub_cmp_gost01, pub_print_gost01,
822 pkey_size_gost, pkey_bits_gost);
824 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
826 case NID_id_Gost28147_89_MAC:
827 EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
828 EVP_PKEY_asn1_set_private(*ameth, priv_decode_mac,
829 priv_encode_mac, priv_print_mac);
830 EVP_PKEY_asn1_set_ctrl(*ameth,mac_ctrl_gost);