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 **********************************************************************/
11 #include <openssl/crypto.h>
12 #include <openssl/err.h>
13 #include <openssl/engine.h>
14 #include <openssl/evp.h>
15 #include <openssl/asn1.h>
16 #include "gost_params.h"
18 #include "e_gost_err.h"
20 int gost94_nid_by_params(DSA *p)
22 R3410_params *gost_params;
24 for (gost_params = R3410_paramset;gost_params->q!=NULL; gost_params++)
26 BN_dec2bn(&q,gost_params->q);
30 return gost_params->nid;
37 static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key)
39 ASN1_STRING *params = ASN1_STRING_new();
40 GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new();
41 int pkey_param_nid = NID_undef;
42 int cipher_param_nid = NID_undef;
45 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
46 ERR_R_MALLOC_FAILURE);
47 ASN1_STRING_free(params);
51 switch (EVP_PKEY_base_id(key))
53 case NID_id_GostR3410_2001:
54 pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)key)));
55 cipher_param_nid = get_encryption_params(NULL)->nid;
57 case NID_id_GostR3410_94:
58 pkey_param_nid = (int) gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)key));
59 if (pkey_param_nid == NID_undef)
61 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
62 GOST_R_INVALID_GOST94_PARMSET);
63 ASN1_STRING_free(params);
67 cipher_param_nid = get_encryption_params(NULL)->nid;
70 gkp->key_params = OBJ_nid2obj(pkey_param_nid);
71 gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet);
72 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid);*/
73 params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data);
74 if (params->length <=0 )
76 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
77 ERR_R_MALLOC_FAILURE);
78 ASN1_STRING_free(params);
82 params ->type = V_ASN1_SEQUENCE;
84 GOST_KEY_PARAMS_free(gkp);
88 /* Parses GOST algorithm parameters from X509_ALGOR and
89 * modifies pkey setting NID and parameters
91 static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)
93 ASN1_OBJECT *palg_obj =NULL;
94 int ptype = V_ASN1_UNDEF;
95 int pkey_nid = NID_undef,param_nid = NID_undef;
97 ASN1_STRING *pval = NULL;
98 const unsigned char *p;
99 GOST_KEY_PARAMS *gkp = NULL;
101 X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);
103 if (ptype != V_ASN1_SEQUENCE)
105 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
106 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
110 pkey_nid = OBJ_obj2nid(palg_obj);
112 gkp = d2i_GOST_KEY_PARAMS(NULL,&p,pval->length);
115 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
116 GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
119 param_nid = OBJ_obj2nid(gkp->key_params);
120 GOST_KEY_PARAMS_free(gkp);
121 EVP_PKEY_set_type(pkey,pkey_nid);
124 case NID_id_GostR3410_94:
126 DSA *dsa= EVP_PKEY_get0(pkey);
130 if (!EVP_PKEY_assign(pkey,pkey_nid,dsa)) return 0;
132 if (!fill_GOST94_params(dsa,param_nid)) return 0;
135 case NID_id_GostR3410_2001:
137 EC_KEY *ec = EVP_PKEY_get0(pkey);
141 if (!EVP_PKEY_assign(pkey,pkey_nid,ec)) return 0;
143 if (!fill_GOST2001_params(ec,param_nid)) return 0;
150 static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv)
152 switch (EVP_PKEY_base_id(pkey))
154 case NID_id_GostR3410_94:
156 DSA *dsa = EVP_PKEY_get0(pkey);
160 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
162 dsa->priv_key = BN_dup(priv);
163 if (!EVP_PKEY_missing_parameters(pkey))
164 gost94_compute_public(dsa);
167 case NID_id_GostR3410_2001:
169 EC_KEY *ec = EVP_PKEY_get0(pkey);
173 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
175 if (!EC_KEY_set_private_key(ec,priv)) return 0;
176 if (!EVP_PKEY_missing_parameters(pkey))
177 gost2001_compute_public(ec);
183 BIGNUM* gost_get0_priv_key(const EVP_PKEY *pkey)
185 switch (EVP_PKEY_base_id(pkey))
187 case NID_id_GostR3410_94:
189 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pkey);
194 if (!dsa->priv_key) return NULL;
195 return dsa->priv_key;
198 case NID_id_GostR3410_2001:
200 EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey);
206 if (!(priv=EC_KEY_get0_private_key(ec))) return NULL;
207 return (BIGNUM *)priv;
214 static int pkey_ctrl_gost(EVP_PKEY *pkey, int op,
215 long arg1, void *arg2)
219 case ASN1_PKEY_CTRL_PKCS7_SIGN:
222 X509_ALGOR *alg1 = NULL, *alg2 = NULL;
223 int nid = EVP_PKEY_base_id(pkey);
224 PKCS7_SIGNER_INFO_get0_algs((PKCS7_SIGNER_INFO*)arg2,
226 X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_id_GostR3411_94),
228 if (nid == NID_undef)
232 X509_ALGOR_set0(alg2, OBJ_nid2obj(nid), V_ASN1_NULL, 0);
235 case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
239 ASN1_STRING * params = encode_gost_algor_params(pkey);
244 PKCS7_RECIP_INFO_get0_alg((PKCS7_RECIP_INFO*)arg2, &alg);
245 X509_ALGOR_set0(alg, OBJ_nid2obj(pkey->type),
246 V_ASN1_SEQUENCE, params);
249 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
250 *(int *)arg2 = NID_id_GostR3411_94;
256 /*----------------------- free functions * ------------------------------*/
257 static void pkey_free_gost94(EVP_PKEY *key)
261 DSA_free(key->pkey.dsa);
265 static void pkey_free_gost01(EVP_PKEY *key)
269 EC_KEY_free(key->pkey.ec);
273 /* ------------------ private key functions -----------------------------*/
274 static int priv_decode_gost( EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
276 const unsigned char *pkey_buf = NULL,*p=NULL;
280 X509_ALGOR *palg =NULL;
281 ASN1_OBJECT *palg_obj = NULL;
282 ASN1_INTEGER *priv_key=NULL;
284 if (!PKCS8_pkey_get0(&palg_obj,&pkey_buf,&priv_len,&palg,p8inf))
287 if (!decode_gost_algor_params(pk,palg))
291 if (V_ASN1_OCTET_STRING == *p)
293 /* New format - Little endian octet string */
294 unsigned char rev_buf[32];
296 ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL,&p,priv_len);
297 if (!s||s->length !=32)
299 GOSTerr(GOST_F_PRIV_DECODE_GOST,
305 rev_buf[31-i]=s->data[i];
308 pk_num = getbnfrombuf(rev_buf,32);
312 priv_key=d2i_ASN1_INTEGER(NULL,&p,priv_len);
313 if (!priv_key) return 0;
314 ret= ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL))!=NULL) ;
315 ASN1_INTEGER_free(priv_key);
318 GOSTerr(GOST_F_PRIV_DECODE_GOST,
324 ret= gost_set_priv_key(pk,pk_num);
329 /* ----------------------------------------------------------------------*/
330 static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk)
332 ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
333 ASN1_STRING *params = encode_gost_algor_params(pk);
334 unsigned char *priv_buf = NULL;
337 ASN1_INTEGER *asn1key=NULL;
342 asn1key = BN_to_ASN1_INTEGER(gost_get0_priv_key(pk),NULL);
343 priv_len = i2d_ASN1_INTEGER(asn1key,&priv_buf);
344 ASN1_INTEGER_free(asn1key);
345 return PKCS8_pkey_set0(p8,algobj,0,V_ASN1_SEQUENCE,params,
348 /* --------- printing keys --------------------------------*/
349 static int print_gost_94(BIO *out, const EVP_PKEY *pkey, int indent,
350 ASN1_PCTX *pctx, int type)
352 int param_nid = NID_undef;
358 if (!BIO_indent(out,indent,128)) return 0;
359 BIO_printf(out,"Private key: ");
360 key = gost_get0_priv_key(pkey);
362 BIO_printf(out,"<undefined>");
365 BIO_printf(out,"\n");
371 pubkey = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key;
372 BIO_indent(out,indent,128);
373 BIO_printf(out,"Public key: ");
374 BN_print(out,pubkey);
375 BIO_printf(out,"\n");
378 param_nid = gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey));
379 BIO_indent(out,indent,128);
380 BIO_printf(out, "Parameter set: %s\n",OBJ_nid2ln(param_nid));
384 static int param_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
387 return print_gost_94(out, pkey, indent, pctx,0);
390 static int pub_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
393 return print_gost_94(out,pkey, indent, pctx,1);
395 static int priv_print_gost94(BIO *out,const EVP_PKEY *pkey, int indent,
398 return print_gost_94(out,pkey,indent,pctx,2);
401 static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent,
402 ASN1_PCTX *pctx, int type)
404 int param_nid = NID_undef;
409 if (!BIO_indent(out,indent,128)) return 0;
410 BIO_printf(out,"Private key: ");
411 key = gost_get0_priv_key(pkey);
413 BIO_printf(out,"<undefined)");
416 BIO_printf(out,"\n");
420 BN_CTX *ctx = BN_CTX_new();
422 const EC_POINT *pubkey;
423 const EC_GROUP *group;
429 GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE);
432 pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
433 group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
434 if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx))
436 GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB);
440 if (!BIO_indent(out,indent,128)) return 0;
441 BIO_printf(out,"Public key:\n");
442 if (!BIO_indent(out,indent+3,128)) return 0;
443 BIO_printf(out,"X:");
445 BIO_printf(out,"\n");
446 BIO_indent(out,indent+3,128);
447 BIO_printf(out,"Y:");
449 BIO_printf(out,"\n");
454 param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
455 if (!BIO_indent(out,indent,128)) return 0;
456 BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid));
459 static int param_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
462 return print_gost_01(out,pkey,indent,pctx,0);
464 static int pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
467 return print_gost_01(out,pkey, indent, pctx,1);
469 static int priv_print_gost01(BIO *out,const EVP_PKEY *pkey, int indent,
472 return print_gost_01(out,pkey,indent,pctx,2);
474 /* ---------------------------------------------------------------------*/
475 static int param_missing_gost94(const EVP_PKEY *pk)
477 const DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
479 if (!dsa->q) return 1;
483 static int param_missing_gost01(const EVP_PKEY *pk)
485 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
487 if (!EC_KEY_get0_group(ec)) return 1;
491 static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from)
493 const DSA *dfrom = EVP_PKEY_get0((EVP_PKEY *)from);
494 DSA *dto = EVP_PKEY_get0(to);
495 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
497 GOSTerr(GOST_F_PARAM_COPY_GOST94,
498 GOST_R_INCOMPATIBLE_ALGORITHMS);
503 GOSTerr(GOST_F_PARAM_COPY_GOST94,
504 GOST_R_KEY_PARAMETERS_MISSING);
510 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),dto);
512 #define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);
513 COPYBIGNUM(dto,dfrom,p)
514 COPYBIGNUM(dto,dfrom,q)
515 COPYBIGNUM(dto,dfrom,g)
518 gost94_compute_public(dto);
521 static int param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
523 EC_KEY *eto = EVP_PKEY_get0(to);
524 const EC_KEY *efrom = EVP_PKEY_get0((EVP_PKEY *)from);
525 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
527 GOSTerr(GOST_F_PARAM_COPY_GOST01,
528 GOST_R_INCOMPATIBLE_ALGORITHMS);
533 GOSTerr(GOST_F_PARAM_COPY_GOST01,
534 GOST_R_KEY_PARAMETERS_MISSING);
540 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),eto);
542 EC_KEY_set_group(eto,EC_KEY_get0_group(efrom));
543 if (EC_KEY_get0_private_key(eto))
545 gost2001_compute_public(eto);
550 static int param_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
552 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
553 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
554 if (!BN_cmp(da->q,db->q)) return 1;
558 static int param_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b)
560 if (EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)a)))==
561 EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)b))))
569 /* ---------- Public key functions * --------------------------------------*/
570 static int pub_decode_gost94(EVP_PKEY *pk, X509_PUBKEY *pub)
572 X509_ALGOR *palg = NULL;
573 const unsigned char *pubkey_buf = NULL;
574 unsigned char *databuf;
575 ASN1_OBJECT *palgobj = NULL;
578 ASN1_OCTET_STRING *octet= NULL;
580 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
581 &palg, pub)) return 0;
582 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
583 if (!decode_gost_algor_params(pk,palg)) return 0;
584 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
587 GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
590 databuf = OPENSSL_malloc(octet->length);
591 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
593 databuf[j]=octet->data[i];
595 dsa = EVP_PKEY_get0(pk);
596 dsa->pub_key=BN_bin2bn(databuf,octet->length,NULL);
597 ASN1_OCTET_STRING_free(octet);
598 OPENSSL_free(databuf);
603 static int pub_encode_gost94(X509_PUBKEY *pub,const EVP_PKEY *pk)
605 ASN1_OBJECT *algobj = NULL;
606 ASN1_OCTET_STRING *octet = NULL;
608 unsigned char *buf=NULL,*databuf,*sptr;
609 int i,j,data_len,ret=0;
611 int ptype = V_ASN1_UNDEF;
612 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
613 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
614 if (pk->save_parameters)
616 ASN1_STRING *params = encode_gost_algor_params(pk);
618 ptype = V_ASN1_SEQUENCE;
620 data_len = BN_num_bytes(dsa->pub_key);
621 databuf = OPENSSL_malloc(data_len);
622 BN_bn2bin(dsa->pub_key,databuf);
623 octet = ASN1_OCTET_STRING_new();
624 ASN1_STRING_set(octet,NULL,data_len);
625 sptr = ASN1_STRING_data(octet);
626 for (i=0,j=data_len-1; i< data_len;i++,j--)
630 OPENSSL_free(databuf);
631 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
632 ASN1_BIT_STRING_free(octet);
633 if (ret <0) return 0;
634 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
637 static int pub_decode_gost01(EVP_PKEY *pk,X509_PUBKEY *pub)
639 X509_ALGOR *palg = NULL;
640 const unsigned char *pubkey_buf = NULL;
641 unsigned char *databuf;
642 ASN1_OBJECT *palgobj = NULL;
646 ASN1_OCTET_STRING *octet= NULL;
648 const EC_GROUP *group;
650 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
651 &palg, pub)) return 0;
652 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
653 if (!decode_gost_algor_params(pk,palg)) return 0;
654 group = EC_KEY_get0_group(EVP_PKEY_get0(pk));
655 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
658 GOSTerr(GOST_F_PUB_DECODE_GOST01,ERR_R_MALLOC_FAILURE);
661 databuf = OPENSSL_malloc(octet->length);
662 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
664 databuf[j]=octet->data[i];
667 ASN1_OCTET_STRING_free(octet);
669 Y= getbnfrombuf(databuf,len);
670 X= getbnfrombuf(databuf+len,len);
671 OPENSSL_free(databuf);
672 pub_key = EC_POINT_new(group);
673 if (!EC_POINT_set_affine_coordinates_GFp(group
676 GOSTerr(GOST_F_PUB_DECODE_GOST01,
678 EC_POINT_free(pub_key);
685 if (!EC_KEY_set_public_key(EVP_PKEY_get0(pk),pub_key))
687 GOSTerr(GOST_F_PUB_DECODE_GOST01,
689 EC_POINT_free(pub_key);
692 EC_POINT_free(pub_key);
697 static int pub_encode_gost01(X509_PUBKEY *pub,const EVP_PKEY *pk)
699 ASN1_OBJECT *algobj = NULL;
700 ASN1_OCTET_STRING *octet = NULL;
702 unsigned char *buf=NULL,*databuf,*sptr;
703 int i,j,data_len,ret=0;
704 const EC_POINT *pub_key;
706 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
707 int ptype = V_ASN1_UNDEF;
709 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
710 if (pk->save_parameters)
712 ASN1_STRING *params = encode_gost_algor_params(pk);
714 ptype = V_ASN1_SEQUENCE;
717 EC_GROUP_get_order(EC_KEY_get0_group(ec),order,NULL);
718 pub_key=EC_KEY_get0_public_key(ec);
721 GOSTerr(GOST_F_PUB_ENCODE_GOST01,
722 GOST_R_PUBLIC_KEY_UNDEFINED);
727 EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
729 data_len = 2*BN_num_bytes(order);
731 databuf = OPENSSL_malloc(data_len);
732 memset(databuf,0,data_len);
734 store_bignum(X,databuf+data_len/2,data_len/2);
735 store_bignum(Y,databuf,data_len/2);
739 octet = ASN1_OCTET_STRING_new();
740 ASN1_STRING_set(octet,NULL,data_len);
741 sptr=ASN1_STRING_data(octet);
742 for (i=0,j=data_len-1;i<data_len;i++,j--)
746 OPENSSL_free(databuf);
747 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
748 ASN1_BIT_STRING_free(octet);
749 if (ret <0) return 0;
750 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
753 static int pub_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
755 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
756 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
757 if (da && db && da->pub_key && db->pub_key
758 && !BN_cmp(da->pub_key,db->pub_key))
765 static int pub_cmp_gost01(const EVP_PKEY *a,const EVP_PKEY *b)
767 const EC_KEY *ea = EVP_PKEY_get0((EVP_PKEY *)a);
768 const EC_KEY *eb = EVP_PKEY_get0((EVP_PKEY *)b);
769 const EC_POINT *ka,*kb;
771 if (!ea || !eb) return 0;
772 ka = EC_KEY_get0_public_key(ea);
773 kb = EC_KEY_get0_public_key(eb);
774 if (!ka || !kb) return 0;
775 ret = (0==EC_POINT_cmp(EC_KEY_get0_group(ea),ka,kb,NULL)) ;
782 static int pkey_size_gost(const EVP_PKEY *pk)
787 static int pkey_bits_gost(const EVP_PKEY *pk)
791 /*------------------------ ASN1 METHOD for GOST MAC -------------------*/
792 static void mackey_free_gost(EVP_PKEY *pk)
795 OPENSSL_free(pk->pkey.ptr);
798 static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
802 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
803 *(int *)arg2 = NID_undef;
808 /* ----------------------------------------------------------------------*/
809 int register_ameth_gost (int nid, EVP_PKEY_ASN1_METHOD **ameth, const char* pemstr, const char* info)
811 *ameth = EVP_PKEY_asn1_new(nid,
812 ASN1_PKEY_SIGPARAM_NULL, pemstr, info);
813 if (!*ameth) return 0;
816 case NID_id_GostR3410_94:
817 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost94);
818 EVP_PKEY_asn1_set_private (*ameth,
819 priv_decode_gost, priv_encode_gost,
822 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
823 param_missing_gost94, param_copy_gost94,
824 param_cmp_gost94,param_print_gost94 );
825 EVP_PKEY_asn1_set_public (*ameth,
826 pub_decode_gost94, pub_encode_gost94,
827 pub_cmp_gost94, pub_print_gost94,
828 pkey_size_gost, pkey_bits_gost);
830 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
832 case NID_id_GostR3410_2001:
833 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost01);
834 EVP_PKEY_asn1_set_private (*ameth,
835 priv_decode_gost, priv_encode_gost,
838 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
839 param_missing_gost01, param_copy_gost01,
840 param_cmp_gost01, param_print_gost01);
841 EVP_PKEY_asn1_set_public (*ameth,
842 pub_decode_gost01, pub_encode_gost01,
843 pub_cmp_gost01, pub_print_gost01,
844 pkey_size_gost, pkey_bits_gost);
846 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
848 case NID_id_Gost28147_89_MAC:
849 EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
850 EVP_PKEY_asn1_set_ctrl(*ameth,mac_ctrl_gost);