Botan 2.19.1
Crypto and TLS for C&
mgf1.cpp
Go to the documentation of this file.
1/*
2* MGF1
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/mgf1.h>
9#include <botan/hash.h>
10#include <algorithm>
11
12namespace Botan {
13
15 const uint8_t in[], size_t in_len,
16 uint8_t out[], size_t out_len)
17 {
18 uint32_t counter = 0;
19
20 secure_vector<uint8_t> buffer(hash.output_length());
21 while(out_len)
22 {
23 hash.update(in, in_len);
24 hash.update_be(counter);
25 hash.final(buffer.data());
26
27 const size_t xored = std::min<size_t>(buffer.size(), out_len);
28 xor_buf(out, buffer.data(), xored);
29 out += xored;
30 out_len -= xored;
31
32 ++counter;
33 }
34 }
35
36}
Definition: alg_id.cpp:13
void mgf1_mask(HashFunction &hash, const uint8_t in[], size_t in_len, uint8_t out[], size_t out_len)
Definition: mgf1.cpp:14
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:262
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
MechanismType hash