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 void cipher_gost_destroy(void)
114 EVP_CIPHER_meth_free(_hidden_Gost28147_89_cipher);
115 _hidden_Gost28147_89_cipher = NULL;
116 EVP_CIPHER_meth_free(_hidden_gost89_cnt);
117 _hidden_gost89_cnt = NULL;
120 /* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
121 /* Init functions which set specific parameters */
122 static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
123 /* process block of data */
124 static int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count);
125 /* Return computed value */
126 static int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md);
128 static int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from);
129 static int gost_imit_cleanup(EVP_MD_CTX *ctx);
130 /* Control function, knows how to set MAC key.*/
131 static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
133 static EVP_MD *_hidden_Gost28147_89_MAC_md = NULL;
134 const EVP_MD *imit_gost_cpa(void)
137 if (_hidden_Gost28147_89_MAC_md == NULL) {
140 if ((md = EVP_MD_meth_new(NID_id_Gost28147_89_MAC, NID_undef)) == NULL
141 || !EVP_MD_meth_set_result_size(md, 4)
142 || !EVP_MD_meth_set_input_blocksize(md, 8)
143 || !EVP_MD_meth_set_app_datasize(md,
144 sizeof(struct ossl_gost_imit_ctx))
145 || !EVP_MD_meth_set_flags(md, 0)
146 || !EVP_MD_meth_set_init(md, gost_imit_init_cpa)
147 || !EVP_MD_meth_set_update(md, gost_imit_update)
148 || !EVP_MD_meth_set_final(md, gost_imit_final)
149 || !EVP_MD_meth_set_copy(md, gost_imit_copy)
150 || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup)
151 || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) {
152 EVP_MD_meth_free(md);
155 _hidden_Gost28147_89_MAC_md = md;
157 return _hidden_Gost28147_89_MAC_md;
159 void imit_gost_cpa_destroy(void)
161 EVP_MD_meth_free(_hidden_Gost28147_89_MAC_md);
162 _hidden_Gost28147_89_MAC_md = NULL;
166 * Correspondence between gost parameter OIDs and substitution blocks
167 * NID field is filed by register_gost_NID function in engine.c
168 * upon engine initialization
171 struct gost_cipher_info gost_cipher_list[] = {
178 * {NID_id_GostR3411_94_CryptoProParamSet,&GostR3411_94_CryptoProParamSet,0},
180 {NID_id_Gost28147_89_CryptoPro_A_ParamSet, &Gost28147_CryptoProParamSetA,
182 {NID_id_Gost28147_89_CryptoPro_B_ParamSet, &Gost28147_CryptoProParamSetB,
184 {NID_id_Gost28147_89_CryptoPro_C_ParamSet, &Gost28147_CryptoProParamSetC,
186 {NID_id_Gost28147_89_CryptoPro_D_ParamSet, &Gost28147_CryptoProParamSetD,
188 {NID_id_Gost28147_89_TestParamSet, &Gost28147_TestParamSet, 1},
193 * get encryption parameters from crypto network settings FIXME For now we
194 * use environment var CRYPT_PARAMS as place to store these settings.
195 * Actually, it is better to use engine control command, read from
196 * configuration file to set them
198 const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj)
201 struct gost_cipher_info *param;
203 const char *params = get_gost_engine_param(GOST_PARAM_CRYPT_PARAMS);
204 if (!params || !strlen(params))
205 return &gost_cipher_list[1];
207 nid = OBJ_txt2nid(params);
208 if (nid == NID_undef) {
209 GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS,
210 GOST_R_INVALID_CIPHER_PARAM_OID);
214 nid = OBJ_obj2nid(obj);
216 for (param = gost_cipher_list; param->sblock != NULL && param->nid != nid;
218 if (!param->sblock) {
219 GOSTerr(GOST_F_GET_ENCRYPTION_PARAMS, GOST_R_INVALID_CIPHER_PARAMS);
225 /* Sets cipher param from paramset NID. */
226 static int gost_cipher_set_param(struct ossl_gost_cipher_ctx *c, int nid)
228 const struct gost_cipher_info *param;
230 get_encryption_params((nid == NID_undef ? NULL : OBJ_nid2obj(nid)));
234 c->paramNID = param->nid;
235 c->key_meshing = param->key_meshing;
237 gost_init(&(c->cctx), param->sblock);
241 /* Initializes EVP_CIPHER_CTX by paramset NID */
242 static int gost_cipher_init_param(EVP_CIPHER_CTX *ctx,
243 const unsigned char *key,
244 const unsigned char *iv, int enc,
245 int paramNID, int mode)
247 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
248 if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
249 if (!gost_cipher_set_param(c, paramNID))
251 EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_cipher_data(ctx));
254 gost_key(&(c->cctx), key);
256 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), iv,
257 EVP_CIPHER_CTX_iv_length(ctx));
258 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
259 EVP_CIPHER_CTX_original_iv(ctx),
260 EVP_CIPHER_CTX_iv_length(ctx));
264 static int gost_cipher_init_cpa(EVP_CIPHER_CTX *ctx, const unsigned char *key,
265 const unsigned char *iv, int enc)
267 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
268 gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
272 gost_key(&(c->cctx), key);
274 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), iv,
275 EVP_CIPHER_CTX_iv_length(ctx));
276 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
277 EVP_CIPHER_CTX_original_iv(ctx),
278 EVP_CIPHER_CTX_iv_length(ctx));
282 /* Initializes EVP_CIPHER_CTX with default values */
283 int gost_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
284 const unsigned char *iv, int enc)
286 return gost_cipher_init_param(ctx, key, iv, enc, NID_undef,
291 * Wrapper around gostcrypt function from gost89.c which perform key meshing
294 static void gost_crypt_mesh(void *ctx, unsigned char *iv, unsigned char *buf)
296 struct ossl_gost_cipher_ctx *c = ctx;
297 assert(c->count % 8 == 0 && c->count <= 1024);
298 if (c->key_meshing && c->count == 1024) {
299 cryptopro_key_meshing(&(c->cctx), iv);
301 gostcrypt(&(c->cctx), iv, buf);
302 c->count = c->count % 1024 + 8;
305 static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf)
307 struct ossl_gost_cipher_ctx *c = ctx;
309 unsigned char buf1[8];
310 assert(c->count % 8 == 0 && c->count <= 1024);
311 if (c->key_meshing && c->count == 1024) {
312 cryptopro_key_meshing(&(c->cctx), iv);
315 gostcrypt(&(c->cctx), iv, buf1);
319 g = buf1[0] | (buf1[1] << 8) | (buf1[2] << 16) | ((word32) buf1[3] << 24);
321 buf1[0] = (unsigned char)(g & 0xff);
322 buf1[1] = (unsigned char)((g >> 8) & 0xff);
323 buf1[2] = (unsigned char)((g >> 16) & 0xff);
324 buf1[3] = (unsigned char)((g >> 24) & 0xff);
325 g = buf1[4] | (buf1[5] << 8) | (buf1[6] << 16) | ((word32) buf1[7] << 24);
328 if (go > g) /* overflow */
330 buf1[4] = (unsigned char)(g & 0xff);
331 buf1[5] = (unsigned char)((g >> 8) & 0xff);
332 buf1[6] = (unsigned char)((g >> 16) & 0xff);
333 buf1[7] = (unsigned char)((g >> 24) & 0xff);
335 gostcrypt(&(c->cctx), buf1, buf);
336 c->count = c->count % 1024 + 8;
339 /* GOST encryption in CFB mode */
340 int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
341 const unsigned char *in, size_t inl)
343 const unsigned char *in_ptr = in;
344 unsigned char *out_ptr = out;
345 unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
348 /* process partial block if any */
349 if (EVP_CIPHER_CTX_num(ctx)) {
350 for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
351 j++, i++, in_ptr++, out_ptr++) {
352 if (!EVP_CIPHER_CTX_encrypting(ctx))
353 buf[j + 8] = *in_ptr;
354 *out_ptr = buf[j] ^ (*in_ptr);
355 if (EVP_CIPHER_CTX_encrypting(ctx))
356 buf[j + 8] = *out_ptr;
359 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), buf + 8, 8);
360 EVP_CIPHER_CTX_set_num(ctx, 0);
362 EVP_CIPHER_CTX_set_num(ctx, j);
367 for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
369 * block cipher current iv
371 gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx),
372 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
374 * xor next block of input text with it and output it
379 if (!EVP_CIPHER_CTX_encrypting(ctx))
380 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), in_ptr, 8);
381 for (j = 0; j < 8; j++) {
382 out_ptr[j] = buf[j] ^ in_ptr[j];
385 /* Next iv is next block of cipher text */
386 if (EVP_CIPHER_CTX_encrypting(ctx))
387 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), out_ptr, 8);
389 /* Process rest of buffer */
391 gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx),
392 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
393 if (!EVP_CIPHER_CTX_encrypting(ctx))
394 memcpy(buf + 8, in_ptr, inl - i);
395 for (j = 0; i < inl; j++, i++) {
396 out_ptr[j] = buf[j] ^ in_ptr[j];
398 EVP_CIPHER_CTX_set_num(ctx, j);
399 if (EVP_CIPHER_CTX_encrypting(ctx))
400 memcpy(buf + 8, out_ptr, j);
402 EVP_CIPHER_CTX_set_num(ctx, 0);
407 static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
408 const unsigned char *in, size_t inl)
410 const unsigned char *in_ptr = in;
411 unsigned char *out_ptr = out;
412 unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
415 /* process partial block if any */
416 if (EVP_CIPHER_CTX_num(ctx)) {
417 for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
418 j++, i++, in_ptr++, out_ptr++) {
419 *out_ptr = buf[j] ^ (*in_ptr);
422 EVP_CIPHER_CTX_set_num(ctx, 0);
424 EVP_CIPHER_CTX_set_num(ctx, j);
429 for (; i + 8 < inl; i += 8, in_ptr += 8, out_ptr += 8) {
431 * block cipher current iv
434 gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx),
435 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
437 * xor next block of input text with it and output it
442 for (j = 0; j < 8; j++) {
443 out_ptr[j] = buf[j] ^ in_ptr[j];
446 /* Process rest of buffer */
448 gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx),
449 EVP_CIPHER_CTX_iv_noconst(ctx), buf);
450 for (j = 0; i < inl; j++, i++) {
451 out_ptr[j] = buf[j] ^ in_ptr[j];
453 EVP_CIPHER_CTX_set_num(ctx, j);
455 EVP_CIPHER_CTX_set_num(ctx, 0);
460 /* Cleaning up of EVP_CIPHER_CTX */
461 int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx)
463 gost_destroy(&((struct ossl_gost_cipher_ctx *)
464 EVP_CIPHER_CTX_cipher_data(ctx))->cctx);
465 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
469 /* Control function for gost cipher */
470 int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
473 case EVP_CTRL_RAND_KEY:
475 if (RAND_bytes((unsigned char *)ptr,
476 EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
477 GOSTerr(GOST_F_GOST_CIPHER_CTL,
478 GOST_R_RANDOM_GENERATOR_ERROR);
483 case EVP_CTRL_PBE_PRF_NID:
485 *((int *)ptr) = NID_id_HMACGostR3411_94;
492 GOSTerr(GOST_F_GOST_CIPHER_CTL,
493 GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
499 /* Set cipher parameters from ASN1 structure */
500 int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
503 unsigned char *buf = NULL;
504 unsigned char *p = NULL;
505 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
506 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
507 ASN1_OCTET_STRING *os = NULL;
509 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
512 if (!ASN1_OCTET_STRING_set(gcp->iv, EVP_CIPHER_CTX_iv(ctx),
513 EVP_CIPHER_CTX_iv_length(ctx))) {
514 GOST_CIPHER_PARAMS_free(gcp);
515 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
518 ASN1_OBJECT_free(gcp->enc_param_set);
519 gcp->enc_param_set = OBJ_nid2obj(c->paramNID);
521 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
522 p = buf = OPENSSL_malloc(len);
524 GOST_CIPHER_PARAMS_free(gcp);
525 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
528 i2d_GOST_CIPHER_PARAMS(gcp, &p);
529 GOST_CIPHER_PARAMS_free(gcp);
531 os = ASN1_OCTET_STRING_new();
533 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
535 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
540 ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
544 /* Store parameters into ASN1 structure */
545 int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
549 GOST_CIPHER_PARAMS *gcp = NULL;
551 struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
552 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
556 p = params->value.sequence->data;
558 gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
559 params->value.sequence->length);
561 len = gcp->iv->length;
562 if (len != EVP_CIPHER_CTX_iv_length(ctx)) {
563 GOST_CIPHER_PARAMS_free(gcp);
564 GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, GOST_R_INVALID_IV_LENGTH);
567 if (!gost_cipher_set_param(c, OBJ_obj2nid(gcp->enc_param_set))) {
568 GOST_CIPHER_PARAMS_free(gcp);
571 memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), gcp->iv->data,
572 EVP_CIPHER_CTX_iv_length(ctx));
574 GOST_CIPHER_PARAMS_free(gcp);
579 int gost_imit_init_cpa(EVP_MD_CTX *ctx)
581 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
582 memset(c->buffer, 0, sizeof(c->buffer));
583 memset(c->partial_block, 0, sizeof(c->partial_block));
587 gost_init(&(c->cctx), &Gost28147_CryptoProParamSetA);
591 static void mac_block_mesh(struct ossl_gost_imit_ctx *c,
592 const unsigned char *data)
594 unsigned char buffer[8];
596 * We are using local buffer for iv because CryptoPro doesn't interpret
597 * internal state of MAC algorithm as iv during keymeshing (but does
598 * initialize internal state from iv in key transport
600 assert(c->count % 8 == 0 && c->count <= 1024);
601 if (c->key_meshing && c->count == 1024) {
602 cryptopro_key_meshing(&(c->cctx), buffer);
604 mac_block(&(c->cctx), c->buffer, data);
605 c->count = c->count % 1024 + 8;
608 int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
610 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
611 const unsigned char *p = data;
612 size_t bytes = count, i;
614 GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
618 for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
619 c->partial_block[i] = *p;
622 mac_block_mesh(c, c->partial_block);
629 mac_block_mesh(c, p);
634 memcpy(c->partial_block, p, bytes);
636 c->bytes_left = bytes;
640 int gost_imit_final(EVP_MD_CTX *ctx, unsigned char *md)
642 struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
644 GOSTerr(GOST_F_GOST_IMIT_FINAL, GOST_R_MAC_KEY_NOT_SET);
647 if (c->count == 0 && c->bytes_left) {
648 unsigned char buffer[8];
649 memset(buffer, 0, 8);
650 gost_imit_update(ctx, buffer, 8);
654 for (i = c->bytes_left; i < 8; i++) {
655 c->partial_block[i] = 0;
657 mac_block_mesh(c, c->partial_block);
659 get_mac(c->buffer, 32, md);
663 int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
666 case EVP_MD_CTRL_KEY_LEN:
667 *((unsigned int *)(ptr)) = 32;
669 case EVP_MD_CTRL_SET_KEY:
672 GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
676 gost_key(&(((struct ossl_gost_imit_ctx *)(EVP_MD_CTX_md_data(ctx)))->cctx),
678 ((struct ossl_gost_imit_ctx *)(EVP_MD_CTX_md_data(ctx)))->key_set = 1;
687 int gost_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
689 memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from),
690 sizeof(struct ossl_gost_imit_ctx));
694 /* Clean up imit ctx */
695 int gost_imit_cleanup(EVP_MD_CTX *ctx)
697 memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_imit_ctx));