3 * This file is distributed under the same license as OpenSSL
6 #ifndef GOST_GRASSHOPPER_CIPHER_H
7 #define GOST_GRASSHOPPER_CIPHER_H
9 #if defined(__cplusplus)
13 #include "gost_grasshopper_defines.h"
15 #include <openssl/evp.h>
21 grasshopper_key_t master_key;
22 grasshopper_key_t key;
23 grasshopper_round_keys_t encrypt_round_keys;
24 grasshopper_round_keys_t decrypt_round_keys;
25 grasshopper_w128_t buffer;
26 } gost_grasshopper_cipher_ctx;
29 gost_grasshopper_cipher_ctx c;
30 grasshopper_w128_t partial_buffer;
31 unsigned int section_size; /* After how much bytes mesh the key,
32 if 0 never mesh and work like plain ctr. */
33 unsigned char kdf_seed[8];
34 } gost_grasshopper_cipher_ctx_ctr;
36 typedef int (* grasshopper_init_cipher_func)(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv,
39 typedef int (* grasshopper_do_cipher_func)(EVP_CIPHER_CTX* ctx, unsigned char* out, const unsigned char* in,
42 typedef void (* grasshopper_destroy_cipher_func)(gost_grasshopper_cipher_ctx* c);
44 void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k);
46 void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c);
48 int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
50 int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
52 int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
54 int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
56 int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
58 int gost_grasshopper_cipher_init_ctracpkm(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
60 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
61 const unsigned char* iv, int enc);
63 int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
64 const unsigned char* in, size_t inl);
66 int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
67 const unsigned char* in, size_t inl);
69 int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
70 const unsigned char* in, size_t inl);
72 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
73 const unsigned char* in, size_t inl);
75 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
76 const unsigned char* in, size_t inl);
78 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
79 const unsigned char* in, size_t inl);
80 int gost_grasshopper_cipher_do_ctracpkm(EVP_CIPHER_CTX* ctx, unsigned char* out,
81 const unsigned char* in, size_t inl);
83 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx);
85 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
87 int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
89 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr);
91 EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size);
93 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding);
95 const EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num);
97 extern const EVP_CIPHER* cipher_gost_grasshopper_ecb();
98 extern const EVP_CIPHER* cipher_gost_grasshopper_cbc();
99 extern const EVP_CIPHER* cipher_gost_grasshopper_ofb();
100 extern const EVP_CIPHER* cipher_gost_grasshopper_cfb();
101 extern const EVP_CIPHER* cipher_gost_grasshopper_ctr();
102 extern const EVP_CIPHER* cipher_gost_grasshopper_ctracpkm();
104 void cipher_gost_grasshopper_destroy(void);
106 #if defined(__cplusplus)