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),
101 /* IV size is set to match full block, to make it responsibility of
102 * user to assign correct values (IV || 0), and to make naive context
103 * copy possible (for software such as openssh) */
109 /* Set 256 bit key into context */
110 GRASSHOPPER_INLINE void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k) {
112 for (i = 0; i < 2; i++) {
113 grasshopper_copy128(&c->key.k.k[i], (const grasshopper_w128_t*) (k + i * 16));
115 grasshopper_set_encrypt_key(&c->encrypt_round_keys, &c->key);
116 grasshopper_set_decrypt_key(&c->decrypt_round_keys, &c->key);
119 /* Cleans up key from context */
120 GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c) {
122 for (i = 0; i < 2; i++) {
123 grasshopper_zero128(&c->key.k.k[i]);
125 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
126 grasshopper_zero128(&c->encrypt_round_keys.k[i]);
128 for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
129 grasshopper_zero128(&c->decrypt_round_keys.k[i]);
131 grasshopper_zero128(&c->buffer);
134 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ofb(gost_grasshopper_cipher_ctx* c) {
135 gost_grasshopper_cipher_ctx_ofb* ctx = (gost_grasshopper_cipher_ctx_ofb*) c;
137 grasshopper_zero128(&ctx->buffer1);
140 static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy_ctr(gost_grasshopper_cipher_ctx* c) {
141 gost_grasshopper_cipher_ctx_ctr* ctx = (gost_grasshopper_cipher_ctx_ctr*) c;
143 grasshopper_zero128(&ctx->partial_buffer);
146 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
147 const unsigned char* iv, int enc) {
148 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
150 if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
151 EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_get_cipher_data(ctx));
155 gost_grasshopper_cipher_key(c, key);
159 memcpy((unsigned char*) EVP_CIPHER_CTX_original_iv(ctx), iv,
160 EVP_CIPHER_CTX_iv_length(ctx));
163 memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
164 EVP_CIPHER_CTX_original_iv(ctx),
165 EVP_CIPHER_CTX_iv_length(ctx));
167 grasshopper_zero128(&c->buffer);
172 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
173 const unsigned char* iv,
175 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
176 c->type = GRASSHOPPER_CIPHER_ECB;
177 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
180 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key,
181 const unsigned char* iv,
183 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
184 c->type = GRASSHOPPER_CIPHER_CBC;
185 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
188 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
189 const unsigned char* iv,
191 gost_grasshopper_cipher_ctx_ofb* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
193 c->c.type = GRASSHOPPER_CIPHER_OFB;
195 grasshopper_zero128(&c->buffer1);
197 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
200 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
201 const unsigned char* iv,
203 gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
204 c->type = GRASSHOPPER_CIPHER_CFB;
205 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
208 GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key,
209 const unsigned char* iv,
211 gost_grasshopper_cipher_ctx_ctr* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
213 c->c.type = GRASSHOPPER_CIPHER_CTR;
214 EVP_CIPHER_CTX_set_num(ctx, 0);
216 grasshopper_zero128(&c->partial_buffer);
218 return gost_grasshopper_cipher_init(ctx, key, iv, enc);
221 GRASSHOPPER_INLINE int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
222 const unsigned char* in, size_t inl) {
223 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
224 struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
226 return params->do_cipher(ctx, out, in, inl);
229 int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
230 const unsigned char* in, size_t inl) {
231 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
232 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
233 const unsigned char* current_in = in;
234 unsigned char* current_out = out;
235 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
238 for (i = 0; i < blocks; i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out += GRASSHOPPER_BLOCK_SIZE) {
240 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) current_in,
241 (grasshopper_w128_t*) current_out,
244 grasshopper_decrypt_block(&c->decrypt_round_keys, (grasshopper_w128_t*) current_in,
245 (grasshopper_w128_t*) current_out,
253 int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
254 const unsigned char* in, size_t inl) {
255 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
256 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
257 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
258 const unsigned char* current_in = in;
259 unsigned char* current_out = out;
260 grasshopper_w128_t* currentInputBlock;
261 grasshopper_w128_t* currentOutputBlock;
262 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
264 grasshopper_w128_t* currentBlock;
266 currentBlock = (grasshopper_w128_t*) iv;
268 for (i = 0; i < blocks; i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out += GRASSHOPPER_BLOCK_SIZE) {
269 currentInputBlock = (grasshopper_w128_t*) current_in;
270 currentOutputBlock = (grasshopper_w128_t*) current_out;
272 grasshopper_append128(currentBlock, currentInputBlock);
273 grasshopper_encrypt_block(&c->encrypt_round_keys, currentBlock, currentOutputBlock, &c->buffer);
274 grasshopper_copy128(currentBlock, currentOutputBlock);
276 grasshopper_decrypt_block(&c->decrypt_round_keys, currentInputBlock, currentOutputBlock, &c->buffer);
277 grasshopper_append128(currentOutputBlock, currentBlock);
278 grasshopper_copy128(currentBlock, currentInputBlock);
285 void inc_counter(unsigned char* counter, size_t counter_bytes)
288 unsigned int n = counter_bytes;
299 /* increment counter (128-bit int) by 1 */
300 static void ctr128_inc(unsigned char *counter)
302 inc_counter(counter, 16);
305 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
306 const unsigned char* in, size_t inl) {
307 gost_grasshopper_cipher_ctx_ctr* c = (gost_grasshopper_cipher_ctx_ctr*) EVP_CIPHER_CTX_get_cipher_data(ctx);
308 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
309 const unsigned char* current_in = in;
310 unsigned char* current_out = out;
311 grasshopper_w128_t* currentInputBlock;
312 grasshopper_w128_t* currentOutputBlock;
313 unsigned int n = EVP_CIPHER_CTX_num(ctx);
318 *(current_out++) = *(current_in++) ^ c->partial_buffer.b[n];
320 n = (n + 1) % GRASSHOPPER_BLOCK_SIZE;
322 EVP_CIPHER_CTX_set_num(ctx, n);
323 size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
325 grasshopper_w128_t* iv_buffer = (grasshopper_w128_t*) iv;
328 for (i = 0; i < blocks; i++) {
329 currentInputBlock = (grasshopper_w128_t*) current_in;
330 currentOutputBlock = (grasshopper_w128_t*) current_out;
331 grasshopper_encrypt_block(&c->c.encrypt_round_keys, iv_buffer, currentOutputBlock, &c->c.buffer);
332 grasshopper_append128(currentOutputBlock, currentInputBlock);
333 ctr128_inc(iv_buffer->b);
334 current_in += GRASSHOPPER_BLOCK_SIZE;
335 current_out += GRASSHOPPER_BLOCK_SIZE;
339 lasted = inl - blocks * GRASSHOPPER_BLOCK_SIZE;
341 currentInputBlock = (grasshopper_w128_t*) current_in;
342 currentOutputBlock = (grasshopper_w128_t*) current_out;
343 grasshopper_encrypt_block(&c->c.encrypt_round_keys, iv_buffer, &c->partial_buffer, &c->c.buffer);
344 for (i = 0; i < lasted; i++) {
345 currentOutputBlock->b[i] = c->partial_buffer.b[i] ^ currentInputBlock->b[i];
347 EVP_CIPHER_CTX_set_num(ctx, i);
348 ctr128_inc(iv_buffer->b);
355 * Fixed 128-bit IV implementation make shift regiser redundant.
357 static void gost_grasshopper_cnt_next(gost_grasshopper_cipher_ctx_ofb* ctx, grasshopper_w128_t* iv,
358 grasshopper_w128_t* buf) {
359 memcpy(&ctx->buffer1, iv, 16);
360 grasshopper_encrypt_block(&ctx->c.encrypt_round_keys, &ctx->buffer1, buf, &ctx->c.buffer);
364 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
365 const unsigned char* in, size_t inl) {
366 gost_grasshopper_cipher_ctx_ofb* c = (gost_grasshopper_cipher_ctx_ofb*) EVP_CIPHER_CTX_get_cipher_data(ctx);
367 const unsigned char* in_ptr = in;
368 unsigned char* out_ptr = out;
369 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
370 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
371 int num = EVP_CIPHER_CTX_num(ctx);
375 /* process partial block if any */
377 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl;
378 j++, i++, in_ptr++, out_ptr++) {
379 *out_ptr = buf[j] ^ (*in_ptr);
381 if (j == GRASSHOPPER_BLOCK_SIZE) {
382 EVP_CIPHER_CTX_set_num(ctx, 0);
384 EVP_CIPHER_CTX_set_num(ctx, (int) j);
389 for (; i + GRASSHOPPER_BLOCK_SIZE <
390 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
392 * block cipher current iv
395 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
398 * xor next block of input text with it and output it
403 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
404 out_ptr[j] = buf[j] ^ in_ptr[j];
408 /* Process rest of buffer */
410 gost_grasshopper_cnt_next(c, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf);
411 for (j = 0; i < inl; j++, i++) {
412 out_ptr[j] = buf[j] ^ in_ptr[j];
414 EVP_CIPHER_CTX_set_num(ctx, (int) j);
416 EVP_CIPHER_CTX_set_num(ctx, 0);
422 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
423 const unsigned char* in, size_t inl) {
424 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
425 const unsigned char* in_ptr = in;
426 unsigned char* out_ptr = out;
427 unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
428 unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
429 bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
430 int num = EVP_CIPHER_CTX_num(ctx);
434 /* process partial block if any */
436 for (j = (size_t) num, i = 0; j < GRASSHOPPER_BLOCK_SIZE && i < inl; j++, i++, in_ptr++, out_ptr++) {
438 buf[j + GRASSHOPPER_BLOCK_SIZE] = *in_ptr;
440 *out_ptr = buf[j] ^ (*in_ptr);
442 buf[j + GRASSHOPPER_BLOCK_SIZE] = *out_ptr;
445 if (j == GRASSHOPPER_BLOCK_SIZE) {
446 memcpy(iv, buf + GRASSHOPPER_BLOCK_SIZE, GRASSHOPPER_BLOCK_SIZE);
447 EVP_CIPHER_CTX_set_num(ctx, 0);
449 EVP_CIPHER_CTX_set_num(ctx, (int) j);
454 for (; i + GRASSHOPPER_BLOCK_SIZE <
455 inl; i += GRASSHOPPER_BLOCK_SIZE, in_ptr += GRASSHOPPER_BLOCK_SIZE, out_ptr += GRASSHOPPER_BLOCK_SIZE) {
457 * block cipher current iv
459 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
462 * xor next block of input text with it and output it
468 memcpy(iv, in_ptr, GRASSHOPPER_BLOCK_SIZE);
470 for (j = 0; j < GRASSHOPPER_BLOCK_SIZE; j++) {
471 out_ptr[j] = buf[j] ^ in_ptr[j];
474 /* Next iv is next block of cipher text */
476 memcpy(iv, out_ptr, GRASSHOPPER_BLOCK_SIZE);
480 /* Process rest of buffer */
482 grasshopper_encrypt_block(&c->encrypt_round_keys, (grasshopper_w128_t*) iv, (grasshopper_w128_t*) buf,
485 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, in_ptr, inl - i);
487 for (j = 0; i < inl; j++, i++) {
488 out_ptr[j] = buf[j] ^ in_ptr[j];
490 EVP_CIPHER_CTX_set_num(ctx, (int) j);
492 memcpy(buf + GRASSHOPPER_BLOCK_SIZE, out_ptr, j);
495 EVP_CIPHER_CTX_set_num(ctx, 0);
501 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx) {
502 gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
503 struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
505 gost_grasshopper_cipher_destroy(c);
506 if (params->destroy_cipher != NULL) {
507 params->destroy_cipher(c);
510 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
515 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
517 unsigned char* buf = NULL;
518 ASN1_OCTET_STRING* os = NULL;
520 os = ASN1_OCTET_STRING_new();
522 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) {
524 GOSTerr(GOST_F_GOST_GRASSHOPPER_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
529 ASN1_TYPE_set(params, V_ASN1_SEQUENCE, os);
533 GRASSHOPPER_INLINE int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params) {
536 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
543 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr) {
545 case EVP_CTRL_RAND_KEY: {
546 if (RAND_bytes((unsigned char*) ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
547 GOSTerr(GOST_F_GOST_GRASSHOPPER_CIPHER_CTL, GOST_R_RNG_ERROR);
553 GOSTerr(GOST_F_GOST_GRASSHOPPER_CIPHER_CTL, GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
559 GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size) {
560 return EVP_CIPHER_meth_new(cipher_type,
561 block_size /* block_size */,
562 GRASSHOPPER_KEY_SIZE /* key_size */);
565 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding) {
566 return EVP_CIPHER_meth_set_iv_length(cipher, iv_size) &&
567 EVP_CIPHER_meth_set_flags(cipher, (unsigned long) (
569 ((!padding) ? EVP_CIPH_NO_PADDING : 0) |
570 ((iv_size > 0) ? EVP_CIPH_CUSTOM_IV : 0) |
572 EVP_CIPH_ALWAYS_CALL_INIT)
574 EVP_CIPHER_meth_set_cleanup(cipher, gost_grasshopper_cipher_cleanup) &&
575 EVP_CIPHER_meth_set_set_asn1_params(cipher, gost_grasshopper_set_asn1_parameters) &&
576 EVP_CIPHER_meth_set_get_asn1_params(cipher, gost_grasshopper_get_asn1_parameters) &&
577 EVP_CIPHER_meth_set_ctrl(cipher, gost_grasshopper_cipher_ctl) &&
578 EVP_CIPHER_meth_set_do_cipher(cipher, gost_grasshopper_cipher_do);
581 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num) {
583 struct GRASSHOPPER_CIPHER_PARAMS* params;
585 cipher = &gost_grasshopper_ciphers[num];
587 if (*cipher == NULL) {
588 params = &gost_cipher_params[num];
590 int nid = params->nid;
591 grasshopper_init_cipher_func init_cipher = params->init_cipher;
592 int block_size = params->block_size;
593 int ctx_size = params->ctx_size;
594 int iv_size = params->iv_size;
595 bool padding = params->padding;
597 *cipher = cipher_gost_grasshopper_create(nid, block_size);
598 if (*cipher == NULL) {
602 if (!cipher_gost_grasshopper_setup(*cipher, mode, iv_size, padding) ||
603 !EVP_CIPHER_meth_set_init(*cipher, init_cipher) ||
604 !EVP_CIPHER_meth_set_impl_ctx_size(*cipher, ctx_size)) {
605 EVP_CIPHER_meth_free(*cipher);
613 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ecb() {
614 return cipher_gost_grasshopper(EVP_CIPH_ECB_MODE, GRASSHOPPER_CIPHER_ECB);
617 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cbc() {
618 return cipher_gost_grasshopper(EVP_CIPH_CBC_MODE, GRASSHOPPER_CIPHER_CBC);
621 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ofb() {
622 return cipher_gost_grasshopper(EVP_CIPH_OFB_MODE, GRASSHOPPER_CIPHER_OFB);
625 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_cfb() {
626 return cipher_gost_grasshopper(EVP_CIPH_CFB_MODE, GRASSHOPPER_CIPHER_CFB);
629 const GRASSHOPPER_INLINE EVP_CIPHER* cipher_gost_grasshopper_ctr() {
630 return cipher_gost_grasshopper(EVP_CIPH_CTR_MODE, GRASSHOPPER_CIPHER_CTR);
633 void cipher_gost_grasshopper_destroy(void)
635 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB]);
636 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_ECB] = NULL;
637 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC]);
638 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CBC] = NULL;
639 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB]);
640 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_OFB] = NULL;
641 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB]);
642 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CFB] = NULL;
643 EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR]);
644 gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTR] = NULL;
647 #if defined(__cplusplus)