Botan 3.6.1
Crypto and TLS for C&
eme_raw.cpp
Go to the documentation of this file.
1/*
2* (C) 2015,2016,2024 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/eme_raw.h>
8
9#include <botan/mem_ops.h>
10#include <botan/internal/ct_utils.h>
11
12namespace Botan {
13
14size_t EME_Raw::pad(std::span<uint8_t> output,
15 std::span<const uint8_t> input,
16 size_t key_length,
17 RandomNumberGenerator& rng) const {
18 BOTAN_UNUSED(rng);
19 BOTAN_ASSERT_NOMSG(input.size() < maximum_input_size(8 * key_length));
20 BOTAN_ASSERT_NOMSG(output.size() >= input.size());
21 copy_mem(output.first(input.size()), input);
22 return input.size();
23}
24
25CT::Option<size_t> EME_Raw::unpad(std::span<uint8_t> output, std::span<const uint8_t> input) const {
26 BOTAN_ASSERT_NOMSG(output.size() >= input.size());
27
28 if(input.empty()) {
29 return CT::Option<size_t>(0);
30 }
31
32 const size_t leading_zeros = CT::count_leading_zero_bytes(input);
33 return CT::copy_output(CT::Choice::yes(), output, input, leading_zeros);
34}
35
36size_t EME_Raw::maximum_input_size(size_t keybits) const {
37 return keybits / 8;
38}
39
40} // namespace Botan
#define BOTAN_UNUSED
Definition assert.h:118
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
static constexpr Choice yes()
Definition ct_utils.h:306
BOTAN_TEST_API CT::Option< size_t > copy_output(CT::Choice accept, std::span< uint8_t > output, std::span< const uint8_t > input, size_t offset)
Definition ct_utils.cpp:13
size_t count_leading_zero_bytes(std::span< const uint8_t > input)
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146