1 /**********************************************************************
3 * Copyright (c) 2005-2006 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * OpenSSL interface to GOST 28147-89 cipher functions *
7 * Requires OpenSSL 0.9.9 for compilation *
8 **********************************************************************/
11 #include <openssl/err.h>
12 #include <openssl/rand.h>
13 #include "e_gost_err.h"
15 #include <openssl/evp.h>
17 #if !defined(CCGOST_DEBUG) && !defined(DEBUG)
24 static int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
25 const unsigned char *iv, int enc);
26 static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
27 const unsigned char *iv, int enc);
28 /* Handles block of data in CFB mode */
29 static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
30 const unsigned char *in, size_t inl);
31 /* Handles block of data in CNT mode */
32 static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
33 const unsigned char *in, size_t inl);
34 /* Cleanup function */
35 static int gost_cipher_cleanup(EVP_CIPHER_CTX *);
36 /* set/get cipher parameters */
37 static int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
38 static int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params);
39 /* Control function */
40 static int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
42 static EVP_CIPHER *_hidden_Gost28147_89_cipher = NULL;
43 const EVP_CIPHER *cipher_gost(void)
45 if (_hidden_Gost28147_89_cipher == NULL
46 && ((_hidden_Gost28147_89_cipher =
47 EVP_CIPHER_meth_new(NID_id_Gost28147_89,
49 32 /* key_size */)) == NULL
50 || !EVP_CIPHER_meth_set_iv_length(_hidden_Gost28147_89_cipher, 8)
51 || !EVP_CIPHER_meth_set_flags(_hidden_Gost28147_89_cipher,
56 EVP_CIPH_ALWAYS_CALL_INIT)
57 || !EVP_CIPHER_meth_set_init(_hidden_Gost28147_89_cipher,
59 || !EVP_CIPHER_meth_set_do_cipher(_hidden_Gost28147_89_cipher,
61 || !EVP_CIPHER_meth_set_cleanup(_hidden_Gost28147_89_cipher,
63 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_Gost28147_89_cipher,
64 sizeof(struct ossl_gost_cipher_ctx))
65 || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_cipher,
66 gost89_set_asn1_parameters)
67 || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_cipher,
68 gost89_get_asn1_parameters)
69 || !EVP_CIPHER_meth_set_ctrl(_hidden_Gost28147_89_cipher,
71 EVP_CIPHER_meth_free(_hidden_Gost28147_89_cipher);
72 _hidden_Gost28147_89_cipher = NULL;
74 return _hidden_Gost28147_89_cipher;
77 static EVP_CIPHER *_hidden_gost89_cnt = NULL;
78 const EVP_CIPHER *cipher_gost_cpacnt(void)
80 if (_hidden_gost89_cnt == NULL
81 && ((_hidden_gost89_cnt =
82 EVP_CIPHER_meth_new(NID_gost89_cnt,
84 32 /* key_size */)) == NULL
85 || !EVP_CIPHER_meth_set_iv_length(_hidden_gost89_cnt, 8)
86 || !EVP_CIPHER_meth_set_flags(_hidden_gost89_cnt,
91 EVP_CIPH_ALWAYS_CALL_INIT)
92 || !EVP_CIPHER_meth_set_init(_hidden_gost89_cnt,
94 || !EVP_CIPHER_meth_set_do_cipher(_hidden_gost89_cnt,
96 || !EVP_CIPHER_meth_set_cleanup(_hidden_gost89_cnt,
98 || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_gost89_cnt,
99 sizeof(struct ossl_gost_cipher_ctx))
100 || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_gost89_cnt,
101 gost89_set_asn1_parameters)
102 || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_gost89_cnt,
103 gost89_get_asn1_parameters)
104 || !EVP_CIPHER_meth_set_ctrl(_hidden_gost89_cnt,
106 EVP_CIPHER_meth_free(_hidden_gost89_cnt);
107 _hidden_gost89_cnt = NULL;
109 return _hidden_gost89_cnt;
112 /* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
113 /* Init functions which set specific parameters */
114 static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
115 /* process block of data */
116 static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count);
117 /* Return computed value */
118 static int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md);
120 static int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from);
121 static int gost_imit_cleanup(EVP_MD_CTX *ctx);
122 /* Control function, knows how to set MAC key.*/
123 static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
125 static EVP_MD *_hidden_Gost28147_89_MAC_md = NULL;
126 const EVP_MD *imit_gost_cpa(void)
129 if (_hidden_Gost28147_89_MAC_md == NULL) {
132 if ((md = EVP_MD_meth_new(NID_id_Gost28147_89_MAC, NID_undef)) == NULL
133 || !EVP_MD_meth_set_result_size(md, 4)
134 || !EVP_MD_meth_set_input_blocksize(md, 8)
135 || !EVP_MD_meth_set_app_datasize(md,
136 sizeof(struct ossl_gost_imit_ctx))
137 || !EVP_MD_meth_set_flags(md, 0)
138 || !EVP_MD_meth_set_init(md, gost_imit_init_cpa)
139 || !EVP_MD_meth_set_update(md, gost_imit_update)
140 || !EVP_MD_meth_set_final(md, gost_imit_final)
141 || !EVP_MD_meth_set_copy(md, gost_imit_copy)
142 || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup)
143 || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) {
144 EVP_MD_meth_free(md);
147 _hidden_Gost28147_89_MAC_md = md;
149 return _hidden_Gost28147_89_MAC_md;
151 void imit_gost_cpa_destroy(void)
153 EVP_MD_meth_free(_hidden_Gost28147_89_MAC_md);
154 _hidden_Gost28147_89_MAC_md = NULL;
158 * Correspondence between gost parameter OIDs and substitution blocks
159 * NID field is filed by register_gost_NID function in engine.c
160 * upon engine initialization
163 struct gost_cipher_info gost_cipher_list[] = {
170 * {NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0},
172 {NID_id_Gost28147_89_CryptoPro_A_ParamSet, &Gost28147_CryptoProParamSetA,
174 {NID_id_Gost28147_89_CryptoPro_B_ParamSet, &Gost28147_CryptoProParamSetB,
176 {NID_id_Gost28147_89_CryptoPro_C_ParamSet, &Gost28147_CryptoProParamSetC,
178 {NID_id_Gost28147_89_CryptoPro_D_ParamSet, &Gost28147_CryptoProParamSetD,
180 {NID_id_Gost28147_89_TestParamSet, &Gost28147_TestParamSet, 1},
185 * get encryption parameters from crypto network settings FIXME For now we
186 * use environment var CRYPT_PARAMS as place to store these settings.
187 * Actually, it is better to use engine control command, read from
188 * configuration file to set them
190 const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj)
193 struct gost_cipher_info *param;
195 const char *params = get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS);
196 if (!params || !strlen(params))
197 return &gost_cipher_list[1];
199 nid = OBJ_txt2nid(params);
200 if (nid == NID_undef) {
201 GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS,
202 GOST_R_INVALID_CIPHER_PARAM_OID);
206 nid = OBJ_obj2nid(obj);
208 for (param = gost_cipher_list; param->sblock != NULL && param->nid != nid;
210 if (!param->sblock) {
211 GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS, GOST_R_INVALID_CIPHER_PARAMS);
217 /* Sets cipher param from paramset NID. */
218 static int gost_cipher_set_param(struct ossl_gost_cipher_ctx *c, int nid)
220 const struct gost_cipher_info *param;
222 get_encryption_params((nid == NID_undef ? NULL : OBJ_nid2obj(nid)));
226 c->paramNID = param->nid;
227 c->key_meshing = param->key_meshing;
229 gost_init(&(c->cctx), param->sblock);
233 /* Initializes EVP_CIPHER_CTX by paramset NID */
234 static int gost_cipher_init_param(EVP_CIPHER_CTX *ctx,
235 const unsigned char *key,
236 const unsigned char *iv, int enc,
237 int paramNID, int mode)
239 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
240 if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
241 if (!gost_cipher_set_param(c, paramNID))
243 EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_cipher_data(ctx));
246 gost_key(&(c->cctx), key);
248 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), iv,
249 EVP_CIPHER_CTX_iv_length(ctx));
250 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
251 EVP_CIPHER_CTX_original_iv(ctx),
252 EVP_CIPHER_CTX_iv_length(ctx));
256 static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
257 const unsigned char *iv, int enc)
259 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
260 gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
264 gost_key(&(c->cctx), key);
266 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), iv,
267 EVP_CIPHER_CTX_iv_length(ctx));
268 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
269 EVP_CIPHER_CTX_original_iv(ctx),
270 EVP_CIPHER_CTX_iv_length(ctx));
274 /* Initializes EVP_CIPHER_CTX with default values */
275 int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
276 const unsigned char *iv, int enc)
278 return gost_cipher_init_param(ctx, key, iv, enc, NID_undef,
283 * Wrapper around gostcrypt function from gost89.c which perform key meshing
286 static void gost_crypt_mesh(void *ctx, unsigned char *iv, unsigned char *buf)
288 struct ossl_gost_cipher_ctx *c = ctx;
289 assert(c->count % 8 == 0 && c->count <= 1024);
290 if (c->key_meshing && c->count == 1024) {
291 cryptopro_key_meshing(&(c->cctx), iv);
293 gostcrypt(&(c->cctx), iv, buf);
294 c->count = c->count % 1024 + 8;
297 static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf)
299 struct ossl_gost_cipher_ctx *c = ctx;
301 unsigned char buf1[8];
302 assert(c->count % 8 == 0 && c->count <= 1024);
303 if (c->key_meshing && c->count == 1024) {
304 cryptopro_key_meshing(&(c->cctx), iv);
307 gostcrypt(&(c->cctx), iv, buf1);
311 g = buf1[0] | (buf1[1] << 8) | (buf1[2] << 16) | ((word32) buf1[3] << 24);
313 buf1[0] = (unsigned char)(g & 0xff);
314 buf1[1] = (unsigned char)((g >> 8) & 0xff);
315 buf1[2] = (unsigned char)((g >> 16) & 0xff);
316 buf1[3] = (unsigned char)((g >> 24) & 0xff);
317 g = buf1[4] | (buf1[5] << 8) | (buf1[6] << 16) | ((word32) buf1[7] << 24);
320 if (go > g) /* overflow */
322 buf1[4] = (unsigned char)(g & 0xff);
323 buf1[5] = (unsigned char)((g >> 8) & 0xff);
324 buf1[6] = (unsigned char)((g >> 16) & 0xff);
325 buf1[7] = (unsigned char)((g >> 24) & 0xff);
327 gostcrypt(&(c->cctx), buf1, buf);
328 c->count = c->count % 1024 + 8;
331 /* GOST encryption in CFB mode */
332 int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
333 const unsigned char *in, size_t inl)
335 const unsigned char *in_ptr = in;
336 unsigned char *out_ptr = out;
337 unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
340 /* process partial block if any */
341 if (EVP_CIPHER_CTX_num(ctx)) {
342 for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
343 j++, i++, in_ptr++, out_ptr++) {
344 if (!EVP_CIPHER_CTX_encrypting(ctx))
345 buf[j + 8] = *in_ptr;
346 *out_ptr = buf[j] ^ (*in_ptr);
347 if (EVP_CIPHER_CTX_encrypting(ctx))
348 buf[j + 8] = *out_ptr;
351 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), buf + 8, 8);
352 EVP_CIPHER_CTX_set_num(ctx, 0);
354 EVP_CIPHER_CTX_set_num(ctx, j);
359 for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
361 * block cipher current iv
363 gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx),
364 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
366 * xor next block of input text with it and output it
371 if (!EVP_CIPHER_CTX_encrypting(ctx))
372 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), in_ptr, 8);
373 for (j = 0; j < 8; j++) {
374 out_ptr[j] = buf[j] ^ in_ptr[j];
377 /* Next iv is next block of cipher text */
378 if (EVP_CIPHER_CTX_encrypting(ctx))
379 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), out_ptr, 8);
381 /* Process rest of buffer */
383 gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx),
384 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
385 if (!EVP_CIPHER_CTX_encrypting(ctx))
386 memcpy(buf + 8, in_ptr, inl - i);
387 for (j = 0; i < inl; j++, i++) {
388 out_ptr[j] = buf[j] ^ in_ptr[j];
390 EVP_CIPHER_CTX_set_num(ctx, j);
391 if (EVP_CIPHER_CTX_encrypting(ctx))
392 memcpy(buf + 8, out_ptr, j);
394 EVP_CIPHER_CTX_set_num(ctx, 0);
399 static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
400 const unsigned char *in, size_t inl)
402 const unsigned char *in_ptr = in;
403 unsigned char *out_ptr = out;
404 unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
407 /* process partial block if any */
408 if (EVP_CIPHER_CTX_num(ctx)) {
409 for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
410 j++, i++, in_ptr++, out_ptr++) {
411 *out_ptr = buf[j] ^ (*in_ptr);
414 EVP_CIPHER_CTX_set_num(ctx, 0);
416 EVP_CIPHER_CTX_set_num(ctx, j);
421 for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
423 * block cipher current iv
426 gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx),
427 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
429 * xor next block of input text with it and output it
434 for (j = 0; j < 8; j++) {
435 out_ptr[j] = buf[j] ^ in_ptr[j];
438 /* Process rest of buffer */
440 gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx),
441 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
442 for (j = 0; i < inl; j++, i++) {
443 out_ptr[j] = buf[j] ^ in_ptr[j];
445 EVP_CIPHER_CTX_set_num(ctx, j);
447 EVP_CIPHER_CTX_set_num(ctx, 0);
452 /* Cleaning up of EVP_CIPHER_CTX */
453 int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx)
455 gost_destroy(&((struct ossl_gost_cipher_ctx *)
456 EVP_CIPHER_CTX_cipher_data(ctx))->cctx);
457 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
461 /* Control function for gost cipher */
462 int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
465 case EVP_CTRL_RAND_KEY:
467 if (RAND_bytes((unsigned char *)ptr,
468 EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
469 GOSTerr(GOST_F_GOST_CIPHER_CTL,
470 GOST_R_RANDOM_GENERATOR_ERROR);
475 case EVP_CTRL_PBE_PRF_NID:
477 *((int *)ptr) = NID_id_HMACGostR3411_94;
484 GOSTerr(GOST_F_GOST_CIPHER_CTL,
485 GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
491 /* Set cipher parameters from ASN1 structure */
492 int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
495 unsigned char *buf = NULL;
496 unsigned char *p = NULL;
497 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
498 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
499 ASN1_OCTET_STRING *os = NULL;
501 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
504 if (!ASN1_OCTET_STRING_set(gcp->iv, EVP_CIPHER_CTX_iv(ctx),
505 EVP_CIPHER_CTX_iv_length(ctx))) {
506 GOST_CIPHER_PARAMS_free(gcp);
507 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
510 ASN1_OBJECT_free(gcp->enc_param_set);
511 gcp->enc_param_set = OBJ_nid2obj(c->paramNID);
513 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
514 p = buf = OPENSSL_malloc(len);
516 GOST_CIPHER_PARAMS_free(gcp);
517 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
520 i2d_GOST_CIPHER_PARAMS(gcp, &p);
521 GOST_CIPHER_PARAMS_free(gcp);
523 os = ASN1_OCTET_STRING_new();
525 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
527 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
532 ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
536 /* Store parameters into ASN1 structure */
537 int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
541 GOST_CIPHER_PARAMS *gcp = NULL;
543 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
544 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
548 p = params->value.sequence->data;
550 gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
551 params->value.sequence->length);
553 len = gcp->iv->length;
554 if (len != EVP_CIPHER_CTX_iv_length(ctx)) {
555 GOST_CIPHER_PARAMS_free(gcp);
556 GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, GOST_R_INVALID_IV_LENGTH);
559 if (!gost_cipher_set_param(c, OBJ_obj2nid(gcp->enc_param_set))) {
560 GOST_CIPHER_PARAMS_free(gcp);
563 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), gcp->iv->data,
564 EVP_CIPHER_CTX_iv_length(ctx));
566 GOST_CIPHER_PARAMS_free(gcp);
571 int gost_imit_init_cpa(EVP_MD_CTX *ctx)
573 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
574 memset(c->buffer, 0, sizeof(c->buffer));
575 memset(c->partial_block, 0, sizeof(c->partial_block));
579 gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
583 static void mac_block_mesh(struct ossl_gost_imit_ctx *c,
584 const unsigned char *data)
586 unsigned char buffer[8];
588 * We are using local buffer for iv because CryptoPro doesn't interpret
589 * internal state of MAC algorithm as iv during keymeshing (but does
590 * initialize internal state from iv in key transport
592 assert(c->count % 8 == 0 && c->count <= 1024);
593 if (c->key_meshing && c->count == 1024) {
594 cryptopro_key_meshing(&(c->cctx), buffer);
596 mac_block(&(c->cctx), c->buffer, data);
597 c->count = c->count % 1024 + 8;
600 int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
602 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
603 const unsigned char *p = data;
604 size_t bytes = count, i;
606 GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
610 for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
611 c->partial_block[i] = *p;
614 mac_block_mesh(c, c->partial_block);
621 mac_block_mesh(c, p);
626 memcpy(c->partial_block, p, bytes);
628 c->bytes_left = bytes;
632 int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md)
634 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
636 GOSTerr(GOST_F_GOST_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET);
639 if (c->count == 0 && c->bytes_left) {
640 unsigned char buffer[8];
641 memset(buffer, 0, 8);
642 gost_imit_update(ctx, buffer, 8);
646 for (i = c->bytes_left; i < 8; i++) {
647 c->partial_block[i] = 0;
649 mac_block_mesh(c, c->partial_block);
651 get_mac(c->buffer, 32, md);
655 int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
658 case EVP_MD_CTRL_KEY_LEN:
659 *((unsigned int *)(ptr)) = 32;
661 case EVP_MD_CTRL_SET_KEY:
664 GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
668 gost_key(&(((struct ossl_gost_imit_ctx *)(EVP_MD_CTX_md_data(ctx)))->cctx),
670 ((struct ossl_gost_imit_ctx *)(EVP_MD_CTX_md_data(ctx)))->key_set = 1;
679 int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
681 memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from),
682 sizeof(struct ossl_gost_imit_ctx));
686 /* Clean up imit ctx */
687 int gost_imit_cleanup(EVP_MD_CTX *ctx)
689 memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_imit_ctx));