8#include <botan/emsa2.h>
9#include <botan/hash_id.h>
23 const size_t HASH_SIZE = empty_hash.
size();
25 size_t output_length = (output_bits + 1) / 8;
27 if(msg.size() != HASH_SIZE)
29 if(output_length < HASH_SIZE + 4)
30 throw Encoding_Error(
"EMSA2::encoding_of: Output length is too small");
33 for(
size_t j = 0; j != HASH_SIZE; ++j)
34 if(empty_hash[j] != msg[j])
39 output[0] = (empty ? 0x4B : 0x6B);
40 output[output_length - 3 - HASH_SIZE] = 0xBA;
41 set_mem(&output[1], output_length - 4 - HASH_SIZE, 0xBB);
42 output.copy(output_length - (HASH_SIZE + 2), &msg[0], msg.size());
43 output[output_length-2] = hash_id;
44 output[output_length-1] = 0xCC;
54void EMSA2::update(
const byte input[],
size_t length)
56 hash->update(input, length);
74 return emsa2_encoding(msg, output_bits, empty_hash, hash_id);
86 return (coded == emsa2_encoding(raw, key_bits,
87 empty_hash, hash_id));
100 empty_hash = hash->final();
102 const std::string hash_name = hash->name();
EMSA2(HashFunction *hash)
virtual SecureVector< byte > raw_data()=0
void set_mem(T *ptr, size_t n, byte val)
byte ieee1363_hash_id(const std::string &name)
Encoding_Error(const std::string &name)