Botan 3.5.0
Crypto and TLS for C&
Botan::SM3 Class Referencefinal

#include <sm3.h>

Inheritance diagram for Botan::SM3:
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>>
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>>
T process (const uint8_t in[], size_t length)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (std::span< const uint8_t > in)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
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::Big
 
static constexpr size_t ctr_bytes = 8
 
static constexpr size_t output_bytes = 32
 

Detailed Description

SM3

Definition at line 18 of file sm3.h.

Member Typedef Documentation

◆ digest_type

Definition at line 20 of file sm3.h.

Member Function Documentation

◆ clear()

void Botan::SM3::clear ( )
inlineoverridevirtual

Reset the state.

Implements Botan::HashFunction.

Definition at line 42 of file sm3.h.

42{ m_md.clear(); }

◆ clone()

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

Definition at line 87 of file hash.h.

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

◆ compress_n()

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

Definition at line 81 of file sm3.cpp.

81 {
82 uint32_t A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4], F = digest[5], G = digest[6],
83 H = digest[7];
84
85 BufferSlicer in(input);
86
87 for(size_t i = 0; i != blocks; ++i) {
88 const auto block = in.take(block_bytes);
89
90 uint32_t W00 = load_be<uint32_t>(block.data(), 0);
91 uint32_t W01 = load_be<uint32_t>(block.data(), 1);
92 uint32_t W02 = load_be<uint32_t>(block.data(), 2);
93 uint32_t W03 = load_be<uint32_t>(block.data(), 3);
94 uint32_t W04 = load_be<uint32_t>(block.data(), 4);
95 uint32_t W05 = load_be<uint32_t>(block.data(), 5);
96 uint32_t W06 = load_be<uint32_t>(block.data(), 6);
97 uint32_t W07 = load_be<uint32_t>(block.data(), 7);
98 uint32_t W08 = load_be<uint32_t>(block.data(), 8);
99 uint32_t W09 = load_be<uint32_t>(block.data(), 9);
100 uint32_t W10 = load_be<uint32_t>(block.data(), 10);
101 uint32_t W11 = load_be<uint32_t>(block.data(), 11);
102 uint32_t W12 = load_be<uint32_t>(block.data(), 12);
103 uint32_t W13 = load_be<uint32_t>(block.data(), 13);
104 uint32_t W14 = load_be<uint32_t>(block.data(), 14);
105 uint32_t W15 = load_be<uint32_t>(block.data(), 15);
106
107 R1(A, B, C, D, E, F, G, H, 0x79CC4519, W00, W00 ^ W04);
108 W00 = SM3_E(W00, W07, W13, W03, W10);
109 R1(D, A, B, C, H, E, F, G, 0xF3988A32, W01, W01 ^ W05);
110 W01 = SM3_E(W01, W08, W14, W04, W11);
111 R1(C, D, A, B, G, H, E, F, 0xE7311465, W02, W02 ^ W06);
112 W02 = SM3_E(W02, W09, W15, W05, W12);
113 R1(B, C, D, A, F, G, H, E, 0xCE6228CB, W03, W03 ^ W07);
114 W03 = SM3_E(W03, W10, W00, W06, W13);
115 R1(A, B, C, D, E, F, G, H, 0x9CC45197, W04, W04 ^ W08);
116 W04 = SM3_E(W04, W11, W01, W07, W14);
117 R1(D, A, B, C, H, E, F, G, 0x3988A32F, W05, W05 ^ W09);
118 W05 = SM3_E(W05, W12, W02, W08, W15);
119 R1(C, D, A, B, G, H, E, F, 0x7311465E, W06, W06 ^ W10);
120 W06 = SM3_E(W06, W13, W03, W09, W00);
121 R1(B, C, D, A, F, G, H, E, 0xE6228CBC, W07, W07 ^ W11);
122 W07 = SM3_E(W07, W14, W04, W10, W01);
123 R1(A, B, C, D, E, F, G, H, 0xCC451979, W08, W08 ^ W12);
124 W08 = SM3_E(W08, W15, W05, W11, W02);
125 R1(D, A, B, C, H, E, F, G, 0x988A32F3, W09, W09 ^ W13);
126 W09 = SM3_E(W09, W00, W06, W12, W03);
127 R1(C, D, A, B, G, H, E, F, 0x311465E7, W10, W10 ^ W14);
128 W10 = SM3_E(W10, W01, W07, W13, W04);
129 R1(B, C, D, A, F, G, H, E, 0x6228CBCE, W11, W11 ^ W15);
130 W11 = SM3_E(W11, W02, W08, W14, W05);
131 R1(A, B, C, D, E, F, G, H, 0xC451979C, W12, W12 ^ W00);
132 W12 = SM3_E(W12, W03, W09, W15, W06);
133 R1(D, A, B, C, H, E, F, G, 0x88A32F39, W13, W13 ^ W01);
134 W13 = SM3_E(W13, W04, W10, W00, W07);
135 R1(C, D, A, B, G, H, E, F, 0x11465E73, W14, W14 ^ W02);
136 W14 = SM3_E(W14, W05, W11, W01, W08);
137 R1(B, C, D, A, F, G, H, E, 0x228CBCE6, W15, W15 ^ W03);
138 W15 = SM3_E(W15, W06, W12, W02, W09);
139 R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
140 W00 = SM3_E(W00, W07, W13, W03, W10);
141 R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
142 W01 = SM3_E(W01, W08, W14, W04, W11);
143 R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
144 W02 = SM3_E(W02, W09, W15, W05, W12);
145 R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
146 W03 = SM3_E(W03, W10, W00, W06, W13);
147 R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
148 W04 = SM3_E(W04, W11, W01, W07, W14);
149 R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
150 W05 = SM3_E(W05, W12, W02, W08, W15);
151 R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
152 W06 = SM3_E(W06, W13, W03, W09, W00);
153 R2(B, C, D, A, F, G, H, E, 0xC53D43CE, W07, W07 ^ W11);
154 W07 = SM3_E(W07, W14, W04, W10, W01);
155 R2(A, B, C, D, E, F, G, H, 0x8A7A879D, W08, W08 ^ W12);
156 W08 = SM3_E(W08, W15, W05, W11, W02);
157 R2(D, A, B, C, H, E, F, G, 0x14F50F3B, W09, W09 ^ W13);
158 W09 = SM3_E(W09, W00, W06, W12, W03);
159 R2(C, D, A, B, G, H, E, F, 0x29EA1E76, W10, W10 ^ W14);
160 W10 = SM3_E(W10, W01, W07, W13, W04);
161 R2(B, C, D, A, F, G, H, E, 0x53D43CEC, W11, W11 ^ W15);
162 W11 = SM3_E(W11, W02, W08, W14, W05);
163 R2(A, B, C, D, E, F, G, H, 0xA7A879D8, W12, W12 ^ W00);
164 W12 = SM3_E(W12, W03, W09, W15, W06);
165 R2(D, A, B, C, H, E, F, G, 0x4F50F3B1, W13, W13 ^ W01);
166 W13 = SM3_E(W13, W04, W10, W00, W07);
167 R2(C, D, A, B, G, H, E, F, 0x9EA1E762, W14, W14 ^ W02);
168 W14 = SM3_E(W14, W05, W11, W01, W08);
169 R2(B, C, D, A, F, G, H, E, 0x3D43CEC5, W15, W15 ^ W03);
170 W15 = SM3_E(W15, W06, W12, W02, W09);
171 R2(A, B, C, D, E, F, G, H, 0x7A879D8A, W00, W00 ^ W04);
172 W00 = SM3_E(W00, W07, W13, W03, W10);
173 R2(D, A, B, C, H, E, F, G, 0xF50F3B14, W01, W01 ^ W05);
174 W01 = SM3_E(W01, W08, W14, W04, W11);
175 R2(C, D, A, B, G, H, E, F, 0xEA1E7629, W02, W02 ^ W06);
176 W02 = SM3_E(W02, W09, W15, W05, W12);
177 R2(B, C, D, A, F, G, H, E, 0xD43CEC53, W03, W03 ^ W07);
178 W03 = SM3_E(W03, W10, W00, W06, W13);
179 R2(A, B, C, D, E, F, G, H, 0xA879D8A7, W04, W04 ^ W08);
180 W04 = SM3_E(W04, W11, W01, W07, W14);
181 R2(D, A, B, C, H, E, F, G, 0x50F3B14F, W05, W05 ^ W09);
182 W05 = SM3_E(W05, W12, W02, W08, W15);
183 R2(C, D, A, B, G, H, E, F, 0xA1E7629E, W06, W06 ^ W10);
184 W06 = SM3_E(W06, W13, W03, W09, W00);
185 R2(B, C, D, A, F, G, H, E, 0x43CEC53D, W07, W07 ^ W11);
186 W07 = SM3_E(W07, W14, W04, W10, W01);
187 R2(A, B, C, D, E, F, G, H, 0x879D8A7A, W08, W08 ^ W12);
188 W08 = SM3_E(W08, W15, W05, W11, W02);
189 R2(D, A, B, C, H, E, F, G, 0x0F3B14F5, W09, W09 ^ W13);
190 W09 = SM3_E(W09, W00, W06, W12, W03);
191 R2(C, D, A, B, G, H, E, F, 0x1E7629EA, W10, W10 ^ W14);
192 W10 = SM3_E(W10, W01, W07, W13, W04);
193 R2(B, C, D, A, F, G, H, E, 0x3CEC53D4, W11, W11 ^ W15);
194 W11 = SM3_E(W11, W02, W08, W14, W05);
195 R2(A, B, C, D, E, F, G, H, 0x79D8A7A8, W12, W12 ^ W00);
196 W12 = SM3_E(W12, W03, W09, W15, W06);
197 R2(D, A, B, C, H, E, F, G, 0xF3B14F50, W13, W13 ^ W01);
198 W13 = SM3_E(W13, W04, W10, W00, W07);
199 R2(C, D, A, B, G, H, E, F, 0xE7629EA1, W14, W14 ^ W02);
200 W14 = SM3_E(W14, W05, W11, W01, W08);
201 R2(B, C, D, A, F, G, H, E, 0xCEC53D43, W15, W15 ^ W03);
202 W15 = SM3_E(W15, W06, W12, W02, W09);
203 R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
204 W00 = SM3_E(W00, W07, W13, W03, W10);
205 R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
206 W01 = SM3_E(W01, W08, W14, W04, W11);
207 R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
208 W02 = SM3_E(W02, W09, W15, W05, W12);
209 R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
210 W03 = SM3_E(W03, W10, W00, W06, W13);
211 R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
212 R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
213 R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
214 R2(B, C, D, A, F, G, H, E, 0xC53D43CE, W07, W07 ^ W11);
215 R2(A, B, C, D, E, F, G, H, 0x8A7A879D, W08, W08 ^ W12);
216 R2(D, A, B, C, H, E, F, G, 0x14F50F3B, W09, W09 ^ W13);
217 R2(C, D, A, B, G, H, E, F, 0x29EA1E76, W10, W10 ^ W14);
218 R2(B, C, D, A, F, G, H, E, 0x53D43CEC, W11, W11 ^ W15);
219 R2(A, B, C, D, E, F, G, H, 0xA7A879D8, W12, W12 ^ W00);
220 R2(D, A, B, C, H, E, F, G, 0x4F50F3B1, W13, W13 ^ W01);
221 R2(C, D, A, B, G, H, E, F, 0x9EA1E762, W14, W14 ^ W02);
222 R2(B, C, D, A, F, G, H, E, 0x3D43CEC5, W15, W15 ^ W03);
223
224 A = (digest[0] ^= A);
225 B = (digest[1] ^= B);
226 C = (digest[2] ^= C);
227 D = (digest[3] ^= D);
228 E = (digest[4] ^= E);
229 F = (digest[5] ^= F);
230 G = (digest[6] ^= G);
231 H = (digest[7] ^= H);
232 }
233}
static constexpr size_t block_bytes
Definition sm3.h:24
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:467

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

