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>
20 #include "e_gost_err.h"
22 enum GRASSHOPPER_CIPHER_TYPE {
23 GRASSHOPPER_CIPHER_ECB = 0,
24 GRASSHOPPER_CIPHER_CBC,
25 GRASSHOPPER_CIPHER_OFB,
26 GRASSHOPPER_CIPHER_CFB,
27 GRASSHOPPER_CIPHER_CTR
30 static EVP_CIPHER* gost_grasshopper_ciphers[5] = {
31 [GRASSHOPPER_CIPHER_ECB] = NULL,
32 [GRASSHOPPER_CIPHER_CBC] = NULL,
33 [GRASSHOPPER_CIPHER_OFB] = NULL,
34 [GRASSHOPPER_CIPHER_CFB] = NULL,
35 [GRASSHOPPER_CIPHER_CTR] = NULL
38 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ofb(gost_grasshopper_cipher_ctx* c);
39 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ctr(gost_grasshopper_cipher_ctx* c);
41 struct GRASSHOPPER_CIPHER_PARAMS {
43 grasshopper_init_cipher_func init_cipher;
44 grasshopper_do_cipher_func do_cipher;
45 grasshopper_destroy_cipher_func destroy_cipher;
52 static struct GRASSHOPPER_CIPHER_PARAMS gost_cipher_params[5] = {
53 [GRASSHOPPER_CIPHER_ECB] = {
55 gost_grasshopper_cipher_init_ecb,
56 gost_grasshopper_cipher_do_ecb,
59 sizeof(gost_grasshopper_cipher_ctx),
63 [GRASSHOPPER_CIPHER_CBC] = {
65 gost_grasshopper_cipher_init_cbc,
66 gost_grasshopper_cipher_do_cbc,
69 sizeof(gost_grasshopper_cipher_ctx),
73 [GRASSHOPPER_CIPHER_OFB] = {
75 gost_grasshopper_cipher_init_ofb,
76 gost_grasshopper_cipher_do_ofb,
77 gost_grasshopper_cipher_destroy_ofb,
79 sizeof(gost_grasshopper_cipher_ctx_ofb),
83 [GRASSHOPPER_CIPHER_CFB] = {
85 gost_grasshopper_cipher_init_cfb,
86 gost_grasshopper_cipher_do_cfb,
89 sizeof(gost_grasshopper_cipher_ctx),
93 [GRASSHOPPER_CIPHER_CTR] = {
95 gost_grasshopper_cipher_init_ctr,
96 gost_grasshopper_cipher_do_ctr,
97 gost_grasshopper_cipher_destroy_ctr,
99 sizeof(gost_grasshopper_cipher_ctx_ctr),
100 /* IV size is set to match full block, to make it responsibility of
101 * user to assign correct values (IV || 0), and to make naive context
102 * copy possible (for software such as openssh) */
108 /* Set 256 bit key into context */
109 GRASSHOPPER_INLINE void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k) {
111 for (i = 0; i < 2; i++) {
112 grasshopper_copy128(&c->key.k.k[i], (const grasshopper_w128_t*) (k + i * 16));
114 grasshopper_set_encrypt_key(&c->encrypt_round_keys, &c->key);
115 grasshopper_set_decrypt_key(&c->decrypt_round_keys, &c->key);
118 /* Cleans up key from context */
119 GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c) {
121 for (i = 0; i < 2; i++) {
122 grasshopper_zero128(&c->key.k.k[i]);
124 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
125 grasshopper_zero128(&c->encrypt_round_keys.k[i]);
127 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
128 grasshopper_zero128(&c->decrypt_round_keys.k[i]);
130 grasshopper_zero128(&c->buffer);
133 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ofb(gost_grasshopper_cipher_ctx* c) {
134 gost_grasshopper_cipher_ctx_ofb* ctx = (gost_grasshopper_cipher_ctx_ofb*) c;
136 grasshopper_zero128(&ctx->buffer1);
139 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ctr(gost_grasshopper_cipher_ctx* c) {
140 gost_grasshopper_cipher_ctx_ctr* ctx = (gost_grasshopper_cipher_ctx_ctr*) c;
142 grasshopper_zero128(&ctx->partial_buffer);
145 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
146 const unsigned char* iv, int enc) {
147 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
149 if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
150 EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_get_cipher_data(ctx));
154 gost_grasshopper_cipher_key(c, key);
158 memcpy((unsigned char*) EVP_CIPHER_CTX_original_iv(ctx), iv,
159 EVP_CIPHER_CTX_iv_length(ctx));
162 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
163 EVP_CIPHER_CTX_original_iv(ctx),
164 EVP_CIPHER_CTX_iv_length(ctx));
166 grasshopper_zero128(&c->buffer);
171 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
172 const unsigned char* iv,
174 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
175 c->type = GRASSHOPPER_CIPHER_ECB;
176 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
179 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key,
180 const unsigned char* iv,
182 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
183 c->type = GRASSHOPPER_CIPHER_CBC;
184 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
187 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
188 const unsigned char* iv,
190 gost_grasshopper_cipher_ctx_ofb* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
192 c->c.type = GRASSHOPPER_CIPHER_OFB;
194 grasshopper_zero128(&c->buffer1);
196 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
199 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
200 const unsigned char* iv,
202 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
203 c->type = GRASSHOPPER_CIPHER_CFB;
204 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
207 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key,
208 const unsigned char* iv,
210 gost_grasshopper_cipher_ctx_ctr* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
212 c->c.type = GRASSHOPPER_CIPHER_CTR;
213 EVP_CIPHER_CTX_set_num(ctx, 0);
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 /* increment counter (128-bit int) by 1 */
285 static void ctr128_inc(unsigned char *counter)
299 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
300 const unsigned char* in, size_t inl) {
301 gost_grasshopper_cipher_ctx_ctr* c = (gost_grasshopper_cipher_ctx_ctr*) EVP_CIPHER_CTX_get_cipher_data(ctx);
302 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
303 const unsigned char* current_in = in;
304 unsigned char* current_out = out;
305 grasshopper_w128_t* currentInputBlock;
306 grasshopper_w128_t* currentOutputBlock;
307 unsigned int n = EVP_CIPHER_CTX_num(ctx);
312 *(current_out++) = *(current_in++) ^ c->partial_buffer.b[n];
314 n = (n + 1) % GRASSHOPPER_BLOCK_SIZE;
316 EVP_CIPHER_CTX_set_num(ctx, n);
317 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
319 grasshopper_w128_t* iv_buffer = (grasshopper_w128_t*) iv;
322 for (i = 0; i < blocks; i++) {
323 currentInputBlock = (grasshopper_w128_t*) current_in;
324 currentOutputBlock = (grasshopper_w128_t*) current_out;
325 grasshopper_encrypt_block(&c->c.encrypt_round_keys, iv_buffer, currentOutputBlock, &c->c.buffer);
326 grasshopper_append128(currentOutputBlock, currentInputBlock);
327 ctr128_inc(iv_buffer->b);
328 current_in += GRASSHOPPER_BLOCK_SIZE;
329 current_out += GRASSHOPPER_BLOCK_SIZE;
333 lasted = inl - blocks * GRASSHOPPER_BLOCK_SIZE;
335 currentInputBlock = (grasshopper_w128_t*) current_in;
336 currentOutputBlock = (grasshopper_w128_t*) current_out;
337 grasshopper_encrypt_block(&c->c.encrypt_round_keys, iv_buffer, &c->partial_buffer, &c->c.buffer);
338 for (i = 0; i < lasted; i++) {
339 currentOutputBlock->b[i] = c->partial_buffer.b[i] ^ currentInputBlock->b[i];
341 EVP_CIPHER_CTX_set_num(ctx, i);
342 ctr128_inc(iv_buffer->b);
349 * Fixed 128-bit IV implementation make shift regiser redundant.
351 static void gost_grasshopper_cnt_next(gost_grasshopper_cipher_ctx_ofb* ctx, grasshopper_w128_t* iv,
352 grasshopper_w128_t* buf) {
353 memcpy(&ctx->buffer1, iv, 16);
354 grasshopper_encrypt_block(&ctx->c.encrypt_round_keys, &ctx->buffer1, buf, &ctx->c.buffer);
358 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
359 const unsigned char* in, size_t inl) {
360 gost_grasshopper_cipher_ctx_ofb* c = (gost_grasshopper_cipher_ctx_ofb*) EVP_CIPHER_CTX_get_cipher_data(ctx);
361 const unsigned char* in_ptr = in;
362 unsigned char* out_ptr = out;
363 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
364 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
365 int num = EVP_CIPHER_CTX_num(ctx);
369 /* process partial block if any */
371 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl;
372 j++, i++, in_ptr++, out_ptr++) {
373 *out_ptr = buf[j] ^ (*in_ptr);
375 if (j == GRASSHOPPER_BLOCK_SIZE) {
376 EVP_CIPHER_CTX_set_num(ctx, 0);
378 EVP_CIPHER_CTX_set_num(ctx, (int) j);
383 for (; i + GRASSHOPPER_BLOCK_SIZE <
384 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
386 * block cipher current iv
389 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
392 * xor next block of input text with it and output it
397 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
398 out_ptr[j] = buf[j] ^ in_ptr[j];
402 /* Process rest of buffer */
404 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
405 for (j = 0; i < inl; j++, i++) {
406 out_ptr[j] = buf[j] ^ in_ptr[j];
408 EVP_CIPHER_CTX_set_num(ctx, (int) j);
410 EVP_CIPHER_CTX_set_num(ctx, 0);
416 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
417 const unsigned char* in, size_t inl) {
418 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
419 const unsigned char* in_ptr = in;
420 unsigned char* out_ptr = out;
421 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
422 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
423 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
424 int num = EVP_CIPHER_CTX_num(ctx);
428 /* process partial block if any */
430 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl; j++, i++, in_ptr++, out_ptr++) {
432 buf[j + GRASSHOPPER_BLOCK_SIZE] = *in_ptr;
434 *out_ptr = buf[j] ^ (*in_ptr);
436 buf[j + GRASSHOPPER_BLOCK_SIZE] = *out_ptr;
439 if (j == GRASSHOPPER_BLOCK_SIZE) {
440 memcpy(iv, buf + GRASSHOPPER_BLOCK_SIZE, GRASSHOPPER_BLOCK_SIZE);
441 EVP_CIPHER_CTX_set_num(ctx, 0);
443 EVP_CIPHER_CTX_set_num(ctx, (int) j);
448 for (; i + GRASSHOPPER_BLOCK_SIZE <
449 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
451 * block cipher current iv
453 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
456 * xor next block of input text with it and output it
462 memcpy(iv, in_ptr, GRASSHOPPER_BLOCK_SIZE);
464 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
465 out_ptr[j] = buf[j] ^ in_ptr[j];
468 /* Next iv is next block of cipher text */
470 memcpy(iv, out_ptr, GRASSHOPPER_BLOCK_SIZE);
474 /* Process rest of buffer */
476 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
479 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, in_ptr, inl - i);
481 for (j = 0; i < inl; j++, i++) {
482 out_ptr[j] = buf[j] ^ in_ptr[j];
484 EVP_CIPHER_CTX_set_num(ctx, (int) j);
486 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, out_ptr, j);
489 EVP_CIPHER_CTX_set_num(ctx, 0);
495 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx) {
496 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
497 struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
499 gost_grasshopper_cipher_destroy(c);
500 if (params->destroy_cipher != NULL) {
501 params->destroy_cipher(c);
504 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
509 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
511 unsigned char* buf = NULL;
512 ASN1_OCTET_STRING* os = NULL;
514 os = ASN1_OCTET_STRING_new();
516 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
518 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
523 ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
527 GRASSHOPPER_INLINE int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
530 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
537 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr) {
539 case EVP_CTRL_RAND_KEY: {
540 if (RAND_bytes((unsigned char*) ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
541 GOSTerr(GOST_F_GOST_CIPHER_CTL, GOST_R_RNG_ERROR);
547 GOSTerr(GOST_F_GOST_CIPHER_CTL, GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
553 GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size) {
554 return EVP_CIPHER_meth_new(cipher_type,
555 block_size /* block_size */,
556 GRASSHOPPER_KEY_SIZE /* key_size */);
559 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding) {
560 return EVP_CIPHER_meth_set_iv_length(cipher, iv_size) &&
561 EVP_CIPHER_meth_set_flags(cipher, (unsigned long) (
563 ((!padding) ? EVP_CIPH_NO_PADDING : 0) |
564 ((iv_size > 0) ? EVP_CIPH_CUSTOM_IV : 0) |
566 EVP_CIPH_ALWAYS_CALL_INIT)
568 EVP_CIPHER_meth_set_cleanup(cipher, gost_grasshopper_cipher_cleanup) &&
569 EVP_CIPHER_meth_set_set_asn1_params(cipher, gost_grasshopper_set_asn1_parameters) &&
570 EVP_CIPHER_meth_set_get_asn1_params(cipher, gost_grasshopper_get_asn1_parameters) &&
571 EVP_CIPHER_meth_set_ctrl(cipher, gost_grasshopper_cipher_ctl) &&
572 EVP_CIPHER_meth_set_do_cipher(cipher, gost_grasshopper_cipher_do);
575 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num) {
577 struct GRASSHOPPER_CIPHER_PARAMS* params;
579 cipher = &gost_grasshopper_ciphers[num];
581 if (*cipher == NULL) {
582 params = &gost_cipher_params[num];
584 int nid = params->nid;
585 grasshopper_init_cipher_func init_cipher = params->init_cipher;
586 int block_size = params->block_size;
587 int ctx_size = params->ctx_size;
588 int iv_size = params->iv_size;
589 bool padding = params->padding;
591 *cipher = cipher_gost_grasshopper_create(nid, block_size);
592 if (*cipher == NULL) {
596 if (!cipher_gost_grasshopper_setup(*cipher, mode, iv_size, padding) ||
597 !EVP_CIPHER_meth_set_init(*cipher, init_cipher) ||
598 !EVP_CIPHER_meth_set_impl_ctx_size(*cipher, ctx_size)) {
599 EVP_CIPHER_meth_free(*cipher);
607 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ecb() {
608 return cipher_gost_grasshopper(EVP_CIPH_ECB_MODE, GRASSHOPPER_CIPHER_ECB);
611 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cbc() {
612 return cipher_gost_grasshopper(EVP_CIPH_CBC_MODE, GRASSHOPPER_CIPHER_CBC);
615 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ofb() {
616 return cipher_gost_grasshopper(EVP_CIPH_OFB_MODE, GRASSHOPPER_CIPHER_OFB);
619 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cfb() {
620 return cipher_gost_grasshopper(EVP_CIPH_CFB_MODE, GRASSHOPPER_CIPHER_CFB);
623 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ctr() {
624 return cipher_gost_grasshopper(EVP_CIPH_CTR_MODE, GRASSHOPPER_CIPHER_CTR);
627 void cipher_gost_grasshopper_destroy(void)
629 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB]);
630 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB] = NULL;
631 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC]);
632 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC] = NULL;
633 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB]);
634 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB] = NULL;
635 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB]);
636 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB] = NULL;
637 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR]);
638 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR] = NULL;
640 #if defined(__cplusplus)