Remove legacy sign/verify from EVP_MD.
[openssl.git] / engines / ccgost / gost_crypt.c
1 /**********************************************************************
2  *                          gost_crypt.c                              *
3  *             Copyright (c) 2005-2006 Cryptocom LTD                  *
4  *         This file is distributed under the same license as OpenSSL *
5  *                                                                    *
6  *       OpenSSL interface to GOST 28147-89 cipher functions          *
7  *          Requires OpenSSL 0.9.9 for compilation                    *
8  **********************************************************************/
9 #include <string.h>
10 #include "gost89.h"
11 #include <openssl/err.h>
12 #include <openssl/rand.h>
13 #include "e_gost_err.h"
14 #include "gost_lcl.h"
15
16 #if !defined(CCGOST_DEBUG) && !defined(DEBUG)
17 # ifndef NDEBUG
18 #  define NDEBUG
19 # endif
20 #endif
21 #include <assert.h>
22
23 static int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
24                             const unsigned char *iv, int enc);
25 static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
26                                 const unsigned char *iv, int enc);
27 /* Handles block of data in CFB mode */
28 static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
29                               const unsigned char *in, size_t inl);
30 /* Handles block of data in CNT mode */
31 static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
32                               const unsigned char *in, size_t inl);
33 /* Cleanup function */
34 static int gost_cipher_cleanup(EVP_CIPHER_CTX *);
35 /* set/get cipher parameters */
36 static int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
37 static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
38 /* Control function */
39 static int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
40
41 EVP_CIPHER cipher_gost = {
42     NID_id_Gost28147_89,
43     1,                          /* block_size */
44     32,                         /* key_size */
45     8,                          /* iv_len */
46     EVP_CIPH_CFB_MODE | EVP_CIPH_NO_PADDING |
47         EVP_CIPH_CUSTOM_IV | EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
48     gost_cipher_init,
49     gost_cipher_do_cfb,
50     gost_cipher_cleanup,
51     sizeof(struct ossl_gost_cipher_ctx), /* ctx_size */
52     gost89_set_asn1_parameters,
53     gost89_get_asn1_parameters,
54     gost_cipher_ctl,
55     NULL,
56 };
57
58 EVP_CIPHER cipher_gost_cpacnt = {
59     NID_gost89_cnt,
60     1,                          /* block_size */
61     32,                         /* key_size */
62     8,                          /* iv_len */
63     EVP_CIPH_OFB_MODE | EVP_CIPH_NO_PADDING |
64         EVP_CIPH_CUSTOM_IV | EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
65     gost_cipher_init_cpa,
66     gost_cipher_do_cnt,
67     gost_cipher_cleanup,
68     sizeof(struct ossl_gost_cipher_ctx), /* ctx_size */
69     gost89_set_asn1_parameters,
70     gost89_get_asn1_parameters,
71     gost_cipher_ctl,
72     NULL,
73 };
74
75 /* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
76 /* Init functions which set specific parameters */
77 static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
78 /* process block of data */
79 static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count);
80 /* Return computed value */
81 static int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md);
82 /* Copies context */
83 static int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from);
84 static int gost_imit_cleanup(EVP_MD_CTX *ctx);
85 /* Control function, knows how to set MAC key.*/
86 static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
87
88 EVP_MD imit_gost_cpa = {
89     NID_id_Gost28147_89_MAC,
90     NID_undef,
91     4,
92     0,
93     gost_imit_init_cpa,
94     gost_imit_update,
95     gost_imit_final,
96     gost_imit_copy,
97     gost_imit_cleanup,
98     8,
99     sizeof(struct ossl_gost_imit_ctx),
100     gost_imit_ctrl
101 };
102
103 /*
104  * Correspondence between gost parameter OIDs and substitution blocks
105  * NID field is filed by register_gost_NID function in engine.c
106  * upon engine initialization
107  */
108
109 struct gost_cipher_info gost_cipher_list[] = {
110     /*- NID *//*
111      * Subst block
112      *//*
113      * Key meshing
114      */
115     /*
116      * {NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0},
117      */
118     {NID_id_Gost28147_89_CryptoPro_A_ParamSet, &Gost28147_CryptoProParamSetA,
119      1},
120     {NID_id_Gost28147_89_CryptoPro_B_ParamSet, &Gost28147_CryptoProParamSetB,
121      1},
122     {NID_id_Gost28147_89_CryptoPro_C_ParamSet, &Gost28147_CryptoProParamSetC,
123      1},
124     {NID_id_Gost28147_89_CryptoPro_D_ParamSet, &Gost28147_CryptoProParamSetD,
125      1},
126     {NID_id_Gost28147_89_TestParamSet, &Gost28147_TestParamSet, 1},
127     {NID_undef, NULL, 0}
128 };
129
130 /*
131  * get encryption parameters from crypto network settings FIXME For now we
132  * use environment var CRYPT_PARAMS as place to store these settings.
133  * Actually, it is better to use engine control command, read from
134  * configuration file to set them
135  */
136 const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj)
137 {
138     int nid;
139     struct gost_cipher_info *param;
140     if (!obj) {
141         const char *params = get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS);
142         if (!params || !strlen(params))
143             return &gost_cipher_list[1];
144
145         nid = OBJ_txt2nid(params);
146         if (nid == NID_undef) {
147             GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS,
148                     GOST_R_INVALID_CIPHER_PARAM_OID);
149             return NULL;
150         }
151     } else {
152         nid = OBJ_obj2nid(obj);
153     }
154     for (param = gost_cipher_list; param->sblock != NULL && param->nid != nid;
155          param++) ;
156     if (!param->sblock) {
157         GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS, GOST_R_INVALID_CIPHER_PARAMS);
158         return NULL;
159     }
160     return param;
161 }
162
163 /* Sets cipher param from paramset NID. */
164 static int gost_cipher_set_param(struct ossl_gost_cipher_ctx *c, int nid)
165 {
166     const struct gost_cipher_info *param;
167     param =
168         get_encryption_params((nid == NID_undef ? NULL : OBJ_nid2obj(nid)));
169     if (!param)
170         return 0;
171
172     c->paramNID = param->nid;
173     c->key_meshing = param->key_meshing;
174     c->count = 0;
175     gost_init(&(c->cctx), param->sblock);
176     return 1;
177 }
178
179 /* Initializes EVP_CIPHER_CTX by paramset NID */
180 static int gost_cipher_init_param(EVP_CIPHER_CTX *ctx,
181                                   const unsigned char *key,
182                                   const unsigned char *iv, int enc,
183                                   int paramNID, int mode)
184 {
185     struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
186     if (ctx->app_data == NULL) {
187         if (!gost_cipher_set_param(c, paramNID))
188             return 0;
189         ctx->app_data = ctx->cipher_data;
190     }
191     if (key)
192         gost_key(&(c->cctx), key);
193     if (iv)
194         memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
195     memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
196     return 1;
197 }
198
199 static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
200                                 const unsigned char *iv, int enc)
201 {
202     struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
203     gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
204     c->key_meshing = 1;
205     c->count = 0;
206     if (key)
207         gost_key(&(c->cctx), key);
208     if (iv)
209         memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
210     memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
211     return 1;
212 }
213
214 /* Initializes EVP_CIPHER_CTX with default values */
215 int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
216                      const unsigned char *iv, int enc)
217 {
218     return gost_cipher_init_param(ctx, key, iv, enc, NID_undef,
219                                   EVP_CIPH_CFB_MODE);
220 }
221
222 /*
223  * Wrapper around gostcrypt function from gost89.c which perform key meshing
224  * when nesseccary
225  */
226 static void gost_crypt_mesh(void *ctx, unsigned char *iv, unsigned char *buf)
227 {
228     struct ossl_gost_cipher_ctx *c = ctx;
229     assert(c->count % 8 == 0 && c->count <= 1024);
230     if (c->key_meshing && c->count == 1024) {
231         cryptopro_key_meshing(&(c->cctx), iv);
232     }
233     gostcrypt(&(c->cctx), iv, buf);
234     c->count = c->count % 1024 + 8;
235 }
236
237 static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf)
238 {
239     struct ossl_gost_cipher_ctx *c = ctx;
240     word32 g, go;
241     unsigned char buf1[8];
242     assert(c->count % 8 == 0 && c->count <= 1024);
243     if (c->key_meshing && c->count == 1024) {
244         cryptopro_key_meshing(&(c->cctx), iv);
245     }
246     if (c->count == 0) {
247         gostcrypt(&(c->cctx), iv, buf1);
248     } else {
249         memcpy(buf1, iv, 8);
250     }
251     g = buf1[0] | (buf1[1] << 8) | (buf1[2] << 16) | ((word32) buf1[3] << 24);
252     g += 0x01010101;
253     buf1[0] = (unsigned char)(g & 0xff);
254     buf1[1] = (unsigned char)((g >> 8) & 0xff);
255     buf1[2] = (unsigned char)((g >> 16) & 0xff);
256     buf1[3] = (unsigned char)((g >> 24) & 0xff);
257     g = buf1[4] | (buf1[5] << 8) | (buf1[6] << 16) | ((word32) buf1[7] << 24);
258     go = g;
259     g += 0x01010104;
260     if (go > g)                 /* overflow */
261         g++;
262     buf1[4] = (unsigned char)(g & 0xff);
263     buf1[5] = (unsigned char)((g >> 8) & 0xff);
264     buf1[6] = (unsigned char)((g >> 16) & 0xff);
265     buf1[7] = (unsigned char)((g >> 24) & 0xff);
266     memcpy(iv, buf1, 8);
267     gostcrypt(&(c->cctx), buf1, buf);
268     c->count = c->count % 1024 + 8;
269 }
270
271 /* GOST encryption in CFB mode */
272 int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
273                        const unsigned char *in, size_t inl)
274 {
275     const unsigned char *in_ptr = in;
276     unsigned char *out_ptr = out;
277     size_t i = 0;
278     size_t j = 0;
279 /* process partial block if any */
280     if (ctx->num) {
281         for (j = ctx->num, i = 0; j < 8 && i < inl;
282              j++, i++, in_ptr++, out_ptr++) {
283             if (!ctx->encrypt)
284                 ctx->buf[j + 8] = *in_ptr;
285             *out_ptr = ctx->buf[j] ^ (*in_ptr);
286             if (ctx->encrypt)
287                 ctx->buf[j + 8] = *out_ptr;
288         }
289         if (j == 8) {
290             memcpy(ctx->iv, ctx->buf + 8, 8);
291             ctx->num = 0;
292         } else {
293             ctx->num = j;
294             return 1;
295         }
296     }
297
298     for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
299         /*
300          * block cipher current iv
301          */
302         gost_crypt_mesh(ctx->cipher_data, ctx->iv, ctx->buf);
303         /*
304          * xor next block of input text with it and output it
305          */
306         /*
307          * output this block
308          */
309         if (!ctx->encrypt)
310             memcpy(ctx->iv, in_ptr, 8);
311         for (j = 0; j < 8; j++) {
312             out_ptr[j] = ctx->buf[j] ^ in_ptr[j];
313         }
314         /* Encrypt */
315         /* Next iv is next block of cipher text */
316         if (ctx->encrypt)
317             memcpy(ctx->iv, out_ptr, 8);
318     }
319 /* Process rest of buffer */
320     if (i < inl) {
321         gost_crypt_mesh(ctx->cipher_data, ctx->iv, ctx->buf);
322         if (!ctx->encrypt)
323             memcpy(ctx->buf + 8, in_ptr, inl - i);
324         for (j = 0; i < inl; j++, i++) {
325             out_ptr[j] = ctx->buf[j] ^ in_ptr[j];
326         }
327         ctx->num = j;
328         if (ctx->encrypt)
329             memcpy(ctx->buf + 8, out_ptr, j);
330     } else {
331         ctx->num = 0;
332     }
333     return 1;
334 }
335
336 static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
337                               const unsigned char *in, size_t inl)
338 {
339     const unsigned char *in_ptr = in;
340     unsigned char *out_ptr = out;
341     size_t i = 0;
342     size_t j;
343 /* process partial block if any */
344     if (ctx->num) {
345         for (j = ctx->num, i = 0; j < 8 && i < inl;
346              j++, i++, in_ptr++, out_ptr++) {
347             *out_ptr = ctx->buf[j] ^ (*in_ptr);
348         }
349         if (j == 8) {
350             ctx->num = 0;
351         } else {
352             ctx->num = j;
353             return 1;
354         }
355     }
356
357     for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
358         /*
359          * block cipher current iv
360          */
361         /* Encrypt */
362         gost_cnt_next(ctx->cipher_data, ctx->iv, ctx->buf);
363         /*
364          * xor next block of input text with it and output it
365          */
366         /*
367          * output this block
368          */
369         for (j = 0; j < 8; j++) {
370             out_ptr[j] = ctx->buf[j] ^ in_ptr[j];
371         }
372     }
373 /* Process rest of buffer */
374     if (i < inl) {
375         gost_cnt_next(ctx->cipher_data, ctx->iv, ctx->buf);
376         for (j = 0; i < inl; j++, i++) {
377             out_ptr[j] = ctx->buf[j] ^ in_ptr[j];
378         }
379         ctx->num = j;
380     } else {
381         ctx->num = 0;
382     }
383     return 1;
384 }
385
386 /* Cleaning up of EVP_CIPHER_CTX */
387 int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx)
388 {
389     gost_destroy(&((struct ossl_gost_cipher_ctx *)ctx->cipher_data)->cctx);
390     ctx->app_data = NULL;
391     return 1;
392 }
393
394 /* Control function for gost cipher */
395 int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
396 {
397     switch (type) {
398     case EVP_CTRL_RAND_KEY:
399         {
400             if (RAND_bytes((unsigned char *)ptr, ctx->key_len) <= 0) {
401                 GOSTerr(GOST_F_GOST_CIPHER_CTL,
402                         GOST_R_RANDOM_GENERATOR_ERROR);
403                 return -1;
404             }
405             break;
406         }
407     case EVP_CTRL_PBE_PRF_NID:
408         if (ptr) {
409             *((int *)ptr) = NID_id_HMACGostR3411_94;
410             return 1;
411         } else {
412             return 0;
413         }
414
415     default:
416         GOSTerr(GOST_F_GOST_CIPHER_CTL,
417                 GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
418         return -1;
419     }
420     return 1;
421 }
422
423 /* Set cipher parameters from ASN1 structure */
424 int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
425 {
426     int len = 0;
427     unsigned char *buf = NULL;
428     unsigned char *p = NULL;
429     struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
430     GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
431     ASN1_OCTET_STRING *os = NULL;
432     if (!gcp) {
433         GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
434         return 0;
435     }
436     if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len)) {
437         GOST_CIPHER_PARAMS_free(gcp);
438         GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
439         return 0;
440     }
441     ASN1_OBJECT_free(gcp->enc_param_set);
442     gcp->enc_param_set = OBJ_nid2obj(c->paramNID);
443
444     len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
445     p = buf = OPENSSL_malloc(len);
446     if (!buf) {
447         GOST_CIPHER_PARAMS_free(gcp);
448         GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
449         return 0;
450     }
451     i2d_GOST_CIPHER_PARAMS(gcp, &p);
452     GOST_CIPHER_PARAMS_free(gcp);
453
454     os = ASN1_OCTET_STRING_new();
455
456     if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
457         OPENSSL_free(buf);
458         GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
459         return 0;
460     }
461     OPENSSL_free(buf);
462
463     ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
464     return 1;
465 }
466
467 /* Store parameters into ASN1 structure */
468 int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
469 {
470     int ret = -1;
471     int len;
472     GOST_CIPHER_PARAMS *gcp = NULL;
473     unsigned char *p;
474     struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
475     if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
476         return ret;
477     }
478
479     p = params->value.sequence->data;
480
481     gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
482                                  params->value.sequence->length);
483
484     len = gcp->iv->length;
485     if (len != ctx->cipher->iv_len) {
486         GOST_CIPHER_PARAMS_free(gcp);
487         GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, GOST_R_INVALID_IV_LENGTH);
488         return -1;
489     }
490     if (!gost_cipher_set_param(c, OBJ_obj2nid(gcp->enc_param_set))) {
491         GOST_CIPHER_PARAMS_free(gcp);
492         return -1;
493     }
494     memcpy(ctx->oiv, gcp->iv->data, len);
495
496     GOST_CIPHER_PARAMS_free(gcp);
497
498     return 1;
499 }
500
501 int gost_imit_init_cpa(EVP_MD_CTX *ctx)
502 {
503     struct ossl_gost_imit_ctx *c = ctx->md_data;
504     memset(c->buffer, 0, sizeof(c->buffer));
505     memset(c->partial_block, 0, sizeof(c->partial_block));
506     c->count = 0;
507     c->bytes_left = 0;
508     c->key_meshing = 1;
509     gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
510     return 1;
511 }
512
513 static void mac_block_mesh(struct ossl_gost_imit_ctx *c,
514                            const unsigned char *data)
515 {
516     unsigned char buffer[8];
517     /*
518      * We are using local buffer for iv because CryptoPro doesn't interpret
519      * internal state of MAC algorithm as iv during keymeshing (but does
520      * initialize internal state from iv in key transport
521      */
522     assert(c->count % 8 == 0 && c->count <= 1024);
523     if (c->key_meshing && c->count == 1024) {
524         cryptopro_key_meshing(&(c->cctx), buffer);
525     }
526     mac_block(&(c->cctx), c->buffer, data);
527     c->count = c->count % 1024 + 8;
528 }
529
530 int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
531 {
532     struct ossl_gost_imit_ctx *c = ctx->md_data;
533     const unsigned char *p = data;
534     size_t bytes = count, i;
535     if (!(c->key_set)) {
536         GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
537         return 0;
538     }
539     if (c->bytes_left) {
540         for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
541             c->partial_block[i] = *p;
542         }
543         if (i == 8) {
544             mac_block_mesh(c, c->partial_block);
545         } else {
546             c->bytes_left = i;
547             return 1;
548         }
549     }
550     while (bytes > 8) {
551         mac_block_mesh(c, p);
552         p += 8;
553         bytes -= 8;
554     }
555     if (bytes > 0) {
556         memcpy(c->partial_block, p, bytes);
557     }
558     c->bytes_left = bytes;
559     return 1;
560 }
561
562 int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md)
563 {
564     struct ossl_gost_imit_ctx *c = ctx->md_data;
565     if (!c->key_set) {
566         GOSTerr(GOST_F_GOST_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET);
567         return 0;
568     }
569     if (c->count == 0 && c->bytes_left) {
570         unsigned char buffer[8];
571         memset(buffer, 0, 8);
572         gost_imit_update(ctx, buffer, 8);
573     }
574     if (c->bytes_left) {
575         int i;
576         for (i = c->bytes_left; i < 8; i++) {
577             c->partial_block[i] = 0;
578         }
579         mac_block_mesh(c, c->partial_block);
580     }
581     get_mac(c->buffer, 32, md);
582     return 1;
583 }
584
585 int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
586 {
587     switch (type) {
588     case EVP_MD_CTRL_KEY_LEN:
589         *((unsigned int *)(ptr)) = 32;
590         return 1;
591     case EVP_MD_CTRL_SET_KEY:
592         {
593             if (arg != 32) {
594                 GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
595                 return 0;
596             }
597
598             gost_key(&(((struct ossl_gost_imit_ctx *)(ctx->md_data))->cctx),
599                      ptr);
600             ((struct ossl_gost_imit_ctx *)(ctx->md_data))->key_set = 1;
601             return 1;
602
603         }
604     default:
605         return 0;
606     }
607 }
608
609 int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
610 {
611     memcpy(to->md_data, from->md_data, sizeof(struct ossl_gost_imit_ctx));
612     return 1;
613 }
614
615 /* Clean up imit ctx */
616 int gost_imit_cleanup(EVP_MD_CTX *ctx)
617 {
618     memset(ctx->md_data, 0, sizeof(struct ossl_gost_imit_ctx));
619     return 1;
620 }