Botan 3.10.0
Crypto and TLS for C&
Botan::RIPEMD_160 Class Referencefinal

#include <rmd160.h>

Inheritance diagram for Botan::RIPEMD_160:
Botan::HashFunction Botan::Buffered_Computation

Public Types

using digest_type = secure_vector<uint32_t>

Public Member Functions

void clear () override
HashFunctionclone () const
std::unique_ptr< HashFunctioncopy_state () const override
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
final ()
void final (std::span< uint8_t > out)
template<concepts::resizable_byte_buffer T>
void final (T &out)
void final (uint8_t out[])
std::vector< uint8_t > final_stdvec ()
size_t hash_block_size () const override
std::string name () const override
std::unique_ptr< HashFunctionnew_object () const override
size_t output_length () const override
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (const uint8_t in[], size_t length)
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::span< const uint8_t > in)
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::string_view in)
virtual std::string provider () const
void update (const uint8_t in[], size_t length)
void update (std::span< const uint8_t > in)
void update (std::string_view str)
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_n (digest_type &digest, std::span< const uint8_t > input, size_t blocks)
static std::unique_ptr< HashFunctioncreate (std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< HashFunctioncreate_or_throw (std::string_view algo_spec, std::string_view provider="")
static void init (digest_type &digest)
static std::vector< std::string > providers (std::string_view algo_spec)

Static Public Attributes

static constexpr MD_Endian bit_endianness = MD_Endian::Big
static constexpr size_t block_bytes = 64
static constexpr MD_Endian byte_endianness = MD_Endian::Little
static constexpr size_t ctr_bytes = 8
static constexpr size_t output_bytes = 20

Detailed Description

RIPEMD-160

Definition at line 18 of file rmd160.h.

Member Typedef Documentation

◆ digest_type

Definition at line 20 of file rmd160.h.

Member Function Documentation

◆ clear()

void Botan::RIPEMD_160::clear ( )
inlineoverridevirtual

Reset the state.

Implements Botan::HashFunction.

Definition at line 42 of file rmd160.h.

42{ m_md.clear(); }

◆ clone()

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

Definition at line 85 of file hash.h.

85{ return this->new_object().release(); }
virtual std::unique_ptr< HashFunction > new_object() const =0

References new_object().

◆ compress_n()

void Botan::RIPEMD_160::compress_n ( digest_type & digest,
std::span< const uint8_t > input,
size_t blocks )
static

Definition at line 76 of file rmd160.cpp.

76 {
77 constexpr uint32_t MAGIC2 = 0x5A827999;
78 constexpr uint32_t MAGIC3 = 0x6ED9EBA1;
79 constexpr uint32_t MAGIC4 = 0x8F1BBCDC;
80 constexpr uint32_t MAGIC5 = 0xA953FD4E;
81 constexpr uint32_t MAGIC6 = 0x50A28BE6;
82 constexpr uint32_t MAGIC7 = 0x5C4DD124;
83 constexpr uint32_t MAGIC8 = 0x6D703EF3;
84 constexpr uint32_t MAGIC9 = 0x7A6D76E9;
85
86 std::array<uint32_t, 16> M{};
87
88 BufferSlicer in(input);
89
90 for(size_t i = 0; i != blocks; ++i) {
91 load_le(M, in.take<block_bytes>());
92
93 uint32_t A1 = digest[0];
94 uint32_t B1 = digest[1];
95 uint32_t C1 = digest[2];
96 uint32_t D1 = digest[3];
97 uint32_t E1 = digest[4];
98
99 uint32_t A2 = A1;
100 uint32_t B2 = B1;
101 uint32_t C2 = C1;
102 uint32_t D2 = D1;
103 uint32_t E2 = E1;
104
105 // clang-format off
106
107 F1<11>(A1, B1, C1, D1, E1, M[ 0]);
108 F5< 8>(A2, B2, C2, D2, E2, M[ 5] + MAGIC6);
109 F1<14>(E1, A1, B1, C1, D1, M[ 1]);
110 F5< 9>(E2, A2, B2, C2, D2, M[14] + MAGIC6);
111 F1<15>(D1, E1, A1, B1, C1, M[ 2]);
112 F5< 9>(D2, E2, A2, B2, C2, M[ 7] + MAGIC6);
113 F1<12>(C1, D1, E1, A1, B1, M[ 3]);
114 F5<11>(C2, D2, E2, A2, B2, M[ 0] + MAGIC6);
115 F1< 5>(B1, C1, D1, E1, A1, M[ 4]);
116 F5<13>(B2, C2, D2, E2, A2, M[ 9] + MAGIC6);
117 F1< 8>(A1, B1, C1, D1, E1, M[ 5]);
118 F5<15>(A2, B2, C2, D2, E2, M[ 2] + MAGIC6);
119 F1< 7>(E1, A1, B1, C1, D1, M[ 6]);
120 F5<15>(E2, A2, B2, C2, D2, M[11] + MAGIC6);
121 F1< 9>(D1, E1, A1, B1, C1, M[ 7]);
122 F5< 5>(D2, E2, A2, B2, C2, M[ 4] + MAGIC6);
123 F1<11>(C1, D1, E1, A1, B1, M[ 8]);
124 F5< 7>(C2, D2, E2, A2, B2, M[13] + MAGIC6);
125 F1<13>(B1, C1, D1, E1, A1, M[ 9]);
126 F5< 7>(B2, C2, D2, E2, A2, M[ 6] + MAGIC6);
127 F1<14>(A1, B1, C1, D1, E1, M[10]);
128 F5< 8>(A2, B2, C2, D2, E2, M[15] + MAGIC6);
129 F1<15>(E1, A1, B1, C1, D1, M[11]);
130 F5<11>(E2, A2, B2, C2, D2, M[ 8] + MAGIC6);
131 F1< 6>(D1, E1, A1, B1, C1, M[12]);
132 F5<14>(D2, E2, A2, B2, C2, M[ 1] + MAGIC6);
133 F1< 7>(C1, D1, E1, A1, B1, M[13]);
134 F5<14>(C2, D2, E2, A2, B2, M[10] + MAGIC6);
135 F1< 9>(B1, C1, D1, E1, A1, M[14]);
136 F5<12>(B2, C2, D2, E2, A2, M[ 3] + MAGIC6);
137 F1< 8>(A1, B1, C1, D1, E1, M[15]);
138 F5< 6>(A2, B2, C2, D2, E2, M[12] + MAGIC6);
139
140 F2< 7>(E1, A1, B1, C1, D1, M[ 7] + MAGIC2);
141 F4< 9>(E2, A2, B2, C2, D2, M[ 6] + MAGIC7);
142 F2< 6>(D1, E1, A1, B1, C1, M[ 4] + MAGIC2);
143 F4<13>(D2, E2, A2, B2, C2, M[11] + MAGIC7);
144 F2< 8>(C1, D1, E1, A1, B1, M[13] + MAGIC2);
145 F4<15>(C2, D2, E2, A2, B2, M[ 3] + MAGIC7);
146 F2<13>(B1, C1, D1, E1, A1, M[ 1] + MAGIC2);
147 F4< 7>(B2, C2, D2, E2, A2, M[ 7] + MAGIC7);
148 F2<11>(A1, B1, C1, D1, E1, M[10] + MAGIC2);
149 F4<12>(A2, B2, C2, D2, E2, M[ 0] + MAGIC7);
150 F2< 9>(E1, A1, B1, C1, D1, M[ 6] + MAGIC2);
151 F4< 8>(E2, A2, B2, C2, D2, M[13] + MAGIC7);
152 F2< 7>(D1, E1, A1, B1, C1, M[15] + MAGIC2);
153 F4< 9>(D2, E2, A2, B2, C2, M[ 5] + MAGIC7);
154 F2<15>(C1, D1, E1, A1, B1, M[ 3] + MAGIC2);
155 F4<11>(C2, D2, E2, A2, B2, M[10] + MAGIC7);
156 F2< 7>(B1, C1, D1, E1, A1, M[12] + MAGIC2);
157 F4< 7>(B2, C2, D2, E2, A2, M[14] + MAGIC7);
158 F2<12>(A1, B1, C1, D1, E1, M[ 0] + MAGIC2);
159 F4< 7>(A2, B2, C2, D2, E2, M[15] + MAGIC7);
160 F2<15>(E1, A1, B1, C1, D1, M[ 9] + MAGIC2);
161 F4<12>(E2, A2, B2, C2, D2, M[ 8] + MAGIC7);
162 F2< 9>(D1, E1, A1, B1, C1, M[ 5] + MAGIC2);
163 F4< 7>(D2, E2, A2, B2, C2, M[12] + MAGIC7);
164 F2<11>(C1, D1, E1, A1, B1, M[ 2] + MAGIC2);
165 F4< 6>(C2, D2, E2, A2, B2, M[ 4] + MAGIC7);
166 F2< 7>(B1, C1, D1, E1, A1, M[14] + MAGIC2);
167 F4<15>(B2, C2, D2, E2, A2, M[ 9] + MAGIC7);
168 F2<13>(A1, B1, C1, D1, E1, M[11] + MAGIC2);
169 F4<13>(A2, B2, C2, D2, E2, M[ 1] + MAGIC7);
170 F2<12>(E1, A1, B1, C1, D1, M[ 8] + MAGIC2);
171 F4<11>(E2, A2, B2, C2, D2, M[ 2] + MAGIC7);
172
173 F3<11>(D1, E1, A1, B1, C1, M[ 3] + MAGIC3);
174 F3< 9>(D2, E2, A2, B2, C2, M[15] + MAGIC8);
175 F3<13>(C1, D1, E1, A1, B1, M[10] + MAGIC3);
176 F3< 7>(C2, D2, E2, A2, B2, M[ 5] + MAGIC8);
177 F3< 6>(B1, C1, D1, E1, A1, M[14] + MAGIC3);
178 F3<15>(B2, C2, D2, E2, A2, M[ 1] + MAGIC8);
179 F3< 7>(A1, B1, C1, D1, E1, M[ 4] + MAGIC3);
180 F3<11>(A2, B2, C2, D2, E2, M[ 3] + MAGIC8);
181 F3<14>(E1, A1, B1, C1, D1, M[ 9] + MAGIC3);
182 F3< 8>(E2, A2, B2, C2, D2, M[ 7] + MAGIC8);
183 F3< 9>(D1, E1, A1, B1, C1, M[15] + MAGIC3);
184 F3< 6>(D2, E2, A2, B2, C2, M[14] + MAGIC8);
185 F3<13>(C1, D1, E1, A1, B1, M[ 8] + MAGIC3);
186 F3< 6>(C2, D2, E2, A2, B2, M[ 6] + MAGIC8);
187 F3<15>(B1, C1, D1, E1, A1, M[ 1] + MAGIC3);
188 F3<14>(B2, C2, D2, E2, A2, M[ 9] + MAGIC8);
189 F3<14>(A1, B1, C1, D1, E1, M[ 2] + MAGIC3);
190 F3<12>(A2, B2, C2, D2, E2, M[11] + MAGIC8);
191 F3< 8>(E1, A1, B1, C1, D1, M[ 7] + MAGIC3);
192 F3<13>(E2, A2, B2, C2, D2, M[ 8] + MAGIC8);
193 F3<13>(D1, E1, A1, B1, C1, M[ 0] + MAGIC3);
194 F3< 5>(D2, E2, A2, B2, C2, M[12] + MAGIC8);
195 F3< 6>(C1, D1, E1, A1, B1, M[ 6] + MAGIC3);
196 F3<14>(C2, D2, E2, A2, B2, M[ 2] + MAGIC8);
197 F3< 5>(B1, C1, D1, E1, A1, M[13] + MAGIC3);
198 F3<13>(B2, C2, D2, E2, A2, M[10] + MAGIC8);
199 F3<12>(A1, B1, C1, D1, E1, M[11] + MAGIC3);
200 F3<13>(A2, B2, C2, D2, E2, M[ 0] + MAGIC8);
201 F3< 7>(E1, A1, B1, C1, D1, M[ 5] + MAGIC3);
202 F3< 7>(E2, A2, B2, C2, D2, M[ 4] + MAGIC8);
203 F3< 5>(D1, E1, A1, B1, C1, M[12] + MAGIC3);
204 F3< 5>(D2, E2, A2, B2, C2, M[13] + MAGIC8);
205
206 F4<11>(C1, D1, E1, A1, B1, M[ 1] + MAGIC4);
207 F2<15>(C2, D2, E2, A2, B2, M[ 8] + MAGIC9);
208 F4<12>(B1, C1, D1, E1, A1, M[ 9] + MAGIC4);
209 F2< 5>(B2, C2, D2, E2, A2, M[ 6] + MAGIC9);
210 F4<14>(A1, B1, C1, D1, E1, M[11] + MAGIC4);
211 F2< 8>(A2, B2, C2, D2, E2, M[ 4] + MAGIC9);
212 F4<15>(E1, A1, B1, C1, D1, M[10] + MAGIC4);
213 F2<11>(E2, A2, B2, C2, D2, M[ 1] + MAGIC9);
214 F4<14>(D1, E1, A1, B1, C1, M[ 0] + MAGIC4);
215 F2<14>(D2, E2, A2, B2, C2, M[ 3] + MAGIC9);
216 F4<15>(C1, D1, E1, A1, B1, M[ 8] + MAGIC4);
217 F2<14>(C2, D2, E2, A2, B2, M[11] + MAGIC9);
218 F4< 9>(B1, C1, D1, E1, A1, M[12] + MAGIC4);
219 F2< 6>(B2, C2, D2, E2, A2, M[15] + MAGIC9);
220 F4< 8>(A1, B1, C1, D1, E1, M[ 4] + MAGIC4);
221 F2<14>(A2, B2, C2, D2, E2, M[ 0] + MAGIC9);
222 F4< 9>(E1, A1, B1, C1, D1, M[13] + MAGIC4);
223 F2< 6>(E2, A2, B2, C2, D2, M[ 5] + MAGIC9);
224 F4<14>(D1, E1, A1, B1, C1, M[ 3] + MAGIC4);
225 F2< 9>(D2, E2, A2, B2, C2, M[12] + MAGIC9);
226 F4< 5>(C1, D1, E1, A1, B1, M[ 7] + MAGIC4);
227 F2<12>(C2, D2, E2, A2, B2, M[ 2] + MAGIC9);
228 F4< 6>(B1, C1, D1, E1, A1, M[15] + MAGIC4);
229 F2< 9>(B2, C2, D2, E2, A2, M[13] + MAGIC9);
230 F4< 8>(A1, B1, C1, D1, E1, M[14] + MAGIC4);
231 F2<12>(A2, B2, C2, D2, E2, M[ 9] + MAGIC9);
232 F4< 6>(E1, A1, B1, C1, D1, M[ 5] + MAGIC4);
233 F2< 5>(E2, A2, B2, C2, D2, M[ 7] + MAGIC9);
234 F4< 5>(D1, E1, A1, B1, C1, M[ 6] + MAGIC4);
235 F2<15>(D2, E2, A2, B2, C2, M[10] + MAGIC9);
236 F4<12>(C1, D1, E1, A1, B1, M[ 2] + MAGIC4);
237 F2< 8>(C2, D2, E2, A2, B2, M[14] + MAGIC9);
238
239 F5< 9>(B1, C1, D1, E1, A1, M[ 4] + MAGIC5);
240 F1< 8>(B2, C2, D2, E2, A2, M[12]);
241 F5<15>(A1, B1, C1, D1, E1, M[ 0] + MAGIC5);
242 F1< 5>(A2, B2, C2, D2, E2, M[15]);
243 F5< 5>(E1, A1, B1, C1, D1, M[ 5] + MAGIC5);
244 F1<12>(E2, A2, B2, C2, D2, M[10]);
245 F5<11>(D1, E1, A1, B1, C1, M[ 9] + MAGIC5);
246 F1< 9>(D2, E2, A2, B2, C2, M[ 4]);
247 F5< 6>(C1, D1, E1, A1, B1, M[ 7] + MAGIC5);
248 F1<12>(C2, D2, E2, A2, B2, M[ 1]);
249 F5< 8>(B1, C1, D1, E1, A1, M[12] + MAGIC5);
250 F1< 5>(B2, C2, D2, E2, A2, M[ 5]);
251 F5<13>(A1, B1, C1, D1, E1, M[ 2] + MAGIC5);
252 F1<14>(A2, B2, C2, D2, E2, M[ 8]);
253 F5<12>(E1, A1, B1, C1, D1, M[10] + MAGIC5);
254 F1< 6>(E2, A2, B2, C2, D2, M[ 7]);
255 F5< 5>(D1, E1, A1, B1, C1, M[14] + MAGIC5);
256 F1< 8>(D2, E2, A2, B2, C2, M[ 6]);
257 F5<12>(C1, D1, E1, A1, B1, M[ 1] + MAGIC5);
258 F1<13>(C2, D2, E2, A2, B2, M[ 2]);
259 F5<13>(B1, C1, D1, E1, A1, M[ 3] + MAGIC5);
260 F1< 6>(B2, C2, D2, E2, A2, M[13]);
261 F5<14>(A1, B1, C1, D1, E1, M[ 8] + MAGIC5);
262 F1< 5>(A2, B2, C2, D2, E2, M[14]);
263 F5<11>(E1, A1, B1, C1, D1, M[11] + MAGIC5);
264 F1<15>(E2, A2, B2, C2, D2, M[ 0]);
265 F5< 8>(D1, E1, A1, B1, C1, M[ 6] + MAGIC5);
266 F1<13>(D2, E2, A2, B2, C2, M[ 3]);
267 F5< 5>(C1, D1, E1, A1, B1, M[15] + MAGIC5);
268 F1<11>(C2, D2, E2, A2, B2, M[ 9]);
269 F5< 6>(B1, C1, D1, E1, A1, M[13] + MAGIC5);
270 F1<11>(B2, C2, D2, E2, A2, M[11]);
271
272 // clang-format on
273
274 C1 = digest[1] + C1 + D2;
275 digest[1] = digest[2] + D1 + E2;
276 digest[2] = digest[3] + E1 + A2;
277 digest[3] = digest[4] + A1 + B2;
278 digest[4] = digest[0] + B1 + C2;
279 digest[0] = C1;
280 }
281}
static constexpr size_t block_bytes
Definition rmd160.h:24
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:495

References block_bytes, Botan::load_le(), and Botan::BufferSlicer::take().

◆ copy_state()

std::unique_ptr< HashFunction > Botan::RIPEMD_160::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 291 of file rmd160.cpp.

291 {
292 return std::make_unique<RIPEMD_160>(*this);
293}

◆ create()

std::unique_ptr< HashFunction > Botan::HashFunction::create ( std::string_view algo_spec,
std::string_view 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 111 of file hash.cpp.

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

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

Referenced by botan_hash_init(), Botan::BlockCipher::create(), Botan::EncryptionPaddingScheme::create(), create(), Botan::KDF::create(), Botan::MessageAuthenticationCode::create(), Botan::PasswordHashFamily::create(), Botan::PBKDF::create(), Botan::SignaturePaddingScheme::create(), and create_or_throw().

◆ create_or_throw()

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

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

Parameters
algo_specalgorithm name
providerprovider implementation to use Throws Lookup_Error if not found.

Definition at line 308 of file hash.cpp.

308 {
309 if(auto hash = HashFunction::create(algo, provider)) {
310 return hash;
311 }
312 throw Lookup_Error("Hash", algo, provider);
313}

References create(), and provider().

Referenced by botan_pubkey_fingerprint(), botan_pubkey_sm2_compute_za(), Botan::OCSP::CertID::CertID(), Botan::create_hex_fingerprint(), Botan::Sodium::crypto_hash_sha256(), Botan::Sodium::crypto_hash_sha512(), Botan::Bcrypt_PBKDF::derive_key(), Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::expand_message_xmd(), Botan::TLS::Handshake_Hash::final(), Botan::Certificate_Store_In_Memory::find_cert_by_pubkey_sha1(), Botan::Certificate_Store_In_Memory::find_cert_by_raw_subject_dn_sha256(), Botan::generate_dsa_primes(), Botan::LMOTS_Params::hash(), Botan::LMS_Params::hash(), Botan::Classic_McEliece_Parameters::hash_func(), Botan::OCSP::CertID::is_id_for(), Botan::TLS::make_hello_random(), Botan::Roughtime::nonce_from_blind(), Botan::PKCS1v15_Raw_SignaturePaddingScheme::PKCS1v15_Raw_SignaturePaddingScheme(), Botan::TLS::Transcript_Hash_State::set_algorithm(), Botan::RTSS_Share::split(), Botan::srp6_client_agree(), Botan::srp6_generate_verifier(), Botan::SRP6_Server_Session::step1(), Botan::SRP6_Server_Session::step2(), Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID(), and Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash().

◆ final() [1/4]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result as a container of your choice.

Returns
a contiguous container holding the result

Definition at line 77 of file buf_comp.h.

77 {
78 T output(output_length());
79 final_result(output);
80 return output;
81 }
virtual size_t output_length() const =0

References output_length().

◆ final() [2/4]

void Botan::Buffered_Computation::final ( std::span< uint8_t > out)
inherited

Definition at line 54 of file buf_comp.cpp.

54 {
55 BOTAN_ARG_CHECK(out.size() >= output_length(), "provided output buffer has insufficient capacity");
56 final_result(out);
57}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and output_length().

◆ final() [3/4]

template<concepts::resizable_byte_buffer T>
void Botan::Buffered_Computation::final ( T & out)
inlineinherited

Definition at line 88 of file buf_comp.h.

88 {
89 out.resize(output_length());
90 final_result(out);
91 }

References output_length().

◆ final() [4/4]

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 69 of file buf_comp.h.

69{ final_result({out, output_length()}); }

References output_length().

Referenced by final_stdvec(), Botan::PseudorandomKeyGeneration::gen(), Botan::TPM2::Verification_Operation::is_valid_signature(), Botan::mgf1_mask(), Botan::KMAC::operator=(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), Botan::TPM2::Signature_Operation::sign(), and Botan::sm2_compute_za().

◆ final_stdvec()

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

Definition at line 83 of file buf_comp.h.

83{ return final<std::vector<uint8_t>>(); }
void final(uint8_t out[])
Definition buf_comp.h:69

References final().

◆ hash_block_size()

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

Reimplemented from Botan::HashFunction.

Definition at line 36 of file rmd160.h.

36{ return block_bytes; }

References block_bytes.

◆ init()

void Botan::RIPEMD_160::init ( digest_type & digest)
static

Definition at line 283 of file rmd160.cpp.

283 {
284 digest.assign({0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0});
285}

◆ name()

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

Implements Botan::HashFunction.

Definition at line 32 of file rmd160.h.

32{ return "RIPEMD-160"; }

◆ new_object()

std::unique_ptr< HashFunction > Botan::RIPEMD_160::new_object ( ) const
overridevirtual
Returns
new object representing the same algorithm as *this

Implements Botan::HashFunction.

Definition at line 287 of file rmd160.cpp.

287 {
288 return std::make_unique<RIPEMD_160>();
289}

◆ output_length()

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

Implements Botan::Buffered_Computation.

Definition at line 34 of file rmd160.h.

34{ return output_bytes; }
static constexpr size_t output_bytes
Definition rmd160.h:25

References output_bytes.

◆ process() [1/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
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 101 of file buf_comp.h.

101 {
102 update(in, length);
103 return final<T>();
104 }
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:34

References final(), and update().

Referenced by Botan::Kyber_Symmetric_Primitives::H(), Botan::Kyber_Symmetric_Primitives::H(), and Botan::Kyber_Symmetric_Primitives::H().

◆ process() [2/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::span< const uint8_t > in)
inlineinherited

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

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

Definition at line 125 of file buf_comp.h.

125 {
126 update(in);
127 return final<T>();
128 }

References final(), and update().

◆ process() [3/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::string_view 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 113 of file buf_comp.h.

113 {
114 update(in);
115 return final<T>();
116 }

References final(), and update().

◆ provider()

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

Reimplemented in Botan::Ascon_Hash256, Botan::Keccak_1600, Botan::SHA_1, Botan::SHA_224, Botan::SHA_256, Botan::SHA_384, Botan::SHA_3, Botan::SHA_512, Botan::SHA_512_256, Botan::SHAKE_128, and Botan::SHAKE_256.

Definition at line 49 of file hash.h.

49{ return "base"; }

Referenced by create(), and create_or_throw().

◆ providers()

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

Definition at line 315 of file hash.cpp.

315 {
316 return probe_providers_of<HashFunction>(algo_spec, {"base", "commoncrypto"});
317}
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
Definition scan_name.h:105

References Botan::probe_providers_of().

◆ update() [1/4]

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 34 of file buf_comp.h.

34{ add_data({in, length}); }

Referenced by Botan::PseudorandomKeyGeneration::gen(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), Botan::TLS::TLS_NULL_HMAC_AEAD_Mode::set_associated_data_n(), and Botan::sm2_compute_za().

◆ update() [2/4]

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

Add new input to process.

Parameters
inthe input to process as a contiguous data range

Definition at line 40 of file buf_comp.h.

40{ add_data(in); }

◆ update() [3/4]

void Botan::Buffered_Computation::update ( std::string_view str)
inherited

Add new input to process.

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

Definition at line 14 of file buf_comp.cpp.

14 {
15 add_data(as_span_of_bytes(str));
16}
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:28

References Botan::as_span_of_bytes().

◆ update() [4/4]

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 61 of file buf_comp.h.

61{ add_data({&in, 1}); }

◆ update_be() [1/3]

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

Definition at line 18 of file buf_comp.cpp.

18 {
19 uint8_t inb[sizeof(val)];
20 store_be(val, inb);
21 add_data({inb, sizeof(inb)});
22}
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::store_be().

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

◆ update_be() [2/3]

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

Definition at line 24 of file buf_comp.cpp.

24 {
25 uint8_t inb[sizeof(val)];
26 store_be(val, inb);
27 add_data({inb, sizeof(inb)});
28}

References Botan::store_be().

◆ update_be() [3/3]

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

Definition at line 30 of file buf_comp.cpp.

30 {
31 uint8_t inb[sizeof(val)];
32 store_be(val, inb);
33 add_data({inb, sizeof(inb)});
34}

References Botan::store_be().

◆ update_le() [1/3]

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

Definition at line 36 of file buf_comp.cpp.

36 {
37 uint8_t inb[sizeof(val)];
38 store_le(val, inb);
39 add_data({inb, sizeof(inb)});
40}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736

References Botan::store_le().

◆ update_le() [2/3]

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

Definition at line 42 of file buf_comp.cpp.

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

References Botan::store_le().

◆ update_le() [3/3]

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

Definition at line 48 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().

Member Data Documentation

◆ bit_endianness

MD_Endian Botan::RIPEMD_160::bit_endianness = MD_Endian::Big
staticconstexpr

Definition at line 23 of file rmd160.h.

◆ block_bytes

size_t Botan::RIPEMD_160::block_bytes = 64
staticconstexpr

Definition at line 24 of file rmd160.h.

Referenced by compress_n(), and hash_block_size().

◆ byte_endianness

MD_Endian Botan::RIPEMD_160::byte_endianness = MD_Endian::Little
staticconstexpr

Definition at line 22 of file rmd160.h.

◆ ctr_bytes

size_t Botan::RIPEMD_160::ctr_bytes = 8
staticconstexpr

Definition at line 26 of file rmd160.h.

◆ output_bytes

size_t Botan::RIPEMD_160::output_bytes = 20
staticconstexpr

Definition at line 25 of file rmd160.h.

Referenced by output_length().


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