Botan  2.1.0
Crypto and TLS for C++11
emsa_raw.cpp
Go to the documentation of this file.
1 /*
2 * EMSA-Raw
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
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 uint8_t input[], size_t length)
16  {
17  m_message += std::make_pair(input, length);
18  }
19 
20 /*
21 * Return the raw (unencoded) data
22 */
23 secure_vector<uint8_t> EMSA_Raw::raw_data()
24  {
25  secure_vector<uint8_t> output;
26  std::swap(m_message, output);
27  return output;
28  }
29 
30 /*
31 * EMSA-Raw Encode Operation
32 */
33 secure_vector<uint8_t> EMSA_Raw::encoding_of(const secure_vector<uint8_t>& 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 secure_vector<uint8_t>& coded,
44  const secure_vector<uint8_t>& 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.data(), raw.data() + leading_zeros_expected, coded.size()))
63  same_modulo_leading_zeros = false;
64 
65  return same_modulo_leading_zeros;
66  }
67 
68 }
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:98
Definition: alg_id.cpp:13