◆ copy_state()

std::unique_ptr< HashFunction > Botan::SM3::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 244 of file sm3.cpp.

244 {
245 return std::make_unique<SM3>(*this);
246}

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

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

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

◆ create_or_throw()

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

78 {
79 T output(output_length());
80 final_result(output);
81 return output;
82 }
virtual size_t output_length() const =0
FE_25519 T
Definition ge.cpp:34

References T.

◆ final() [2/4]

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

Definition at line 86 of file buf_comp.h.

86 {
87 BOTAN_ARG_CHECK(out.size() >= output_length(), "provided output buffer has insufficient capacity");
88 final_result(out);
89 }
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29

References BOTAN_ARG_CHECK.

◆ final() [3/4]

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

Definition at line 92 of file buf_comp.h.

92 {
93 out.resize(output_length());
94 final_result(out);
95 }

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

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

Referenced by Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::PseudorandomKeyGeneration::gen(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Dilithium::Polynomial::poly_challenge(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), Botan::Sphincs_Hash_Functions_Shake::PRF_msg(), and Botan::sm2_compute_za().

◆ final_stdvec()

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

Definition at line 84 of file buf_comp.h.

References final.

◆ hash_block_size()

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

Reimplemented from Botan::HashFunction.

Definition at line 36 of file sm3.h.

36{ return block_bytes; }

References block_bytes.

◆ init()

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

Definition at line 235 of file sm3.cpp.

235 {
236 digest.assign(
237 {0x7380166fUL, 0x4914b2b9UL, 0x172442d7UL, 0xda8a0600UL, 0xa96f30bcUL, 0x163138aaUL, 0xe38dee4dUL, 0xb0fb0e4eUL});
238}

◆ name()

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

Implements Botan::HashFunction.

Definition at line 32 of file sm3.h.

32{ return "SM3"; }

◆ new_object()

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

Implements Botan::HashFunction.

Definition at line 240 of file sm3.cpp.

240 {
241 return std::make_unique<SM3>();
242}

◆ output_length()

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

Implements Botan::Buffered_Computation.

Definition at line 34 of file sm3.h.

34{ return output_bytes; }
static constexpr size_t output_bytes
Definition sm3.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 105 of file buf_comp.h.

105 {
106 update(in, length);
107 return final<T>();
108 }
int(* update)(CTX *, const void *, CC_LONG len)

References final, and update.

Referenced by Botan::Dilithium_Symmetric_Primitives::CRH(), Botan::Dilithium_Symmetric_Primitives::H(), 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 129 of file buf_comp.h.

129 {
130 update(in);
131 return final<T>();
132 }

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

117 {
118 update(in);
119 return final<T>();
120 }

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::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 Botan::HashFunction::create(), and Botan::HashFunction::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 305 of file hash.cpp.

305 {
306 return probe_providers_of<HashFunction>(algo_spec, {"base", "commoncrypto"});
307}
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

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

41{ add_data(in); }

◆ update() [3/4]

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

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

56{ add_data({cast_char_ptr_to_uint8(str.data()), str.size()}); }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:273

References Botan::cast_char_ptr_to_uint8().

◆ update() [4/4]

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 62 of file buf_comp.h.

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

◆ update_be() [1/3]

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

Definition at line 13 of file buf_comp.cpp.

13 {
14 uint8_t inb[sizeof(val)];
15 store_be(val, inb);
16 add_data({inb, sizeof(inb)});
17}
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:707

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 19 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_be() [3/3]

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

Definition at line 25 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_le() [1/3]

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

Definition at line 31 of file buf_comp.cpp.

31 {
32 uint8_t inb[sizeof(val)];
33 store_le(val, inb);
34 add_data({inb, sizeof(inb)});
35}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:698

References Botan::store_le().

◆ update_le() [2/3]

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

Definition at line 37 of file buf_comp.cpp.

37 {
38 uint8_t inb[sizeof(val)];
39 store_le(val, inb);
40 add_data({inb, sizeof(inb)});
41}

References Botan::store_le().

◆ update_le() [3/3]

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

Definition at line 43 of file buf_comp.cpp.

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

References Botan::store_le().

Member Data Documentation

◆ bit_endianness

MD_Endian Botan::SM3::bit_endianness = MD_Endian::Big
staticconstexpr

Definition at line 23 of file sm3.h.

◆ block_bytes

size_t Botan::SM3::block_bytes = 64
staticconstexpr

Definition at line 24 of file sm3.h.

Referenced by compress_n(), and hash_block_size().

◆ byte_endianness

MD_Endian Botan::SM3::byte_endianness = MD_Endian::Big
staticconstexpr

Definition at line 22 of file sm3.h.

◆ ctr_bytes

size_t Botan::SM3::ctr_bytes = 8
staticconstexpr

Definition at line 26 of file sm3.h.

◆ output_bytes

size_t Botan::SM3::output_bytes = 32
staticconstexpr

Definition at line 25 of file sm3.h.

Referenced by output_length().


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