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

randombit / botan / 16439795343

22 Jul 2025 09:05AM UTC coverage: 90.698% (-0.001%) from 90.699%
16439795343

push

github

web-flow
Merge pull request #5008 from randombit/jack/no-more-emsa-wars

Remove 'EMSA' terminology where possible

99978 of 110232 relevant lines covered (90.7%)

12351726.08 hits per line

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

75.76
/src/tests/test_pk_pad.cpp
1
/*
2
* (C) 2016 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_PK_PADDING)
10
   #include <botan/internal/eme.h>
11
#endif
12

13
#if defined(BOTAN_HAS_RSA_SIGNATURE_PADDING)
14
   #include <botan/internal/fmt.h>
15
   #include <botan/internal/sig_padding.h>
16
#endif
17

18
namespace Botan_Tests {
19

20
#if defined(BOTAN_HAS_EME_PKCS1)
21
class EME_PKCS1v15_Decoding_Tests final : public Text_Based_Test {
×
22
   public:
23
      EME_PKCS1v15_Decoding_Tests() : Text_Based_Test("pk_pad_eme/pkcs1.vec", "RawCiphertext", "Plaintext") {}
2✔
24

25
      Test::Result run_one_test(const std::string& hdr, const VarMap& vars) override {
18✔
26
         const bool is_valid = (hdr == "valid");
18✔
27

28
         Test::Result result("PKCSv15 Decoding");
18✔
29

30
         auto pkcs = Botan::EME::create("PKCS1v15");
18✔
31
         if(!pkcs) {
18✔
32
            return result;
33
         }
34

35
         const std::vector<uint8_t> ciphertext = vars.get_req_bin("RawCiphertext");
18✔
36
         const std::vector<uint8_t> plaintext = vars.get_opt_bin("Plaintext");
18✔
37

38
         if(is_valid == false) {
18✔
39
            result.test_eq("Plaintext value should be empty for invalid EME inputs", plaintext.size(), 0);
22✔
40
         }
41

42
         std::vector<uint8_t> decoded(ciphertext.size());
18✔
43
         auto len = pkcs->unpad(decoded, ciphertext);
18✔
44

45
         result.test_eq("EME decoding valid/invalid matches", len.has_value().as_bool(), is_valid);
18✔
46

47
         if(len.has_value().as_bool()) {
18✔
48
            decoded.resize(len.value_or(0));
7✔
49
            result.test_eq("EME decoded plaintext correct", decoded, plaintext);
14✔
50
         } else {
51
            bool all_zeros = true;
52
            for(uint8_t b : decoded) {
137✔
53
               if(b != 0) {
126✔
54
                  all_zeros = false;
×
55
               }
56
            }
57

58
            result.confirm("On invalid padding output is all zero", all_zeros);
22✔
59
         }
60

61
         // TODO: also test that encoding is accepted
62

63
         return result;
18✔
64
      }
61✔
65
};
66

67
BOTAN_REGISTER_TEST("pubkey", "eme_pkcs1v15", EME_PKCS1v15_Decoding_Tests);
68
#endif
69

70
#if defined(BOTAN_HAS_RSA_SIGNATURE_PADDING)
71
class SignaturePaddingSchemeNameTests final : public Test {
×
72
   public:
73
      std::vector<Test::Result> run() override {
1✔
74
         Test::Result result("SignaturePaddingScheme::name");
1✔
75

76
         std::vector<std::string> pads_need_hash = {
1✔
77
   #if BOTAN_HAS_EMSA_X931
78
            "X9.31",
79
   #endif
80
   #if BOTAN_HAS_EMSA_PKCS1
81
            "PKCS1v15",
82
   #endif
83
   #if BOTAN_HAS_EMSA_PSSR
84
            "PSS",
85
            "PSS_Raw",
86
   #endif
87
   #if BOTAN_HAS_ISO_9796
88
            "ISO_9796_DS2",
89
            "ISO_9796_DS3",
90
   #endif
91
         };
1✔
92

93
         std::vector<std::string> pads_no_hash = {
1✔
94
   #if BOTAN_HAS_EMSA_RAW
95
            "Raw",
96
   #endif
97
   #if BOTAN_HAS_EMSA_PKCS1
98
            "PKCS1v15(Raw)",
99
            "PKCS1v15(Raw,SHA-512)",
100
   #endif
101
         };
1✔
102

103
         for(const auto& pad : pads_need_hash) {
7✔
104
            try {
6✔
105
               const std::string hash_to_use = "SHA-256";
6✔
106
               auto padding = Botan::SignaturePaddingScheme::create_or_throw(Botan::fmt("{}({})", pad, hash_to_use));
6✔
107
               auto padding_copy = Botan::SignaturePaddingScheme::create(padding->name());
6✔
108
               result.test_eq("SignaturePaddingScheme::name for " + pad, padding->name(), padding_copy->name());
12✔
109
            } catch(Botan::Lookup_Error&) {
12✔
110
               result.test_note("Skipping test due to missing hash");
×
111
            } catch(const std::exception& e) {
×
112
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " + e.what());
×
113
            }
×
114
         }
115

116
         for(const auto& pad : pads_need_hash) {
7✔
117
            std::string algo_name = pad + "(YYZ)";
6✔
118
            try {
6✔
119
               auto padding = Botan::SignaturePaddingScheme::create_or_throw(algo_name);
6✔
120
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " +
×
121
                                   "Could create SignaturePaddingScheme with fantasy hash YYZ");
122
            } catch(Botan::Lookup_Error&) {
6✔
123
               result.test_note("Skipping test due to missing hash");
6✔
124
            } catch(const std::exception& e) {
6✔
125
               result.test_eq("SignaturePaddingScheme::name for " + pad,
×
126
                              e.what(),
×
127
                              "Could not find any algorithm named \"" + algo_name + "\"");
×
128
            }
×
129
         }
6✔
130

131
         for(const auto& pad : pads_no_hash) {
4✔
132
            try {
3✔
133
               auto padding = Botan::SignaturePaddingScheme::create(pad);
3✔
134
               auto padding_copy = Botan::SignaturePaddingScheme::create(padding->name());
3✔
135
               result.test_eq("SignaturePaddingScheme::name for " + pad, padding->name(), padding_copy->name());
6✔
136
            } catch(Botan::Lookup_Error&) {
6✔
137
               result.test_note("Skipping test due to missing hash");
×
138
            } catch(const std::exception& e) {
×
139
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " + e.what());
×
140
            }
×
141
         }
142

143
         return {result};
3✔
144
      }
2✔
145
};
146

147
BOTAN_REGISTER_TEST("pubkey", "sig_padding_name", SignaturePaddingSchemeNameTests);
148

149
#endif
150

151
}  // namespace Botan_Tests
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

© 2026 Coveralls, Inc