Botan 3.9.0
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/internal/mgf1.h>
9
10#include <botan/hash.h>
11#include <botan/mem_ops.h>
12#include <algorithm>
13
14namespace Botan {
15
16void mgf1_mask(HashFunction& hash, const uint8_t in[], size_t in_len, uint8_t out[], size_t out_len) {
17 uint32_t counter = 0;
18
19 std::vector<uint8_t> buffer(hash.output_length());
20 while(out_len > 0) {
21 hash.update(in, in_len);
22 hash.update_be(counter);
23 hash.final(buffer.data());
24
25 const size_t xored = std::min<size_t>(buffer.size(), out_len);
26 xor_buf(out, buffer.data(), xored);
27 out += xored;
28 out_len -= xored;
29
30 ++counter;
31 }
32}
33
34} // namespace Botan
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:34
virtual size_t output_length() const =0
void update_be(uint16_t val)
Definition buf_comp.cpp:18
void final(uint8_t out[])
Definition buf_comp.h:69
void mgf1_mask(HashFunction &hash, const uint8_t in[], size_t in_len, uint8_t out[], size_t out_len)
Definition mgf1.cpp:16
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:342