• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 4805055462

26 Apr 2023 05:37AM UTC coverage: 92.146% (-0.002%) from 92.148%
4805055462

push

github

77579 of 84191 relevant lines covered (92.15%)

11871996.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/src/lib/pk_pad/emsa_raw/emsa_raw.cpp
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/internal/emsa_raw.h>
9

10
#include <botan/exceptn.h>
11

12
namespace Botan {
13

14
std::string EMSA_Raw::name() const
3✔
15
   {
16
   if(m_expected_size > 0)
3✔
17
      return "Raw(" + std::to_string(m_expected_size) + ")";
×
18
   return "Raw";
3✔
19
   }
20

21
/*
22
* EMSA-Raw Encode Operation
23
*/
24
void EMSA_Raw::update(const uint8_t input[], size_t length)
814✔
25
   {
26
   m_message += std::make_pair(input, length);
814✔
27
   }
814✔
28

29
/*
30
* Return the raw (unencoded) data
31
*/
32
std::vector<uint8_t> EMSA_Raw::raw_data()
814✔
33
   {
34
   if(m_expected_size && m_message.size() != m_expected_size)
814✔
35
      throw Invalid_Argument("EMSA_Raw was configured to use a " +
×
36
                             std::to_string(m_expected_size) +
×
37
                             " byte hash but instead was used for a " +
×
38
                             std::to_string(m_message.size()) + " hash");
×
39

40
   std::vector<uint8_t> output;
814✔
41
   std::swap(m_message, output);
814✔
42
   return output;
814✔
43
   }
44

45
/*
46
* EMSA-Raw Encode Operation
47
*/
48
std::vector<uint8_t>
49
EMSA_Raw::encoding_of(const std::vector<uint8_t>& msg,
385✔
50
                      size_t /*output_bits*/,
51
                      RandomNumberGenerator& /*rng*/)
52
   {
53
   if(m_expected_size && msg.size() != m_expected_size)
385✔
54
      throw Invalid_Argument("EMSA_Raw was configured to use a " +
×
55
                             std::to_string(m_expected_size) +
×
56
                             " byte hash but instead was used for a " +
×
57
                             std::to_string(msg.size()) + " hash");
×
58

59
   return msg;
385✔
60
   }
61

62
/*
63
* EMSA-Raw Verify Operation
64
*/
65
bool EMSA_Raw::verify(const std::vector<uint8_t>& coded,
429✔
66
                      const std::vector<uint8_t>& raw,
67
                      size_t /*key_bits*/)
68
   {
69
   if(m_expected_size && raw.size() != m_expected_size)
429✔
70
      return false;
71

72
   if(coded.size() == raw.size())
429✔
73
      return (coded == raw);
20✔
74

75
   if(coded.size() > raw.size())
409✔
76
      return false;
77

78
   // handle zero padding differences
79
   const size_t leading_zeros_expected = raw.size() - coded.size();
389✔
80

81
   bool same_modulo_leading_zeros = true;
389✔
82

83
   for(size_t i = 0; i != leading_zeros_expected; ++i)
6,434✔
84
      if(raw[i])
6,045✔
85
         same_modulo_leading_zeros = false;
270✔
86

87
   if(!constant_time_compare(coded.data(), raw.data() + leading_zeros_expected, coded.size()))
389✔
88
      same_modulo_leading_zeros = false;
×
89

90
   return same_modulo_leading_zeros;
91
   }
92

93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc