Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::GOST_34_11 Class Referencefinal

`#include <gost_3411.h>`

Inheritance diagram for Botan::GOST_34_11:

## Public Member Functions
void | clear () override
HashFunction * | clone () const override
void | final (uint8_t out[])
secure_vector< uint8_t > | final ()
template<typename Alloc >
void | final (std::vector< uint8_t, Alloc > &out)
std::vector< uint8_t > | final_stdvec ()
| GOST_34_11 ()
size_t | hash_block_size () const override
std::string | name () const override
size_t | output_length () const override
secure_vector< uint8_t > | process (const uint8_t in[], size_t length)
secure_vector< uint8_t > | process (const secure_vector< uint8_t > &in)
secure_vector< uint8_t > | process (const std::vector< uint8_t > &in)
secure_vector< uint8_t > | process (const std::string &in)
virtual std::string | provider () const
void | update (const uint8_t in[], size_t length)
void | update (const secure_vector< uint8_t > &in)
void | update (const std::vector< uint8_t > &in)
void | update (const std::string &str)
void | update (uint8_t in)
template<typename T >
void | update_be (const T in)

## Static Public Member Functions
static std::unique_ptr< HashFunction > | create (const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< HashFunction > | create_or_throw (const std::string &algo_spec, const std::string &provider="")
static std::vector< std::string > | providers (const std::string &algo_spec)

## Detailed Description

GOST 34.11

Definition at line 19 of file gost_3411.h.

## Constructor & Destructor Documentation

Botan::GOST_34_11::GOST_34_11 | ( |  | ) |

GOST 34.11 Constructor

Definition at line 15 of file gost_3411.cpp.

15 :
16 m_cipher(GOST_28147_89_Params("R3411_CryptoPro")),
17 m_buffer(32),
18 m_sum(32),
19 m_hash(32)
20 {
21 m_count = 0;
22 m_position = 0;
23 }

## Member Function Documentation

void Botan::GOST_34_11::clear | ( |  | ) |
| override virtual

Reset the state.

Implements Botan::HashFunction.

Definition at line 25 of file gost_3411.cpp.

References Botan::GOST_28147_89::clear(), and Botan::zeroise().

26 {
27 m_cipher.clear();
28 zeroise(m_sum);
29 zeroise(m_hash);
30 m_count = 0;
31 m_position = 0;
32 }
Botan::GOST_28147_89::clear
void clear() override
Definition: gost_28147.cpp:171
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:211

HashFunction* Botan::GOST_34_11::clone | ( |  | ) | const
| inline override virtual

Returns
  new object representing the same algorithm as *this

Implements Botan::HashFunction.

Definition at line 25 of file gost_3411.h.

25 { return new GOST_34_11; }
Botan::GOST_34_11::GOST_34_11
GOST_34_11()
Definition: gost_3411.cpp:15

std::unique_ptr< HashFunction > Botan::HashFunction::create | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

Create an instance based on a name, or return null if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 93 of file hash.cpp.

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), hash, and Botan::make_openssl_hash().

Referenced by botan_hash_init(), botan_pubkey_fingerprint(), Botan::OCSP::CertID::CertID(), Botan::BlockCipher::create(), Botan::MessageAuthenticationCode::create(), Botan::PBKDF::create(), Botan::KDF::create(), Botan::HashFunction::create_or_throw(), Botan::Certificate_Store_In_Memory::find_cert_by_pubkey_sha1(), Botan::Certificate_Store_In_Memory::find_cert_by_raw_subject_dn_sha256(), Botan::Private_Key::fingerprint(), Botan::X509_Certificate::fingerprint(), Botan::get_eme(), Botan::get_emsa(), Botan::get_hash(), Botan::get_hash_function(), Botan::OCSP::CertID::is_id_for(), Botan::X942_PRF::kdf(), Botan::newhope_shareda(), Botan::newhope_sharedb(), Botan::X509_Certificate::raw_issuer_dn_sha256(), Botan::X509_Certificate::raw_subject_dn_sha256(), and Botan::X509_Certificate::subject_public_key_bitstring_sha1().

