8 #include <botan/emsa1.h>
14 secure_vector<byte> emsa1_encoding(
const secure_vector<byte>& msg,
17 if(8*msg.size() <= output_bits)
20 size_t shift = 8*msg.size() - output_bits;
22 size_t byte_shift = shift / 8, bit_shift = shift % 8;
23 secure_vector<byte> digest(msg.size() - byte_shift);
25 for(
size_t j = 0; j != msg.size() - byte_shift; ++j)
31 for(
size_t j = 0; j != digest.size(); ++j)
33 byte temp = digest[j];
34 digest[j] = (temp >> bit_shift) | carry;
35 carry = (temp << (8 - bit_shift));
46 void EMSA1::update(
const byte input[],
size_t length)
48 hash->
update(input, length);
54 secure_vector<byte> EMSA1::raw_data()
62 secure_vector<byte> EMSA1::encoding_of(
const secure_vector<byte>& msg,
64 RandomNumberGenerator&)
67 throw Encoding_Error(
"EMSA1::encoding_of: Invalid size for input");
68 return emsa1_encoding(msg, output_bits);
74 bool EMSA1::verify(
const secure_vector<byte>& coded,
75 const secure_vector<byte>& raw,
size_t key_bits)
79 throw Encoding_Error(
"EMSA1::encoding_of: Invalid size for input");
81 secure_vector<byte> our_coding = emsa1_encoding(raw, key_bits);
83 if(our_coding == coded)
return true;
84 if(our_coding.empty() || our_coding[0] != 0)
return false;
85 if(our_coding.size() <= coded.size())
return false;
88 while(offset < our_coding.size() && our_coding[offset] == 0)
90 if(our_coding.size() - offset != coded.size())
93 for(
size_t j = 0; j != coded.size(); ++j)
94 if(coded[j] != our_coding[j+offset])