Coverage Report

Created: 2021-06-10 10:30

/src/botan/build/include/botan/internal/emsa_pkcs1.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* PKCS #1 v1.5 signature padding
3
* (C) 1999-2008 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_EMSA_PKCS1_H_
9
#define BOTAN_EMSA_PKCS1_H_
10
11
#include <botan/internal/emsa.h>
12
#include <botan/hash.h>
13
14
namespace Botan {
15
16
/**
17
* PKCS #1 v1.5 signature padding
18
* aka PKCS #1 block type 1
19
* aka EMSA3 from IEEE 1363
20
*/
21
class EMSA_PKCS1v15 final : public EMSA
22
   {
23
   public:
24
      /**
25
      * @param hash the hash function to use
26
      */
27
      explicit EMSA_PKCS1v15(std::unique_ptr<HashFunction> hash);
28
29
      std::unique_ptr<EMSA> new_object() override
30
0
         {
31
0
         return std::make_unique<EMSA_PKCS1v15>(m_hash->new_object());
32
0
         }
33
34
      void update(const uint8_t[], size_t) override;
35
36
      secure_vector<uint8_t> raw_data() override;
37
38
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
39
                                     RandomNumberGenerator& rng) override;
40
41
      bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
42
                  size_t) override;
43
44
      std::string name() const override
45
0
         { return "EMSA3(" + m_hash->name() + ")"; }
46
47
      AlgorithmIdentifier config_for_x509(const Private_Key& key,
48
                                          const std::string& cert_hash_name) const override;
49
50
0
      bool requires_message_recovery() const override { return true; }
51
   private:
52
      std::unique_ptr<HashFunction> m_hash;
53
      std::vector<uint8_t> m_hash_id;
54
   };
55
56
/**
57
* EMSA_PKCS1v15_Raw which is EMSA_PKCS1v15 without a hash or digest id
58
* (which according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS
59
* mechanism", something I have not confirmed)
60
*/
61
class EMSA_PKCS1v15_Raw final : public EMSA
62
   {
63
   public:
64
0
      std::unique_ptr<EMSA> new_object() override { return std::make_unique<EMSA_PKCS1v15_Raw>(); }
65
66
      void update(const uint8_t[], size_t) override;
67
68
      secure_vector<uint8_t> raw_data() override;
69
70
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
71
                                     RandomNumberGenerator& rng) override;
72
73
      bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
74
                  size_t) override;
75
76
      EMSA_PKCS1v15_Raw();
77
78
      /**
79
      * @param hash_algo t he digest id for that hash is included in
80
      * the signature.
81
      */
82
      EMSA_PKCS1v15_Raw(const std::string& hash_algo);
83
84
      std::string name() const override
85
0
         {
86
0
         if(m_hash_name.empty()) return "EMSA3(Raw)";
87
0
         else return "EMSA3(Raw," + m_hash_name + ")";
88
0
         }
89
90
0
      bool requires_message_recovery() const override { return true; }
91
   private:
92
      size_t m_hash_output_len = 0;
93
      std::string m_hash_name;
94
      std::vector<uint8_t> m_hash_id;
95
      secure_vector<uint8_t> m_message;
96
   };
97
98
}
99
100
#endif