Botan 2.19.3
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Botan::SHA_256 Class Referencefinal

#include <sha2_32.h>

Inheritance diagram for Botan::SHA_256:
Botan::MDx_HashFunction Botan::HashFunction Botan::Buffered_Computation

Public Member Functions

void clear () override
 
HashFunctionclone () const override
 
std::unique_ptr< HashFunctioncopy_state () const override
 
secure_vector< uint8_t > final ()
 
template<typename Alloc >
void final (std::vector< uint8_t, Alloc > &out)
 
void final (uint8_t out[])
 
std::vector< uint8_t > final_stdvec ()
 
size_t hash_block_size () const override final
 
std::string name () const override
 
size_t output_length () const override
 
secure_vector< uint8_t > process (const secure_vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const std::string &in)
 
secure_vector< uint8_t > process (const std::vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const uint8_t in[], size_t length)
 
std::string provider () const override
 
 SHA_256 ()
 
void update (const secure_vector< uint8_t > &in)
 
void update (const std::string &str)
 
void update (const std::vector< uint8_t > &in)
 
void update (const uint8_t in[], size_t length)
 
void update (uint8_t in)
 
void update_be (uint16_t val)
 
void update_be (uint32_t val)
 
void update_be (uint64_t val)
 
void update_le (uint16_t val)
 
void update_le (uint32_t val)
 
void update_le (uint64_t val)
 

Static Public Member Functions

static void compress_digest (secure_vector< uint32_t > &digest, const uint8_t input[], size_t blocks)
 
static std::unique_ptr< HashFunctioncreate (const std::string &algo_spec, const std::string &provider="")
 
static std::unique_ptr< HashFunctioncreate_or_throw (const std::string &algo_spec, const std::string &provider="")
 
static std::vector< std::string > providers (const std::string &algo_spec)
 

Protected Member Functions

void add_data (const uint8_t input[], size_t length) override final
 
void final_result (uint8_t output[]) override final
 
virtual void write_count (uint8_t out[])
 

Detailed Description

SHA-256

Definition at line 45 of file sha2_32.h.

Constructor & Destructor Documentation

◆ SHA_256()

Botan::SHA_256::SHA_256 ( )
inline

Definition at line 57 of file sha2_32.h.

57 : MDx_HashFunction(64, true, true), m_digest(8)
58 { clear(); }
MDx_HashFunction(size_t block_length, bool big_byte_endian, bool big_bit_endian, uint8_t counter_size=8)
Definition mdx_hash.cpp:18
void clear() override
Definition sha2_32.cpp:265

References Botan::MDx_HashFunction::clear().

Referenced by copy_state().

Member Function Documentation

◆ add_data()

void Botan::MDx_HashFunction::add_data ( const uint8_t  input[],
size_t  length 
)
finaloverrideprotectedvirtualinherited

Add more data to the computation

Parameters
inputis an input buffer
lengthis the length of input in bytes

Implements Botan::Buffered_Computation.

Definition at line 50 of file mdx_hash.cpp.

51 {
52 const size_t block_len = static_cast<size_t>(1) << m_block_bits;
53
54 m_count += length;
55
56 if(m_position)
57 {
58 buffer_insert(m_buffer, m_position, input, length);
59
60 if(m_position + length >= block_len)
61 {
62 compress_n(m_buffer.data(), 1);
63 input += (block_len - m_position);
64 length -= (block_len - m_position);
65 m_position = 0;
66 }
67 }
68
69 // Just in case the compiler can't figure out block_len is a power of 2
70 const size_t full_blocks = length >> m_block_bits;
71 const size_t remaining = length & (block_len - 1);
72
73 if(full_blocks > 0)
74 {
75 compress_n(input, full_blocks);
76 }
77
78 buffer_insert(m_buffer, m_position, input + full_blocks * block_len, remaining);
79 m_position += remaining;
80 }
virtual void compress_n(const uint8_t blocks[], size_t block_n)=0
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
Definition mem_ops.h:228

References Botan::buffer_insert(), and Botan::MDx_HashFunction::compress_n().

◆ clear()

void Botan::SHA_256::clear ( )
overridevirtual

