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