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)
372 const BIGNUM *sig_r = NULL, *sig_s = NULL;
373 DSA_SIG_get0(s, &sig_r, &sig_s);
375 memset(sig, 0, *siglen);
376 store_bignum(sig_s, sig, order);
377 store_bignum(sig_r, sig + order, order);
382 static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
383 size_t *siglen, const unsigned char *tbs,
386 DSA_SIG *unpacked_sig = NULL;
387 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
395 switch (EVP_PKEY_base_id(pkey)) {
396 case NID_id_GostR3410_2001:
397 case NID_id_GostR3410_2012_256:
400 case NID_id_GostR3410_2012_512:
411 unpacked_sig = gost_ec_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
415 return pack_sign_cp(unpacked_sig, order / 2, sig, siglen);
418 /* ------------------- verify callbacks ---------------------------*/
419 /* Unpack signature according to cryptopro rules */
420 DSA_SIG *unpack_cp_signature(const unsigned char *sigbuf, size_t siglen)
423 BIGNUM *r = NULL, *s = NULL;
427 GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE);
430 s = BN_bin2bn(sigbuf, siglen / 2, NULL);
431 r = BN_bin2bn(sigbuf + siglen / 2, siglen / 2, NULL);
432 DSA_SIG_set0(sig, r, s);
436 static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
437 size_t siglen, const unsigned char *tbs,
441 EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
442 DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
446 fprintf(stderr, "R=");
447 BN_print_fp(stderr, s->r);
448 fprintf(stderr, "\nS=");
449 BN_print_fp(stderr, s->s);
450 fprintf(stderr, "\n");
453 ok = gost_ec_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
458 /* ------------- encrypt init -------------------------------------*/
459 /* Generates ephermeral key */
460 static int pkey_gost_encrypt_init(EVP_PKEY_CTX *ctx)
465 /* --------------- Derive init ------------------------------------*/
466 static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
471 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
472 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
474 struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data));
475 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
479 memset(data, 0, sizeof(*data));
481 data->mac_param_nid = NID_undef;
484 struct gost_mac_key *key = EVP_PKEY_get0(pkey);
486 data->mac_param_nid = key->mac_param_nid;
487 data->mac_size = key->mac_size;
491 EVP_PKEY_CTX_set_data(ctx, data);
495 static void pkey_gost_mac_cleanup(EVP_PKEY_CTX *ctx)
497 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
502 static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
504 struct gost_mac_pmeth_data *dst_data, *src_data;
505 if (!pkey_gost_mac_init(dst)) {
508 src_data = EVP_PKEY_CTX_get_data(src);
509 dst_data = EVP_PKEY_CTX_get_data(dst);
510 if (!src_data || !dst_data)
513 *dst_data = *src_data;
517 static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
519 struct gost_mac_pmeth_data *data =
520 (struct gost_mac_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
523 case EVP_PKEY_CTRL_MD:
525 int nid = EVP_MD_type((const EVP_MD *)p2);
526 if (nid != NID_id_Gost28147_89_MAC && nid != NID_gost_mac_12) {
527 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
528 GOST_R_INVALID_DIGEST_TYPE);
531 data->md = (EVP_MD *)p2;
535 case EVP_PKEY_CTRL_GET_MD:
536 *(const EVP_MD **)p2 = data->md;
539 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
540 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
541 case EVP_PKEY_CTRL_PKCS7_SIGN:
543 case EVP_PKEY_CTRL_SET_MAC_KEY:
545 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
549 memcpy(data->key, p2, 32);
552 case EVP_PKEY_CTRL_GOST_PARAMSET:
554 struct gost_cipher_info *param = p2;
555 data->mac_param_nid = param->nid;
558 case EVP_PKEY_CTRL_DIGESTINIT:
560 EVP_MD_CTX *mctx = p2;
561 struct gost_mac_key *key;
562 if (!data->key_set) {
563 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
565 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
566 GOST_R_MAC_KEY_NOT_SET);
569 key = EVP_PKEY_get0(pkey);
571 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
572 GOST_R_MAC_KEY_NOT_SET);
575 return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
576 (mctx, EVP_MD_CTRL_SET_KEY, 0, key);
578 return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
579 (mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key));
582 case EVP_PKEY_CTRL_MAC_LEN:
584 if (p1 < 1 || p1 > 8) {
586 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE);
596 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
597 const char *type, const char *value)
599 if (strcmp(type, key_ctrl_string) == 0) {
600 if (strlen(value) != 32) {
601 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
602 GOST_R_INVALID_MAC_KEY_LENGTH);
605 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
608 if (strcmp(type, hexkey_ctrl_string) == 0) {
611 unsigned char *keybuf = string_to_hex(value, &keylen);
612 if (!keybuf || keylen != 32) {
613 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
614 GOST_R_INVALID_MAC_KEY_LENGTH);
615 OPENSSL_free(keybuf);
618 ret = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32, keybuf);
619 OPENSSL_free(keybuf);
623 if (!strcmp(type, maclen_ctrl_string)) {
625 long size = strtol(value, &endptr, 10);
626 if (*endptr != '\0') {
627 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_SIZE);
630 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN, size, NULL);
632 if (strcmp(type, param_ctrl_string) == 0) {
633 ASN1_OBJECT *obj = OBJ_txt2obj(value, 0);
634 const struct gost_cipher_info *param = NULL;
636 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
640 param = get_encryption_params(obj);
641 ASN1_OBJECT_free(obj);
643 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
648 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0,
654 static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx,
655 EVP_PKEY *pkey, int mac_nid)
657 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
658 struct gost_mac_key *keydata;
659 if (!data || !data->key_set) {
660 GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET);
663 keydata = OPENSSL_malloc(sizeof(struct gost_mac_key));
666 memcpy(keydata->key, data->key, 32);
667 keydata->mac_param_nid = data->mac_param_nid;
668 keydata->mac_size = data->mac_size;
669 EVP_PKEY_assign(pkey, mac_nid, keydata);
673 static int pkey_gost_mac_keygen_12(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
675 return pkey_gost_mac_keygen_base(ctx, pkey, NID_gost_mac_12);
678 static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
680 return pkey_gost_mac_keygen_base(ctx, pkey, NID_id_Gost28147_89_MAC);
683 static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
685 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
688 pkey_gost_mac_init(ctx);
691 data = EVP_PKEY_CTX_get_data(ctx);
693 GOSTerr(GOST_F_PKEY_GOST_MAC_SIGNCTX_INIT, GOST_R_MAC_KEY_NOT_SET);
700 static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
701 size_t *siglen, EVP_MD_CTX *mctx)
703 unsigned int tmpsiglen;
705 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
709 tmpsiglen = *siglen; /* for platforms where sizeof(int) !=
713 *siglen = data->mac_size;
717 EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
718 (mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL);
719 ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
720 *siglen = data->mac_size;
724 /* ----------------------------------------------------------------*/
725 int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
727 *pmeth = EVP_PKEY_meth_new(id, flags);
732 case NID_id_GostR3410_2001:
733 EVP_PKEY_meth_set_ctrl(*pmeth,
734 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
735 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
736 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
738 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2001cp_keygen);
740 EVP_PKEY_meth_set_encrypt(*pmeth,
741 pkey_gost_encrypt_init,
742 pkey_GOST_ECcp_encrypt);
743 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
744 EVP_PKEY_meth_set_derive(*pmeth,
745 pkey_gost_derive_init, pkey_gost_ec_derive);
746 EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
747 pkey_gost2001_paramgen);
749 case NID_id_GostR3410_2012_256:
750 EVP_PKEY_meth_set_ctrl(*pmeth,
751 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
752 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
753 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
755 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
757 EVP_PKEY_meth_set_encrypt(*pmeth,
758 pkey_gost_encrypt_init,
759 pkey_GOST_ECcp_encrypt);
760 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
761 EVP_PKEY_meth_set_derive(*pmeth,
762 pkey_gost_derive_init, pkey_gost_ec_derive);
763 EVP_PKEY_meth_set_paramgen(*pmeth,
764 pkey_gost_paramgen_init,
765 pkey_gost2012_paramgen);
767 case NID_id_GostR3410_2012_512:
768 EVP_PKEY_meth_set_ctrl(*pmeth,
769 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_512);
770 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
771 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
773 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
775 EVP_PKEY_meth_set_encrypt(*pmeth,
776 pkey_gost_encrypt_init,
777 pkey_GOST_ECcp_encrypt);
778 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
779 EVP_PKEY_meth_set_derive(*pmeth,
780 pkey_gost_derive_init, pkey_gost_ec_derive);
781 EVP_PKEY_meth_set_paramgen(*pmeth,
782 pkey_gost_paramgen_init,
783 pkey_gost2012_paramgen);
785 case NID_id_Gost28147_89_MAC:
786 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
787 pkey_gost_mac_ctrl_str);
788 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
789 pkey_gost_mac_signctx);
790 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen);
791 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
792 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
793 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
795 case NID_gost_mac_12:
796 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
797 pkey_gost_mac_ctrl_str);
798 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
799 pkey_gost_mac_signctx);
800 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen_12);
801 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
802 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
803 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
805 default: /* Unsupported method */
808 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init);
809 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_cleanup);
811 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_copy);
813 * FIXME derive etc...