Botan 3.13.0
Crypto and TLS for C&
dlies.h
Go to the documentation of this file.
1/*
2* DLIES
3* (C) 1999-2007 Jack Lloyd
4* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_DLIES_H_
10#define BOTAN_DLIES_H_
11
12#include <botan/cipher_mode.h>
13#include <botan/dh.h>
14#include <botan/kdf.h>
15#include <botan/mac.h>
16#include <botan/pubkey.h>
17
19
20namespace Botan {
21
22/**
23* DLIES Encryption
24*/
25class BOTAN_PUBLIC_API(2, 0) DLIES_Encryptor final : public PK_Encryptor {
26 public:
27 /**
28 * Stream mode: use KDF to provide a stream of bytes to xor with the message
29 *
30 * @param own_priv_key own (ephemeral) DH private key
31 * @param rng the RNG to use
32 * @param kdf the KDF that should be used
33 * @param mac the MAC function that should be used
34 * @param mac_key_len key length of the MAC function. Default = 20 bytes
35 *
36 * output = (ephemeral) public key + ciphertext + tag
37 */
38 BOTAN_DEPRECATED("DLIES support is deprecated")
39 DLIES_Encryptor(const DH_PrivateKey& own_priv_key,
41 std::unique_ptr<KDF> kdf,
42 std::unique_ptr<MessageAuthenticationCode> mac,
43 size_t mac_key_len = 20);
44
45 /**
46 * Block cipher mode
47 *
48 * @param own_priv_key own (ephemeral) DH private key
49 * @param rng the RNG to use
50 * @param kdf the KDF that should be used
51 * @param cipher the block cipher that should be used
52 * @param cipher_key_len the key length of the block cipher
53 * @param mac the MAC function that should be used
54 * @param mac_key_len key length of the MAC function. Default = 20 bytes
55 *
56 * output = (ephemeral) public key + ciphertext + tag
57 */
58 BOTAN_DEPRECATED("DLIES support is deprecated")
59 DLIES_Encryptor(const DH_PrivateKey& own_priv_key,
61 std::unique_ptr<KDF> kdf,
62 std::unique_ptr<Cipher_Mode> cipher,
63 size_t cipher_key_len,
64 std::unique_ptr<MessageAuthenticationCode> mac,
65 size_t mac_key_len = 20);
66
67 // Set the other parties public key
68 inline void set_other_key(const std::vector<uint8_t>& other_pub_key) { m_other_pub_key = other_pub_key; }
69
70 /// Set the initialization vector for the data encryption method
71 ///
72 /// If DLIES is being used with a cipher, a fresh IV must be provided for
73 /// each message; it is not included in the serialized ciphertext and must
74 /// be conveyed separately.
75 inline void set_initialization_vector(const InitializationVector& iv) { m_iv = iv; }
76
77 private:
78 std::vector<uint8_t> enc(const uint8_t in[], size_t length, RandomNumberGenerator& rng) const override;
79
80 size_t maximum_input_size() const override;
81
82 size_t ciphertext_length(size_t ptext_len) const override;
83
84 std::vector<uint8_t> m_other_pub_key;
85 std::vector<uint8_t> m_own_pub_key;
87 std::unique_ptr<KDF> m_kdf;
88 std::unique_ptr<Cipher_Mode> m_cipher;
89 const size_t m_cipher_key_len;
90 std::unique_ptr<MessageAuthenticationCode> m_mac;
91 const size_t m_mac_keylen;
93};
94
95/**
96* DLIES Decryption
97*/
98class BOTAN_PUBLIC_API(2, 0) DLIES_Decryptor final : public PK_Decryptor {
99 public:
100 /**
101 * Stream mode: use KDF to provide a stream of bytes to xor with the message
102 *
103 * @param own_priv_key own (ephemeral) DH private key
104 * @param rng the RNG to use
105 * @param kdf the KDF that should be used
106 * @param mac the MAC function that should be used
107 * @param mac_key_len key length of the MAC function. Default = 20 bytes
108 *
109 * input = (ephemeral) public key + ciphertext + tag
110 */
111 BOTAN_DEPRECATED("DLIES support is deprecated")
112 DLIES_Decryptor(const DH_PrivateKey& own_priv_key,
114 std::unique_ptr<KDF> kdf,
115 std::unique_ptr<MessageAuthenticationCode> mac,
116 size_t mac_key_len = 20);
117
118 /**
119 * Block cipher mode
120 *
121 * @param own_priv_key own (ephemeral) DH private key
122 * @param rng the RNG to use
123 * @param kdf the KDF that should be used
124 * @param cipher the block cipher that should be used
125 * @param cipher_key_len the key length of the block cipher
126 * @param mac the MAC function that should be used
127 * @param mac_key_len key length of the MAC function. Default = 20 bytes
128 *
129 * input = (ephemeral) public key + ciphertext + tag
130 */
131 BOTAN_DEPRECATED("DLIES support is deprecated")
132 DLIES_Decryptor(const DH_PrivateKey& own_priv_key,
134 std::unique_ptr<KDF> kdf,
135 std::unique_ptr<Cipher_Mode> cipher,
136 size_t cipher_key_len,
137 std::unique_ptr<MessageAuthenticationCode> mac,
138 size_t mac_key_len = 20);
139
140 /// Set the initialization vector for the data decryption method
141 ///
142 /// If DLIES is being used with a cipher, a fresh IV must be provided for
143 /// each message; it is not included in the serialized ciphertext and must
144 /// be conveyed separately.
145 inline void set_initialization_vector(const InitializationVector& iv) { m_iv = iv; }
146
147 private:
148 secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask, const uint8_t in[], size_t in_len) const override;
149
150 size_t plaintext_length(size_t ctext_len) const override;
151
152 size_t ciphertext_length(size_t ptext_len) const override;
153
154 const size_t m_pub_key_size;
155 PK_Key_Agreement m_ka;
156 std::unique_ptr<KDF> m_kdf;
157 std::unique_ptr<Cipher_Mode> m_cipher;
158 const size_t m_cipher_key_len;
159 std::unique_ptr<MessageAuthenticationCode> m_mac;
160 const size_t m_mac_keylen;
162};
163
164} // namespace Botan
165
166#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:100
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
void set_initialization_vector(const InitializationVector &iv)
Definition dlies.h:145
DLIES_Decryptor(const DH_PrivateKey &own_priv_key, RandomNumberGenerator &rng, std::unique_ptr< KDF > kdf, std::unique_ptr< MessageAuthenticationCode > mac, size_t mac_key_len=20)
Definition dlies.cpp:115
DLIES_Encryptor(const DH_PrivateKey &own_priv_key, RandomNumberGenerator &rng, std::unique_ptr< KDF > kdf, std::unique_ptr< MessageAuthenticationCode > mac, size_t mac_key_len=20)
Definition dlies.cpp:17
void set_initialization_vector(const InitializationVector &iv)
Definition dlies.h:75
void set_other_key(const std::vector< uint8_t > &other_pub_key)
Definition dlies.h:68
PK_Decryptor()=default
virtual size_t ciphertext_length(size_t ptext_len) const =0
virtual size_t maximum_input_size() const =0
PK_Encryptor()=default
OctetString InitializationVector
Definition symkey.h:158
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128