Botan 3.0.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/internal/pk_ops.h>
12#include <botan/internal/eme.h>
13#include <botan/kdf.h>
14#include <botan/hash.h>
15
16namespace Botan {
17
18namespace PK_Ops {
19
21 {
22 public:
23 size_t max_input_bits() const override;
24
25 secure_vector<uint8_t> encrypt(const uint8_t msg[], size_t msg_len,
26 RandomNumberGenerator& rng) override;
27
29 protected:
30 explicit Encryption_with_EME(std::string_view eme);
31 private:
32 virtual size_t max_ptext_input_bits() const = 0;
33
34 virtual secure_vector<uint8_t> raw_encrypt(const uint8_t msg[], size_t len,
35 RandomNumberGenerator& rng) = 0;
36 std::unique_ptr<EME> m_eme;
37 };
38
40 {
41 public:
42 secure_vector<uint8_t> decrypt(uint8_t& valid_mask,
43 const uint8_t msg[], size_t msg_len) override;
44
46 protected:
47 explicit Decryption_with_EME(std::string_view eme);
48 private:
49 virtual secure_vector<uint8_t> raw_decrypt(const uint8_t msg[], size_t len) = 0;
50 std::unique_ptr<EME> m_eme;
51 };
52
54 {
55 public:
57
58 void update(const uint8_t msg[], size_t msg_len) override;
59 bool is_valid_signature(const uint8_t sig[], size_t sig_len) override;
60
61 std::string hash_function() const override final { return m_hash->name(); }
62
63 protected:
64 explicit Verification_with_Hash(std::string_view hash);
65
66 explicit Verification_with_Hash(const AlgorithmIdentifier& alg_id,
67 std::string_view pk_algo,
68 bool allow_null_parameters = false);
69
70 /*
71 * Perform a signature check operation
72 * @param msg the message
73 * @param msg_len the length of msg in bytes
74 * @param sig the signature
75 * @param sig_len the length of sig in bytes
76 * @returns if signature is a valid one for message
77 */
78 virtual bool verify(const uint8_t msg[], size_t msg_len,
79 const uint8_t sig[], size_t sig_len) = 0;
80 private:
81 std::unique_ptr<HashFunction> m_hash;
82 };
83
85 {
86 public:
87 void update(const uint8_t msg[], size_t msg_len) override;
88
90 protected:
91 explicit Signature_with_Hash(std::string_view hash);
92
94
95 std::string hash_function() const override final { return m_hash->name(); }
96
97#if defined(BOTAN_HAS_RFC6979_GENERATOR)
98 std::string rfc6979_hash_function() const;
99#endif
100
101 private:
102 virtual secure_vector<uint8_t> raw_sign(const uint8_t msg[], size_t msg_len,
103 RandomNumberGenerator& rng) = 0;
104
105 std::unique_ptr<HashFunction> m_hash;
106 };
107
109 {
110 public:
111 secure_vector<uint8_t> agree(size_t key_len,
112 const uint8_t other_key[], size_t other_key_len,
113 const uint8_t salt[], size_t salt_len) override;
114
115 protected:
116 explicit Key_Agreement_with_KDF(std::string_view kdf);
118 private:
119 virtual secure_vector<uint8_t> raw_agree(const uint8_t w[], size_t w_len) = 0;
120 std::unique_ptr<KDF> m_kdf;
121 };
122
124 {
125 public:
126 void kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
127 secure_vector<uint8_t>& out_shared_key,
128 size_t desired_shared_key_len,
130 const uint8_t salt[],
131 size_t salt_len) override final;
132
133 size_t shared_key_length(size_t desired_shared_key_len) const override final;
134
135 protected:
136 virtual void raw_kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
137 secure_vector<uint8_t>& raw_shared_key,
138 RandomNumberGenerator& rng) = 0;
139
140 virtual size_t raw_kem_shared_key_length() const = 0;
141
142 explicit KEM_Encryption_with_KDF(std::string_view kdf);
144 private:
145 std::unique_ptr<KDF> m_kdf;
146 };
147
149 {
150 public:
151 secure_vector<uint8_t> kem_decrypt(const uint8_t encap_key[],
152 size_t len,
153 size_t desired_shared_key_len,
154 const uint8_t salt[],
155 size_t salt_len) override final;
156
157 size_t shared_key_length(size_t desired_shared_key_len) const override final;
158
159 protected:
161 raw_kem_decrypt(const uint8_t encap_key[], size_t len) = 0;
162
163 virtual size_t raw_kem_shared_key_length() const = 0;
164
165 explicit KEM_Decryption_with_KDF(std::string_view kdf);
167 private:
168 std::unique_ptr<KDF> m_kdf;
169 };
170
171}
172
173}
174
175#endif
secure_vector< uint8_t > decrypt(uint8_t &valid_mask, const uint8_t msg[], size_t msg_len) override
Definition: pk_ops.cpp:52
size_t max_input_bits() const override
Definition: pk_ops.cpp:33
secure_vector< uint8_t > encrypt(const uint8_t msg[], size_t msg_len, RandomNumberGenerator &rng) override
Definition: pk_ops.cpp:38
virtual secure_vector< uint8_t > raw_kem_decrypt(const uint8_t encap_key[], size_t len)=0
size_t shared_key_length(size_t desired_shared_key_len) const override final
Definition: pk_ops.cpp:230
secure_vector< uint8_t > kem_decrypt(const uint8_t encap_key[], size_t len, size_t desired_shared_key_len, const uint8_t salt[], size_t salt_len) override final
Definition: pk_ops.cpp:239
virtual size_t raw_kem_shared_key_length() const =0
size_t shared_key_length(size_t desired_shared_key_len) const override final
Definition: pk_ops.cpp:190
void kem_encrypt(secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, size_t desired_shared_key_len, RandomNumberGenerator &rng, const uint8_t salt[], size_t salt_len) override final
Definition: pk_ops.cpp:198
virtual void raw_kem_encrypt(secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &raw_shared_key, RandomNumberGenerator &rng)=0
virtual size_t raw_kem_shared_key_length() const =0
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:66
std::string hash_function() const override final
Definition: pk_ops_impl.h:95
secure_vector< uint8_t > sign(RandomNumberGenerator &rng) override
Definition: pk_ops.cpp:136
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 override final
Definition: pk_ops_impl.h:61
bool is_valid_signature(const uint8_t sig[], size_t sig_len) override
Definition: pk_ops.cpp:184
int(* update)(CTX *, const void *, CC_LONG len)
int(* final)(unsigned char *, CTX *)
Definition: alg_id.cpp:12
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64