]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost89.h
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / gost89.h
1 /**********************************************************************
2  *                        gost89.h                                    *
3  *             Copyright (c) 2005-2006 Cryptocom LTD                  *
4  *     This file is distributed under the same license as OpenSSL     *
5  *                                                                    *
6  *          Declarations for GOST 28147-89 encryption algorithm       *
7  *            No OpenSSL libraries required to compile and use        *
8  *                       this code                                    *
9  **********************************************************************/
10 #ifndef GOST89_H
11 # define GOST89_H
12
13 /* Typedef for unsigned 32-bit integer */
14 # if __LONG_MAX__ > 2147483647L
15 typedef unsigned int u4;
16 # else
17 typedef unsigned long u4;
18 # endif
19 /* Typedef for unsigned 8-bit integer */
20 typedef unsigned char byte;
21
22 /* Internal representation of GOST substitution blocks */
23 typedef struct {
24     byte k8[16];
25     byte k7[16];
26     byte k6[16];
27     byte k5[16];
28     byte k4[16];
29     byte k3[16];
30     byte k2[16];
31     byte k1[16];
32 } gost_subst_block;
33
34 /* Cipher context includes key and preprocessed  substitution block */
35 typedef struct {
36     u4 master_key[8];
37     u4 key[8];
38     u4 mask[8];
39     /* Constant s-boxes -- set up in gost_init(). */
40     u4 k87[256], k65[256], k43[256], k21[256];
41 } gost_ctx;
42 /*
43  * Note: encrypt and decrypt expect full blocks--padding blocks is caller's
44  * responsibility. All bulk encryption is done in ECB mode by these calls.
45  * Other modes may be added easily enough.
46  */
47 /* Encrypt several full blocks in ECB mode */
48 void gost_enc(gost_ctx * c, const byte * clear, byte * cipher, int blocks);
49 /* Decrypt several full blocks in ECB mode */
50 void gost_dec(gost_ctx * c, const byte * cipher, byte * clear, int blocks);
51 /* Encrypts several full blocks in CFB mode using 8byte IV */
52 void gost_enc_cfb(gost_ctx * ctx, const byte * iv, const byte * clear,
53                   byte * cipher, int blocks);
54 /* Decrypts several full blocks in CFB mode using 8byte IV */
55 void gost_dec_cfb(gost_ctx * ctx, const byte * iv, const byte * cipher,
56                   byte * clear, int blocks);
57
58 /* Encrypt one  block */
59 void gostcrypt(gost_ctx * c, const byte * in, byte * out);
60 /* Decrypt one  block */
61 void gostdecrypt(gost_ctx * c, const byte * in, byte * out);
62 /* Encrypt one  block */
63 void magmacrypt(gost_ctx * c, const byte * in, byte * out);
64 /* Decrypt one  block */
65 void magmadecrypt(gost_ctx * c, const byte * in, byte * out);
66 /* Set key into context */
67 void gost_key(gost_ctx * c, const byte * k);
68 /* Set key into context without key mask */
69 void gost_key_nomask(gost_ctx * c, const byte * k);
70 /* Set key into context */
71 void magma_key(gost_ctx * c, const byte * k);
72 /* Set master 256-bit key to be used in TLSTREE calculation into context */
73 void magma_master_key(gost_ctx *c, const byte *k);
74 /* Get key from context */
75 void gost_get_key(gost_ctx * c, byte * k);
76 /* Set S-blocks into context */
77 void gost_init(gost_ctx * c, const gost_subst_block * b);
78 /* Clean up context */
79 void gost_destroy(gost_ctx * c);
80 /* Intermediate function used for calculate hash */
81 void gost_enc_with_key(gost_ctx *, byte * key, byte * inblock,
82                        byte * outblock);
83 /* Compute MAC of given length in bits from data */
84 int gost_mac(gost_ctx * ctx, int mac_len, const unsigned char *data,
85              unsigned int data_len, unsigned char *mac);
86 /*
87  * Compute MAC of given length in bits from data, using non-zero 8-byte IV
88  * (non-standard, for use in CryptoPro key transport only
89  */
90 int gost_mac_iv(gost_ctx * ctx, int mac_len, const unsigned char *iv,
91                 const unsigned char *data, unsigned int data_len,
92                 unsigned char *mac);
93 /* Perform one step of MAC calculation like gostcrypt */
94 void mac_block(gost_ctx * c, byte * buffer, const byte * block);
95 /* Extracts MAC value from mac state buffer */
96 void get_mac(byte * buffer, int nbits, byte * out);
97 /* Implements cryptopro key meshing algorithm. Expect IV to be 8-byte size*/
98 void cryptopro_key_meshing(gost_ctx * ctx, unsigned char *iv);
99 /* Parameter sets specified in RFC 4357 */
100 extern gost_subst_block GostR3411_94_TestParamSet;
101 extern gost_subst_block GostR3411_94_CryptoProParamSet;
102 extern gost_subst_block Gost28147_TestParamSet;
103 extern gost_subst_block Gost28147_CryptoProParamSetA;
104 extern gost_subst_block Gost28147_CryptoProParamSetB;
105 extern gost_subst_block Gost28147_CryptoProParamSetC;
106 extern gost_subst_block Gost28147_CryptoProParamSetD;
107 extern gost_subst_block Gost28147_TC26ParamSetZ;
108 extern const byte CryptoProKeyMeshingKey[];
109 typedef unsigned int word32;
110 /* For tests. */
111 void kboxinit(gost_ctx * c, const gost_subst_block * b);
112 void magma_get_key(gost_ctx * c, byte * k);
113 void acpkm_magma_key_meshing(gost_ctx * ctx);
114 #endif