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:
52 pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)key)));
53 cipher_param_nid = get_encryption_params(NULL)->nid;
55 case NID_id_GostR3410_94:
56 pkey_param_nid = (int) gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)key));
57 if (pkey_param_nid == NID_undef)
59 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
60 GOST_R_INVALID_GOST94_PARMSET);
61 ASN1_STRING_free(params);
65 cipher_param_nid = get_encryption_params(NULL)->nid;
68 gkp->key_params = OBJ_nid2obj(pkey_param_nid);
69 gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet);
70 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid);*/
71 params->length = i2d_GOST_KEY_PARAMS(gkp, ¶ms->data);
72 if (params->length <=0 )
74 GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS,
75 ERR_R_MALLOC_FAILURE);
76 ASN1_STRING_free(params);
80 params ->type = V_ASN1_SEQUENCE;
82 GOST_KEY_PARAMS_free(gkp);
86 /* Parses GOST algorithm parameters from X509_ALGOR and
87 * modifies pkey setting NID and parameters
89 static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)
91 ASN1_OBJECT *palg_obj =NULL;
92 int ptype = V_ASN1_UNDEF;
93 int pkey_nid = NID_undef,param_nid = NID_undef;
95 ASN1_STRING *pval = NULL;
96 const unsigned char *p;
97 GOST_KEY_PARAMS *gkp = NULL;
99 X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);
101 if (ptype != V_ASN1_SEQUENCE)
103 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
104 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
108 pkey_nid = OBJ_obj2nid(palg_obj);
110 gkp = d2i_GOST_KEY_PARAMS(NULL,&p,pval->length);
113 GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
114 GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
117 param_nid = OBJ_obj2nid(gkp->key_params);
118 GOST_KEY_PARAMS_free(gkp);
119 EVP_PKEY_set_type(pkey,pkey_nid);
122 case NID_id_GostR3410_94:
124 DSA *dsa= EVP_PKEY_get0(pkey);
128 if (!EVP_PKEY_assign(pkey,pkey_nid,dsa)) return 0;
130 if (!fill_GOST94_params(dsa,param_nid)) return 0;
133 case NID_id_GostR3410_2001:
135 EC_KEY *ec = EVP_PKEY_get0(pkey);
139 if (!EVP_PKEY_assign(pkey,pkey_nid,ec)) return 0;
141 if (!fill_GOST2001_params(ec,param_nid)) return 0;
148 static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv)
150 switch (EVP_PKEY_base_id(pkey))
152 case NID_id_GostR3410_94:
154 DSA *dsa = EVP_PKEY_get0(pkey);
158 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
160 dsa->priv_key = BN_dup(priv);
161 if (!EVP_PKEY_missing_parameters(pkey))
162 gost94_compute_public(dsa);
165 case NID_id_GostR3410_2001:
167 EC_KEY *ec = EVP_PKEY_get0(pkey);
171 EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
173 if (!EC_KEY_set_private_key(ec,priv)) return 0;
174 if (!EVP_PKEY_missing_parameters(pkey))
175 gost2001_compute_public(ec);
181 BIGNUM* gost_get0_priv_key(const EVP_PKEY *pkey)
183 switch (EVP_PKEY_base_id(pkey))
185 case NID_id_GostR3410_94:
187 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pkey);
192 if (!dsa->priv_key) return NULL;
193 return dsa->priv_key;
196 case NID_id_GostR3410_2001:
198 EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey);
204 if (!(priv=EC_KEY_get0_private_key(ec))) return NULL;
205 return (BIGNUM *)priv;
212 static int pkey_ctrl_gost(EVP_PKEY *pkey, int op,
213 long arg1, void *arg2)
217 case ASN1_PKEY_CTRL_PKCS7_SIGN:
220 X509_ALGOR *alg1 = NULL, *alg2 = NULL;
221 int nid = EVP_PKEY_base_id(pkey);
222 PKCS7_SIGNER_INFO_get0_algs((PKCS7_SIGNER_INFO*)arg2,
224 X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_id_GostR3411_94),
226 if (nid == NID_undef)
230 X509_ALGOR_set0(alg2, OBJ_nid2obj(nid), V_ASN1_NULL, 0);
233 case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
237 ASN1_STRING * params = encode_gost_algor_params(pkey);
242 PKCS7_RECIP_INFO_get0_alg((PKCS7_RECIP_INFO*)arg2, &alg);
243 X509_ALGOR_set0(alg, OBJ_nid2obj(pkey->type),
244 V_ASN1_SEQUENCE, params);
247 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
248 *(int *)arg2 = NID_id_GostR3411_94;
254 /*----------------------- free functions * ------------------------------*/
255 static void pkey_free_gost94(EVP_PKEY *key)
259 DSA_free(key->pkey.dsa);
263 static void pkey_free_gost01(EVP_PKEY *key)
267 EC_KEY_free(key->pkey.ec);
271 /* ------------------ private key functions -----------------------------*/
272 static int priv_decode_gost( EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
274 const unsigned char *pkey_buf = NULL,*p=NULL;
278 X509_ALGOR *palg =NULL;
279 ASN1_OBJECT *palg_obj = NULL;
280 ASN1_INTEGER *priv_key=NULL;
282 if (!PKCS8_pkey_get0(&palg_obj,&pkey_buf,&priv_len,&palg,p8inf))
285 if (!decode_gost_algor_params(pk,palg))
289 if (V_ASN1_OCTET_STRING == *p)
291 /* New format - Little endian octet string */
292 unsigned char rev_buf[32];
294 ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL,&p,priv_len);
295 if (!s||s->length !=32)
297 GOSTerr(GOST_F_PRIV_DECODE_GOST_94,
303 rev_buf[31-i]=s->data[i];
306 pk_num = getbnfrombuf(rev_buf,32);
310 priv_key=d2i_ASN1_INTEGER(NULL,&p,priv_len);
311 if (!priv_key) return 0;
312 ret= ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL))!=NULL) ;
313 ASN1_INTEGER_free(priv_key);
316 GOSTerr(GOST_F_PRIV_DECODE_GOST_94,
322 ret= gost_set_priv_key(pk,pk_num);
327 /* ----------------------------------------------------------------------*/
328 static int priv_encode_gost(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk)
330 ASN1_OBJECT *algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
331 ASN1_STRING *params = encode_gost_algor_params(pk);
332 unsigned char *priv_buf = NULL;
335 ASN1_INTEGER *asn1key=NULL;
340 asn1key = BN_to_ASN1_INTEGER(gost_get0_priv_key(pk),NULL);
341 priv_len = i2d_ASN1_INTEGER(asn1key,&priv_buf);
342 ASN1_INTEGER_free(asn1key);
343 return PKCS8_pkey_set0(p8,algobj,0,V_ASN1_SEQUENCE,params,
346 /* --------- printing keys --------------------------------*/
347 static int print_gost_94(BIO *out, const EVP_PKEY *pkey, int indent,
348 ASN1_PCTX *pctx, int type)
350 int param_nid = NID_undef;
356 if (!BIO_indent(out,indent,128)) return 0;
357 BIO_printf(out,"Private key: ");
358 key = gost_get0_priv_key(pkey);
360 BIO_printf(out,"<undefined>");
363 BIO_printf(out,"\n");
369 pubkey = ((DSA *)EVP_PKEY_get0((EVP_PKEY *)pkey))->pub_key;
370 BIO_indent(out,indent,128);
371 BIO_printf(out,"Public key: ");
372 BN_print(out,pubkey);
373 BIO_printf(out,"\n");
376 param_nid = gost94_nid_by_params(EVP_PKEY_get0((EVP_PKEY *)pkey));
377 BIO_indent(out,indent,128);
378 BIO_printf(out, "Parameter set: %s\n",OBJ_nid2ln(param_nid));
382 static int param_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
385 return print_gost_94(out, pkey, indent, pctx,0);
388 static int pub_print_gost94(BIO *out, const EVP_PKEY *pkey, int indent,
391 return print_gost_94(out,pkey, indent, pctx,1);
393 static int priv_print_gost94(BIO *out,const EVP_PKEY *pkey, int indent,
396 return print_gost_94(out,pkey,indent,pctx,2);
399 static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent,
400 ASN1_PCTX *pctx, int type)
402 int param_nid = NID_undef;
407 if (!BIO_indent(out,indent,128)) return 0;
408 BIO_printf(out,"Private key: ");
409 key = gost_get0_priv_key(pkey);
411 BIO_printf(out,"<undefined)");
414 BIO_printf(out,"\n");
418 BN_CTX *ctx = BN_CTX_new();
420 const EC_POINT *pubkey;
421 const EC_GROUP *group;
427 GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE);
430 pubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
431 group = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));
432 if (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx))
434 GOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB);
438 if (!BIO_indent(out,indent,128)) return 0;
439 BIO_printf(out,"Public key:\n");
440 if (!BIO_indent(out,indent+3,128)) return 0;
441 BIO_printf(out,"X:");
443 BIO_printf(out,"\n");
444 BIO_indent(out,indent+3,128);
445 BIO_printf(out,"Y:");
447 BIO_printf(out,"\n");
452 param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));
453 if (!BIO_indent(out,indent,128)) return 0;
454 BIO_printf(out,"Parameter set: %s\n",OBJ_nid2ln(param_nid));
457 static int param_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
460 return print_gost_01(out,pkey,indent,pctx,0);
462 static int pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent,
465 return print_gost_01(out,pkey, indent, pctx,1);
467 static int priv_print_gost01(BIO *out,const EVP_PKEY *pkey, int indent,
470 return print_gost_01(out,pkey,indent,pctx,2);
472 /* ---------------------------------------------------------------------*/
473 static int param_missing_gost94(const EVP_PKEY *pk)
475 const DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
477 if (!dsa->q) return 1;
481 static int param_missing_gost01(const EVP_PKEY *pk)
483 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
485 if (!EC_KEY_get0_group(ec)) return 1;
489 static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from)
491 const DSA *dfrom = EVP_PKEY_get0((EVP_PKEY *)from);
492 DSA *dto = EVP_PKEY_get0(to);
493 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
495 GOSTerr(GOST_F_PARAM_COPY_GOST94,
496 GOST_R_INCOMPATIBLE_ALGORITHMS);
501 GOSTerr(GOST_F_PARAM_COPY_GOST94,
502 GOST_R_KEY_PARAMETERS_MISSING);
508 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),dto);
510 #define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);
511 COPYBIGNUM(dto,dfrom,p)
512 COPYBIGNUM(dto,dfrom,q)
513 COPYBIGNUM(dto,dfrom,g)
516 gost94_compute_public(dto);
519 static int param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
521 EC_KEY *eto = EVP_PKEY_get0(to);
522 const EC_KEY *efrom = EVP_PKEY_get0((EVP_PKEY *)from);
523 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))
525 GOSTerr(GOST_F_PARAM_COPY_GOST01,
526 GOST_R_INCOMPATIBLE_ALGORITHMS);
531 GOSTerr(GOST_F_PARAM_COPY_GOST94,
532 GOST_R_KEY_PARAMETERS_MISSING);
538 EVP_PKEY_assign(to,EVP_PKEY_base_id(from),eto);
540 EC_KEY_set_group(eto,EC_KEY_get0_group(efrom));
541 if (EC_KEY_get0_private_key(eto))
543 gost2001_compute_public(eto);
548 static int param_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
550 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
551 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
552 if (!BN_cmp(da->q,db->q)) return 1;
556 static int param_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b)
558 if (EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)a)))==
559 EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)b))))
567 /* ---------- Public key functions * --------------------------------------*/
568 static int pub_decode_gost94(EVP_PKEY *pk, X509_PUBKEY *pub)
570 X509_ALGOR *palg = NULL;
571 const unsigned char *pubkey_buf = NULL;
572 unsigned char *databuf;
573 ASN1_OBJECT *palgobj = NULL;
576 ASN1_OCTET_STRING *octet= NULL;
578 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
579 &palg, pub)) return 0;
580 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
581 if (!decode_gost_algor_params(pk,palg)) return 0;
582 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
585 GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
588 databuf = OPENSSL_malloc(octet->length);
589 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
591 databuf[j]=octet->data[i];
593 dsa = EVP_PKEY_get0(pk);
594 dsa->pub_key=BN_bin2bn(databuf,octet->length,NULL);
595 ASN1_OCTET_STRING_free(octet);
596 OPENSSL_free(databuf);
601 static int pub_encode_gost94(X509_PUBKEY *pub,const EVP_PKEY *pk)
603 ASN1_OBJECT *algobj = NULL;
604 ASN1_OCTET_STRING *octet = NULL;
606 unsigned char *buf=NULL,*databuf,*sptr;
607 int i,j,data_len,ret=0;
609 int ptype = V_ASN1_UNDEF;
610 DSA *dsa = EVP_PKEY_get0((EVP_PKEY *)pk);
611 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
612 if (pk->save_parameters)
614 ASN1_STRING *params = encode_gost_algor_params(pk);
616 ptype = V_ASN1_SEQUENCE;
618 data_len = BN_num_bytes(dsa->pub_key);
619 databuf = OPENSSL_malloc(data_len);
620 BN_bn2bin(dsa->pub_key,databuf);
621 octet = ASN1_OCTET_STRING_new();
622 ASN1_STRING_set(octet,NULL,data_len);
623 sptr = ASN1_STRING_data(octet);
624 for (i=0,j=data_len-1; i< data_len;i++,j--)
628 OPENSSL_free(databuf);
629 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
630 ASN1_BIT_STRING_free(octet);
631 if (ret <0) return 0;
632 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
635 static int pub_decode_gost01(EVP_PKEY *pk,X509_PUBKEY *pub)
637 X509_ALGOR *palg = NULL;
638 const unsigned char *pubkey_buf = NULL;
639 unsigned char *databuf;
640 ASN1_OBJECT *palgobj = NULL;
644 ASN1_OCTET_STRING *octet= NULL;
646 const EC_GROUP *group;
648 if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
649 &palg, pub)) return 0;
650 EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);
651 if (!decode_gost_algor_params(pk,palg)) return 0;
652 group = EC_KEY_get0_group(EVP_PKEY_get0(pk));
653 octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
656 GOSTerr(GOST_F_PUB_DECODE_GOST94,ERR_R_MALLOC_FAILURE);
659 databuf = OPENSSL_malloc(octet->length);
660 for (i=0,j=octet->length-1;i<octet->length;i++,j--)
662 databuf[j]=octet->data[i];
665 ASN1_OCTET_STRING_free(octet);
667 Y= getbnfrombuf(databuf,len);
668 X= getbnfrombuf(databuf+len,len);
669 OPENSSL_free(databuf);
670 pub_key = EC_POINT_new(group);
671 if (!EC_POINT_set_affine_coordinates_GFp(group
674 GOSTerr(GOST_F_PUB_DECODE_GOST01,
676 EC_POINT_free(pub_key);
683 if (!EC_KEY_set_public_key(EVP_PKEY_get0(pk),pub_key))
685 GOSTerr(GOST_F_PUB_DECODE_GOST01,
687 EC_POINT_free(pub_key);
690 EC_POINT_free(pub_key);
695 static int pub_encode_gost01(X509_PUBKEY *pub,const EVP_PKEY *pk)
697 ASN1_OBJECT *algobj = NULL;
698 ASN1_OCTET_STRING *octet = NULL;
700 unsigned char *buf=NULL,*databuf,*sptr;
701 int i,j,data_len,ret=0;
702 const EC_POINT *pub_key;
704 const EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pk);
705 int ptype = V_ASN1_UNDEF;
707 algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
708 if (pk->save_parameters)
710 ASN1_STRING *params = encode_gost_algor_params(pk);
712 ptype = V_ASN1_SEQUENCE;
715 EC_GROUP_get_order(EC_KEY_get0_group(ec),order,NULL);
716 pub_key=EC_KEY_get0_public_key(ec);
719 GOSTerr(GOST_F_PUB_ENCODE_GOST01,
720 GOST_R_PUBLIC_KEY_UNDEFINED);
725 EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec),
727 data_len = 2*BN_num_bytes(order);
729 databuf = OPENSSL_malloc(data_len);
730 memset(databuf,0,data_len);
732 store_bignum(X,databuf+data_len/2,data_len/2);
733 store_bignum(Y,databuf,data_len/2);
737 octet = ASN1_OCTET_STRING_new();
738 ASN1_STRING_set(octet,NULL,data_len);
739 sptr=ASN1_STRING_data(octet);
740 for (i=0,j=data_len-1;i<data_len;i++,j--)
744 OPENSSL_free(databuf);
745 ret = i2d_ASN1_OCTET_STRING(octet,&buf);
746 ASN1_BIT_STRING_free(octet);
747 if (ret <0) return 0;
748 return X509_PUBKEY_set0_param(pub,algobj,ptype,pval,buf,ret);
751 static int pub_cmp_gost94(const EVP_PKEY *a, const EVP_PKEY *b)
753 const DSA *da = EVP_PKEY_get0((EVP_PKEY *)a);
754 const DSA *db = EVP_PKEY_get0((EVP_PKEY *)b);
755 if (da && db && da->pub_key && db->pub_key
756 && !BN_cmp(da->pub_key,db->pub_key))
763 static int pub_cmp_gost01(const EVP_PKEY *a,const EVP_PKEY *b)
765 const EC_KEY *ea = EVP_PKEY_get0((EVP_PKEY *)a);
766 const EC_KEY *eb = EVP_PKEY_get0((EVP_PKEY *)b);
767 const EC_POINT *ka,*kb;
769 if (!ea || !eb) return 0;
770 ka = EC_KEY_get0_public_key(ea);
771 kb = EC_KEY_get0_public_key(eb);
772 if (!ka || !kb) return 0;
773 ret = (0==EC_POINT_cmp(EC_KEY_get0_group(ea),ka,kb,NULL)) ;
780 static int pkey_size_gost(const EVP_PKEY *pk)
785 static int pkey_bits_gost(const EVP_PKEY *pk)
789 /*------------------------ ASN1 METHOD for GOST MAC -------------------*/
790 static void mackey_free_gost(EVP_PKEY *pk)
793 OPENSSL_free(pk->pkey.ptr);
796 static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
800 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
801 *(int *)arg2 = NID_undef;
806 /* ----------------------------------------------------------------------*/
807 int register_ameth_gost (int nid, EVP_PKEY_ASN1_METHOD **ameth, const char* pemstr, const char* info)
809 *ameth = EVP_PKEY_asn1_new(nid,
810 ASN1_PKEY_SIGPARAM_NULL, pemstr, info);
811 if (!*ameth) return 0;
814 case NID_id_GostR3410_94:
815 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost94);
816 EVP_PKEY_asn1_set_private (*ameth,
817 priv_decode_gost, priv_encode_gost,
820 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
821 param_missing_gost94, param_copy_gost94,
822 param_cmp_gost94,param_print_gost94 );
823 EVP_PKEY_asn1_set_public (*ameth,
824 pub_decode_gost94, pub_encode_gost94,
825 pub_cmp_gost94, pub_print_gost94,
826 pkey_size_gost, pkey_bits_gost);
828 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
830 case NID_id_GostR3410_2001:
831 EVP_PKEY_asn1_set_free (*ameth, pkey_free_gost01);
832 EVP_PKEY_asn1_set_private (*ameth,
833 priv_decode_gost, priv_encode_gost,
836 EVP_PKEY_asn1_set_param (*ameth, 0, 0,
837 param_missing_gost01, param_copy_gost01,
838 param_cmp_gost01, param_print_gost01);
839 EVP_PKEY_asn1_set_public (*ameth,
840 pub_decode_gost01, pub_encode_gost01,
841 pub_cmp_gost01, pub_print_gost01,
842 pkey_size_gost, pkey_bits_gost);
844 EVP_PKEY_asn1_set_ctrl (*ameth, pkey_ctrl_gost);
846 case NID_id_Gost28147_89_MAC:
847 EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost);
848 EVP_PKEY_asn1_set_ctrl(*ameth,mac_ctrl_gost);