1 /**********************************************************************
3 * Copyright (c) 2005-2013 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Implementation of RFC 4357 (GOST R 34.10) Publick key method *
8 * Requires OpenSSL 1.0.0+ for compilation *
9 **********************************************************************/
10 #include <openssl/evp.h>
11 #include <openssl/objects.h>
12 #include <openssl/ec.h>
13 #include <openssl/err.h>
14 #include <openssl/x509v3.h> /* For string_to_hex */
19 #include "e_gost_err.h"
21 /* -----init, cleanup, copy - uniform for all algs --------------*/
22 /* Allocates new gost_pmeth_data structure and assigns it as data */
23 static int pkey_gost_init(EVP_PKEY_CTX *ctx)
25 struct gost_pmeth_data *data;
26 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
28 data = OPENSSL_malloc(sizeof(*data));
31 memset(data, 0, sizeof(*data));
32 if (pkey && EVP_PKEY_get0(pkey)) {
33 switch (EVP_PKEY_base_id(pkey)) {
34 case NID_id_GostR3410_2001:
35 case NID_id_GostR3410_2012_256:
36 case NID_id_GostR3410_2012_512:
38 const EC_GROUP *group =
39 EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey));
41 data->sign_param_nid = EC_GROUP_get_curve_name(group);
51 EVP_PKEY_CTX_set_data(ctx, data);
55 /* Copies contents of gost_pmeth_data structure */
56 static int pkey_gost_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
58 struct gost_pmeth_data *dst_data, *src_data;
59 if (!pkey_gost_init(dst)) {
62 src_data = EVP_PKEY_CTX_get_data(src);
63 dst_data = EVP_PKEY_CTX_get_data(dst);
64 if (!src_data || !dst_data)
67 *dst_data = *src_data;
68 if (src_data->shared_ukm) {
69 dst_data->shared_ukm = NULL;
74 /* Frees up gost_pmeth_data structure */
75 static void pkey_gost_cleanup(EVP_PKEY_CTX *ctx)
77 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
80 OPENSSL_free(data->shared_ukm);
84 /* --------------------- control functions ------------------------------*/
85 static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
87 struct gost_pmeth_data *pctx =
88 (struct gost_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
93 case EVP_PKEY_CTRL_MD:
95 EVP_PKEY *key = EVP_PKEY_CTX_get0_pkey(ctx);
96 int pkey_nid = (key == NULL) ? NID_undef : EVP_PKEY_base_id(key);
98 OPENSSL_assert(p2 != NULL);
100 switch (EVP_MD_type((const EVP_MD *)p2)) {
101 case NID_id_GostR3411_94:
102 if (pkey_nid == NID_id_GostR3410_2001
103 || pkey_nid == NID_id_GostR3410_94) {
104 pctx->md = (EVP_MD *)p2;
109 case NID_id_GostR3411_2012_256:
110 if (pkey_nid == NID_id_GostR3410_2012_256) {
111 pctx->md = (EVP_MD *)p2;
116 case NID_id_GostR3411_2012_512:
117 if (pkey_nid == NID_id_GostR3410_2012_512) {
118 pctx->md = (EVP_MD *)p2;
124 GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);
128 case EVP_PKEY_CTRL_GET_MD:
129 *(const EVP_MD **)p2 = pctx->md;
132 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
133 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
134 case EVP_PKEY_CTRL_PKCS7_SIGN:
135 case EVP_PKEY_CTRL_DIGESTINIT:
136 #ifndef OPENSSL_NO_CMS
137 case EVP_PKEY_CTRL_CMS_ENCRYPT:
138 case EVP_PKEY_CTRL_CMS_DECRYPT:
139 case EVP_PKEY_CTRL_CMS_SIGN:
143 case EVP_PKEY_CTRL_GOST_PARAMSET:
144 pctx->sign_param_nid = (int)p1;
146 case EVP_PKEY_CTRL_SET_IV:
147 OPENSSL_assert(p2 != NULL);
148 pctx->shared_ukm = OPENSSL_malloc((int)p1);
149 if (pctx->shared_ukm == NULL) {
150 GOSTerr(GOST_F_PKEY_GOST_CTRL, ERR_R_MALLOC_FAILURE);
153 memcpy(pctx->shared_ukm, p2, (int)p1);
155 case EVP_PKEY_CTRL_PEER_KEY:
156 if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
158 if (p1 == 2) /* TLS: peer key used? */
159 return pctx->peer_key_used;
160 if (p1 == 3) /* TLS: peer key used! */
161 return (pctx->peer_key_used = 1);
165 GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_CTRL_CALL_FAILED);
169 static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
170 const char *type, const char *value)
174 if (strcmp(type, param_ctrl_string) == 0) {
178 if (strlen(value) == 1) {
179 switch (toupper((unsigned char)value[0])) {
181 param_nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
184 param_nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet;
187 param_nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet;
190 param_nid = NID_id_GostR3410_2001_TestParamSet;
195 } else if ((strlen(value) == 2)
196 && (toupper((unsigned char)value[0]) == 'X')) {
197 switch (toupper((unsigned char)value[1])) {
199 param_nid = NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet;
202 param_nid = NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet;
208 R3410_ec_params *p = R3410_2001_paramset;
209 param_nid = OBJ_txt2nid(value);
210 if (param_nid == NID_undef) {
213 for (; p->nid != NID_undef; p++) {
214 if (p->nid == param_nid)
217 if (p->nid == NID_undef) {
218 GOSTerr(GOST_F_PKEY_GOST_EC_CTRL_STR_256,
219 GOST_R_INVALID_PARAMSET);
224 return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
230 static int pkey_gost_ec_ctrl_str_512(EVP_PKEY_CTX *ctx,
231 const char *type, const char *value)
233 int param_nid = NID_undef;
235 if (strcmp(type, param_ctrl_string))
241 if (strlen(value) == 1) {
242 switch (toupper((unsigned char)value[0])) {
244 param_nid = NID_id_tc26_gost_3410_2012_512_paramSetA;
248 param_nid = NID_id_tc26_gost_3410_2012_512_paramSetB;
255 R3410_ec_params *p = R3410_2012_512_paramset;
256 param_nid = OBJ_txt2nid(value);
257 if (param_nid == NID_undef)
260 while (p->nid != NID_undef && p->nid != param_nid)
263 if (p->nid == NID_undef) {
264 GOSTerr(GOST_F_PKEY_GOST_EC_CTRL_STR_512,
265 GOST_R_INVALID_PARAMSET);
270 return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, param_nid, NULL);
273 /* --------------------- key generation --------------------------------*/
275 static int pkey_gost_paramgen_init(EVP_PKEY_CTX *ctx)
280 static int pkey_gost2001_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
282 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
285 if (!data || data->sign_param_nid == NID_undef) {
286 GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
291 if (!fill_GOST_EC_params(ec, data->sign_param_nid)
292 || !EVP_PKEY_assign(pkey, NID_id_GostR3410_2001, ec)) {
299 static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
301 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
305 if (!data || data->sign_param_nid == NID_undef) {
306 GOSTerr(GOST_F_PKEY_GOST12_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
311 if (!fill_GOST_EC_params(ec, data->sign_param_nid)) {
316 switch (data->sign_param_nid) {
317 case NID_id_tc26_gost_3410_2012_512_paramSetA:
318 case NID_id_tc26_gost_3410_2012_512_paramSetB:
320 (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_512, ec)) ? 1 : 0;
323 case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
324 case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
325 case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
326 case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
327 case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
328 case NID_id_GostR3410_2001_TestParamSet:
330 (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_256, ec)) ? 1 : 0;
343 /* ----------- keygen callbacks --------------------------------------*/
344 /* Generates GOST_R3410 2001 key and assigns it using specified type */
345 static int pkey_gost2001cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
348 if (!pkey_gost2001_paramgen(ctx, pkey))
350 ec = EVP_PKEY_get0(pkey);
355 /* Generates GOST_R3410 2012 key and assigns it using specified type */
356 static int pkey_gost2012cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
358 if (!pkey_gost2012_paramgen(ctx, pkey))
361 gost_ec_keygen(EVP_PKEY_get0(pkey));
365 /* ----------- sign callbacks --------------------------------------*/
367 * Packs signature according to Cryptopro rules
368 * and frees up DSA_SIG structure
370 int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
373 memset(sig, 0, *siglen);
374 store_bignum(s->s, sig, order);
375 store_bignum(s->r, sig + order, order);
380 static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
381 size_t *siglen, const unsigned char *tbs,
384 DSA_SIG *unpacked_sig = NULL;
385 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
393 switch (EVP_PKEY_base_id(pkey)) {
394 case NID_id_GostR3410_2001:
395 case NID_id_GostR3410_2012_256:
398 case NID_id_GostR3410_2012_512:
409 unpacked_sig = gost_ec_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
413 return pack_sign_cp(unpacked_sig, order / 2, sig, siglen);
416 /* ------------------- verify callbacks ---------------------------*/
417 /* Unpack signature according to cryptopro rules */
418 DSA_SIG *unpack_cp_signature(const unsigned char *sig, size_t siglen)
424 GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE);
427 s->s = BN_bin2bn(sig, siglen / 2, NULL);
428 s->r = BN_bin2bn(sig + siglen / 2, siglen / 2, NULL);
432 static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
433 size_t siglen, const unsigned char *tbs,
437 EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
438 DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
442 fprintf(stderr, "R=");
443 BN_print_fp(stderr, s->r);
444 fprintf(stderr, "\nS=");
445 BN_print_fp(stderr, s->s);
446 fprintf(stderr, "\n");
449 ok = gost_ec_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
454 /* ------------- encrypt init -------------------------------------*/
455 /* Generates ephermeral key */
456 static int pkey_gost_encrypt_init(EVP_PKEY_CTX *ctx)
461 /* --------------- Derive init ------------------------------------*/
462 static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
467 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
468 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
470 struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data));
471 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
475 memset(data, 0, sizeof(*data));
477 data->mac_param_nid = NID_undef;
480 struct gost_mac_key *key = EVP_PKEY_get0(pkey);
482 data->mac_param_nid = key->mac_param_nid;
483 data->mac_size = key->mac_size;
487 EVP_PKEY_CTX_set_data(ctx, data);
491 static void pkey_gost_mac_cleanup(EVP_PKEY_CTX *ctx)
493 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
498 static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
500 struct gost_mac_pmeth_data *dst_data, *src_data;
501 if (!pkey_gost_mac_init(dst)) {
504 src_data = EVP_PKEY_CTX_get_data(src);
505 dst_data = EVP_PKEY_CTX_get_data(dst);
506 if (!src_data || !dst_data)
509 *dst_data = *src_data;
513 static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
515 struct gost_mac_pmeth_data *data =
516 (struct gost_mac_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
519 case EVP_PKEY_CTRL_MD:
521 int nid = EVP_MD_type((const EVP_MD *)p2);
522 if (nid != NID_id_Gost28147_89_MAC && nid != NID_gost_mac_12) {
523 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
524 GOST_R_INVALID_DIGEST_TYPE);
527 data->md = (EVP_MD *)p2;
531 case EVP_PKEY_CTRL_GET_MD:
532 *(const EVP_MD **)p2 = data->md;
535 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
536 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
537 case EVP_PKEY_CTRL_PKCS7_SIGN:
539 case EVP_PKEY_CTRL_SET_MAC_KEY:
541 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
545 memcpy(data->key, p2, 32);
548 case EVP_PKEY_CTRL_GOST_PARAMSET:
550 struct gost_cipher_info *param = p2;
551 data->mac_param_nid = param->nid;
554 case EVP_PKEY_CTRL_DIGESTINIT:
556 EVP_MD_CTX *mctx = p2;
557 struct gost_mac_key *key;
558 if (!data->key_set) {
559 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
561 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
562 GOST_R_MAC_KEY_NOT_SET);
565 key = EVP_PKEY_get0(pkey);
567 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
568 GOST_R_MAC_KEY_NOT_SET);
571 return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
572 (mctx, EVP_MD_CTRL_SET_KEY, 0, key);
574 return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
575 (mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key));
578 case EVP_PKEY_CTRL_MAC_LEN:
580 if (p1 < 1 || p1 > 8) {
582 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE);
592 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
593 const char *type, const char *value)
595 if (strcmp(type, key_ctrl_string) == 0) {
596 if (strlen(value) != 32) {
597 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
598 GOST_R_INVALID_MAC_KEY_LENGTH);
601 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
604 if (strcmp(type, hexkey_ctrl_string) == 0) {
607 unsigned char *keybuf = string_to_hex(value, &keylen);
608 if (!keybuf || keylen != 32) {
609 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
610 GOST_R_INVALID_MAC_KEY_LENGTH);
611 OPENSSL_free(keybuf);
614 ret = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32, keybuf);
615 OPENSSL_free(keybuf);
619 if (!strcmp(type, maclen_ctrl_string)) {
621 long size = strtol(value, &endptr, 10);
622 if (*endptr != '\0') {
623 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_SIZE);
626 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN, size, NULL);
628 if (strcmp(type, param_ctrl_string) == 0) {
629 ASN1_OBJECT *obj = OBJ_txt2obj(value, 0);
630 const struct gost_cipher_info *param = NULL;
632 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
636 param = get_encryption_params(obj);
638 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
642 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0,
648 static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx,
649 EVP_PKEY *pkey, int mac_nid)
651 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
652 struct gost_mac_key *keydata;
653 if (!data || !data->key_set) {
654 GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET);
657 keydata = OPENSSL_malloc(sizeof(struct gost_mac_key));
660 memcpy(keydata->key, data->key, 32);
661 keydata->mac_param_nid = data->mac_param_nid;
662 keydata->mac_size = data->mac_size;
663 EVP_PKEY_assign(pkey, mac_nid, keydata);
667 static int pkey_gost_mac_keygen_12(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
669 return pkey_gost_mac_keygen_base(ctx, pkey, NID_gost_mac_12);
672 static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
674 return pkey_gost_mac_keygen_base(ctx, pkey, NID_id_Gost28147_89_MAC);
677 static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
679 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
682 pkey_gost_mac_init(ctx);
685 data = EVP_PKEY_CTX_get_data(ctx);
687 GOSTerr(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT, GOST_R_MAC_KEY_NOT_SET);
694 static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
695 size_t *siglen, EVP_MD_CTX *mctx)
697 unsigned int tmpsiglen;
699 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
703 tmpsiglen = *siglen; /* for platforms where sizeof(int) !=
707 *siglen = data->mac_size;
711 EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
712 (mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL);
713 ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
714 *siglen = data->mac_size;
718 /* ----------------------------------------------------------------*/
719 int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
721 *pmeth = EVP_PKEY_meth_new(id, flags);
726 case NID_id_GostR3410_2001:
727 EVP_PKEY_meth_set_ctrl(*pmeth,
728 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
729 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
730 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
732 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2001cp_keygen);
734 EVP_PKEY_meth_set_encrypt(*pmeth,
735 pkey_gost_encrypt_init,
736 pkey_GOST_ECcp_encrypt);
737 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
738 EVP_PKEY_meth_set_derive(*pmeth,
739 pkey_gost_derive_init, pkey_gost_ec_derive);
740 EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
741 pkey_gost2001_paramgen);
743 case NID_id_GostR3410_2012_256:
744 EVP_PKEY_meth_set_ctrl(*pmeth,
745 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
746 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
747 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
749 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
751 EVP_PKEY_meth_set_encrypt(*pmeth,
752 pkey_gost_encrypt_init,
753 pkey_GOST_ECcp_encrypt);
754 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
755 EVP_PKEY_meth_set_derive(*pmeth,
756 pkey_gost_derive_init, pkey_gost_ec_derive);
757 EVP_PKEY_meth_set_paramgen(*pmeth,
758 pkey_gost_paramgen_init,
759 pkey_gost2012_paramgen);
761 case NID_id_GostR3410_2012_512:
762 EVP_PKEY_meth_set_ctrl(*pmeth,
763 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_512);
764 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
765 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
767 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
769 EVP_PKEY_meth_set_encrypt(*pmeth,
770 pkey_gost_encrypt_init,
771 pkey_GOST_ECcp_encrypt);
772 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
773 EVP_PKEY_meth_set_derive(*pmeth,
774 pkey_gost_derive_init, pkey_gost_ec_derive);
775 EVP_PKEY_meth_set_paramgen(*pmeth,
776 pkey_gost_paramgen_init,
777 pkey_gost2012_paramgen);
779 case NID_id_Gost28147_89_MAC:
780 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
781 pkey_gost_mac_ctrl_str);
782 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
783 pkey_gost_mac_signctx);
784 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen);
785 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
786 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
787 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
789 case NID_gost_mac_12:
790 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
791 pkey_gost_mac_ctrl_str);
792 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
793 pkey_gost_mac_signctx);
794 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen_12);
795 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
796 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
797 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
799 default: /* Unsupported method */
802 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init);
803 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_cleanup);
805 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_copy);
807 * FIXME derive etc...