8#include <botan/internal/emsa_pkcs1.h>
10#include <botan/exceptn.h>
11#include <botan/internal/hash_id.h>
12#include <botan/internal/stl_util.h>
18std::vector<uint8_t> pkcs1v15_sig_encoding(
const std::vector<uint8_t>& msg,
20 std::span<const uint8_t> hash_id) {
21 const size_t output_length = output_bits / 8;
23 if(output_length < hash_id.size() + msg.size() + 2 + 8) {
24 throw Encoding_Error(
"pkcs1v15_sig_encoding: Output length is too small");
27 std::vector<uint8_t> padded(output_length);
28 BufferStuffer stuffer(padded);
31 stuffer.append(0xFF, stuffer.remaining_capacity() - (1 + hash_id.size() + msg.size()));
33 stuffer.append(hash_id);
43 m_hash->update(input, length);
47 return m_hash->final_stdvec();
53 if(msg.size() != m_hash->output_length()) {
54 throw Encoding_Error(
"EMSA_PKCS1v15::encoding_of: Bad input length");
57 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
60bool EMSA_PKCS1v15::verify(
const std::vector<uint8_t>& coded,
const std::vector<uint8_t>& raw,
size_t key_bits) {
61 if(raw.size() != m_hash->output_length()) {
66 return coded == pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
77 m_hash_output_len = 0;
84 m_hash_name = hash->name();
85 m_hash_output_len = hash->output_length();
89 m_message += std::make_pair(input, length);
93 std::vector<uint8_t> ret;
94 std::swap(ret, m_message);
96 if(m_hash_output_len > 0 && ret.size() != m_hash_output_len) {
97 throw Encoding_Error(
"EMSA_PKCS1v15_Raw::encoding_of: Bad input length");
106 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
110 if(m_hash_output_len > 0 && raw.size() != m_hash_output_len) {
115 return coded == pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
#define BOTAN_ASSERT_NOMSG(expr)
std::vector< uint8_t > encoding_of(const std::vector< uint8_t > &, size_t, RandomNumberGenerator &rng) override
void update(const uint8_t[], size_t) override
std::vector< uint8_t > raw_data() override
bool verify(const std::vector< uint8_t > &, const std::vector< uint8_t > &, size_t) override
std::vector< uint8_t > raw_data() override
EMSA_PKCS1v15(std::unique_ptr< HashFunction > hash)
bool verify(const std::vector< uint8_t > &, const std::vector< uint8_t > &, size_t) override
void update(const uint8_t[], size_t) override
std::vector< uint8_t > encoding_of(const std::vector< 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)