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

randombit / botan / 6057704243

02 Sep 2023 10:05AM UTC coverage: 91.729% (+0.01%) from 91.718%
6057704243

Pull #3680

github

web-flow
Merge fc59ca615 into 2c2ff3c71
Pull Request #3680: Kuznyechik block cipher

78780 of 85883 relevant lines covered (91.73%)

8435879.14 hits per line

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

80.65
/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
   if(m_expected_size > 0) {
3✔
16
      return "Raw(" + std::to_string(m_expected_size) + ")";
×
17
   }
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
   m_message += std::make_pair(input, length);
814✔
26
}
814✔
27

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

37
   std::vector<uint8_t> output;
814✔
38
   std::swap(m_message, output);
814✔
39
   return output;
814✔
40
}
41

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

53
   return msg;
385✔
54
}
55

56
/*
57
* EMSA-Raw Verify Operation
58
*/
59
bool EMSA_Raw::verify(const std::vector<uint8_t>& coded, const std::vector<uint8_t>& raw, size_t /*key_bits*/) {
429✔
60
   if(m_expected_size && raw.size() != m_expected_size) {
429✔
61
      return false;
62
   }
63

64
   if(coded.size() == raw.size()) {
429✔
65
      return (coded == raw);
20✔
66
   }
67

68
   if(coded.size() > raw.size()) {
409✔
69
      return false;
70
   }
71

72
   // handle zero padding differences
73
   const size_t leading_zeros_expected = raw.size() - coded.size();
389✔
74

75
   bool same_modulo_leading_zeros = true;
389✔
76

77
   for(size_t i = 0; i != leading_zeros_expected; ++i) {
6,434✔
78
      if(raw[i]) {
6,045✔
79
         same_modulo_leading_zeros = false;
270✔
80
      }
81
   }
82

83
   if(!constant_time_compare(coded.data(), raw.data() + leading_zeros_expected, coded.size())) {
389✔
84
      same_modulo_leading_zeros = false;
×
85
   }
86

87
   return same_modulo_leading_zeros;
88
}
89

90
}  // namespace Botan
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