Reset the state.

Reimplemented from Botan::MDx_HashFunction.

Definition at line 265 of file sha2_32.cpp.

266 {
268 m_digest[0] = 0x6A09E667;
269 m_digest[1] = 0xBB67AE85;
270 m_digest[2] = 0x3C6EF372;
271 m_digest[3] = 0xA54FF53A;
272 m_digest[4] = 0x510E527F;
273 m_digest[5] = 0x9B05688C;
274 m_digest[6] = 0x1F83D9AB;
275 m_digest[7] = 0x5BE0CD19;
276 }
void clear() override
Definition mdx_hash.cpp:41

References Botan::MDx_HashFunction::clear().

◆ clone()

HashFunction * Botan::SHA_256::clone ( ) const
inlineoverridevirtual
Returns
new object representing the same algorithm as *this

Implements Botan::HashFunction.

Definition at line 50 of file sha2_32.h.

50{ return new SHA_256; }

◆ compress_digest()

void Botan::SHA_256::compress_digest ( secure_vector< uint32_t > &  digest,
const uint8_t  input[],
size_t  blocks 
)
static

Definition at line 76 of file sha2_32.cpp.

78 {
79#if defined(BOTAN_HAS_SHA2_32_X86)
80 if(CPUID::has_intel_sha())
81 {
82 return SHA_256::compress_digest_x86(digest, input, blocks);
83 }
84#endif
85
86#if defined(BOTAN_HAS_SHA2_32_X86_BMI2)
87 if(CPUID::has_bmi2())
88 {
89 return SHA_256::compress_digest_x86_bmi2(digest, input, blocks);
90 }
91#endif
92
93#if defined(BOTAN_HAS_SHA2_32_ARMV8)
94 if(CPUID::has_arm_sha2())
95 {
96 return SHA_256::compress_digest_armv8(digest, input, blocks);
97 }
98#endif
99
100 uint32_t A = digest[0], B = digest[1], C = digest[2],
101 D = digest[3], E = digest[4], F = digest[5],
102 G = digest[6], H = digest[7];
103
104 for(size_t i = 0; i != blocks; ++i)
105 {
106 uint32_t W00 = load_be<uint32_t>(input, 0);
107 uint32_t W01 = load_be<uint32_t>(input, 1);
108 uint32_t W02 = load_be<uint32_t>(input, 2);
109 uint32_t W03 = load_be<uint32_t>(input, 3);
110 uint32_t W04 = load_be<uint32_t>(input, 4);
111 uint32_t W05 = load_be<uint32_t>(input, 5);
112 uint32_t W06 = load_be<uint32_t>(input, 6);
113 uint32_t W07 = load_be<uint32_t>(input, 7);
114 uint32_t W08 = load_be<uint32_t>(input, 8);
115 uint32_t W09 = load_be<uint32_t>(input, 9);
116 uint32_t W10 = load_be<uint32_t>(input, 10);
117 uint32_t W11 = load_be<uint32_t>(input, 11);
118 uint32_t W12 = load_be<uint32_t>(input, 12);
119 uint32_t W13 = load_be<uint32_t>(input, 13);
120 uint32_t W14 = load_be<uint32_t>(input, 14);
121 uint32_t W15 = load_be<uint32_t>(input, 15);
122
123 SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x428A2F98);
124 SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x71374491);
125 SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0xB5C0FBCF);
126 SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0xE9B5DBA5);
127 SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x3956C25B);
128 SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x59F111F1);
129 SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x923F82A4);
130 SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0xAB1C5ED5);
131 SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xD807AA98);
132 SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x12835B01);
133 SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x243185BE);
134 SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x550C7DC3);
135 SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x72BE5D74);
136 SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0x80DEB1FE);
137 SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x9BDC06A7);
138 SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC19BF174);
139
140 SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0xE49B69C1);
141 SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0xEFBE4786);
142 SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x0FC19DC6);
143 SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x240CA1CC);
144 SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x2DE92C6F);
145 SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4A7484AA);
146 SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5CB0A9DC);
147 SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x76F988DA);
148 SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x983E5152);
149 SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA831C66D);
150 SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xB00327C8);
151 SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xBF597FC7);
152 SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xC6E00BF3);
153 SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD5A79147);
154 SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x06CA6351);
155 SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x14292967);
156
157 SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x27B70A85);
158 SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x2E1B2138);
159 SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x4D2C6DFC);
160 SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x53380D13);
161 SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x650A7354);
162 SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x766A0ABB);
163 SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x81C2C92E);
164 SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x92722C85);
165 SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xA2BFE8A1);
166 SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA81A664B);
167 SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xC24B8B70);
168 SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xC76C51A3);
169 SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xD192E819);
170 SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD6990624);
171 SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xF40E3585);
172 SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x106AA070);
173
174 SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x19A4C116);
175 SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x1E376C08);
176 SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x2748774C);
177 SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x34B0BCB5);
178 SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x391C0CB3);
179 SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4ED8AA4A);
180 SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5B9CCA4F);
181 SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x682E6FF3);
182 SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x748F82EE);
183 SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x78A5636F);
184 SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x84C87814);
185 SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x8CC70208);
186 SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x90BEFFFA);
187 SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xA4506CEB);
188 SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xBEF9A3F7);
189 SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC67178F2);
190
191 A = (digest[0] += A);
192 B = (digest[1] += B);
193 C = (digest[2] += C);
194 D = (digest[3] += D);
195 E = (digest[4] += E);
196 F = (digest[5] += F);
197 G = (digest[6] += G);
198 H = (digest[7] += H);
199
200 input += 64;
201 }
202 }
uint32_t load_be< uint32_t >(const uint8_t in[], size_t off)
Definition loadstor.h:179
#define SHA2_32_F(A, B, C, D, E, F, G, H, M1, M2, M3, M4, magic)
Definition sha2_32.cpp:62

