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