95 {
96 #if defined(BOTAN_HAS_OPENSSL)
97 if(provider.empty() || provider == "openssl")
98 {
99 if(auto hash = make_openssl_hash(algo_spec))
100 return hash;
101
102 if(!provider.empty())
103 return nullptr;
104 }
105 #endif
106
107 // TODO: CommonCrypto hashes
108
109 if(provider.empty() == false && provider != "base")
110 return nullptr; // unknown provider
111
112 #if defined(BOTAN_HAS_SHA1)
113 if(algo_spec == "SHA-160" ||
114 algo_spec == "SHA-1" ||
115 algo_spec == "SHA1")
116 {
117 return std::unique_ptr<HashFunction>(new SHA_160);
118 }
119 #endif
120
121 #if defined(BOTAN_HAS_SHA2_32)
122 if(algo_spec == "SHA-224")
123 {
124 return std::unique_ptr<HashFunction>(new SHA_224);
125 }
126
127 if(algo_spec == "SHA-256")
128 {
129 return std::unique_ptr<HashFunction>(new SHA_256);
130 }
131 #endif
132
133 #if defined(BOTAN_HAS_SHA2_64)
134 if(algo_spec == "SHA-384")
135 {
136 return std::unique_ptr<HashFunction>(new SHA_384);
137 }
138
139 if(algo_spec == "SHA-512")
140 {
141 return std::unique_ptr<HashFunction>(new SHA_512);
142 }
143
144 if(algo_spec == "SHA-512-256")
145 {
146 return std::unique_ptr<HashFunction>(new SHA_512_256);
147 }
148 #endif
149
150 #if defined(BOTAN_HAS_RIPEMD_160)
151 if(algo_spec == "RIPEMD-160")
152 {
153 return std::unique_ptr<HashFunction>(new RIPEMD_160);
154 }
155 #endif
156
157 #if defined(BOTAN_HAS_WHIRLPOOL)
158 if(algo_spec == "Whirlpool")
159 {
160 return std::unique_ptr<HashFunction>(new Whirlpool);
161 }
162 #endif
163
164 #if defined(BOTAN_HAS_MD5)
165 if(algo_spec == "MD5")
166 {
167 return std::unique_ptr<HashFunction>(new MD5);
168 }
169 #endif
170
171 #if defined(BOTAN_HAS_MD4)
172 if(algo_spec == "MD4")
173 {
174 return std::unique_ptr<HashFunction>(new MD4);
175 }
176 #endif
177
178 #if defined(BOTAN_HAS_GOST_34_11)
179 if(algo_spec == "GOST-R-34.11-94" || algo_spec == "GOST-34.11")
180 {
181 return std::unique_ptr<HashFunction>(new GOST_34_11);
182 }
183 #endif
184
185 #if defined(BOTAN_HAS_ADLER32)
186 if(algo_spec == "Adler32")
187 {
188 return std::unique_ptr<HashFunction>(new Adler32);
189 }
190 #endif
191
192 #if defined(BOTAN_HAS_CRC24)
193 if(algo_spec == "CRC24")
194 {
195 return std::unique_ptr<HashFunction>(new CRC24);
196 }
197 #endif
198
199 #if defined(BOTAN_HAS_CRC32)
200 if(algo_spec == "CRC32")
201 {
202 return std::unique_ptr<HashFunction>(new CRC32);
203 }
204 #endif
205
206 const SCAN_Name req(algo_spec);
207
208 #if defined(BOTAN_HAS_TIGER)
209 if(req.algo_name() == "Tiger")
210 {
211 return std::unique_ptr<HashFunction>(
212 new Tiger(req.arg_as_integer(0, 24),
213 req.arg_as_integer(1, 3)));
214 }
215 #endif
216
217 #if defined(BOTAN_HAS_SKEIN_512)
218 if(req.algo_name() == "Skein-512")
219 {
220 return std::unique_ptr<HashFunction>(
221 new Skein_512(req.arg_as_integer(0, 512), req.arg(1, "")));
222 }
223 #endif
224
225 #if defined(BOTAN_HAS_BLAKE2B)
226 if(req.algo_name() == "Blake2b")
227 {
228 return std::unique_ptr<HashFunction>(
229 new Blake2b(req.arg_as_integer(0, 512)));
230 }
231 #endif
232
233 #if defined(BOTAN_HAS_KECCAK)
234 if(req.algo_name() == "Keccak-1600")
235 {
236 return std::unique_ptr<HashFunction>(
237 new Keccak_1600(req.arg_as_integer(0, 512)));
238 }
239 #endif
240
241 #if defined(BOTAN_HAS_SHA3)
242 if(req.algo_name() == "SHA-3")
243 {
244 return std::unique_ptr<HashFunction>(
245 new SHA_3(req.arg_as_integer(0, 512)));
246 }
247 #endif
248
249 #if defined(BOTAN_HAS_SHAKE)
250 if(req.algo_name() == "SHAKE-128")
251 {
252 return std::unique_ptr<HashFunction>(new SHAKE_128(req.arg_as_integer(0, 128)));
253 }
254 if(req.algo_name() == "SHAKE-256")
255 {
256 return std::unique_ptr<HashFunction>(new SHAKE_256(req.arg_as_integer(0, 256)));
257 }
258 #endif
259
260 #if defined(BOTAN_HAS_WHIRLPOOL)
261 if(req.algo_name() == "Whirlpool")
262 {
263 return std::unique_ptr<HashFunction>(new Whirlpool);
264 }
265 #endif
266
267 #if defined(BOTAN_HAS_PARALLEL_HASH)
268 if(req.algo_name() == "Parallel")
269 {
270 std::vector<std::unique_ptr<HashFunction>> hashes;
271
272 for(size_t i = 0; i != req.arg_count(); ++i)
273 {
274 auto h = HashFunction::create(req.arg(i));
275 if(!h)
276 {
277 return nullptr;
278 }
279 hashes.push_back(std::move(h));
280 }
281
282 return std::unique_ptr<HashFunction>(new Parallel(hashes));
283 }
284 #endif
285
286 #if defined(BOTAN_HAS_COMB4P)
287 if(req.algo_name() == "Comb4P" && req.arg_count() == 2)
288 {
289 std::unique_ptr<HashFunction> h1(HashFunction::create(req.arg(0)));
290 std::unique_ptr<HashFunction> h2(HashFunction::create(req.arg(1)));
291
292 if(h1 && h2)
293 return std::unique_ptr<HashFunction>(new Comb4P(h1.release(), h2.release()));
294 }
295 #endif
296
297
298 return nullptr;
299 }
Botan::HashFunction::provider
virtual std::string provider() const
Definition: hash.h:57
Botan::make_openssl_hash
std::unique_ptr< HashFunction > make_openssl_hash(const std::string &name)
Definition: openssl_hash.cpp:76
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