References Botan::load_be< uint32_t >(), and SHA2_32_F.

◆ copy_state()

std::unique_ptr< HashFunction > Botan::SHA_256::copy_state ( ) const
overridevirtual

Return a new hash object with the same state as *this. This allows computing the hash of several messages with a common prefix more efficiently than would otherwise be possible.

This function should be called clone but that was already used for the case of returning an uninitialized object.

Returns
new hash object

Implements Botan::HashFunction.

Definition at line 51 of file sha2_32.cpp.

52 {
53 return std::unique_ptr<HashFunction>(new SHA_256(*this));
54 }

References SHA_256().

◆ create()

std::unique_ptr< HashFunction > Botan::HashFunction::create ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
staticinherited

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 102 of file hash.cpp.

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

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), Botan::HashFunction::create(), hash, Botan::make_commoncrypto_hash(), and Botan::HashFunction::provider().

Referenced by botan_hash_init(), botan_pubkey_fingerprint(), Botan::BlockCipher::create(), Botan::HashFunction::create(), Botan::KDF::create(), Botan::MessageAuthenticationCode::create(), Botan::PBKDF::create(), Botan::PasswordHashFamily::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::get_eme(), Botan::get_emsa(), and Botan::X942_PRF::kdf().

◆ create_or_throw()

std::unique_ptr< HashFunction > Botan::HashFunction::create_or_throw ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
staticinherited

◆ final() [1/3]

secure_vector< uint8_t > Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result.

Returns
secure_vector holding the result

Definition at line 90 of file buf_comp.h.

91 {
92 secure_vector<uint8_t> output(output_length());
93 final_result(output.data());
94 return output;
95 }
virtual size_t output_length() const =0

◆ final() [2/3]

template<typename Alloc >
void Botan::Buffered_Computation::final ( std::vector< uint8_t, Alloc > &  out)
inlineinherited

Definition at line 105 of file buf_comp.h.

106 {
107 out.resize(output_length());
108 final_result(out.data());
109 }

◆ final() [3/3]

void Botan::Buffered_Computation::final ( uint8_t  out[])
inlineinherited

Complete the computation and retrieve the final result.

Parameters
outThe byte array to be filled with the result. Must be of length output_length()

Definition at line 83 of file buf_comp.h.

83{ final_result(out); }

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

◆ final_result()

void Botan::MDx_HashFunction::final_result ( uint8_t  out[])
finaloverrideprotectedvirtualinherited

