/src/botan/build/include/botan/gost_28147.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * GOST 28147-89 |
3 | | * (C) 1999-2009 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_GOST_28147_89_H_ |
9 | | #define BOTAN_GOST_28147_89_H_ |
10 | | |
11 | | #include <botan/block_cipher.h> |
12 | | |
13 | | BOTAN_FUTURE_INTERNAL_HEADER(gost_28147.h) |
14 | | |
15 | | namespace Botan { |
16 | | |
17 | | /** |
18 | | * The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however |
19 | | * the standard does not actually define these Sboxes; they are |
20 | | * considered a local configuration issue. Several different sets are |
21 | | * used. |
22 | | */ |
23 | | class BOTAN_PUBLIC_API(2,0) GOST_28147_89_Params final |
24 | | { |
25 | | public: |
26 | | /** |
27 | | * @param row the row |
28 | | * @param col the column |
29 | | * @return sbox entry at this row/column |
30 | | */ |
31 | | uint8_t sbox_entry(size_t row, size_t col) const; |
32 | | |
33 | | /** |
34 | | * @return name of this parameter set |
35 | | */ |
36 | 0 | std::string param_name() const { return m_name; } |
37 | | |
38 | | /** |
39 | | * Return a representation used for building larger tables |
40 | | * For internal use |
41 | | */ |
42 | | uint8_t sbox_pair(size_t row, size_t col) const; |
43 | | |
44 | | /** |
45 | | * Default GOST parameters are the ones given in GOST R 34.11 for |
46 | | * testing purposes; these sboxes are also used by Crypto++, and, |
47 | | * at least according to Wikipedia, the Central Bank of Russian |
48 | | * Federation |
49 | | * @param name of the parameter set |
50 | | */ |
51 | | explicit GOST_28147_89_Params(const std::string& name = "R3411_94_TestParam"); |
52 | | private: |
53 | | const uint8_t* m_sboxes; |
54 | | std::string m_name; |
55 | | }; |
56 | | |
57 | | /** |
58 | | * GOST 28147-89 |
59 | | */ |
60 | | class BOTAN_PUBLIC_API(2,0) GOST_28147_89 final : public Block_Cipher_Fixed_Params<8, 32> |
61 | | { |
62 | | public: |
63 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
64 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
65 | | |
66 | | void clear() override; |
67 | | |
68 | | std::string name() const override; |
69 | 0 | BlockCipher* clone() const override { return new GOST_28147_89(m_SBOX); } |
70 | | |
71 | | /** |
72 | | * @param params the sbox parameters to use |
73 | | */ |
74 | | explicit GOST_28147_89(const GOST_28147_89_Params& params); |
75 | | |
76 | | explicit GOST_28147_89(const std::string& param_name) : |
77 | 0 | GOST_28147_89(GOST_28147_89_Params(param_name)) {} |
78 | | private: |
79 | | explicit GOST_28147_89(const std::vector<uint32_t>& other_SBOX) : |
80 | 0 | m_SBOX(other_SBOX), m_EK(8) {} |
81 | | |
82 | | void key_schedule(const uint8_t[], size_t) override; |
83 | | |
84 | | /* |
85 | | * The sbox is not secret, this is just a larger expansion of it |
86 | | * which we generate at runtime for faster execution |
87 | | */ |
88 | | std::vector<uint32_t> m_SBOX; |
89 | | |
90 | | secure_vector<uint32_t> m_EK; |
91 | | }; |
92 | | |
93 | | } |
94 | | |
95 | | #endif |