Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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/pubkey.h>
13 #include <botan/mac.h>
14 #include <botan/kdf.h>
15 #include <botan/dh.h>
16 #include <botan/cipher_mode.h>
17
18 namespace Botan {
19
20 /**
21 * DLIES Encryption
22 */
23 class BOTAN_DLL DLIES_Encryptor : public PK_Encryptor
24 {
25 public:
26 /**
27 * Stream mode: use KDF to provide a stream of bytes to xor with the message
28 *
29 * @param own_priv_key own (ephemeral) DH private key
30 * @param rng the RNG to use
31 * @param kdf the KDF that should be used
32 * @param mac the MAC function that should be used
33 * @param mac_key_len key length of the MAC function. Default = 20 bytes
34 *
35 * output = (ephemeral) public key + ciphertext + tag
36 */
37 DLIES_Encryptor(const DH_PrivateKey& own_priv_key,
38 RandomNumberGenerator& rng,
39 KDF* kdf,
40 MessageAuthenticationCode* mac,
41 size_t mac_key_len = 20);
42
43 /**
44 * Block cipher mode
45 *
46 * @param own_priv_key own (ephemeral) DH private key
47 * @param rng the RNG to use
48 * @param kdf the KDF that should be used
49 * @param cipher the block cipher that should be used
50 * @param cipher_key_len the key length of the block cipher
51 * @param mac the MAC function that should be used
52 * @param mac_key_len key length of the MAC function. Default = 20 bytes
53 *
54 * output = (ephemeral) public key + ciphertext + tag
55 */
56 DLIES_Encryptor(const DH_PrivateKey& own_priv_key,
57 RandomNumberGenerator& rng,
58 KDF* kdf,
59 Cipher_Mode* cipher,
60 size_t cipher_key_len,
61 MessageAuthenticationCode* mac,
62 size_t mac_key_len = 20);
63
64 // Set the other parties public key
65 inline void set_other_key(const std::vector<uint8_t>& other_pub_key)
66 {
67 m_other_pub_key = other_pub_key;
68 }
69
70 /// Set the initialization vector for the data encryption method
71 inline void set_initialization_vector(const InitializationVector& iv)
72 {
73 m_iv = iv;
74 }
75
76 private:
77 std::vector<uint8_t> enc(const uint8_t[], size_t,
78 RandomNumberGenerator&) const override;
79
80 size_t maximum_input_size() const override;
81
82 std::vector<uint8_t> m_other_pub_key;
83 std::vector<uint8_t> m_own_pub_key;
84 PK_Key_Agreement m_ka;
85 std::unique_ptr<KDF> m_kdf;
86 std::unique_ptr<Cipher_Mode> m_cipher;
87 const size_t m_cipher_key_len;
88 std::unique_ptr<MessageAuthenticationCode> m_mac;
89 const size_t m_mac_keylen;
90 InitializationVector m_iv;
91 };
92
93 /**
94 * DLIES Decryption
95 */
96 class BOTAN_DLL DLIES_Decryptor : public PK_Decryptor
97 {
98 public:
99 /**
100 * Stream mode: use KDF to provide a stream of bytes to xor with the message
101 *
102 * @param own_priv_key own (ephemeral) DH private key
103 * @param rng the RNG to use
104 * @param kdf the KDF that should be used
105 * @param mac the MAC function that should be used
106 * @param mac_key_len key length of the MAC function. Default = 20 bytes
107 *
108 * input = (ephemeral) public key + ciphertext + tag
109 */
110 DLIES_Decryptor(const DH_PrivateKey& own_priv_key,
111 RandomNumberGenerator& rng,
112 KDF* kdf,
113 MessageAuthenticationCode* mac,
114 size_t mac_key_len = 20);
115
116 /**
117 * Block cipher mode
118 *
119 * @param own_priv_key own (ephemeral) DH private key
120 * @param rng the RNG to use
121 * @param kdf the KDF that should be used
122 * @param cipher the block cipher that should be used
123 * @param cipher_key_len the key length of the block cipher
124 * @param mac the MAC function that should be used
125 * @param mac_key_len key length of the MAC function. Default = 20 bytes
126 *
127 * input = (ephemeral) public key + ciphertext + tag
128 */
129 DLIES_Decryptor(const DH_PrivateKey& own_priv_key,
130 RandomNumberGenerator& rng,
131 KDF* kdf,
132 Cipher_Mode* cipher,
133 size_t cipher_key_len,
134 MessageAuthenticationCode* mac,
135 size_t mac_key_len = 20);
136
137 /// Set the initialization vector for the data decryption method
138 inline void set_initialization_vector(const InitializationVector& iv)
139 {
140 m_iv = iv;
141 }
142
143 private:
144 secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask,
145 const uint8_t in[], size_t in_len) const override;
146
147 const size_t m_pub_key_size;
148 PK_Key_Agreement m_ka;
149 std::unique_ptr<KDF> m_kdf;
150 std::unique_ptr<Cipher_Mode> m_cipher;
151 const size_t m_cipher_key_len;
152 std::unique_ptr<MessageAuthenticationCode> m_mac;
153 const size_t m_mac_keylen;
154 InitializationVector m_iv;
155 };
156
157 }
158
159 #endif
Botan::OctetString
Definition: symkey.h:19
m_mac
std::unique_ptr< MessageAuthenticationCode > m_mac
Definition: fpe_fe1.cpp:88
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::DLIES_Encryptor::set_initialization_vector
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data encryption method.
Definition: dlies.h:71
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::DLIES_Decryptor::set_initialization_vector
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data decryption method.
Definition: dlies.h:138
Botan
Definition: alg_id.cpp:13
Botan::DLIES_Encryptor
Definition: dlies.h:23
Botan::PK_Key_Agreement
Definition: pubkey.h:400
Botan::DLIES_Encryptor::set_other_key
void set_other_key(const std::vector< uint8_t > &other_pub_key)
Definition: dlies.h:65
Botan::KDF
Definition: kdf.h:20
Botan::Cipher_Mode
Definition: cipher_mode.h:23
Botan::DH_PrivateKey
Definition: dh.h:49
Botan::DLIES_Decryptor
Definition: dlies.h:96
Botan::PK_Decryptor
Definition: pubkey.h:85
Botan::PK_Encryptor
Definition: pubkey.h:35