8#include <botan/internal/emsa_pkcs1.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
12#include <botan/internal/hash_id.h>
13#include <botan/internal/stl_util.h>
19std::vector<uint8_t> pkcs1v15_sig_encoding(std::span<const uint8_t> msg,
21 std::span<const uint8_t> hash_id) {
22 const size_t output_length = output_bits / 8;
24 if(output_length < hash_id.size() + msg.size() + 2 + 8) {
25 throw Encoding_Error(
"pkcs1v15_sig_encoding: Output length is too small");
28 std::vector<uint8_t> padded(output_length);
32 stuffer.append(0xFF, stuffer.remaining_capacity() - (1 + hash_id.size() + msg.size()));
34 stuffer.append(hash_id);
44 m_hash->update(input, length);
48 return m_hash->final_stdvec();
54 if(msg.size() != m_hash->output_length()) {
55 throw Encoding_Error(
"EMSA_PKCS1v15::encoding_of: Bad input length");
58 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
62 if(raw.size() != m_hash->output_length()) {
67 const auto pkcs1 = pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
79 return "PKCS1v15(" + m_hash->name() +
")";
83 if(m_hash_name.empty()) {
84 return "PKCS1v15(Raw)";
86 return "PKCS1v15(Raw," + m_hash_name +
")";
91 m_hash_output_len = 0;
98 m_hash_name = hash->name();
99 m_hash_output_len = hash->output_length();
103 m_message += std::make_pair(input, length);
107 std::vector<uint8_t> ret;
108 std::swap(ret, m_message);
110 if(m_hash_output_len > 0 && ret.size() != m_hash_output_len) {
111 throw Encoding_Error(
"EMSA_PKCS1v15_Raw::encoding_of: Bad input length");
120 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
124 if(m_hash_output_len > 0 && raw.size() != m_hash_output_len) {
129 const auto pkcs1 = pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
#define BOTAN_ASSERT_NOMSG(expr)
Helper class to ease in-place marshalling of concatenated fixed-length values.
void update(const uint8_t[], size_t) override
std::string name() const override
std::vector< uint8_t > raw_data() override
std::vector< uint8_t > encoding_of(std::span< const uint8_t >, size_t, RandomNumberGenerator &rng) override
bool verify(std::span< const uint8_t >, std::span< const uint8_t >, size_t) override
std::string name() const override
std::vector< uint8_t > raw_data() override
EMSA_PKCS1v15(std::unique_ptr< HashFunction > hash)
bool verify(std::span< const uint8_t >, std::span< const uint8_t >, size_t) override
void update(const uint8_t[], size_t) override
std::vector< uint8_t > encoding_of(std::span< const uint8_t >, size_t, RandomNumberGenerator &rng) override
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)