Coverage Report

Created: 2021-05-04 09:02

/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
   private:
50
      std::unique_ptr<HashFunction> m_hash;
51
      std::vector<uint8_t> m_hash_id;
52
   };
53
54
/**
55
* EMSA_PKCS1v15_Raw which is EMSA_PKCS1v15 without a hash or digest id
56
* (which according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS
57
* mechanism", something I have not confirmed)
58
*/
59
class EMSA_PKCS1v15_Raw final : public EMSA
60
   {
61
   public:
62
0
      std::unique_ptr<EMSA> new_object() override { return std::make_unique<EMSA_PKCS1v15_Raw>(); }
63
64
      void update(const uint8_t[], size_t) override;
65
66
      secure_vector<uint8_t> raw_data() override;
67
68
      secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
69
                                     RandomNumberGenerator& rng) override;
70
71
      bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
72
                  size_t) override;
73
74
      /**
75
      * @param hash_algo if non-empty, the digest id for that hash is
76
      * included in the signature.
77
      */
78
      EMSA_PKCS1v15_Raw(const std::string& hash_algo = "");
79
80
      std::string name() const override
81
0
         {
82
0
         if(m_hash_name.empty()) return "EMSA3(Raw)";
83
0
         else return "EMSA3(Raw," + m_hash_name + ")";
84
0
         }
85
86
   private:
87
      size_t m_hash_output_len = 0;
88
      std::string m_hash_name;
89
      std::vector<uint8_t> m_hash_id;
90
      secure_vector<uint8_t> m_message;
91
   };
92
93
}
94
95
#endif