Coverage Report

Created: 2021-02-21 07:20

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