Write the final output to out

Parameters
outis an output buffer of output_length()

Implements Botan::Buffered_Computation.

Definition at line 85 of file mdx_hash.cpp.

86 {
87 const size_t block_len = static_cast<size_t>(1) << m_block_bits;
88
89 clear_mem(&m_buffer[m_position], block_len - m_position);
90 m_buffer[m_position] = m_pad_char;
91
92 if(m_position >= block_len - m_counter_size)
93 {
94 compress_n(m_buffer.data(), 1);
95 zeroise(m_buffer);
96 }
97
98 write_count(&m_buffer[block_len - m_counter_size]);
99
100 compress_n(m_buffer.data(), 1);
101 copy_out(output);
102 clear();
103 }
virtual void write_count(uint8_t out[])
Definition mdx_hash.cpp:108
virtual void copy_out(uint8_t buffer[])=0
void zeroise(std::vector< T, Alloc > &vec)
Definition secmem.h:114
void clear_mem(T *ptr, size_t n)
Definition mem_ops.h:115

References Botan::MDx_HashFunction::clear(), Botan::clear_mem(), Botan::MDx_HashFunction::compress_n(), Botan::MDx_HashFunction::copy_out(), Botan::MDx_HashFunction::write_count(), and Botan::zeroise().

◆ final_stdvec()

std::vector< uint8_t > Botan::Buffered_Computation::final_stdvec ( )
inlineinherited

Definition at line 97 of file buf_comp.h.

98 {
99 std::vector<uint8_t> output(output_length());
100 final_result(output.data());
101 return output;
102 }

◆ hash_block_size()

size_t Botan::MDx_HashFunction::hash_block_size ( ) const
inlinefinaloverridevirtualinherited
Returns
hash block size as defined for this algorithm

Reimplemented from Botan::HashFunction.

Definition at line 35 of file mdx_hash.h.

35{ return m_buffer.size(); }

◆ name()

std::string Botan::SHA_256::name ( ) const
inlineoverridevirtual
Returns
the hash function name

Implements Botan::HashFunction.

Definition at line 48 of file sha2_32.h.

48{ return "SHA-256"; }

◆ output_length()

size_t Botan::SHA_256::output_length ( ) const
inlineoverridevirtual
Returns
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 49 of file sha2_32.h.

49{ return 32; }

◆ process() [1/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const secure_vector< uint8_t > &  in)
inlineinherited

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

Parameters
inthe input to process
Returns
the result of the call to final()

Definition at line 130 of file buf_comp.h.

131 {
132 add_data(in.data(), in.size());
133 return final();
134 }

◆ process() [2/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const std::string &  in)
inlineinherited

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

Parameters
inthe input to process as a string
Returns
the result of the call to final()

Definition at line 154 of file buf_comp.h.

155 {
156 update(in);
157 return final();
158 }
int(* update)(CTX *, const void *, CC_LONG len)

References update.

◆ process() [3/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const std::vector< uint8_t > &  in)
inlineinherited

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

Parameters
inthe input to process
Returns
the result of the call to final()

Definition at line 142 of file buf_comp.h.

143 {
144 add_data(in.data(), in.size());
145 return final();
146 }

◆ process() [4/4]

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

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

Parameters
inthe input to process as a byte array
lengththe length of the byte array
Returns
the result of the call to final()

Definition at line 118 of file buf_comp.h.

119 {
120 add_data(in, length);
121 return final();
122 }

◆ provider()

std::string Botan::SHA_256::provider ( ) const
overridevirtual
Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Reimplemented from Botan::HashFunction.

Definition at line 209 of file sha2_32.cpp.

210 {
211 return sha256_provider();
212 }

◆ providers()

std::vector< std::string > Botan::HashFunction::providers ( const std::string &  algo_spec)
staticinherited
Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 339 of file hash.cpp.

340 {
341 return probe_providers_of<HashFunction>(algo_spec, {"base", "openssl", "commoncrypto"});
342 }

◆ update() [1/5]

