af1d29e35c55abf9772791e5ba67ccb0b6e65bd2
[openssl.git] / engines / ccgost / gost_pmeth.c
1 /**********************************************************************
2  *                          gost_pmeth.c                              *
3  *             Copyright (c) 2005-2006 Cryptocom LTD                  *
4  *         This file is distributed under the same license as OpenSSL *
5  *                                                                    *
6  *   Implementation of RFC 4357 (GOST R 34.10) Publick key method     *
7  *       for OpenSSL                                                  *
8  *          Requires OpenSSL 0.9.9 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 */
15 #include <stdlib.h>
16 #include <string.h>
17 #include <ctype.h>
18 #include "gost_params.h"
19 #include "gost_lcl.h"
20 #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)
24 {
25     struct gost_pmeth_data *data;
26     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
27
28     data = OPENSSL_malloc(sizeof(*data));
29     if (!data)
30         return 0;
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_94:
35             data->sign_param_nid = gost94_nid_by_params(EVP_PKEY_get0(pkey));
36             break;
37         case NID_id_GostR3410_2001:
38             data->sign_param_nid =
39                 EC_GROUP_get_curve_name(EC_KEY_get0_group
40                                         (EVP_PKEY_get0((EVP_PKEY *)pkey)));
41             break;
42         default:
43             return 0;
44         }
45     }
46     EVP_PKEY_CTX_set_data(ctx, data);
47     return 1;
48 }
49
50 /* Copies contents of gost_pmeth_data structure */
51 static int pkey_gost_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
52 {
53     struct gost_pmeth_data *dst_data, *src_data;
54     if (!pkey_gost_init(dst)) {
55         return 0;
56     }
57     src_data = EVP_PKEY_CTX_get_data(src);
58     dst_data = EVP_PKEY_CTX_get_data(dst);
59     *dst_data = *src_data;
60     if (src_data->shared_ukm) {
61         dst_data->shared_ukm = NULL;
62     }
63     return 1;
64 }
65
66 /* Frees up gost_pmeth_data structure */
67 static void pkey_gost_cleanup(EVP_PKEY_CTX *ctx)
68 {
69     struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
70
71     OPENSSL_free(data->shared_ukm);
72     OPENSSL_free(data);
73 }
74
75 /* --------------------- control functions  ------------------------------*/
76 static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
77 {
78     struct gost_pmeth_data *pctx =
79         (struct gost_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
80     switch (type) {
81     case EVP_PKEY_CTRL_MD:
82         {
83             if (EVP_MD_type((const EVP_MD *)p2) != NID_id_GostR3411_94) {
84                 GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE);
85                 return 0;
86             }
87             pctx->md = (EVP_MD *)p2;
88             return 1;
89         }
90
91     case EVP_PKEY_CTRL_GET_MD:
92         *(const EVP_MD **)p2 = pctx->md;
93         return 1;
94
95     case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
96     case EVP_PKEY_CTRL_PKCS7_DECRYPT:
97     case EVP_PKEY_CTRL_PKCS7_SIGN:
98     case EVP_PKEY_CTRL_DIGESTINIT:
99 #ifndef OPENSSL_NO_CMS
100     case EVP_PKEY_CTRL_CMS_ENCRYPT:
101     case EVP_PKEY_CTRL_CMS_DECRYPT:
102     case EVP_PKEY_CTRL_CMS_SIGN:
103 #endif
104         return 1;
105
106     case EVP_PKEY_CTRL_GOST_PARAMSET:
107         pctx->sign_param_nid = (int)p1;
108         return 1;
109     case EVP_PKEY_CTRL_SET_IV:
110         pctx->shared_ukm = OPENSSL_malloc((int)p1);
111         if (pctx->shared_ukm == NULL) {
112             GOSTerr(GOST_F_PKEY_GOST_CTRL, ERR_R_MALLOC_FAILURE);
113             return 0;
114         }
115         memcpy(pctx->shared_ukm, p2, (int)p1);
116         return 1;
117     case EVP_PKEY_CTRL_PEER_KEY:
118         if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */
119             return 1;
120         if (p1 == 2)            /* TLS: peer key used? */
121             return pctx->peer_key_used;
122         if (p1 == 3)            /* TLS: peer key used! */
123             return (pctx->peer_key_used = 1);
124         return -2;
125     }
126     return -2;
127 }
128
129 static int pkey_gost_ctrl94_str(EVP_PKEY_CTX *ctx,
130                                 const char *type, const char *value)
131 {
132     int param_nid = 0;
133
134     if (strcmp(type, param_ctrl_string) == 0) {
135         if (!value) {
136             return 0;
137         }
138         if (strlen(value) == 1) {
139             switch (toupper((unsigned char)value[0])) {
140             case 'A':
141                 param_nid = NID_id_GostR3410_94_CryptoPro_A_ParamSet;
142                 break;
143             case 'B':
144                 param_nid = NID_id_GostR3410_94_CryptoPro_B_ParamSet;
145                 break;
146             case 'C':
147                 param_nid = NID_id_GostR3410_94_CryptoPro_C_ParamSet;
148                 break;
149             case 'D':
150                 param_nid = NID_id_GostR3410_94_CryptoPro_D_ParamSet;
151                 break;
152             default:
153                 return 0;
154             }
155         } else if ((strlen(value) == 2)
156                    && (toupper((unsigned char)value[0]) == 'X')) {
157             switch (toupper((unsigned char)value[1])) {
158             case 'A':
159                 param_nid = NID_id_GostR3410_94_CryptoPro_XchA_ParamSet;
160                 break;
161             case 'B':
162                 param_nid = NID_id_GostR3410_94_CryptoPro_XchB_ParamSet;
163                 break;
164             case 'C':
165                 param_nid = NID_id_GostR3410_94_CryptoPro_XchC_ParamSet;
166                 break;
167             default:
168                 return 0;
169             }
170         } else {
171             R3410_params *p = R3410_paramset;
172             param_nid = OBJ_txt2nid(value);
173             if (param_nid == NID_undef) {
174                 return 0;
175             }
176             for (; p->nid != NID_undef; p++) {
177                 if (p->nid == param_nid)
178                     break;
179             }
180             if (p->nid == NID_undef) {
181                 GOSTerr(GOST_F_PKEY_GOST_CTRL94_STR, GOST_R_INVALID_PARAMSET);
182                 return 0;
183             }
184         }
185
186         return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
187                               param_nid, NULL);
188     }
189     return -2;
190 }
191
192 static int pkey_gost_ctrl01_str(EVP_PKEY_CTX *ctx,
193                                 const char *type, const char *value)
194 {
195     int param_nid = 0;
196
197     if (strcmp(type, param_ctrl_string) == 0) {
198         if (!value) {
199             return 0;
200         }
201         if (strlen(value) == 1) {
202             switch (toupper((unsigned char)value[0])) {
203             case 'A':
204                 param_nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet;
205                 break;
206             case 'B':
207                 param_nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet;
208                 break;
209             case 'C':
210                 param_nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet;
211                 break;
212             case '0':
213                 param_nid = NID_id_GostR3410_2001_TestParamSet;
214                 break;
215             default:
216                 return 0;
217             }
218         } else if ((strlen(value) == 2)
219                    && (toupper((unsigned char)value[0]) == 'X')) {
220             switch (toupper((unsigned char)value[1])) {
221             case 'A':
222                 param_nid = NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet;
223                 break;
224             case 'B':
225                 param_nid = NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet;
226                 break;
227             default:
228                 return 0;
229             }
230         } else {
231             R3410_2001_params *p = R3410_2001_paramset;
232             param_nid = OBJ_txt2nid(value);
233             if (param_nid == NID_undef) {
234                 return 0;
235             }
236             for (; p->nid != NID_undef; p++) {
237                 if (p->nid == param_nid)
238                     break;
239             }
240             if (p->nid == NID_undef) {
241                 GOSTerr(GOST_F_PKEY_GOST_CTRL01_STR, GOST_R_INVALID_PARAMSET);
242                 return 0;
243             }
244         }
245
246         return pkey_gost_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
247                               param_nid, NULL);
248     }
249     return -2;
250 }
251
252 /* --------------------- key generation  --------------------------------*/
253
254 static int pkey_gost_paramgen_init(EVP_PKEY_CTX *ctx)
255 {
256     return 1;
257 }
258
259 static int pkey_gost94_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
260 {
261     struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
262     DSA *dsa = NULL;
263     if (data->sign_param_nid == NID_undef) {
264         GOSTerr(GOST_F_PKEY_GOST94_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
265         return 0;
266     }
267     dsa = DSA_new();
268     if (!fill_GOST94_params(dsa, data->sign_param_nid)) {
269         DSA_free(dsa);
270         return 0;
271     }
272     EVP_PKEY_assign(pkey, NID_id_GostR3410_94, dsa);
273     return 1;
274 }
275
276 static int pkey_gost01_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
277 {
278     struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
279     EC_KEY *ec = NULL;
280
281     if (data->sign_param_nid == NID_undef) {
282         GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
283         return 0;
284     }
285     if (!ec)
286         ec = EC_KEY_new();
287     if (!fill_GOST2001_params(ec, data->sign_param_nid)) {
288         EC_KEY_free(ec);
289         return 0;
290     }
291     EVP_PKEY_assign(pkey, NID_id_GostR3410_2001, ec);
292     return 1;
293 }
294
295 /* Generates Gost_R3410_94_cp key */
296 static int pkey_gost94cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
297 {
298     DSA *dsa;
299     if (!pkey_gost94_paramgen(ctx, pkey))
300         return 0;
301     dsa = EVP_PKEY_get0(pkey);
302     gost_sign_keygen(dsa);
303     return 1;
304 }
305
306 /* Generates GOST_R3410 2001 key and assigns it using specified type */
307 static int pkey_gost01cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
308 {
309     EC_KEY *ec;
310     if (!pkey_gost01_paramgen(ctx, pkey))
311         return 0;
312     ec = EVP_PKEY_get0(pkey);
313     gost2001_keygen(ec);
314     return 1;
315 }
316
317 /* ----------- sign callbacks --------------------------------------*/
318
319 static int pkey_gost94_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
320                                size_t *siglen, const unsigned char *tbs,
321                                size_t tbs_len)
322 {
323     DSA_SIG *unpacked_sig = NULL;
324     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
325     if (!siglen)
326         return 0;
327     if (!sig) {
328         *siglen = 64;           /* better to check size of pkey->pkey.dsa-q */
329         return 1;
330     }
331     unpacked_sig = gost_do_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
332     if (!unpacked_sig) {
333         return 0;
334     }
335     return pack_sign_cp(unpacked_sig, 32, sig, siglen);
336 }
337
338 static int pkey_gost01_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
339                                size_t *siglen, const unsigned char *tbs,
340                                size_t tbs_len)
341 {
342     DSA_SIG *unpacked_sig = NULL;
343     EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
344     if (!siglen)
345         return 0;
346     if (!sig) {
347         *siglen = 64;           /* better to check size of curve order */
348         return 1;
349     }
350     unpacked_sig = gost2001_do_sign(tbs, tbs_len, EVP_PKEY_get0(pkey));
351     if (!unpacked_sig) {
352         return 0;
353     }
354     return pack_sign_cp(unpacked_sig, 32, sig, siglen);
355 }
356
357 /* ------------------- verify callbacks ---------------------------*/
358
359 static int pkey_gost94_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
360                                  size_t siglen, const unsigned char *tbs,
361                                  size_t tbs_len)
362 {
363     int ok = 0;
364     EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
365     DSA_SIG *s = unpack_cp_signature(sig, siglen);
366     if (!s)
367         return 0;
368     if (pub_key)
369         ok = gost_do_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
370     DSA_SIG_free(s);
371     return ok;
372 }
373
374 static int pkey_gost01_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
375                                  size_t siglen, const unsigned char *tbs,
376                                  size_t tbs_len)
377 {
378     int ok = 0;
379     EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
380     DSA_SIG *s = unpack_cp_signature(sig, siglen);
381     if (!s)
382         return 0;
383 #ifdef DEBUG_SIGN
384     fprintf(stderr, "R=");
385     BN_print_fp(stderr, s->r);
386     fprintf(stderr, "\nS=");
387     BN_print_fp(stderr, s->s);
388     fprintf(stderr, "\n");
389 #endif
390     if (pub_key)
391         ok = gost2001_do_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key));
392     DSA_SIG_free(s);
393     return ok;
394 }
395
396 /* ------------- encrypt init -------------------------------------*/
397 /* Generates ephermeral key */
398 static int pkey_gost_encrypt_init(EVP_PKEY_CTX *ctx)
399 {
400     return 1;
401 }
402
403 /* --------------- Derive init ------------------------------------*/
404 static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx)
405 {
406     return 1;
407 }
408
409 /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/
410 static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
411 {
412     struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data));
413
414     if (!data)
415         return 0;
416     memset(data, 0, sizeof(*data));
417     EVP_PKEY_CTX_set_data(ctx, data);
418     return 1;
419 }
420
421 static void pkey_gost_mac_cleanup(EVP_PKEY_CTX *ctx)
422 {
423     struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
424     OPENSSL_free(data);
425 }
426
427 static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
428 {
429     struct gost_mac_pmeth_data *dst_data, *src_data;
430     if (!pkey_gost_mac_init(dst)) {
431         return 0;
432     }
433     src_data = EVP_PKEY_CTX_get_data(src);
434     dst_data = EVP_PKEY_CTX_get_data(dst);
435     *dst_data = *src_data;
436     return 1;
437 }
438
439 static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
440 {
441     struct gost_mac_pmeth_data *data =
442         (struct gost_mac_pmeth_data *)EVP_PKEY_CTX_get_data(ctx);
443
444     switch (type) {
445     case EVP_PKEY_CTRL_MD:
446         {
447             if (EVP_MD_type((const EVP_MD *)p2) != NID_id_Gost28147_89_MAC) {
448                 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
449                         GOST_R_INVALID_DIGEST_TYPE);
450                 return 0;
451             }
452             data->md = (EVP_MD *)p2;
453             return 1;
454         }
455
456     case EVP_PKEY_CTRL_GET_MD:
457         *(const EVP_MD **)p2 = data->md;
458         return 1;
459
460     case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
461     case EVP_PKEY_CTRL_PKCS7_DECRYPT:
462     case EVP_PKEY_CTRL_PKCS7_SIGN:
463         return 1;
464     case EVP_PKEY_CTRL_SET_MAC_KEY:
465         if (p1 != 32) {
466             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
467             return 0;
468         }
469
470         memcpy(data->key, p2, 32);
471         data->key_set = 1;
472         return 1;
473     case EVP_PKEY_CTRL_DIGESTINIT:
474         {
475             EVP_MD_CTX *mctx = p2;
476             void *key;
477             if (!data->key_set) {
478                 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
479                 if (!pkey) {
480                     GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
481                             GOST_R_MAC_KEY_NOT_SET);
482                     return 0;
483                 }
484                 key = EVP_PKEY_get0(pkey);
485                 if (!key) {
486                     GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
487                             GOST_R_MAC_KEY_NOT_SET);
488                     return 0;
489                 }
490             } else {
491                 key = &(data->key);
492             }
493             return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, key);
494         }
495     }
496     return -2;
497 }
498
499 static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
500                                   const char *type, const char *value)
501 {
502     if (strcmp(type, key_ctrl_string) == 0) {
503         if (strlen(value) != 32) {
504             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
505                     GOST_R_INVALID_MAC_KEY_LENGTH);
506             return 0;
507         }
508         return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
509                                   32, (char *)value);
510     }
511     if (strcmp(type, hexkey_ctrl_string) == 0) {
512         long keylen;
513         int ret;
514         unsigned char *keybuf = string_to_hex(value, &keylen);
515         if (!keybuf || keylen != 32) {
516             GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
517                     GOST_R_INVALID_MAC_KEY_LENGTH);
518             OPENSSL_free(keybuf);
519             return 0;
520         }
521         ret = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, 32, keybuf);
522         OPENSSL_free(keybuf);
523         return ret;
524
525     }
526     return -2;
527 }
528
529 static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
530 {
531     struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
532     unsigned char *keydata;
533     if (!data->key_set) {
534         GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET);
535         return 0;
536     }
537     keydata = OPENSSL_malloc(32);
538     if (keydata == NULL)
539         return 0;
540     memcpy(keydata, data->key, 32);
541     EVP_PKEY_assign(pkey, NID_id_Gost28147_89_MAC, keydata);
542     return 1;
543 }
544
545 static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
546 {
547     return 1;
548 }
549
550 static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
551                                  size_t *siglen, EVP_MD_CTX *mctx)
552 {
553     unsigned int tmpsiglen = *siglen; /* for platforms where
554                                        * sizeof(int)!=sizeof(size_t) */
555     int ret;
556     if (!sig) {
557         *siglen = 4;
558         return 1;
559     }
560     ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
561     *siglen = tmpsiglen;
562     return ret;
563 }
564
565 /* ----------------------------------------------------------------*/
566 int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
567 {
568     *pmeth = EVP_PKEY_meth_new(id, flags);
569     if (!*pmeth)
570         return 0;
571
572     switch (id) {
573     case NID_id_GostR3410_94:
574         EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost_ctrl94_str);
575         EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost94cp_keygen);
576         EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost94_cp_sign);
577         EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost94_cp_verify);
578         EVP_PKEY_meth_set_encrypt(*pmeth,
579                                   pkey_gost_encrypt_init,
580                                   pkey_GOST94cp_encrypt);
581         EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST94cp_decrypt);
582         EVP_PKEY_meth_set_derive(*pmeth,
583                                  pkey_gost_derive_init, pkey_gost94_derive);
584         EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
585                                    pkey_gost94_paramgen);
586         break;
587     case NID_id_GostR3410_2001:
588         EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost_ctrl01_str);
589         EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost01_cp_sign);
590         EVP_PKEY_meth_set_verify(*pmeth, NULL, pkey_gost01_cp_verify);
591
592         EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost01cp_keygen);
593
594         EVP_PKEY_meth_set_encrypt(*pmeth,
595                                   pkey_gost_encrypt_init,
596                                   pkey_GOST01cp_encrypt);
597         EVP_PKEY_meth_set_decrypt(*pmeth, NULL, pkey_GOST01cp_decrypt);
598         EVP_PKEY_meth_set_derive(*pmeth,
599                                  pkey_gost_derive_init, pkey_gost2001_derive);
600         EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init,
601                                    pkey_gost01_paramgen);
602         break;
603     case NID_id_Gost28147_89_MAC:
604         EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl,
605                                pkey_gost_mac_ctrl_str);
606         EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init,
607                                   pkey_gost_mac_signctx);
608         EVP_PKEY_meth_set_keygen(*pmeth, NULL, pkey_gost_mac_keygen);
609         EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init);
610         EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup);
611         EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy);
612         return 1;
613     default:                   /* Unsupported method */
614         return 0;
615     }
616     EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init);
617     EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_cleanup);
618
619     EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_copy);
620     /*
621      * FIXME derive etc...
622      */
623
624     return 1;
625 }