]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost_grasshopper_cipher.h
patches: improve ssl trace output
[openssl-gost/engine.git] / gost_grasshopper_cipher.h
1 /*
2  * Maxim Tishkov 2016
3  * This file is distributed under the same license as OpenSSL
4  */
5
6 #ifndef GOST_GRASSHOPPER_CIPHER_H
7 #define GOST_GRASSHOPPER_CIPHER_H
8
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12
13 #include "gost_grasshopper_defines.h"
14
15 #include "gost_lcl.h"
16 #include <openssl/evp.h>
17
18 // not thread safe
19 // because of buffers
20 typedef struct {
21     uint8_t type;
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;
28
29 typedef struct {
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];
36                 EVP_MD_CTX *omac_ctx;
37 } gost_grasshopper_cipher_ctx_ctr;
38
39 static void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k);
40
41 static void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c);
42
43 static int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx,
44     const unsigned char* key, const unsigned char* iv, int enc);
45
46 static int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx,
47     const unsigned char* key, const unsigned char* iv, int enc);
48
49 static int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx,
50     const unsigned char* key, const unsigned char* iv, int enc);
51
52 static int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx,
53     const unsigned char* key, const unsigned char* iv, int enc);
54
55 static int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx,
56     const unsigned char* key, const unsigned char* iv, int enc);
57
58 static int gost_grasshopper_cipher_init_ctracpkm(EVP_CIPHER_CTX* ctx,
59     const unsigned char* key, const unsigned char* iv, int enc);
60
61 static int gost_grasshopper_cipher_init_ctracpkm_omac(EVP_CIPHER_CTX* ctx,
62     const unsigned char* key, const unsigned char* iv, int enc);
63
64 static int gost_grasshopper_cipher_init_mgm(EVP_CIPHER_CTX* ctx, 
65     const unsigned char* key, const unsigned char* iv, int enc);
66
67 static int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
68     const unsigned char* iv, int enc);
69
70 static int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
71     const unsigned char* in, size_t inl);
72
73 static int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
74     const unsigned char* in, size_t inl);
75
76 static int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
77     const unsigned char* in, size_t inl);
78
79 static int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
80     const unsigned char* in, size_t inl);
81
82 static int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
83     const unsigned char* in, size_t inl);
84
85 static int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
86     const unsigned char* in, size_t inl);
87
88 static int gost_grasshopper_cipher_do_ctracpkm(EVP_CIPHER_CTX* ctx, unsigned char* out,
89     const unsigned char* in, size_t inl);
90
91 static int gost_grasshopper_cipher_do_ctracpkm_omac(EVP_CIPHER_CTX* ctx, unsigned char* out,
92     const unsigned char* in, size_t inl);
93
94 static int gost_grasshopper_cipher_do_mgm(EVP_CIPHER_CTX* ctx, unsigned char* out,
95     const unsigned char* in, size_t inl);
96
97 static int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx);
98
99 static int gost_grasshopper_mgm_cleanup(EVP_CIPHER_CTX *c);
100
101 static int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
102
103 static int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
104
105 static int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr);
106
107 static int gost_grasshopper_mgm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
108
109 const EVP_CIPHER* cipher_gost_grasshopper_ctracpkm();
110
111 #if defined(__cplusplus)
112 }
113 #endif
114
115 #endif