8#include <botan/internal/emsa_x931.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
12#include <botan/internal/fmt.h>
13#include <botan/internal/hash_id.h>
14#include <botan/internal/stl_util.h>
20std::vector<uint8_t> emsa2_encoding(std::span<const uint8_t> msg,
22 std::span<const uint8_t> empty_hash,
24 const size_t HASH_SIZE = empty_hash.size();
26 const size_t output_length = (output_bits + 1) / 8;
28 if(msg.size() != HASH_SIZE) {
31 if(output_length < HASH_SIZE + 4) {
32 throw Encoding_Error(
"EMSA_X931::encoding_of: Output length is too small");
37 std::vector<uint8_t> output(output_length);
40 stuffer.append(empty_input ? 0x4B : 0x6B);
41 stuffer.append(0xBB, stuffer.remaining_capacity() - (1 + msg.size() + 2));
44 stuffer.append(hash_id);
54 return fmt(
"X9.31({})", m_hash->name());
57void EMSA_X931::update(
const uint8_t input[],
size_t length) {
58 m_hash->update(input, length);
61std::vector<uint8_t> EMSA_X931::raw_data() {
62 return m_hash->final_stdvec();
68std::vector<uint8_t> EMSA_X931::encoding_of(std::span<const uint8_t> msg,
71 return emsa2_encoding(msg, output_bits, m_empty_hash, m_hash_id);
77bool EMSA_X931::verify(std::span<const uint8_t> coded, std::span<const uint8_t> raw,
size_t key_bits) {
79 const auto emsa2 = emsa2_encoding(raw, key_bits, m_empty_hash, m_hash_id);
90 m_empty_hash = m_hash->final_stdvec();
95 throw Encoding_Error(
"EMSA_X931 no hash identifier for " + m_hash->name());
#define BOTAN_ASSERT_NOMSG(expr)
Helper class to ease in-place marshalling of concatenated fixed-length values.
EMSA_X931(std::unique_ptr< HashFunction > hash)
std::string name() const override
std::string fmt(std::string_view format, const T &... args)
uint8_t ieee1363_hash_id(std::string_view name)
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)