8#include <botan/internal/eme_pkcs.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
13#include <botan/internal/ct_utils.h>
14#include <botan/internal/int_utils.h>
15#include <botan/internal/stl_util.h>
22size_t EME_PKCS1v15::pad(std::span<uint8_t> output,
23 std::span<const uint8_t> input,
25 RandomNumberGenerator& rng)
const {
28 if(input.size() > maximum_input_size(key_length * 8)) {
29 throw Invalid_Argument(
"PKCS1: Input is too large");
32 BufferStuffer stuffer(output);
34 const size_t padding_bytes = [&]() {
41 for(
size_t i = 0; i != padding_bytes; ++i) {
42 stuffer.append(rng.next_nonzero_byte());
45 stuffer.append(input);
47 return output.size() - stuffer.remaining_capacity();
53CT::Option<size_t> EME_PKCS1v15::unpad(std::span<uint8_t> output, std::span<const uint8_t> input)
const {
62 if(input.size() < 11) {
72 bad_input_m |= ~CT::Mask<uint8_t>::is_equal(input[0], 0);
73 bad_input_m |= ~CT::Mask<uint8_t>::is_equal(input[1], 2);
75 for(
size_t i = 2; i < input.size(); ++i) {
77 delim_idx += seen_zero_m.if_not_set_return(1);
78 seen_zero_m |= is_zero_m;
82 bad_input_m |= ~seen_zero_m;
90 const CT::Choice accept = !(bad_input_m.as_choice());
98size_t EME_PKCS1v15::maximum_input_size(
size_t keybits)
const {
99 if(keybits / 8 > 10) {
100 return ((keybits / 8) - 10);
#define BOTAN_ASSERT_NOMSG(expr)
static constexpr Mask< T > is_lt(T x, T y)
static constexpr Mask< T > is_zero(T x)
static constexpr Mask< T > cleared()
constexpr auto scoped_poison(const Ts &... xs)
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)
constexpr std::optional< T > checked_sub(T a, T b)