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