]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost_grasshopper_cipher.h
Add kuznyechik_ctracpkm
[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 <openssl/evp.h>
16
17 // not thread safe
18 // because of buffers
19 typedef struct {
20     uint8_t type;
21     grasshopper_key_t key;
22     grasshopper_round_keys_t encrypt_round_keys;
23     grasshopper_round_keys_t decrypt_round_keys;
24     grasshopper_w128_t buffer;
25 } gost_grasshopper_cipher_ctx;
26
27 typedef struct {
28     gost_grasshopper_cipher_ctx c;
29     grasshopper_w128_t buffer1;
30 } gost_grasshopper_cipher_ctx_ofb;
31
32 typedef struct {
33     gost_grasshopper_cipher_ctx c;
34     grasshopper_w128_t partial_buffer;
35     unsigned int skip_sections; /* 1 or 0, used to skip meshing for a first section */
36     unsigned int section_size;  /* After how much bytes mesh the key,
37                                    if 0 never mesh and work like plain ctr. */
38 } gost_grasshopper_cipher_ctx_ctr;
39
40 typedef int (* grasshopper_init_cipher_func)(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv,
41                                              int enc);
42
43 typedef int (* grasshopper_do_cipher_func)(EVP_CIPHER_CTX* ctx, unsigned char* out, const unsigned char* in,
44                                            size_t inl);
45
46 typedef void (* grasshopper_destroy_cipher_func)(gost_grasshopper_cipher_ctx* c);
47
48 void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k);
49
50 void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c);
51
52 int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
53
54 int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
55
56 int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
57
58 int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
59
60 int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
61
62 int gost_grasshopper_cipher_init_ctracpkm(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
63
64 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
65                                  const unsigned char* iv, int enc);
66
67 int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
68                                const unsigned char* in, size_t inl);
69
70 int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
71                                    const unsigned char* in, size_t inl);
72
73 int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
74                                    const unsigned char* in, size_t inl);
75
76 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
77                                    const unsigned char* in, size_t inl);
78
79 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
80                                    const unsigned char* in, size_t inl);
81
82 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
83                                    const unsigned char* in, size_t inl);
84 int gost_grasshopper_cipher_do_ctracpkm(EVP_CIPHER_CTX* ctx, unsigned char* out,
85                                    const unsigned char* in, size_t inl);
86
87 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx);
88
89 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
90
91 int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
92
93 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr);
94
95 EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size);
96
97 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding);
98
99 const EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num);
100
101 extern const EVP_CIPHER* cipher_gost_grasshopper_ecb();
102 extern const EVP_CIPHER* cipher_gost_grasshopper_cbc();
103 extern const EVP_CIPHER* cipher_gost_grasshopper_ofb();
104 extern const EVP_CIPHER* cipher_gost_grasshopper_cfb();
105 extern const EVP_CIPHER* cipher_gost_grasshopper_ctr();
106 extern const EVP_CIPHER* cipher_gost_grasshopper_ctracpkm();
107
108 void cipher_gost_grasshopper_destroy(void);
109
110 #if defined(__cplusplus)
111 }
112 #endif
113
114 #endif