std::unique_ptr< HashFunction > Botan::HashFunction::create_or_throw | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters

  algo_spec | algorithm name
  provider | provider implementation to use Throws Lookup_Error if not not found.

Definition at line 303 of file hash.cpp.

References Botan::HashFunction::create(), and hash.

Referenced by Botan::choose_sig_format(), Botan::TLS::Handshake_Hash::final(), Botan::generate_dsa_primes(), and Botan::make_hash_function().

305 {
306 if(auto hash = HashFunction::create(algo, provider))
307 {
308 return hash;
309 }
310 throw Lookup_Error("Hash", algo, provider);
311 }
Botan::HashFunction::provider
virtual std::string provider() const
Definition: hash.h:57
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
hash
MechanismType hash
Definition: p11_mechanism.cpp:63

void Botan::Buffered_Computation::final | ( | uint8_t | out[] | ) |
| inline inherited

Complete the computation and retrieve the final result.

Parameters

  out | The byte array to be filled with the result. Must be of length output_length()

Definition at line 89 of file buf_comp.h.

Referenced by botan_hash_final(), botan_mac_final(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::mgf1_mask(), and Botan::pbkdf2().

89 { final_result(out); }

secure_vector<uint8_t> Botan::Buffered_Computation::final | ( |  | ) |
| inline inherited

Complete the computation and retrieve the final result.

Returns
  secure_vector holding the result

Definition at line 96 of file buf_comp.h.

97 {
98 secure_vector<uint8_t> output(output_length());
99 final_result(output.data());
100 return output;
101 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0
template<typename Alloc >

void Botan::Buffered_Computation::final | ( | std::vector< uint8_t, Alloc > & | out | ) |
| inline inherited

Definition at line 111 of file buf_comp.h.

112 {
113 out.resize(output_length());
114 final_result(out.data());
115 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

std::vector<uint8_t> Botan::Buffered_Computation::final_stdvec | ( |  | ) |
| inline inherited

Definition at line 103 of file buf_comp.h.

104 {
105 std::vector<uint8_t> output(output_length());
106 final_result(output.data());
107 return output;
108 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

size_t Botan::GOST_34_11::hash_block_size | ( |  | ) | const
| inline override virtual

Returns
  hash block size as defined for this algorithm

Reimplemented from Botan::HashFunction.

Definition at line 24 of file gost_3411.h.

24 { return 32; }

std::string Botan::GOST_34_11::name | ( |  | ) | const
| inline override virtual

Returns
  the hash function name

Implements Botan::HashFunction.

Definition at line 22 of file gost_3411.h.

22 { return "GOST-R-34.11-94" ; }

size_t Botan::GOST_34_11::output_length | ( |  | ) | const
| inline override virtual

Returns
  length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 23 of file gost_3411.h.

23 { return 32; }

secure_vector<uint8_t> Botan::Buffered_Computation::process | ( | const uint8_t | in[],
|  | size_t | length
| ) |  |
| inline inherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters

  in | the input to process as a byte array
  length | the length of the byte array

Returns
  the result of the call to final()

Definition at line 124 of file buf_comp.h.

Referenced by Botan::RTSS_Share::split().

125 {
126 add_data(in, length);
127 return final();
128 }

secure_vector<uint8_t> Botan::Buffered_Computation::process | ( | const secure_vector< uint8_t > & | in | ) |
| inline inherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters

  in | the input to process

Returns
  the result of the call to final()

Definition at line 136 of file buf_comp.h.

137 {
138 add_data(in.data(), in.size());
139 return final();
140 }

secure_vector<uint8_t> Botan::Buffered_Computation::process | ( | const std::vector< uint8_t > & | in | ) |
| inline inherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters

  in | the input to process

Returns
  the result of the call to final()

Definition at line 148 of file buf_comp.h.

149 {
150 add_data(in.data(), in.size());
151 return final();
152 }

secure_vector<uint8_t> Botan::Buffered_Computation::process | ( | const std::string & | in | ) |
| inline inherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters

  in | the input to process as a string

Returns
  the result of the call to final()

Definition at line 160 of file buf_comp.h.

161 {
162 update(in);
163 return final();
164 }
Botan::Buffered_Computation::update
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:34

virtual std::string Botan::HashFunction::provider | ( |  | ) | const
| inline virtual inherited

Returns
  provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Definition at line 57 of file hash.h.

57 { return "base"; }

std::vector< std::string > Botan::HashFunction::providers | ( | const std::string & | algo_spec | ) |
| static inherited

Returns
  list of available providers for this algorithm, empty if not available

Parameters

  algo_spec | algorithm name

Definition at line 313 of file hash.cpp.

Referenced by Botan::get_hash_function_providers().

314 {
315 return probe_providers_of<HashFunction>(algo_spec, {"base", "openssl"});
316 }

void Botan::Buffered_Computation::update | ( | const uint8_t | in[],
|  | size_t | length
| ) |  |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a byte array
  length | of param in in bytes

Definition at line 34 of file buf_comp.h.

Referenced by botan_hash_update(), botan_mac_update(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::mgf1_mask(), and Botan::pbkdf2().

34 { add_data(in, length); }

void Botan::Buffered_Computation::update | ( | const secure_vector< uint8_t > & | in | ) |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a secure_vector

Definition at line 40 of file buf_comp.h.

41 {
42 add_data(in.data(), in.size());
43 }

void Botan::Buffered_Computation::update | ( | const std::vector< uint8_t > & | in | ) |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a std::vector

Definition at line 49 of file buf_comp.h.

50 {
51 add_data(in.data(), in.size());
52 }

void Botan::Buffered_Computation::update | ( | const std::string & | str | ) |
| inline inherited

Add new input to process.

Parameters

  str | the input to process as a std::string. Will be interpreted as a byte array based on the strings encoding.

Definition at line 72 of file buf_comp.h.

73 {
74 add_data(reinterpret_cast<const uint8_t*>(str.data()), str.size());
75 }

void Botan::Buffered_Computation::update | ( | uint8_t | in | ) |
| inline inherited

Process a single byte.

Parameters

  in | the byte to process

Definition at line 81 of file buf_comp.h.

81 { add_data(&in, 1); }
template<typename T >

void Botan::Buffered_Computation::update_be | ( | const T | in | ) |
| inline inherited

Add an integer in big-endian order

Parameters

  in | the value

Definition at line 58 of file buf_comp.h.

References Botan::get_byte().

Referenced by Botan::mgf1_mask(), and Botan::pbkdf2().

59 {
60 for(size_t i = 0; i != sizeof(T); ++i)
61 {
62 uint8_t b = get_byte(i, in);
63 add_data(&b, 1);
64 }
65 }
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47

The documentation for this class was generated from the following files:

- src/lib/hash/gost_3411/gost_3411.h
- src/lib/hash/gost_3411/gost_3411.cpp