Botan 3.10.0
Crypto and TLS for C&
mgf1.cpp
Go to the documentation of this file.
1/*
2* (C) 1999-2007,2025 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/mgf1.h>
8
9#include <botan/hash.h>
10#include <botan/mem_ops.h>
11#include <algorithm>
12
13namespace Botan {
14
15void mgf1_mask(HashFunction& hash, std::span<const uint8_t> input, std::span<uint8_t> output) {
16 uint32_t counter = 0;
17
18 std::vector<uint8_t> buffer(hash.output_length());
19 while(!output.empty()) {
20 hash.update(input);
21 hash.update_be(counter);
22 hash.final(buffer);
23
24 const size_t xored = std::min<size_t>(buffer.size(), output.size());
25 xor_buf(output.first(xored), std::span{buffer}.first(xored));
26 output = output.subspan(xored);
27
28 ++counter;
29 }
30}
31
32} // 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, std::span< const uint8_t > input, std::span< uint8_t > output)
Definition mgf1.cpp:15
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:342