A Discrete-Event Network Simulator
API
qkd-encryptor.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 DOTFEESA www.tk.etf.unsa.ba
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Miralem Mehic <miralem.mehic@ieee.org>
19  */
20 
21 #ifndef QKDEncryptor_H
22 #define QKDEncryptor_H
23 
24 #include <algorithm>
25 #include <stdint.h>
26 
27 #include "ns3/header.h"
28 #include "ns3/tcp-header.h"
29 #include "ns3/udp-header.h"
30 #include "ns3/icmpv4.h"
31 
32 #include "ns3/dsdv-packet.h"
33 #include "ns3/aodv-packet.h"
34 #include "ns3/olsr-header.h"
35 
36 #include "ns3/packet.h"
37 #include "ns3/tag.h"
38 #include "ns3/object.h"
39 #include "ns3/callback.h"
40 #include "ns3/assert.h"
41 #include "ns3/ptr.h"
42 #include "ns3/deprecated.h"
43 #include "ns3/traced-value.h"
44 #include "ns3/packet-metadata.h"
45 #include "ns3/trace-source-accessor.h"
46 #include "ns3/qkd-buffer.h"
47 #include "ns3/qkd-key.h"
48 #include "ns3/net-device.h"
49 #include "ns3/node.h"
50 
51 #include <crypto++/aes.h>
52 #include <crypto++/modes.h>
53 #include <crypto++/filters.h>
54 #include <crypto++/hex.h>
55 #include <crypto++/osrng.h>
56 #include <crypto++/ccm.h>
57 #include <crypto++/vmac.h>
58 #include <crypto++/iterhash.h>
59 #include <crypto++/secblock.h>
60 #include <crypto++/sha.h>
61 #include <cryptopp/base64.h>
62 #include <vector>
63 
64 typedef unsigned char byte;
65 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
66 #include <crypto++/md5.h>
67 
68 namespace ns3 {
69 
89 class QKDEncryptor : public Object
90 {
91 public:
92 
100  };
101 
110  };
111 
119  QKDEncryptor (EncryptionType type1, AuthenticationType type2, uint32_t authTagLength);
123  void ChangeSettings (EncryptionType type1, AuthenticationType type2, uint32_t authTagLength);
127  virtual ~QKDEncryptor ();
128 
133  static TypeId GetTypeId (void);
134 
139  void SetNode (Ptr<Node> node);
140 
145  Ptr<Node> GetNode ();
146 
151  void SetIndex (uint32_t index);
152 
157  uint32_t GetIndex ();
158 
165  std::string OTP (const std::string& key, const std::string& data);
166 
173  std::string AESEncrypt (const std::string& key, const std::string& data);
174 
181  std::string AESDecrypt (const std::string& key, const std::string& data);
182 
189  std::string EncryptMsg(std::string input, std::string key);
190 
197  std::string DecryptMsg (std::string input, std::string key);
198 
205  std::string Authenticate(std::string& data, std::string key = "0");
206 
214  bool CheckAuthentication(std::string payload, std::string authTag, std::string key = "0");
215 
221  std::string HexEncode(const std::string& data);
222 
228  std::string HexDecode(const std::string& data);
229 
235  std::string Base64Encode(std::string input);
236 
242  std::string Base64Decode(std::string input);
243 
250  std::string VMAC (std::string& key, std::string& inputString);
251 
257  std::string MD5 (std::string& inputString);
258 
264  std::string SHA1 (std::string& inputString);
265 
266 private:
267 
268  byte m_iv [ CryptoPP::AES::BLOCKSIZE ];
269 
271  uint32_t m_index;
272 
276 
279 
282 
285 
286 
287 };
288 } // namespace ns3
289 
290 #endif /* QKDEncryptor_QKD_H */
A base class which provides memory management and object aggregation.
Definition: object.h:88
Introspection did not find any typical Config paths.
Definition: qkd-encryptor.h:90
uint32_t m_index
An index in the qkd encryptor container.
bool m_encryptionEnabled
Execute the actual encryption algorithm?
std::string EncryptMsg(std::string input, std::string key)
Encrypt a plaintext.
std::string HexDecode(const std::string &data)
Decode the HEX string.
std::string AESEncrypt(const std::string &key, const std::string &data)
Encrypt data using AES algorithm.
EncryptionType
Encryption type.
Definition: qkd-encryptor.h:96
uint32_t GetIndex()
Get the internal index identifier in the qkd encryptor container.
void SetNode(Ptr< Node > node)
Set node on which qkd encryptor is installed.
void SetIndex(uint32_t index)
Set the internal index identifier in the qkd encryptor container.
static TypeId GetTypeId(void)
Get the TypeId.
std::string Authenticate(std::string &data, std::string key="0")
Calculate an authentication tag on a message.
bool CheckAuthentication(std::string payload, std::string authTag, std::string key="0")
Authenticate the packet.
byte m_iv[CryptoPP::AES::BLOCKSIZE]
std::string Base64Decode(std::string input)
Base64 decoder.
TracedCallback< Ptr< Packet >, std::string > m_authenticationTrace
A trace callback for the authentication.
std::string VMAC(std::string &key, std::string &inputString)
Calculate authentication tag in Wegman-Carter fashion.
std::string OTP(const std::string &key, const std::string &data)
Apply the One-Time Pad cipher.
uint32_t m_authenticationTagLengthInBits
A length of the authentication tag in bits (32 by default).
std::string SHA1(std::string &inputString)
Calucale SHA1 authentication tag.
TracedCallback< Ptr< Packet >, std::string > m_deauthenticationTrace
A trace callback for the authentication check.
AuthenticationType m_authenticationType
The authentication algorithm.
Ptr< Node > m_node
A pointer to the node on which the encryptor is installed.
Ptr< Node > GetNode()
Get details about the node on which qkd encryptor is installed.
TracedCallback< Ptr< Packet > > m_decryptionTrace
A trace callback for the decryption.
AuthenticationType
Authentication type.
TracedCallback< Ptr< Packet > > m_encryptionTrace
A trace callback for the encryption.
QKDEncryptor(EncryptionType type1, AuthenticationType type2)
Constructor.
std::string HexEncode(const std::string &data)
Encode the string to the HEX string.
void ChangeSettings(EncryptionType type1, AuthenticationType type2, uint32_t authTagLength)
Constructor.
bool m_compressionEnabled
Should compression algorithms be used?
std::string DecryptMsg(std::string input, std::string key)
Decrypt a ciphertext.
std::string Base64Encode(std::string input)
Base64 encoder.
virtual ~QKDEncryptor()
Destructor.
EncryptionType m_encryptionType
The encryption algorithm.
std::string MD5(std::string &inputString)
Calculate MD5 authentication tag.
std::string AESDecrypt(const std::string &key, const std::string &data)
Decrypt data using AES algorithm.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
unsigned char byte
Definition: qkd-encryptor.h:64
uint8_t data[writeSize]