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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

66.67
/src/fuzzer/oaep.cpp
1
/*
2
* (C) 2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "fuzzers.h"
8

9
#include <botan/hex.h>
10
#include <botan/internal/oaep.h>
11

12
namespace {
13

14
Botan::secure_vector<uint8_t> ref_oaep_unpad(uint8_t& valid_mask,
1,000✔
15
                                             const uint8_t in[],
16
                                             size_t len,
17
                                             const Botan::secure_vector<uint8_t>& Phash) {
18
   const size_t hlen = Phash.size();
1,000✔
19

20
   if(len < 2 * hlen + 1) {
1,000✔
21
      return Botan::secure_vector<uint8_t>();
9✔
22
   }
23

24
   for(size_t i = hlen; i != 2 * hlen; ++i) {
995✔
25
      if(in[i] != Phash[i - hlen]) {
995✔
26
         return Botan::secure_vector<uint8_t>();
991✔
27
      }
28
   }
29

30
   for(size_t i = 2 * hlen; i != len; ++i) {
×
31
      if(in[i] != 0x00 && in[i] != 0x01) {
×
32
         return Botan::secure_vector<uint8_t>();
×
33
      }
34

35
      if(in[i] == 0x01) {
×
36
         valid_mask = 0xFF;
×
37
         return Botan::secure_vector<uint8_t>(in + i + 1, in + len);
×
38
      }
39
   }
40

41
   return Botan::secure_vector<uint8_t>();
×
42
}
43

44
inline bool all_zeros(const Botan::secure_vector<uint8_t>& v) {
45
   for(size_t i = 0; i != v.size(); ++i) {
2,000✔
46
      if(v[i] != 0)
×
47
         return false;
48
   }
49
   return true;
50
}
51

52
}
53

54
void fuzz(const uint8_t in[], size_t len) {
1,000✔
55
   static const Botan::secure_vector<uint8_t> Phash = {1, 2, 3, 4};
1,000✔
56

57
   uint8_t lib_valid_mask = 0;
1,000✔
58
   const Botan::secure_vector<uint8_t> lib_output = Botan::oaep_find_delim(lib_valid_mask, in, len, Phash);
1,000✔
59
   FUZZER_ASSERT_TRUE(lib_valid_mask == 0 || lib_valid_mask == 0xFF);
1,000✔
60

61
   uint8_t ref_valid_mask = 0;
1,000✔
62
   const Botan::secure_vector<uint8_t> ref_output = ref_oaep_unpad(ref_valid_mask, in, len, Phash);
1,000✔
63
   FUZZER_ASSERT_TRUE(ref_valid_mask == 0 || ref_valid_mask == 0xFF);
1,000✔
64

65
   if(ref_valid_mask == 0xFF && lib_valid_mask == 0x00) {
1,000✔
66
      FUZZER_WRITE_AND_CRASH("Ref accepted but library rejected, output " << Botan::hex_encode(ref_output) << "\n");
×
67
   } else if(ref_valid_mask == 0x00 && lib_valid_mask == 0xFF) {
1,000✔
68
      FUZZER_WRITE_AND_CRASH("Lib accepted but ref rejected, output = " << Botan::hex_encode(lib_output) << "\n");
×
69
   }
70

71
   if(ref_valid_mask == 0x00) {
1,000✔
72
      FUZZER_ASSERT_TRUE(all_zeros(ref_output));
1,000✔
73
   }
74

75
   if(lib_valid_mask == 0x00) {
1,000✔
76
      FUZZER_ASSERT_TRUE(all_zeros(lib_output));
1,000✔
77
   }
78

79
   if(ref_valid_mask && lib_valid_mask) {
1,000✔
80
      if(ref_output != lib_output) {
×
81
         FUZZER_WRITE_AND_CRASH("Ref and lib both accepted but produced different output:"
×
82
                                << " ref = " << Botan::hex_encode(ref_output)
83
                                << " lib = " << Botan::hex_encode(lib_output));
84
      }
85
   }
86
}
1,991✔
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