3 * This file is distributed under the same license as OpenSSL
6 #if defined(__cplusplus)
10 #include "gost_grasshopper_cipher.h"
11 #include "gost_grasshopper_defines.h"
12 #include "gost_grasshopper_math.h"
13 #include "gost_grasshopper_core.h"
15 #include <openssl/evp.h>
16 #include <openssl/rand.h>
17 #include <openssl/err.h>
21 #include "e_gost_err.h"
23 enum GRASSHOPPER_CIPHER_TYPE {
24 GRASSHOPPER_CIPHER_ECB = 0,
25 GRASSHOPPER_CIPHER_CBC,
26 GRASSHOPPER_CIPHER_OFB,
27 GRASSHOPPER_CIPHER_CFB,
28 GRASSHOPPER_CIPHER_CTR
31 static EVP_CIPHER* gost_grasshopper_ciphers[5] = {
32 [GRASSHOPPER_CIPHER_ECB] = NULL,
33 [GRASSHOPPER_CIPHER_CBC] = NULL,
34 [GRASSHOPPER_CIPHER_OFB] = NULL,
35 [GRASSHOPPER_CIPHER_CFB] = NULL,
36 [GRASSHOPPER_CIPHER_CTR] = NULL
39 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ofb(gost_grasshopper_cipher_ctx* c);
40 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ctr(gost_grasshopper_cipher_ctx* c);
42 struct GRASSHOPPER_CIPHER_PARAMS {
44 grasshopper_init_cipher_func init_cipher;
45 grasshopper_do_cipher_func do_cipher;
46 grasshopper_destroy_cipher_func destroy_cipher;
53 static struct GRASSHOPPER_CIPHER_PARAMS gost_cipher_params[5] = {
54 [GRASSHOPPER_CIPHER_ECB] = {
56 gost_grasshopper_cipher_init_ecb,
57 gost_grasshopper_cipher_do_ecb,
60 sizeof(gost_grasshopper_cipher_ctx),
64 [GRASSHOPPER_CIPHER_CBC] = {
66 gost_grasshopper_cipher_init_cbc,
67 gost_grasshopper_cipher_do_cbc,
70 sizeof(gost_grasshopper_cipher_ctx),
74 [GRASSHOPPER_CIPHER_OFB] = {
76 gost_grasshopper_cipher_init_ofb,
77 gost_grasshopper_cipher_do_ofb,
78 gost_grasshopper_cipher_destroy_ofb,
80 sizeof(gost_grasshopper_cipher_ctx_ofb),
84 [GRASSHOPPER_CIPHER_CFB] = {
86 gost_grasshopper_cipher_init_cfb,
87 gost_grasshopper_cipher_do_cfb,
90 sizeof(gost_grasshopper_cipher_ctx),
94 [GRASSHOPPER_CIPHER_CTR] = {
96 gost_grasshopper_cipher_init_ctr,
97 gost_grasshopper_cipher_do_ctr,
98 gost_grasshopper_cipher_destroy_ctr,
100 sizeof(gost_grasshopper_cipher_ctx_ctr),
106 /* Set 256 bit key into context */
107 GRASSHOPPER_INLINE void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k) {
109 for (i = 0; i < 2; i++) {
110 grasshopper_copy128(&c->key.k.k[i], (const grasshopper_w128_t*) (k + i * 16));
112 grasshopper_set_encrypt_key(&c->encrypt_round_keys, &c->key);
113 grasshopper_set_decrypt_key(&c->decrypt_round_keys, &c->key);
116 /* Cleans up key from context */
117 GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c) {
119 for (i = 0; i < 2; i++) {
120 grasshopper_zero128(&c->key.k.k[i]);
122 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
123 grasshopper_zero128(&c->encrypt_round_keys.k[i]);
125 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
126 grasshopper_zero128(&c->decrypt_round_keys.k[i]);
128 grasshopper_zero128(&c->buffer);
131 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ofb(gost_grasshopper_cipher_ctx* c) {
132 gost_grasshopper_cipher_ctx_ofb* ctx = (gost_grasshopper_cipher_ctx_ofb*) c;
134 grasshopper_zero128(&ctx->buffer1);
137 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ctr(gost_grasshopper_cipher_ctx* c) {
138 gost_grasshopper_cipher_ctx_ctr* ctx = (gost_grasshopper_cipher_ctx_ctr*) c;
140 grasshopper_zero128(&ctx->iv_buffer);
141 grasshopper_zero128(&ctx->partial_buffer);
144 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
145 const unsigned char* iv, int enc) {
146 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
148 if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
149 EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_get_cipher_data(ctx));
153 gost_grasshopper_cipher_key(c, key);
157 memcpy((unsigned char*) EVP_CIPHER_CTX_original_iv(ctx), iv,
158 EVP_CIPHER_CTX_iv_length(ctx));
161 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
162 EVP_CIPHER_CTX_original_iv(ctx),
163 EVP_CIPHER_CTX_iv_length(ctx));
165 grasshopper_zero128(&c->buffer);
170 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
171 const unsigned char* iv,
173 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
174 c->type = GRASSHOPPER_CIPHER_ECB;
175 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
178 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key,
179 const unsigned char* iv,
181 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
182 c->type = GRASSHOPPER_CIPHER_CBC;
183 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
186 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
187 const unsigned char* iv,
189 gost_grasshopper_cipher_ctx_ofb* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
191 c->c.type = GRASSHOPPER_CIPHER_OFB;
193 grasshopper_zero128(&c->buffer1);
195 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
198 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
199 const unsigned char* iv,
201 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
202 c->type = GRASSHOPPER_CIPHER_CFB;
203 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
206 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key,
207 const unsigned char* iv,
209 gost_grasshopper_cipher_ctx_ctr* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
211 c->c.type = GRASSHOPPER_CIPHER_CTR;
214 grasshopper_zero128(&c->iv_buffer);
215 grasshopper_zero128(&c->partial_buffer);
217 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
220 GRASSHOPPER_INLINE int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
221 const unsigned char* in, size_t inl) {
222 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
223 struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
225 return params->do_cipher(ctx, out, in, inl);
228 int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
229 const unsigned char* in, size_t inl) {
230 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
231 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
232 const unsigned char* current_in = in;
233 unsigned char* current_out = out;
234 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
237 for (i = 0; i < blocks; i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out += GRASSHOPPER_BLOCK_SIZE) {
239 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) current_in,
240 (grasshopper_w128_t*) current_out,
243 grasshopper_decrypt_block(&c->decrypt_round_keys, (grasshopper_w128_t*) current_in,
244 (grasshopper_w128_t*) current_out,
252 int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
253 const unsigned char* in, size_t inl) {
254 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
255 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
256 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
257 const unsigned char* current_in = in;
258 unsigned char* current_out = out;
259 grasshopper_w128_t* currentInputBlock;
260 grasshopper_w128_t* currentOutputBlock;
261 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
263 grasshopper_w128_t* currentBlock;
265 currentBlock = (grasshopper_w128_t*) iv;
267 for (i = 0; i < blocks; i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out += GRASSHOPPER_BLOCK_SIZE) {
268 currentInputBlock = (grasshopper_w128_t*) current_in;
269 currentOutputBlock = (grasshopper_w128_t*) current_out;
271 grasshopper_append128(currentBlock, currentInputBlock);
272 grasshopper_encrypt_block(&c->encrypt_round_keys, currentBlock, currentOutputBlock, &c->buffer);
273 grasshopper_copy128(currentBlock, currentOutputBlock);
275 grasshopper_decrypt_block(&c->decrypt_round_keys, currentInputBlock, currentOutputBlock, &c->buffer);
276 grasshopper_append128(currentOutputBlock, currentBlock);
277 grasshopper_copy128(currentBlock, currentInputBlock);
284 void inc_counter(unsigned char* counter, size_t counter_bytes)
287 unsigned int n = counter_bytes;
298 /* increment counter (128-bit int) by 1 */
299 static void ctr128_inc(unsigned char *counter)
301 inc_counter(counter, 16);
304 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
305 const unsigned char* in, size_t inl) {
306 gost_grasshopper_cipher_ctx_ctr* c = (gost_grasshopper_cipher_ctx_ctr*) EVP_CIPHER_CTX_get_cipher_data(ctx);
307 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
308 const unsigned char* current_in = in;
309 unsigned char* current_out = out;
310 grasshopper_w128_t* currentInputBlock;
311 grasshopper_w128_t* currentOutputBlock;
312 unsigned int n = ctx->num;
317 *(current_out++) = *(current_in++) ^ c->partial_buffer.b[n];
319 n = (n + 1) % GRASSHOPPER_BLOCK_SIZE;
322 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
324 memcpy(&c->iv_buffer, iv, 8);
327 for (i = 0; i < blocks; i++) {
328 currentInputBlock = (grasshopper_w128_t*) current_in;
329 currentOutputBlock = (grasshopper_w128_t*) current_out;
330 grasshopper_encrypt_block(&c->c.encrypt_round_keys, &c->iv_buffer, currentOutputBlock, &c->c.buffer);
331 grasshopper_append128(currentOutputBlock, currentInputBlock);
332 ctr128_inc(c->iv_buffer.b);
333 current_in += GRASSHOPPER_BLOCK_SIZE;
334 current_out += GRASSHOPPER_BLOCK_SIZE;
338 lasted = inl - blocks * GRASSHOPPER_BLOCK_SIZE;
340 currentInputBlock = (grasshopper_w128_t*) current_in;
341 currentOutputBlock = (grasshopper_w128_t*) current_out;
342 grasshopper_encrypt_block(&c->c.encrypt_round_keys, &c->iv_buffer, &c->partial_buffer, &c->c.buffer);
343 for (i = 0; i < lasted; i++) {
344 currentOutputBlock->b[i] = c->partial_buffer.b[i] ^ currentInputBlock->b[i];
347 ctr128_inc(c->iv_buffer.b);
354 * Fixed 128-bit IV implementation make shift regiser redundant.
356 static void gost_grasshopper_cnt_next(gost_grasshopper_cipher_ctx_ofb* ctx, grasshopper_w128_t* iv,
357 grasshopper_w128_t* buf) {
358 memcpy(&ctx->buffer1, iv, 16);
359 grasshopper_encrypt_block(&ctx->c.encrypt_round_keys, &ctx->buffer1, buf, &ctx->c.buffer);
363 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
364 const unsigned char* in, size_t inl) {
365 gost_grasshopper_cipher_ctx_ofb* c = (gost_grasshopper_cipher_ctx_ofb*) EVP_CIPHER_CTX_get_cipher_data(ctx);
366 const unsigned char* in_ptr = in;
367 unsigned char* out_ptr = out;
368 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
369 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
370 int num = EVP_CIPHER_CTX_num(ctx);
374 /* process partial block if any */
376 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl;
377 j++, i++, in_ptr++, out_ptr++) {
378 *out_ptr = buf[j] ^ (*in_ptr);
380 if (j == GRASSHOPPER_BLOCK_SIZE) {
381 EVP_CIPHER_CTX_set_num(ctx, 0);
383 EVP_CIPHER_CTX_set_num(ctx, (int) j);
388 for (; i + GRASSHOPPER_BLOCK_SIZE <
389 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
391 * block cipher current iv
394 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
397 * xor next block of input text with it and output it
402 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
403 out_ptr[j] = buf[j] ^ in_ptr[j];
407 /* Process rest of buffer */
409 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
410 for (j = 0; i < inl; j++, i++) {
411 out_ptr[j] = buf[j] ^ in_ptr[j];
413 EVP_CIPHER_CTX_set_num(ctx, (int) j);
415 EVP_CIPHER_CTX_set_num(ctx, 0);
421 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
422 const unsigned char* in, size_t inl) {
423 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
424 const unsigned char* in_ptr = in;
425 unsigned char* out_ptr = out;
426 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
427 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
428 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
429 int num = EVP_CIPHER_CTX_num(ctx);
433 /* process partial block if any */
435 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl; j++, i++, in_ptr++, out_ptr++) {
437 buf[j + GRASSHOPPER_BLOCK_SIZE] = *in_ptr;
439 *out_ptr = buf[j] ^ (*in_ptr);
441 buf[j + GRASSHOPPER_BLOCK_SIZE] = *out_ptr;
444 if (j == GRASSHOPPER_BLOCK_SIZE) {
445 memcpy(iv, buf + GRASSHOPPER_BLOCK_SIZE, GRASSHOPPER_BLOCK_SIZE);
446 EVP_CIPHER_CTX_set_num(ctx, 0);
448 EVP_CIPHER_CTX_set_num(ctx, (int) j);
453 for (; i + GRASSHOPPER_BLOCK_SIZE <
454 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
456 * block cipher current iv
458 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
461 * xor next block of input text with it and output it
467 memcpy(iv, in_ptr, GRASSHOPPER_BLOCK_SIZE);
469 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
470 out_ptr[j] = buf[j] ^ in_ptr[j];
473 /* Next iv is next block of cipher text */
475 memcpy(iv, out_ptr, GRASSHOPPER_BLOCK_SIZE);
479 /* Process rest of buffer */
481 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
484 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, in_ptr, inl - i);
486 for (j = 0; i < inl; j++, i++) {
487 out_ptr[j] = buf[j] ^ in_ptr[j];
489 EVP_CIPHER_CTX_set_num(ctx, (int) j);
491 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, out_ptr, j);
494 EVP_CIPHER_CTX_set_num(ctx, 0);
500 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx) {
501 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
502 struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
504 gost_grasshopper_cipher_destroy(c);
505 if (params->destroy_cipher != NULL) {
506 params->destroy_cipher(c);
509 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
514 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
516 unsigned char* buf = NULL;
517 ASN1_OCTET_STRING* os = NULL;
519 os = ASN1_OCTET_STRING_new();
521 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
523 GOSTerr(GOST_F_GOST_GRASSHOPPER_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
528 ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
532 GRASSHOPPER_INLINE int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
535 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
542 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr) {
544 case EVP_CTRL_RAND_KEY: {
545 if (RAND_bytes((unsigned char*) ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
546 GOSTerr(GOST_F_GOST_GRASSHOPPER_CIPHER_CTL, GOST_R_RNG_ERROR);
552 GOSTerr(GOST_F_GOST_GRASSHOPPER_CIPHER_CTL, GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
558 GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size) {
559 return EVP_CIPHER_meth_new(cipher_type,
560 block_size /* block_size */,
561 GRASSHOPPER_KEY_SIZE /* key_size */);
564 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding) {
565 return EVP_CIPHER_meth_set_iv_length(cipher, iv_size) &&
566 EVP_CIPHER_meth_set_flags(cipher, (unsigned long) (
568 ((!padding) ? EVP_CIPH_NO_PADDING : 0) |
569 ((iv_size > 0) ? EVP_CIPH_CUSTOM_IV : 0) |
571 EVP_CIPH_ALWAYS_CALL_INIT)
573 EVP_CIPHER_meth_set_cleanup(cipher, gost_grasshopper_cipher_cleanup) &&
574 EVP_CIPHER_meth_set_set_asn1_params(cipher, gost_grasshopper_set_asn1_parameters) &&
575 EVP_CIPHER_meth_set_get_asn1_params(cipher, gost_grasshopper_get_asn1_parameters) &&
576 EVP_CIPHER_meth_set_ctrl(cipher, gost_grasshopper_cipher_ctl) &&
577 EVP_CIPHER_meth_set_do_cipher(cipher, gost_grasshopper_cipher_do);
580 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num) {
582 struct GRASSHOPPER_CIPHER_PARAMS* params;
584 cipher = &gost_grasshopper_ciphers[num];
586 if (*cipher == NULL) {
587 params = &gost_cipher_params[num];
589 int nid = params->nid;
590 grasshopper_init_cipher_func init_cipher = params->init_cipher;
591 int block_size = params->block_size;
592 int ctx_size = params->ctx_size;
593 int iv_size = params->iv_size;
594 bool padding = params->padding;
596 *cipher = cipher_gost_grasshopper_create(nid, block_size);
597 if (*cipher == NULL) {
601 if (!cipher_gost_grasshopper_setup(*cipher, mode, iv_size, padding) ||
602 !EVP_CIPHER_meth_set_init(*cipher, init_cipher) ||
603 !EVP_CIPHER_meth_set_impl_ctx_size(*cipher, ctx_size)) {
604 EVP_CIPHER_meth_free(*cipher);
612 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ecb() {
613 return cipher_gost_grasshopper(EVP_CIPH_ECB_MODE, GRASSHOPPER_CIPHER_ECB);
616 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cbc() {
617 return cipher_gost_grasshopper(EVP_CIPH_CBC_MODE, GRASSHOPPER_CIPHER_CBC);
620 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ofb() {
621 return cipher_gost_grasshopper(EVP_CIPH_OFB_MODE, GRASSHOPPER_CIPHER_OFB);
624 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cfb() {
625 return cipher_gost_grasshopper(EVP_CIPH_CFB_MODE, GRASSHOPPER_CIPHER_CFB);
628 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ctr() {
629 return cipher_gost_grasshopper(EVP_CIPH_CTR_MODE, GRASSHOPPER_CIPHER_CTR);
632 void cipher_gost_grasshopper_destroy(void)
634 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB]);
635 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB] = NULL;
636 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC]);
637 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC] = NULL;
638 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB]);
639 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB] = NULL;
640 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB]);
641 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB] = NULL;
642 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR]);
643 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR] = NULL;
646 #if defined(__cplusplus)