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