Botan 3.0.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/pubkey.h>
13#include <botan/mac.h>
14#include <botan/kdf.h>
15#include <botan/dh.h>
16#include <botan/cipher_mode.h>
17
18namespace 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 std::unique_ptr<KDF> kdf,
40 std::unique_ptr<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,
58 std::unique_ptr<KDF> kdf,
59 std::unique_ptr<Cipher_Mode> cipher,
60 size_t cipher_key_len,
61 std::unique_ptr<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
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 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*/
99 {
100 public:
101 /**
102 * Stream mode: use KDF to provide a stream of bytes to xor with the message
103 *
104 * @param own_priv_key own (ephemeral) DH private key
105 * @param rng the RNG to use
106 * @param kdf the KDF that should be used
107 * @param mac the MAC function that should be used
108 * @param mac_key_len key length of the MAC function. Default = 20 bytes
109 *
110 * input = (ephemeral) public key + ciphertext + tag
111 */
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 DLIES_Decryptor(const DH_PrivateKey& own_priv_key,
133 std::unique_ptr<KDF> kdf,
134 std::unique_ptr<Cipher_Mode> cipher,
135 size_t cipher_key_len,
136 std::unique_ptr<MessageAuthenticationCode> mac,
137 size_t mac_key_len = 20);
138
139 /// Set the initialization vector for the data decryption method
141 {
142 m_iv = iv;
143 }
144
145 private:
146 secure_vector<uint8_t> do_decrypt(uint8_t& valid_mask,
147 const uint8_t in[], size_t in_len) const override;
148
149 size_t plaintext_length(size_t ctext_len) const override;
150
151 const size_t m_pub_key_size;
152 PK_Key_Agreement m_ka;
153 std::unique_ptr<KDF> m_kdf;
154 std::unique_ptr<Cipher_Mode> m_cipher;
155 const size_t m_cipher_key_len;
156 std::unique_ptr<MessageAuthenticationCode> m_mac;
157 const size_t m_mac_keylen;
159 };
160
161}
162
163#endif
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data decryption method.
Definition: dlies.h:140
void set_initialization_vector(const InitializationVector &iv)
Set the initialization vector for the data encryption method.
Definition: dlies.h:71
void set_other_key(const std::vector< uint8_t > &other_pub_key)
Definition: dlies.h:65
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64