Botan  2.4.0
Crypto and TLS for C++11
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 */
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,
39  KDF* kdf,
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,
58  KDF* kdf,
59  Cipher_Mode* cipher,
60  size_t cipher_key_len,
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
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;
91  };
92 
93 /**
94 * DLIES Decryption
95 */
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,
112  KDF* kdf,
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,
131  KDF* kdf,
132  Cipher_Mode* cipher,
133  size_t cipher_key_len,
135  size_t mac_key_len = 20);
136 
137  /// Set the initialization vector for the data decryption method
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;
155  };
156 
157 }
158 
159 #endif
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data encryption method.
Definition: dlies.h:71
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data decryption method.
Definition: dlies.h:138
Definition: alg_id.cpp:13
void set_other_key(const std::vector< uint8_t > &other_pub_key)
Definition: dlies.h:65
Definition: kdf.h:20
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88