Botan 1.10.17

emsa_raw.cpp
Go to the documentation of this file.
1 /*
2 * EMSA-Raw
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/emsa_raw.h>
9
10 namespace Botan {
11
12 /*
13 * EMSA-Raw Encode Operation
14 */
15 void EMSA_Raw::update(const byte input[], size_t length)
16 {
17 message += std::make_pair(input, length);
18 }
19
20 /*
21 * Return the raw (unencoded) data
22 */
23 SecureVector<byte> EMSA_Raw::raw_data()
24 {
25 SecureVector<byte> output;
26 std::swap(message, output);
27 return output;
28 }
29
30 /*
31 * EMSA-Raw Encode Operation
32 */
33 SecureVector<byte> EMSA_Raw::encoding_of(const MemoryRegion<byte>& msg,
34 size_t,
35 RandomNumberGenerator&)
36 {
37 return msg;
38 }
39
40 /*
41 * EMSA-Raw Verify Operation
42 */
43 bool EMSA_Raw::verify(const MemoryRegion<byte>& coded,
44 const MemoryRegion<byte>& raw,
45 size_t)
46 {
47 if(coded.size() == raw.size())
48 return (coded == raw);
49
50 if(coded.size() > raw.size())
51 return false;
52
53 // handle zero padding differences
54 const size_t leading_zeros_expected = raw.size() - coded.size();
55
56 bool same_modulo_leading_zeros = true;
57
58 for(size_t i = 0; i != leading_zeros_expected; ++i)
59 if(raw[i])
60 same_modulo_leading_zeros = false;
61
62 if(!same_mem(&coded[0], &raw[leading_zeros_expected], coded.size()))
63 same_modulo_leading_zeros = false;
64
65 return same_modulo_leading_zeros;
66 }
67
68 }
Botan::same_mem
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:57
Botan::byte
unsigned char byte
Definition: types.h:22
Botan
Definition: algo_base.h:14
std::swap
void swap(Botan::MemoryRegion< T > &x, Botan::MemoryRegion< T > &y)
Definition: secmem.h:438