• 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

96.77
/src/fuzzer/pkcs1.cpp
1
/*
2
* (C) 2015,2016 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/eme_pkcs.h>
11

12
namespace {
13

14
std::vector<uint8_t> simple_pkcs1_unpad(const uint8_t in[], size_t len) {
48✔
15
   if(len < 10)
48✔
16
      throw Botan::Decoding_Error("bad len");
9✔
17

18
   if(in[0] != 0 || in[1] != 2)
39✔
19
      throw Botan::Decoding_Error("bad header field");
16✔
20

21
   for(size_t i = 2; i < len; ++i) {
1,128✔
22
      if(in[i] == 0) {
1,124✔
23
         if(i < 10)  // at least 8 padding bytes required
19✔
24
            throw Botan::Decoding_Error("insufficient padding bytes");
5✔
25
         return std::vector<uint8_t>(in + i + 1, in + len);
14✔
26
      }
27
   }
28

29
   throw Botan::Decoding_Error("delim not found");
4✔
30
}
31

32
}
33

34
void fuzz(const uint8_t in[], size_t len) {
48✔
35
   static Botan::EME_PKCS1v15 pkcs1;
48✔
36

37
   Botan::secure_vector<uint8_t> lib_result;
48✔
38
   std::vector<uint8_t> ref_result;
48✔
39
   bool lib_rejected = false, ref_rejected = false;
48✔
40

41
   try {
48✔
42
      uint8_t valid_mask = 0;
48✔
43
      Botan::secure_vector<uint8_t> decoded = (static_cast<Botan::EME*>(&pkcs1))->unpad(valid_mask, in, len);
48✔
44

45
      if(valid_mask == 0)
48✔
46
         lib_rejected = true;
47
      else if(valid_mask == 0xFF)
14✔
48
         lib_rejected = false;
49
      else
50
         FUZZER_WRITE_AND_CRASH("Invalid valid_mask from unpad");
48✔
51
   } catch(Botan::Decoding_Error&) { lib_rejected = true; }
48✔
52

53
   try {
48✔
54
      ref_result = simple_pkcs1_unpad(in, len);
62✔
55
   } catch(Botan::Decoding_Error& e) { ref_rejected = true; }
34✔
56

57
   if(lib_rejected == true && ref_rejected == false) {
48✔
58
      FUZZER_WRITE_AND_CRASH("Library rejected input accepted by ref " << Botan::hex_encode(ref_result));
×
59
   } else if(ref_rejected == true && lib_rejected == false) {
48✔
60
      FUZZER_WRITE_AND_CRASH("Library accepted input rejected by ref " << Botan::hex_encode(lib_result));
48✔
61
   }
62
   // otherwise the two implementations agree
63
}
48✔
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