void Botan::Buffered_Computation::update ( const secure_vector< uint8_t > &  in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a secure_vector

Definition at line 39 of file buf_comp.h.

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

◆ update() [2/5]

void Botan::Buffered_Computation::update ( const std::string &  str)
inlineinherited

Add new input to process.

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

Definition at line 66 of file buf_comp.h.

67 {
68 add_data(cast_char_ptr_to_uint8(str.data()), str.size());
69 }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:190

References Botan::cast_char_ptr_to_uint8().

◆ update() [3/5]

void Botan::Buffered_Computation::update ( const std::vector< uint8_t > &  in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a std::vector

Definition at line 48 of file buf_comp.h.

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

◆ update() [4/5]

void Botan::Buffered_Computation::update ( const uint8_t  in[],
size_t  length 
)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a byte array
lengthof param in in bytes

Definition at line 33 of file buf_comp.h.

33{ add_data(in, length); }

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

◆ update() [5/5]

void Botan::Buffered_Computation::update ( uint8_t  in)
inlineinherited

Process a single byte.

Parameters
inthe byte to process

Definition at line 75 of file buf_comp.h.

75{ add_data(&in, 1); }

◆ update_be() [1/3]

void Botan::Buffered_Computation::update_be ( uint16_t  val)
inherited

Definition at line 12 of file buf_comp.cpp.

13 {
14 uint8_t inb[sizeof(val)];
15 store_be(val, inb);
16 add_data(inb, sizeof(inb));
17 }
void store_be(uint16_t in, uint8_t out[2])
Definition loadstor.h:438

References Botan::store_be().

Referenced by Botan::pbkdf2().

◆ update_be() [2/3]

void Botan::Buffered_Computation::update_be ( uint32_t  val)
inherited

Definition at line 19 of file buf_comp.cpp.

20 {
21 uint8_t inb[sizeof(val)];
22 store_be(val, inb);
23 add_data(inb, sizeof(inb));
24 }

References Botan::store_be().

◆ update_be() [3/3]

void Botan::Buffered_Computation::update_be ( uint64_t  val)
inherited

Definition at line 26 of file buf_comp.cpp.

27 {
28 uint8_t inb[sizeof(val)];
29 store_be(val, inb);
30 add_data(inb, sizeof(inb));
31 }

References Botan::store_be().

◆ update_le() [1/3]

void Botan::Buffered_Computation::update_le ( uint16_t  val)
inherited

Definition at line 33 of file buf_comp.cpp.

34 {
35 uint8_t inb[sizeof(val)];
36 store_le(val, inb);
37 add_data(inb, sizeof(inb));
38 }
void store_le(uint16_t in, uint8_t out[2])
Definition loadstor.h:454

References Botan::store_le().

◆ update_le() [2/3]

void Botan::Buffered_Computation::update_le ( uint32_t  val)
inherited

Definition at line 40 of file buf_comp.cpp.

41 {
42 uint8_t inb[sizeof(val)];
43 store_le(val, inb);
44 add_data(inb, sizeof(inb));
45 }

References Botan::store_le().

◆ update_le() [3/3]

void Botan::Buffered_Computation::update_le ( uint64_t  val)
inherited

Definition at line 47 of file buf_comp.cpp.

48 {
49 uint8_t inb[sizeof(val)];
50 store_le(val, inb);
51 add_data(inb, sizeof(inb));
52 }

References Botan::store_le().

◆ write_count()

void Botan::MDx_HashFunction::write_count ( uint8_t  out[])
protectedvirtualinherited

Write the count, if used, to this spot

Parameters
outwhere to write the counter to

Definition at line 108 of file mdx_hash.cpp.

109 {
110 BOTAN_ASSERT_NOMSG(m_counter_size <= output_length());
111 BOTAN_ASSERT_NOMSG(m_counter_size >= 8);
112
113 const uint64_t bit_count = m_count * 8;
114
115 if(m_count_big_endian)
116 store_be(bit_count, out + m_counter_size - 8);
117 else
118 store_le(bit_count, out + m_counter_size - 8);
119 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:68

References BOTAN_ASSERT_NOMSG, Botan::Buffered_Computation::output_length(), Botan::store_be(), and Botan::store_le().

Referenced by Botan::MDx_HashFunction::final_result().


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