Botan 3.6.1
Crypto and TLS for C&
pk_ops_impl.h
Go to the documentation of this file.
1
2/*
3* (C) 2015 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_PK_OPERATION_IMPL_H_
9#define BOTAN_PK_OPERATION_IMPL_H_
10
11#include <botan/hash.h>
12#include <botan/kdf.h>
13#include <botan/pk_ops.h>
14#include <botan/internal/eme.h>
15
16namespace Botan::PK_Ops {
17
19 public:
20 size_t max_input_bits() const override;
21
22 std::vector<uint8_t> encrypt(std::span<const uint8_t> ptext, RandomNumberGenerator& rng) override;
23
24 ~Encryption_with_EME() override = default;
25
26 protected:
27 explicit Encryption_with_EME(std::string_view eme);
28
29 private:
30 virtual size_t max_ptext_input_bits() const = 0;
31
32 virtual std::vector<uint8_t> raw_encrypt(std::span<const uint8_t> msg, RandomNumberGenerator& rng) = 0;
33 std::unique_ptr<EME> m_eme;
34};
35
37 public:
38 secure_vector<uint8_t> decrypt(uint8_t& valid_mask, std::span<const uint8_t> ctext) override;
39
40 ~Decryption_with_EME() override = default;
41
42 protected:
43 explicit Decryption_with_EME(std::string_view eme);
44
45 private:
46 virtual secure_vector<uint8_t> raw_decrypt(std::span<const uint8_t> ctext) = 0;
47 std::unique_ptr<EME> m_eme;
48};
49
51 public:
52 ~Verification_with_Hash() override = default;
53
54 void update(std::span<const uint8_t> input) override;
55 bool is_valid_signature(std::span<const uint8_t> sig) override;
56
57 std::string hash_function() const final { return m_hash->name(); }
58
59 protected:
60 explicit Verification_with_Hash(std::string_view hash);
61
62 explicit Verification_with_Hash(const AlgorithmIdentifier& alg_id,
63 std::string_view pk_algo,
64 bool allow_null_parameters = false);
65
66 /*
67 * Perform a signature check operation
68 * @param msg the message
69 * @param msg_len the length of msg in bytes
70 * @param sig the signature
71 * @param sig_len the length of sig in bytes
72 * @returns if signature is a valid one for message
73 */
74 virtual bool verify(std::span<const uint8_t> input, std::span<const uint8_t> sig) = 0;
75
76 private:
77 std::unique_ptr<HashFunction> m_hash;
78};
79
81 public:
82 void update(std::span<const uint8_t> input) override;
83
84 std::vector<uint8_t> sign(RandomNumberGenerator& rng) override;
85
86 ~Signature_with_Hash() override = default;
87
88 protected:
89 explicit Signature_with_Hash(std::string_view hash);
90
91 std::string hash_function() const final { return m_hash->name(); }
92
93#if defined(BOTAN_HAS_RFC6979_GENERATOR)
94 std::string rfc6979_hash_function() const;
95#endif
96
97 private:
98 virtual std::vector<uint8_t> raw_sign(std::span<const uint8_t> input, RandomNumberGenerator& rng) = 0;
99
100 std::unique_ptr<HashFunction> m_hash;
101};
102
104 public:
105 secure_vector<uint8_t> agree(size_t key_len,
106 std::span<const uint8_t> other_key,
107 std::span<const uint8_t> salt) override;
108
109 ~Key_Agreement_with_KDF() override = default;
110
111 protected:
112 explicit Key_Agreement_with_KDF(std::string_view kdf);
113
114 private:
115 virtual secure_vector<uint8_t> raw_agree(const uint8_t w[], size_t w_len) = 0;
116 std::unique_ptr<KDF> m_kdf;
117};
118
120 public:
121 void kem_encrypt(std::span<uint8_t> out_encapsulated_key,
122 std::span<uint8_t> out_shared_key,
124 size_t desired_shared_key_len,
125 std::span<const uint8_t> salt) final;
126
127 size_t shared_key_length(size_t desired_shared_key_len) const final;
128
129 ~KEM_Encryption_with_KDF() override = default;
130
131 protected:
132 virtual void raw_kem_encrypt(std::span<uint8_t> out_encapsulated_key,
133 std::span<uint8_t> out_raw_shared_key,
134 RandomNumberGenerator& rng) = 0;
135
136 virtual size_t raw_kem_shared_key_length() const = 0;
137
138 explicit KEM_Encryption_with_KDF(std::string_view kdf);
139
140 private:
141 std::unique_ptr<KDF> m_kdf;
142};
143
145 public:
146 void kem_decrypt(std::span<uint8_t> out_shared_key,
147 std::span<const uint8_t> encapsulated_key,
148 size_t desired_shared_key_len,
149 std::span<const uint8_t> salt) final;
150
151 size_t shared_key_length(size_t desired_shared_key_len) const final;
152
153 ~KEM_Decryption_with_KDF() override = default;
154
155 protected:
156 virtual void raw_kem_decrypt(std::span<uint8_t> out_raw_shared_key,
157 std::span<const uint8_t> encapsulated_key) = 0;
158
159 virtual size_t raw_kem_shared_key_length() const = 0;
160
161 explicit KEM_Decryption_with_KDF(std::string_view kdf);
162
163 private:
164 std::unique_ptr<KDF> m_kdf;
165};
166
167} // namespace Botan::PK_Ops
168
169#endif
~Decryption_with_EME() override=default
Decryption_with_EME(std::string_view eme)
Definition pk_ops.cpp:41
secure_vector< uint8_t > decrypt(uint8_t &valid_mask, std::span< const uint8_t > ctext) override
Definition pk_ops.cpp:43
std::vector< uint8_t > encrypt(std::span< const uint8_t > ptext, RandomNumberGenerator &rng) override
Definition pk_ops.cpp:34
size_t max_input_bits() const override
Definition pk_ops.cpp:30
~Encryption_with_EME() override=default
Encryption_with_EME(std::string_view eme)
Definition pk_ops.cpp:28
void kem_decrypt(std::span< uint8_t > out_shared_key, std::span< const uint8_t > encapsulated_key, size_t desired_shared_key_len, std::span< const uint8_t > salt) final
Definition pk_ops.cpp:219
~KEM_Decryption_with_KDF() override=default
KEM_Decryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:238
virtual void raw_kem_decrypt(std::span< uint8_t > out_raw_shared_key, std::span< const uint8_t > encapsulated_key)=0
size_t shared_key_length(size_t desired_shared_key_len) const final
Definition pk_ops.cpp:211
virtual size_t raw_kem_shared_key_length() const =0
void kem_encrypt(std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len, std::span< const uint8_t > salt) final
Definition pk_ops.cpp:184
virtual size_t raw_kem_shared_key_length() const =0
size_t shared_key_length(size_t desired_shared_key_len) const final
Definition pk_ops.cpp:176
~KEM_Encryption_with_KDF() override=default
virtual void raw_kem_encrypt(std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_raw_shared_key, RandomNumberGenerator &rng)=0
KEM_Encryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:205
Key_Agreement_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:65
~Key_Agreement_with_KDF() override=default
secure_vector< uint8_t > agree(size_t key_len, std::span< const uint8_t > other_key, std::span< const uint8_t > salt) override
Definition pk_ops.cpp:71
std::vector< uint8_t > sign(RandomNumberGenerator &rng) override
Definition pk_ops.cpp:136
~Signature_with_Hash() override=default
std::string hash_function() const final
Definition pk_ops_impl.h:91
Signature_with_Hash(std::string_view hash)
Definition pk_ops.cpp:119
~Verification_with_Hash() override=default
std::string hash_function() const final
Definition pk_ops_impl.h:57
virtual bool verify(std::span< const uint8_t > input, std::span< const uint8_t > sig)=0
Verification_with_Hash(std::string_view hash)
Definition pk_ops.cpp:141
bool is_valid_signature(std::span< const uint8_t > sig) override
Definition pk_ops.cpp:171
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61