Botan  2.7.0
Crypto and TLS for C++11
emsa_pkcs1.h
Go to the documentation of this file.
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/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 BOTAN_PUBLIC_API(2,0) 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  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  { 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 BOTAN_PUBLIC_API(2,0) EMSA_PKCS1v15_Raw final : public EMSA
57  {
58  public:
59  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  {
79  if(m_hash_name.empty()) return "EMSA3(Raw)";
80  else return "EMSA3(Raw," + m_hash_name + ")";
81  }
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
std::string name() const override
Definition: emsa_pkcs1.h:77
EMSA * clone() override
Definition: emsa_pkcs1.h:59
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
EMSA * clone() override
Definition: emsa_pkcs1.h:29
Definition: alg_id.cpp:13
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23
std::string name() const override
Definition: emsa_pkcs1.h:41
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
MechanismType hash