Botan 3.4.0
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 secure_vector<uint8_t> encrypt(const uint8_t msg[], size_t msg_len, 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 secure_vector<uint8_t> raw_encrypt(const uint8_t msg[], size_t len, RandomNumberGenerator& rng) = 0;
33 std::unique_ptr<EME> m_eme;
34};
35
37 public:
38 secure_vector<uint8_t> decrypt(uint8_t& valid_mask, const uint8_t msg[], size_t msg_len) 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(const uint8_t msg[], size_t len) = 0;
47 std::unique_ptr<EME> m_eme;
48};
49
51 public:
52 ~Verification_with_Hash() override = default;
53
54 void update(const uint8_t msg[], size_t msg_len) override;
55 bool is_valid_signature(const uint8_t sig[], size_t sig_len) 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(const uint8_t msg[], size_t msg_len, const uint8_t sig[], size_t sig_len) = 0;
75
76 private:
77 std::unique_ptr<HashFunction> m_hash;
78};
79
81 public:
82 void update(const uint8_t msg[], size_t msg_len) override;
83
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 secure_vector<uint8_t> raw_sign(const uint8_t msg[], size_t msg_len, 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 const uint8_t other_key[],
107 size_t other_key_len,
108 const uint8_t salt[],
109 size_t salt_len) override;
110
111 ~Key_Agreement_with_KDF() override = default;
112
113 protected:
114 explicit Key_Agreement_with_KDF(std::string_view kdf);
115
116 private:
117 virtual secure_vector<uint8_t> raw_agree(const uint8_t w[], size_t w_len) = 0;
118 std::unique_ptr<KDF> m_kdf;
119};
120
122 public:
123 void kem_encrypt(std::span<uint8_t> out_encapsulated_key,
124 std::span<uint8_t> out_shared_key,
126 size_t desired_shared_key_len,
127 std::span<const uint8_t> salt) final;
128
129 size_t shared_key_length(size_t desired_shared_key_len) const final;
130
131 ~KEM_Encryption_with_KDF() override = default;
132
133 protected:
134 virtual void raw_kem_encrypt(std::span<uint8_t> out_encapsulated_key,
135 std::span<uint8_t> out_raw_shared_key,
136 RandomNumberGenerator& rng) = 0;
137
138 virtual size_t raw_kem_shared_key_length() const = 0;
139
140 explicit KEM_Encryption_with_KDF(std::string_view kdf);
141
142 private:
143 std::unique_ptr<KDF> m_kdf;
144};
145
147 public:
148 void kem_decrypt(std::span<uint8_t> out_shared_key,
149 std::span<const uint8_t> encapsulated_key,
150 size_t desired_shared_key_len,
151 std::span<const uint8_t> salt) final;
152
153 size_t shared_key_length(size_t desired_shared_key_len) const final;
154
155 ~KEM_Decryption_with_KDF() override = default;
156
157 protected:
158 virtual void raw_kem_decrypt(std::span<uint8_t> out_raw_shared_key,
159 std::span<const uint8_t> encapsulated_key) = 0;
160
161 virtual size_t raw_kem_shared_key_length() const = 0;
162
163 explicit KEM_Decryption_with_KDF(std::string_view kdf);
164
165 private:
166 std::unique_ptr<KDF> m_kdf;
167};
168
169} // namespace Botan::PK_Ops
170
171#endif
secure_vector< uint8_t > decrypt(uint8_t &valid_mask, const uint8_t msg[], size_t msg_len) override
Definition pk_ops.cpp:44
~Decryption_with_EME() override=default
Decryption_with_EME(std::string_view eme)
Definition pk_ops.cpp:42
size_t max_input_bits() const override
Definition pk_ops.cpp:30
secure_vector< uint8_t > encrypt(const uint8_t msg[], size_t msg_len, RandomNumberGenerator &rng) override
Definition pk_ops.cpp:34
~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:204
~KEM_Decryption_with_KDF() override=default
KEM_Decryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:223
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:196
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:169
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:161
~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:190
Key_Agreement_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:51
~Key_Agreement_with_KDF() override=default
secure_vector< uint8_t > agree(size_t key_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len) override
Definition pk_ops.cpp:57
~Signature_with_Hash() override=default
std::string hash_function() const final
Definition pk_ops_impl.h:91
secure_vector< uint8_t > sign(RandomNumberGenerator &rng) override
Definition pk_ops.cpp:121
Signature_with_Hash(std::string_view hash)
Definition pk_ops.cpp:104
~Verification_with_Hash() override=default
virtual bool verify(const uint8_t msg[], size_t msg_len, const uint8_t sig[], size_t sig_len)=0
std::string hash_function() const final
Definition pk_ops_impl.h:57
Verification_with_Hash(std::string_view hash)
Definition pk_ops.cpp:126
bool is_valid_signature(const uint8_t sig[], size_t sig_len) override
Definition pk_ops.cpp:156
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