Botan 2.19.5 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
18 namespace Botan {
19
20/**
21* DLIES Encryption
22*/
23 class BOTAN_PUBLIC_API(2,0) DLIES_Encryptor final : 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 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;
86 PK_Key_Agreement m_ka;
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;
92 InitializationVector m_iv;
93 };
94
95/**
96* DLIES Decryption
97*/
98 class BOTAN_PUBLIC_API(2,0) DLIES_Decryptor final : public PK_Decryptor
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,
113 RandomNumberGenerator& rng,
114 KDF* kdf,
115 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,
132 RandomNumberGenerator& rng,
133 KDF* kdf,
134 Cipher_Mode* cipher,
135 size_t cipher_key_len,
136 MessageAuthenticationCode* mac,
137 size_t mac_key_len = 20);
138
139 /// Set the initialization vector for the data decryption method
140 inline void set_initialization_vector(const InitializationVector& iv)
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;
158 InitializationVector m_iv;
159 };
160
161}
162
163#endif
Botan::Cipher_Mode
Definition: cipher_mode.h:29
Botan::DH_PrivateKey
Definition: dh.h:52
Botan::DLIES_Decryptor
Definition: dlies.h:99
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:140
Botan::DLIES_Encryptor
Definition: dlies.h:24
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::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:21
Botan::MessageAuthenticationCode
Definition: mac.h:23
Botan::OctetString
Definition: symkey.h:20
Botan::PK_Decryptor
Definition: pubkey.h:85
Botan::PK_Encryptor
Definition: pubkey.h:30
Botan::PK_Key_Agreement
Definition: pubkey.h:414
Botan::RandomNumberGenerator
Definition: rng.h:26
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan
Definition: alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65