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"
16 #include <openssl/evp.h>
22 grasshopper_key_t master_key;
23 grasshopper_key_t key;
24 grasshopper_round_keys_t encrypt_round_keys;
25 grasshopper_round_keys_t decrypt_round_keys;
26 grasshopper_w128_t buffer;
27 } gost_grasshopper_cipher_ctx;
30 gost_grasshopper_cipher_ctx c;
31 grasshopper_w128_t partial_buffer;
32 unsigned int section_size; /* After how much bytes mesh the key,
33 if 0 never mesh and work like plain ctr. */
34 unsigned char kdf_seed[8];
35 unsigned char tag[16];
37 } gost_grasshopper_cipher_ctx_ctr;
39 static void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k);
41 static void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c);
43 static int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx,
44 const unsigned char* key, const unsigned char* iv, int enc);
46 static int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx,
47 const unsigned char* key, const unsigned char* iv, int enc);
49 static int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx,
50 const unsigned char* key, const unsigned char* iv, int enc);
52 static int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx,
53 const unsigned char* key, const unsigned char* iv, int enc);
55 static int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx,
56 const unsigned char* key, const unsigned char* iv, int enc);
58 static int gost_grasshopper_cipher_init_ctracpkm(EVP_CIPHER_CTX* ctx,
59 const unsigned char* key, const unsigned char* iv, int enc);
61 static int gost_grasshopper_cipher_init_ctracpkm_omac(EVP_CIPHER_CTX* ctx,
62 const unsigned char* key, const unsigned char* iv, int enc);
64 static int gost_grasshopper_cipher_init_mgm(EVP_CIPHER_CTX* ctx,
65 const unsigned char* key, const unsigned char* iv, int enc);
67 static int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
68 const unsigned char* iv, int enc);
70 static int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
71 const unsigned char* in, size_t inl);
73 static int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
74 const unsigned char* in, size_t inl);
76 static int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
77 const unsigned char* in, size_t inl);
79 static int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
80 const unsigned char* in, size_t inl);
82 static int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
83 const unsigned char* in, size_t inl);
85 static int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
86 const unsigned char* in, size_t inl);
88 static int gost_grasshopper_cipher_do_ctracpkm(EVP_CIPHER_CTX* ctx, unsigned char* out,
89 const unsigned char* in, size_t inl);
91 static int gost_grasshopper_cipher_do_ctracpkm_omac(EVP_CIPHER_CTX* ctx, unsigned char* out,
92 const unsigned char* in, size_t inl);
94 static int gost_grasshopper_cipher_do_mgm(EVP_CIPHER_CTX* ctx, unsigned char* out,
95 const unsigned char* in, size_t inl);
97 static int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx);
99 static int gost_grasshopper_mgm_cleanup(EVP_CIPHER_CTX *c);
101 static int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
103 static int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
105 static int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr);
107 static int gost_grasshopper_mgm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
109 const EVP_CIPHER* cipher_gost_grasshopper_ctracpkm();
111 #if defined(__cplusplus)