Botan 3.12.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 const size_t hlen = hash.output_length();
19
20 BOTAN_ASSERT_NOMSG(hlen > 0);
21
22 std::vector<uint8_t> buffer(hlen);
23 while(!output.empty()) {
24 hash.update(input);
25 hash.update_be(counter);
26 hash.final(buffer);
27
28 const size_t xored = std::min<size_t>(buffer.size(), output.size());
29 xor_buf(output.first(xored), std::span{buffer}.first(xored));
30 output = output.subspan(xored);
31
32 ++counter;
33 }
34}
35
36} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
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:341