8#include <botan/internal/emsa_raw.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
12#include <botan/internal/ct_utils.h>
17 if(m_expected_size > 0) {
18 return "Raw(" + std::to_string(m_expected_size) +
")";
26void EMSA_Raw::update(
const uint8_t input[],
size_t length) {
27 m_message += std::make_pair(input, length);
33std::vector<uint8_t> EMSA_Raw::raw_data() {
34 if(m_expected_size && m_message.size() != m_expected_size) {
35 throw Invalid_Argument(
"EMSA_Raw was configured to use a " + std::to_string(m_expected_size) +
36 " byte hash but instead was used for a " + std::to_string(m_message.size()) +
" hash");
39 std::vector<uint8_t> output;
40 std::swap(m_message, output);
47std::vector<uint8_t> EMSA_Raw::encoding_of(
const std::vector<uint8_t>& msg,
49 RandomNumberGenerator& ) {
50 if(m_expected_size && msg.size() != m_expected_size) {
51 throw Invalid_Argument(
"EMSA_Raw was configured to use a " + std::to_string(m_expected_size) +
52 " byte hash but instead was used for a " + std::to_string(msg.size()) +
" hash");
61bool EMSA_Raw::verify(
const std::vector<uint8_t>& coded,
const std::vector<uint8_t>& raw,
size_t ) {
62 if(m_expected_size && raw.size() != m_expected_size) {
66 if(coded.size() == raw.size()) {
67 return (coded == raw);
70 if(coded.size() > raw.size()) {
75 const size_t leading_zeros_expected = raw.size() - coded.size();
77 bool same_modulo_leading_zeros =
true;
79 for(
size_t i = 0; i != leading_zeros_expected; ++i) {
81 same_modulo_leading_zeros =
false;
85 if(!
CT::is_equal(coded.data(), raw.data() + leading_zeros_expected, coded.size()).as_bool()) {
86 same_modulo_leading_zeros =
false;
89 return same_modulo_leading_zeros;
std::string name() const override
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)