Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 BOTAN_FUTURE_INTERNAL_HEADER(emsa_pkcs1.h)
15
16 namespace Botan {
17
18 /**
19 * PKCS #1 v1.5 signature padding
20 * aka PKCS #1 block type 1
21 * aka EMSA3 from IEEE 1363
22 */
23 class BOTAN_PUBLIC_API(2,0) EMSA_PKCS1v15 final : public EMSA
24 {
25 public:
26 /**
27 * @param hash the hash function to use
28 */
29 explicit EMSA_PKCS1v15(HashFunction* hash);
30
31 EMSA* clone() override { return new EMSA_PKCS1v15(m_hash->clone()); }
32
33 void update(const uint8_t[], size_t) override;
34
35 secure_vector<uint8_t> raw_data() override;
36
37 secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
38 RandomNumberGenerator& rng) override;
39
40 bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
41 size_t) override;
42
43 std::string name() const override
44 { return "EMSA3(" + m_hash->name() + ")"; }
45
46 AlgorithmIdentifier config_for_x509(const Private_Key& key,
47 const std::string& cert_hash_name) const override;
48 private:
49 std::unique_ptr<HashFunction> m_hash;
50 std::vector<uint8_t> m_hash_id;
51 };
52
53 /**
54 * EMSA_PKCS1v15_Raw which is EMSA_PKCS1v15 without a hash or digest id
55 * (which according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS
56 * mechanism", something I have not confirmed)
57 */
58 class BOTAN_PUBLIC_API(2,0) EMSA_PKCS1v15_Raw final : public EMSA
59 {
60 public:
61 EMSA* clone() override { return new EMSA_PKCS1v15_Raw(); }
62
63 void update(const uint8_t[], size_t) override;
64
65 secure_vector<uint8_t> raw_data() override;
66
67 secure_vector<uint8_t> encoding_of(const secure_vector<uint8_t>&, size_t,
68 RandomNumberGenerator& rng) override;
69
70 bool verify(const secure_vector<uint8_t>&, const secure_vector<uint8_t>&,
71 size_t) override;
72
73 /**
74 * @param hash_algo if non-empty, the digest id for that hash is
75 * included in the signature.
76 */
77 EMSA_PKCS1v15_Raw(const std::string& hash_algo = "");
78
79 std::string name() const override
80 {
81 if(m_hash_name.empty()) return "EMSA3(Raw)";
82 else return "EMSA3(Raw," + m_hash_name + ")";
83 }
84
85 private:
86 size_t m_hash_output_len = 0;
87 std::string m_hash_name;
88 std::vector<uint8_t> m_hash_id;
89 secure_vector<uint8_t> m_message;
90 };
91
92 }
93
94 #endif
Botan::EMSA_PKCS1v15_Raw::name
std::string name() const override
Definition: emsa_pkcs1.h:79
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::Private_Key
Definition: pk_keys.h:181
Botan::EMSA_PKCS1v15_Raw::clone
EMSA * clone() override
Definition: emsa_pkcs1.h:61
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::EMSA::update
virtual void update(const uint8_t input[], size_t length)=0
Botan::EMSA_PKCS1v15::clone
EMSA * clone() override
Definition: emsa_pkcs1.h:31
m_hash_id
std::vector< uint8_t > m_hash_id
Definition: tpm.cpp:447
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::EMSA::verify
virtual bool verify(const secure_vector< uint8_t > &coded, const secure_vector< uint8_t > &raw, size_t key_bits)=0
Botan::EMSA_PKCS1v15
Definition: emsa_pkcs1.h:23
Botan::EMSA
Definition: emsa.h:27
Botan
Definition: alg_id.cpp:13
Botan::EMSA::raw_data
virtual secure_vector< uint8_t > raw_data()=0
Botan::EMSA_PKCS1v15_Raw
Definition: emsa_pkcs1.h:58
hash_algo
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22
Botan::EMSA::encoding_of
virtual secure_vector< uint8_t > encoding_of(const secure_vector< uint8_t > &msg, size_t output_bits, RandomNumberGenerator &rng)=0
Botan::HashFunction
Definition: hash.h:20
Botan::EMSA_PKCS1v15::name
std::string name() const override
Definition: emsa_pkcs1.h:43
Botan::AlgorithmIdentifier
Definition: alg_id.h:21
Botan::EMSA::config_for_x509
virtual AlgorithmIdentifier config_for_x509(const Private_Key &key, const std::string &cert_hash_name) const
Definition: emsa.cpp:38
m_hash
std::unique_ptr< HashFunction > m_hash
Definition: tpm.cpp:446
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
hash
MechanismType hash
Definition: p11_mechanism.cpp:64