Botan 3.4.0
Crypto and TLS for C&
gost_28147.h
Go to the documentation of this file.
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
13namespace Botan {
14
15/**
16* The GOST 28147-89 block cipher uses a set of 4 bit Sboxes, however
17* the standard does not actually define these Sboxes; they are
18* considered a local configuration issue. Several different sets are
19* used.
20*/
22 public:
23 /**
24 * @param row the row
25 * @param col the column
26 * @return sbox entry at this row/column
27 */
28 uint8_t sbox_entry(size_t row, size_t col) const;
29
30 /**
31 * @return name of this parameter set
32 */
33 std::string param_name() const { return m_name; }
34
35 /**
36 * Return a representation used for building larger tables
37 * For internal use
38 */
39 uint8_t sbox_pair(size_t row, size_t col) const;
40
41 /**
42 * Default GOST parameters are the ones given in GOST R 34.11 for
43 * testing purposes; these sboxes are also used by Crypto++, and,
44 * at least according to Wikipedia, the Central Bank of Russian
45 * Federation
46 * @param name of the parameter set
47 */
48 explicit GOST_28147_89_Params(std::string_view name = "R3411_94_TestParam");
49
50 private:
51 const uint8_t* m_sboxes;
52 std::string m_name;
53};
54
55/**
56* GOST 28147-89
57*/
59 public:
60 void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
61 void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
62
63 void clear() override;
64
65 std::string name() const override;
66
67 std::unique_ptr<BlockCipher> new_object() const override {
68 return std::make_unique<GOST_28147_89>(m_SBOX, m_name);
69 }
70
71 bool has_keying_material() const override;
72
73 /**
74 * @param params the sbox parameters to use
75 */
76 explicit GOST_28147_89(const GOST_28147_89_Params& params);
77
78 explicit GOST_28147_89(std::string_view param_name) : GOST_28147_89(GOST_28147_89_Params(param_name)) {}
79
80 explicit GOST_28147_89(const std::vector<uint32_t>& other_SBOX, std::string_view name) :
81 m_SBOX(other_SBOX), m_EK(8), m_name(name) {}
82
83 private:
84 void key_schedule(std::span<const uint8_t> key) override;
85
86 /*
87 * The sbox is not secret, this is just a larger expansion of it
88 * which we generate at runtime for faster execution
89 */
90 std::vector<uint32_t> m_SBOX;
92 std::string m_name;
93};
94
95} // namespace Botan
96
97#endif
uint8_t sbox_pair(size_t row, size_t col) const
std::string param_name() const
Definition gost_28147.h:33
uint8_t sbox_entry(size_t row, size_t col) const
GOST_28147_89_Params(std::string_view name="R3411_94_TestParam")
void clear() override
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
GOST_28147_89(std::string_view param_name)
Definition gost_28147.h:78
std::unique_ptr< BlockCipher > new_object() const override
Definition gost_28147.h:67
std::string name() const override
GOST_28147_89(const std::vector< uint32_t > &other_SBOX, std::string_view name)
Definition gost_28147.h:80
GOST_28147_89(const GOST_28147_89_Params &params)
bool has_keying_material() const override
std::string name
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61