]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost_grasshopper_cipher.h
Merge remote-tracking branch 'origin/openssl_1_1_0'
[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     uint32_t g;
31     uint32_t go;
32 } gost_grasshopper_cipher_ctx_ofb;
33
34 typedef struct {
35     gost_grasshopper_cipher_ctx c;
36     grasshopper_w128_t iv_buffer;
37     grasshopper_w128_t partial_buffer;
38     uint64_t counter;
39 } gost_grasshopper_cipher_ctx_ctr;
40
41 typedef int (* grasshopper_init_cipher_func)(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv,
42                                              int enc);
43
44 typedef int (* grasshopper_do_cipher_func)(EVP_CIPHER_CTX* ctx, unsigned char* out, const unsigned char* in,
45                                            size_t inl);
46
47 typedef void (* grasshopper_destroy_cipher_func)(gost_grasshopper_cipher_ctx* c);
48
49 void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k);
50
51 void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c);
52
53 int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
54
55 int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
56
57 int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
58
59 int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
60
61 int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key, const unsigned char* iv, int enc);
62
63 int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
64                                  const unsigned char* iv, int enc);
65
66 int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
67                                const unsigned char* in, size_t inl);
68
69 int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
70                                    const unsigned char* in, size_t inl);
71
72 int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
73                                    const unsigned char* in, size_t inl);
74
75 int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
76                                    const unsigned char* in, size_t inl);
77
78 int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
79                                    const unsigned char* in, size_t inl);
80
81 int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
82                                    const unsigned char* in, size_t inl);
83
84 int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx);
85
86 int gost_grasshopper_set_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
87
88 int gost_grasshopper_get_asn1_parameters(EVP_CIPHER_CTX* ctx, ASN1_TYPE* params);
89
90 int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr);
91
92 EVP_CIPHER* cipher_gost_grasshopper_create(int cipher_type, int block_size);
93
94 const int cipher_gost_grasshopper_setup(EVP_CIPHER* cipher, uint8_t mode, int iv_size, bool padding);
95
96 const EVP_CIPHER* cipher_gost_grasshopper(uint8_t mode, uint8_t num);
97
98 extern const EVP_CIPHER* cipher_gost_grasshopper_ecb();
99 extern const EVP_CIPHER* cipher_gost_grasshopper_cbc();
100 extern const EVP_CIPHER* cipher_gost_grasshopper_ofb();
101 extern const EVP_CIPHER* cipher_gost_grasshopper_cfb();
102 extern const EVP_CIPHER* cipher_gost_grasshopper_ctr();
103
104 #if defined(__cplusplus)
105 }
106 #endif
107
108 #endif