1 /**********************************************************************
3 * Copyright (c) 2005-2006 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Declarations for GOST 28147-89 encryption algorithm *
7 * No OpenSSL libraries required to compile and use *
9 **********************************************************************/
13 /* Typedef for unsigned 32-bit integer */
14 # if __LONG_MAX__ > 2147483647L
15 typedef unsigned int u4;
17 typedef unsigned long u4;
19 /* Typedef for unsigned 8-bit integer */
20 typedef unsigned char byte;
22 /* Internal representation of GOST substitution blocks */
34 /* Cipher context includes key and preprocessed substitution block */
38 /* Constant s-boxes -- set up in gost_init(). */
39 u4 k87[256], k65[256], k43[256], k21[256];
42 * Note: encrypt and decrypt expect full blocks--padding blocks is caller's
43 * responsibility. All bulk encryption is done in ECB mode by these calls.
44 * Other modes may be added easily enough.
46 /* Encrypt several full blocks in ECB mode */
47 void gost_enc(gost_ctx * c, const byte * clear, byte * cipher, int blocks);
48 /* Decrypt several full blocks in ECB mode */
49 void gost_dec(gost_ctx * c, const byte * cipher, byte * clear, int blocks);
50 /* Encrypts several full blocks in CFB mode using 8byte IV */
51 void gost_enc_cfb(gost_ctx * ctx, const byte * iv, const byte * clear,
52 byte * cipher, int blocks);
53 /* Decrypts several full blocks in CFB mode using 8byte IV */
54 void gost_dec_cfb(gost_ctx * ctx, const byte * iv, const byte * cipher,
55 byte * clear, int blocks);
57 /* Encrypt one block */
58 void gostcrypt(gost_ctx * c, const byte * in, byte * out);
59 /* Decrypt one block */
60 void gostdecrypt(gost_ctx * c, const byte * in, byte * out);
61 /* Set key into context */
62 void gost_key(gost_ctx * c, const byte * k);
63 /* Set key into context */
64 void magma_key(gost_ctx * c, const byte * k);
65 /* Get key from context */
66 void gost_get_key(gost_ctx * c, byte * k);
67 /* Set S-blocks into context */
68 void gost_init(gost_ctx * c, const gost_subst_block * b);
69 /* Clean up context */
70 void gost_destroy(gost_ctx * c);
71 /* Intermediate function used for calculate hash */
72 void gost_enc_with_key(gost_ctx *, byte * key, byte * inblock,
74 /* Compute MAC of given length in bits from data */
75 int gost_mac(gost_ctx * ctx, int mac_len, const unsigned char *data,
76 unsigned int data_len, unsigned char *mac);
78 * Compute MAC of given length in bits from data, using non-zero 8-byte IV
79 * (non-standard, for use in CryptoPro key transport only
81 int gost_mac_iv(gost_ctx * ctx, int mac_len, const unsigned char *iv,
82 const unsigned char *data, unsigned int data_len,
84 /* Perform one step of MAC calculation like gostcrypt */
85 void mac_block(gost_ctx * c, byte * buffer, const byte * block);
86 /* Extracts MAC value from mac state buffer */
87 void get_mac(byte * buffer, int nbits, byte * out);
88 /* Implements cryptopro key meshing algorithm. Expect IV to be 8-byte size*/
89 void cryptopro_key_meshing(gost_ctx * ctx, unsigned char *iv);
90 /* Parameter sets specified in RFC 4357 */
91 extern gost_subst_block GostR3411_94_TestParamSet;
92 extern gost_subst_block GostR3411_94_CryptoProParamSet;
93 extern gost_subst_block Gost28147_TestParamSet;
94 extern gost_subst_block Gost28147_CryptoProParamSetA;
95 extern gost_subst_block Gost28147_CryptoProParamSetB;
96 extern gost_subst_block Gost28147_CryptoProParamSetC;
97 extern gost_subst_block Gost28147_CryptoProParamSetD;
98 extern gost_subst_block Gost28147_TC26ParamSetZ;
99 extern const byte CryptoProKeyMeshingKey[];
100 typedef unsigned int word32;
102 void kboxinit(gost_ctx * c, const gost_subst_block * b);
103 void magma_get_key(gost_ctx * c, byte * k);
104 void acpkm_magma_key_meshing(gost_ctx * ctx);