7#include <botan/internal/raw_sig_padding.h>
9#include <botan/exceptn.h>
10#include <botan/hash.h>
11#include <botan/mem_ops.h>
12#include <botan/pk_options_readers.h>
13#include <botan/internal/ct_utils.h>
14#include <botan/internal/fmt.h>
15#include <botan/internal/pk_options_impl.h>
20 m_expected_size([&]() -> size_t {
25 if(auto prehash = externally_computed_prehash_name(options)) {
26 return HashFunction::create_or_throw(*prehash)->output_length();
33 if(m_expected_size > 0) {
34 return fmt(
"Raw({})", m_expected_size);
39void SignRawBytes::update(
const uint8_t input[],
size_t length) {
41 m_message += std::make_pair(input, length);
44std::vector<uint8_t> SignRawBytes::raw_data() {
50 if(m_expected_size > 0 && m_message.size() != m_expected_size) {
51 throw Invalid_Argument(
52 fmt(
"SignRawBytes was configured to use a {} byte hash but instead was used for a {} byte hash",
57 std::vector<uint8_t> output;
58 std::swap(m_message, output);
62std::vector<uint8_t> SignRawBytes::encoding_of(std::span<const uint8_t> msg,
64 RandomNumberGenerator& ) {
65 if(m_expected_size > 0 && msg.size() != m_expected_size) {
66 throw Invalid_Argument(
67 fmt(
"SignRawBytes was configured to use a {} byte hash but instead was used for a {} byte hash",
72 return std::vector<uint8_t>(msg.begin(), msg.end());
75bool SignRawBytes::verify(std::span<const uint8_t> coded, std::span<const uint8_t> raw,
size_t ) {
76 if(m_expected_size > 0 && raw.size() != m_expected_size) {
80 if(raw.size() > coded.size()) {
82 const size_t expected_lz = raw.size() - coded.size();
83 const auto zeros_ok = CT::all_zeros(raw.data(), expected_lz);
84 const auto contents_ok = CT::is_equal(coded.data(), raw.data() + expected_lz, coded.size());
85 return (zeros_ok & contents_ok).as_bool();
bool using_externally_computed_prehash() const
SignRawBytes(const PK_Signature_Options_Reader &options)
std::string name() const override
std::string fmt(std::string_view format, const T &... args)
void acknowledge_always_deterministic(const PK_Signature_Options_Reader &options)
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)