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/x509v3.h> /* For string_to_hex */
17 #include "gost_params.h"
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);
27 data = OPENSSL_malloc(sizeof(struct gost_pmeth_data));
30 memset(data, 0, sizeof(struct gost_pmeth_data));
31 if (pkey && EVP_PKEY_get0(pkey)) {
32 switch (EVP_PKEY_base_id(pkey)) {
33 case NID_id_GostR3410_94:
34 data->sign_param_nid = gost94_nid_by_params(EVP_PKEY_get0(pkey));
36 case NID_id_GostR3410_2001:
37 case NID_id_GostR3410_2012_256:
38 case NID_id_GostR3410_2012_512:
40 const EC_GROUP *group =
41 EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey));
43 data->sign_param_nid = EC_GROUP_get_curve_name(group);
53 EVP_PKEY_CTX_set_data(ctx, data);
57 /* Copies contents of gost_pmeth_data structure */
58 static int pkey_gost_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
60 struct gost_pmeth_data *dst_data, *src_data;
61 if (!pkey_gost_init(dst)) {
64 src_data = EVP_PKEY_CTX_get_data(src);
65 dst_data = EVP_PKEY_CTX_get_data(dst);
66 if (!src_data || !dst_data)
69 *dst_data = *src_data;
70 if (src_data->shared_ukm) {
71 dst_data->shared_ukm = NULL;
76 /* Frees up gost_pmeth_data structure */
77 static void pkey_gost_cleanup(EVP_PKEY_CTX *ctx)
79 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
83 OPENSSL_free(data->shared_ukm);
87 /* --------------------- control functions ------------------------------*/
88 static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
90 struct gost_pmeth_data *pctx =
91 (struct gost_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
96 case EVP_PKEY_CTRL_MD:
98 EVP_PKEY *key = EVP_PKEY_CTX_get0_pkey(ctx);
99 int pkey_nid = (key == NULL) ? NID_undef : EVP_PKEY_base_id(key);
101 OPENSSL_assert(p2 != NULL);
103 switch (EVP_MD_type((const EVP_MD *)p2)) {
104 case NID_id_GostR3411_94:
105 if (pkey_nid == NID_id_GostR3410_2001
106 || pkey_nid == NID_id_GostR3410_94) {
107 pctx->md = (EVP_MD *)p2;
112 case NID_id_GostR3411_2012_256:
113 if (pkey_nid == NID_id_GostR3410_2012_256) {
114 pctx->md = (EVP_MD *)p2;
119 case NID_id_GostR3411_2012_512:
120 if (pkey_nid == NID_id_GostR3410_2012_512) {
121 pctx->md = (EVP_MD *)p2;
127 GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);
131 case EVP_PKEY_CTRL_GET_MD:
132 *(const EVP_MD **)p2 = pctx->md;
135 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
136 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
137 case EVP_PKEY_CTRL_PKCS7_SIGN:
138 case EVP_PKEY_CTRL_DIGESTINIT:
139 #ifndef OPENSSL_NO_CMS
140 case EVP_PKEY_CTRL_CMS_ENCRYPT:
141 case EVP_PKEY_CTRL_CMS_DECRYPT:
142 case EVP_PKEY_CTRL_CMS_SIGN:
146 case EVP_PKEY_CTRL_GOST_PARAMSET:
147 pctx->sign_param_nid = (int)p1;
149 case EVP_PKEY_CTRL_SET_IV:
150 OPENSSL_assert(p2 != NULL);
151 pctx->shared_ukm = OPENSSL_malloc((int)p1);
152 if (!pctx->shared_ukm)
154 memcpy(pctx->shared_ukm, p2, (int)p1);
156 case EVP_PKEY_CTRL_PEER_KEY:
157 if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
159 if (p1 == 2) /* TLS: peer key used? */
160 return pctx->peer_key_used;
161 if (p1 == 3) /* TLS: peer key used! */
162 return (pctx->peer_key_used = 1);
166 GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_CTRL_CALL_FAILED);
170 static int pkey_gost94_ctrl_str(EVP_PKEY_CTX *ctx,
171 const char *type, const char *value)
174 if (!strcmp(type, param_ctrl_string)) {
178 if (strlen(value) == 1) {
179 switch (toupper((unsigned char)value[0])) {
181 param_nid = NID_id_GostR3410_94_CryptoPro_A_ParamSet;
184 param_nid = NID_id_GostR3410_94_CryptoPro_B_ParamSet;
187 param_nid = NID_id_GostR3410_94_CryptoPro_C_ParamSet;
190 param_nid = NID_id_GostR3410_94_CryptoPro_D_ParamSet;
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_94_CryptoPro_XchA_ParamSet;
202 param_nid = NID_id_GostR3410_94_CryptoPro_XchB_ParamSet;
205 param_nid = NID_id_GostR3410_94_CryptoPro_XchC_ParamSet;
211 R3410_params *p = R3410_paramset;
212 param_nid = OBJ_txt2nid(value);
213 if (param_nid == NID_undef) {
216 for (; p->nid != NID_undef; p++) {
217 if (p->nid == param_nid)
220 if (p->nid == NID_undef) {
221 GOSTerr(GOST_F_PKEY_GOST94_CTRL_STR, GOST_R_INVALID_PARAMSET);
226 return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
232 static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
233 const char *type, const char *value)
236 if (!strcmp(type, param_ctrl_string)) {
240 if (strlen(value) == 1) {
241 switch (toupper((unsigned char)value[0])) {
243 param_nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
246 param_nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet;
249 param_nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet;
252 param_nid = NID_id_GostR3410_2001_TestParamSet;
257 } else if ((strlen(value) == 2)
258 && (toupper((unsigned char)value[0]) == 'X')) {
259 switch (toupper((unsigned char)value[1])) {
261 param_nid = NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet;
264 param_nid = NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet;
270 R3410_ec_params *p = R3410_2001_paramset;
271 param_nid = OBJ_txt2nid(value);
272 if (param_nid == NID_undef) {
275 for (; p->nid != NID_undef; p++) {
276 if (p->nid == param_nid)
279 if (p->nid == NID_undef) {
280 GOSTerr(GOST_F_PKEY_GOST_EC_CTRL_STR_256,
281 GOST_R_INVALID_PARAMSET);
286 return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
292 static int pkey_gost_ec_ctrl_str_512(EVP_PKEY_CTX *ctx,
293 const char *type, const char *value)
295 int param_nid = NID_undef;
297 if (strcmp(type, param_ctrl_string))
303 if (strlen(value) == 1) {
304 switch (toupper((unsigned char)value[0])) {
306 param_nid = NID_id_tc26_gost_3410_2012_512_paramSetA;
310 param_nid = NID_id_tc26_gost_3410_2012_512_paramSetB;
317 R3410_ec_params *p = R3410_2012_512_paramset;
318 param_nid = OBJ_txt2nid(value);
319 if (param_nid == NID_undef)
322 while (p->nid != NID_undef && p->nid != param_nid)
325 if (p->nid == NID_undef) {
326 GOSTerr(GOST_F_PKEY_GOST_EC_CTRL_STR_512,
327 GOST_R_INVALID_PARAMSET);
332 return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, param_nid, NULL);
335 /* --------------------- key generation --------------------------------*/
337 static int pkey_gost_paramgen_init(EVP_PKEY_CTX *ctx)
342 static int pkey_gost94_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
344 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
346 if (!data || data->sign_param_nid == NID_undef) {
347 GOSTerr(GOST_F_PKEY_GOST94_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
351 if (!fill_GOST94_params(dsa, data->sign_param_nid)
352 || !EVP_PKEY_assign(pkey, NID_id_GostR3410_94, dsa)) {
359 static int pkey_gost2001_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
361 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
364 if (!data || data->sign_param_nid == NID_undef) {
365 GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
370 if (!fill_GOST_EC_params(ec, data->sign_param_nid)
371 || !EVP_PKEY_assign(pkey, NID_id_GostR3410_2001, ec)) {
378 static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
380 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
384 if (!data || data->sign_param_nid == NID_undef) {
385 GOSTerr(GOST_F_PKEY_GOST12_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
390 if (!fill_GOST_EC_params(ec, data->sign_param_nid)) {
395 switch (data->sign_param_nid) {
396 case NID_id_tc26_gost_3410_2012_512_paramSetA:
397 case NID_id_tc26_gost_3410_2012_512_paramSetB:
399 (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_512, ec)) ? 1 : 0;
402 case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
403 case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
404 case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
405 case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
406 case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
407 case NID_id_GostR3410_2001_TestParamSet:
409 (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_256, ec)) ? 1 : 0;
422 /* ----------- keygen callbacks --------------------------------------*/
423 /* Generates Gost_R3410_94_cp key */
424 static int pkey_gost94cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
427 if (!pkey_gost94_paramgen(ctx, pkey))
429 dsa = EVP_PKEY_get0(pkey);
430 gost_sign_keygen(dsa);
434 /* Generates GOST_R3410 2001 key and assigns it using specified type */
435 static int pkey_gost2001cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
438 if (!pkey_gost2001_paramgen(ctx, pkey))
440 ec = EVP_PKEY_get0(pkey);
445 /* Generates GOST_R3410 2012 key and assigns it using specified type */
446 static int pkey_gost2012cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
448 if (!pkey_gost2012_paramgen(ctx, pkey))
451 gost_ec_keygen(EVP_PKEY_get0(pkey));
455 /* ----------- sign callbacks --------------------------------------*/
457 static int pkey_gost94_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
458 size_t *siglen, const unsigned char *tbs,
461 DSA_SIG *unpacked_sig = NULL;
462 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
466 *siglen = 64; /* better to check size of pkey->pkey.dsa-q */
469 unpacked_sig = gost_do_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
473 return pack_sign_cp(unpacked_sig, 32, sig, siglen);
476 static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
477 size_t *siglen, const unsigned char *tbs,
480 DSA_SIG *unpacked_sig = NULL;
481 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
489 switch (EVP_PKEY_base_id(pkey)) {
490 case NID_id_GostR3410_2001:
491 case NID_id_GostR3410_2012_256:
494 case NID_id_GostR3410_2012_512:
505 unpacked_sig = gost_ec_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
509 return pack_sign_cp(unpacked_sig, order / 2, sig, siglen);
512 /* ------------------- verify callbacks ---------------------------*/
514 static int pkey_gost94_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
515 size_t siglen, const unsigned char *tbs,
519 EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
520 DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
524 ok = gost_do_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
529 static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
530 size_t siglen, const unsigned char *tbs,
534 EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
535 DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL;
539 fprintf(stderr, "R=");
540 BN_print_fp(stderr, s->r);
541 fprintf(stderr, "\nS=");
542 BN_print_fp(stderr, s->s);
543 fprintf(stderr, "\n");
546 ok = gost_ec_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
551 /* ------------- encrypt init -------------------------------------*/
552 /* Generates ephermeral key */
553 static int pkey_gost_encrypt_init(EVP_PKEY_CTX *ctx)
558 /* --------------- Derive init ------------------------------------*/
559 static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
564 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
565 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
567 struct gost_mac_pmeth_data *data;
568 data = OPENSSL_malloc(sizeof(struct gost_mac_pmeth_data));
571 memset(data, 0, sizeof(struct gost_mac_pmeth_data));
572 EVP_PKEY_CTX_set_data(ctx, data);
576 static void pkey_gost_mac_cleanup(EVP_PKEY_CTX *ctx)
578 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
583 static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
585 struct gost_mac_pmeth_data *dst_data, *src_data;
586 if (!pkey_gost_mac_init(dst)) {
589 src_data = EVP_PKEY_CTX_get_data(src);
590 dst_data = EVP_PKEY_CTX_get_data(dst);
591 if (!src_data || !dst_data)
594 *dst_data = *src_data;
598 static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
600 struct gost_mac_pmeth_data *data =
601 (struct gost_mac_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
604 case EVP_PKEY_CTRL_MD:
606 int nid = EVP_MD_type((const EVP_MD *)p2);
607 if (nid != NID_id_Gost28147_89_MAC && nid != NID_gost_mac_12) {
608 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
609 GOST_R_INVALID_DIGEST_TYPE);
612 data->md = (EVP_MD *)p2;
617 case EVP_PKEY_CTRL_GET_MD:
618 *(const EVP_MD **)p2 = data->md;
621 case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
622 case EVP_PKEY_CTRL_PKCS7_DECRYPT:
623 case EVP_PKEY_CTRL_PKCS7_SIGN:
625 case EVP_PKEY_CTRL_SET_MAC_KEY:
627 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
631 memcpy(data->key, p2, 32);
634 case EVP_PKEY_CTRL_DIGESTINIT:
636 EVP_MD_CTX *mctx = p2;
638 if (!data->key_set) {
639 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
641 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
642 GOST_R_MAC_KEY_NOT_SET);
645 key = EVP_PKEY_get0(pkey);
647 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
648 GOST_R_MAC_KEY_NOT_SET);
654 return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, key);
660 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
661 const char *type, const char *value)
663 if (!strcmp(type, key_ctrl_string)) {
664 if (strlen(value) != 32) {
665 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
666 GOST_R_INVALID_MAC_KEY_LENGTH);
669 return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
672 if (!strcmp(type, hexkey_ctrl_string)) {
675 unsigned char *keybuf = string_to_hex(value, &keylen);
676 if (!keybuf || keylen != 32) {
677 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
678 GOST_R_INVALID_MAC_KEY_LENGTH);
679 OPENSSL_free(keybuf);
682 ret = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32, keybuf);
683 OPENSSL_free(keybuf);
690 static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx,
691 EVP_PKEY *pkey, int mac_nid)
693 struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
694 unsigned char *keydata;
695 if (!data || !data->key_set) {
696 GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET);
699 keydata = OPENSSL_malloc(32);
702 memcpy(keydata, data->key, 32);
703 EVP_PKEY_assign(pkey, mac_nid, keydata);
707 static int pkey_gost_mac_keygen_12(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
709 return pkey_gost_mac_keygen_base(ctx, pkey, NID_gost_mac_12);
712 static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
714 return pkey_gost_mac_keygen_base(ctx, pkey, NID_id_Gost28147_89_MAC);
717 static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
722 static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
723 size_t *siglen, EVP_MD_CTX *mctx)
725 unsigned int tmpsiglen;
730 tmpsiglen = *siglen; /* for platforms where sizeof(int) !=
737 ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
742 /* ----------------------------------------------------------------*/
743 int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
745 *pmeth = EVP_PKEY_meth_new(id, flags);
750 case NID_id_GostR3410_94:
751 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost94_ctrl_str);
752 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost94cp_keygen);
753 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost94_cp_sign);
754 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost94_cp_verify);
755 EVP_PKEY_meth_set_encrypt(*pmeth,
756 pkey_gost_encrypt_init,
757 pkey_GOST94cp_encrypt);
758 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST94cp_decrypt);
759 EVP_PKEY_meth_set_derive(*pmeth,
760 pkey_gost_derive_init, pkey_gost94_derive);
761 EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
762 pkey_gost94_paramgen);
764 case NID_id_GostR3410_2001:
765 EVP_PKEY_meth_set_ctrl(*pmeth,
766 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
767 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
768 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
770 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2001cp_keygen);
772 EVP_PKEY_meth_set_encrypt(*pmeth,
773 pkey_gost_encrypt_init,
774 pkey_GOST_ECcp_encrypt);
775 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
776 EVP_PKEY_meth_set_derive(*pmeth,
777 pkey_gost_derive_init, pkey_gost_ec_derive);
778 EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
779 pkey_gost2001_paramgen);
781 case NID_id_GostR3410_2012_256:
782 EVP_PKEY_meth_set_ctrl(*pmeth,
783 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256);
784 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
785 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
787 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
789 EVP_PKEY_meth_set_encrypt(*pmeth,
790 pkey_gost_encrypt_init,
791 pkey_GOST_ECcp_encrypt);
792 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
793 EVP_PKEY_meth_set_derive(*pmeth,
794 pkey_gost_derive_init, pkey_gost_ec_derive);
795 EVP_PKEY_meth_set_paramgen(*pmeth,
796 pkey_gost_paramgen_init,
797 pkey_gost2012_paramgen);
799 case NID_id_GostR3410_2012_512:
800 EVP_PKEY_meth_set_ctrl(*pmeth,
801 pkey_gost_ctrl, pkey_gost_ec_ctrl_str_512);
802 EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign);
803 EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost_ec_cp_verify);
805 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost2012cp_keygen);
807 EVP_PKEY_meth_set_encrypt(*pmeth,
808 pkey_gost_encrypt_init,
809 pkey_GOST_ECcp_encrypt);
810 EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST_ECcp_decrypt);
811 EVP_PKEY_meth_set_derive(*pmeth,
812 pkey_gost_derive_init, pkey_gost_ec_derive);
813 EVP_PKEY_meth_set_paramgen(*pmeth,
814 pkey_gost_paramgen_init,
815 pkey_gost2012_paramgen);
817 case NID_id_Gost28147_89_MAC:
818 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
819 pkey_gost_mac_ctrl_str);
820 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
821 pkey_gost_mac_signctx);
822 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen);
823 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
824 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
825 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
827 case NID_gost_mac_12:
828 EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
829 pkey_gost_mac_ctrl_str);
830 EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
831 pkey_gost_mac_signctx);
832 EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen_12);
833 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
834 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
835 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
837 default: /* Unsupported method */
840 EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init);
841 EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_cleanup);
843 EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_copy);
845 * FIXME derive etc...