Botan 3.6.1
Crypto and TLS for C&
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/hash.h>
12#include <botan/internal/emsa.h>
13
14namespace Botan {
15
16/**
17* PKCS #1 v1.5 signature padding
18* aka PKCS #1 block type 1
19* aka EMSA3 from IEEE 1363
20*/
21class EMSA_PKCS1v15 final : public EMSA {
22 public:
23 /**
24 * @param hash the hash function to use
25 */
26 explicit EMSA_PKCS1v15(std::unique_ptr<HashFunction> hash);
27
28 void update(const uint8_t[], size_t) override;
29
30 std::vector<uint8_t> raw_data() override;
31
32 std::vector<uint8_t> encoding_of(const std::vector<uint8_t>&, size_t, RandomNumberGenerator& rng) override;
33
34 bool verify(const std::vector<uint8_t>&, const std::vector<uint8_t>&, size_t) override;
35
36 std::string name() const override { return "EMSA3(" + m_hash->name() + ")"; }
37
38 std::string hash_function() const override { return m_hash->name(); }
39
40 private:
41 std::unique_ptr<HashFunction> m_hash;
42 std::vector<uint8_t> m_hash_id;
43};
44
45/**
46* EMSA_PKCS1v15_Raw which is EMSA_PKCS1v15 without a hash or digest id
47* (which according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS
48* mechanism", something I have not confirmed)
49*/
51 public:
52 void update(const uint8_t[], size_t) override;
53
54 std::vector<uint8_t> raw_data() override;
55
56 std::vector<uint8_t> encoding_of(const std::vector<uint8_t>&, size_t, RandomNumberGenerator& rng) override;
57
58 bool verify(const std::vector<uint8_t>&, const std::vector<uint8_t>&, size_t) override;
59
61
62 /**
63 * @param hash_algo the digest id for that hash is included in
64 * the signature.
65 */
66 EMSA_PKCS1v15_Raw(std::string_view hash_algo);
67
68 std::string hash_function() const override { return m_hash_name; }
69
70 std::string name() const override {
71 if(m_hash_name.empty()) {
72 return "EMSA3(Raw)";
73 } else {
74 return "EMSA3(Raw," + m_hash_name + ")";
75 }
76 }
77
78 private:
79 size_t m_hash_output_len = 0;
80 std::string m_hash_name;
81 std::vector<uint8_t> m_hash_id;
82 std::vector<uint8_t> m_message;
83};
84
85} // namespace Botan
86
87#endif
std::vector< uint8_t > encoding_of(const std::vector< uint8_t > &, size_t, RandomNumberGenerator &rng) override
std::string name() const override
Definition emsa_pkcs1.h:70
std::vector< uint8_t > raw_data() override
bool verify(const std::vector< uint8_t > &, const std::vector< uint8_t > &, size_t) override
std::string hash_function() const override
Definition emsa_pkcs1.h:68
std::string name() const override
Definition emsa_pkcs1.h:36
std::vector< uint8_t > raw_data() override
EMSA_PKCS1v15(std::unique_ptr< HashFunction > hash)
bool verify(const std::vector< uint8_t > &, const std::vector< uint8_t > &, size_t) override
std::string hash_function() const override
Definition emsa_pkcs1.h:38
std::vector< uint8_t > encoding_of(const std::vector< uint8_t > &, size_t, RandomNumberGenerator &rng) override
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)