A Discrete-Event Network Simulator
API
qkd-key.h
Go to the documentation of this file.
1 
2 
3 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4 /*
5  * Copyright (c) 2020 DOTFEESA www.tk.etf.unsa.ba
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation;
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
21  * Miralem Mehic <miralem.mehic@ieee.org>
22  */
23 #ifndef QKD_KEY_H
24 #define QKD_KEY_H
25 
26 #include <stdint.h>
27 #include <algorithm>
28 #include <stdint.h>
29 
30 #include "ns3/packet.h"
31 #include "ns3/object.h"
32 #include "ns3/callback.h"
33 #include "ns3/assert.h"
34 #include "ns3/ptr.h"
35 #include "ns3/simulator.h"
36 #include <time.h>
37 #include "ns3/nstime.h"
38 #include "ns3/traced-callback.h"
39 #include "ns3/random-variable-stream.h"
40 #include "ns3/deprecated.h"
41 #include <string>
42 #include <iomanip>
43 #include <vector>
44 #include <bitset>
45 /*
46 #include <crypto++/iterhash.h>
47 #include <crypto++/secblock.h>
48 */
49 namespace ns3 {
50 
69 class QKDKey : public Object
70 {
71  public:
72 
84  RESERVED
85  };
86 
91  static TypeId GetTypeId (void);
92 
97  QKDKey (uint64_t keySize);
98 
105  QKDKey (std::string keyId, uint64_t keyIdnum, uint64_t keySize);
106 
113  QKDKey (std::string keyId, uint64_t keyIdnum, std::string key);
114 
120  QKDKey (std::string keyId, std::string key); //KMS key generation!
121 
126  std::string GetId (void) const;
127 
132  void SetId (std::string value);
133 
138  Ptr<QKDKey> Copy (void) const;
139 
147  uint8_t * GetKey (void);
148 
153  std::string GetKeyString (void);
154 
159  std::string GetKeyBinary();
160 
165  uint64_t GetSize(void) const;
166 
171  uint64_t GetSizeInBits(void) const;
172 
177  void SetSize(uint64_t sizeInBytes);
178 
182  void MarkReady();
183 
187  void MarkUsed();
188 
192  void MarkRestored();
193 
197  void MarkServed();
198 
202  void MarkReserved();
203 
207  void MarkTransformed();
208 
213  std::string ConsumeKeyString (void);
214 
219  std::string ToString (void);
220 
226  std::string GenerateRandomString(const int len);
227 
232  QKDKeyState_e GetState () const;
233 
238  std::string GetStateString () const;
239 
245  static std::string GetStateString (QKDKeyState_e state);
246 
251  void SwitchToState (QKDKeyState_e state);
252 
258 
261 
262  private:
263  uint64_t m_internalID; //<! The internal key identifier.
264  std::string m_id; //<! The key identifier.
265  static uint64_t m_globalUid; //<! The global static key identifier.
266  uint64_t m_sizeInBytes; //<! The key size in bytes.
267  uint64_t m_sizeInBits; //<! The key size in bits.
268  std::string m_key; //<! The key value.
269  Time m_timestamp; //<! The key timestamp.
271  Ptr<UniformRandomVariable> m_random; //<! The uniform random variable.
272 
273  };
274 
275 } // namespace ns3
276 
277 #endif /* QKD_KEY_H */
A base class which provides memory management and object aggregation.
Definition: object.h:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
The QKD key is an elementary class of QKDNetSim.
Definition: qkd-key.h:70
void MarkUsed()
Mark the key as used.
Definition: qkd-key.cc:265
std::string GenerateRandomString(const int len)
Get a random string.
Definition: qkd-key.cc:292
void SetId(std::string value)
Set the key identifier.
Definition: qkd-key.cc:196
uint64_t m_sizeInBits
Definition: qkd-key.h:267
Time GetKeyTimestamp()
Get the key timestamp.
Definition: qkd-key.cc:376
std::string GetId(void) const
Get the key identifier.
Definition: qkd-key.cc:190
std::string GetKeyString(void)
Get QKD key value.
Definition: qkd-key.cc:170
uint64_t m_internalID
Definition: qkd-key.h:263
std::string GetKeyBinary()
Get key value in bit notation.
Definition: qkd-key.cc:177
void MarkReady()
Mark the key as ready.
Definition: qkd-key.cc:252
QKDKeyState_e
The QKD key states.
Definition: qkd-key.h:76
@ OBSOLETE
Definition: qkd-key.h:82
@ TRANSFORMED
Definition: qkd-key.h:80
@ RESTORED
Definition: qkd-key.h:83
@ RESERVED
Definition: qkd-key.h:84
std::string ConsumeKeyString(void)
Get the key value and switch the key state to SERVED.
Definition: qkd-key.cc:227
uint8_t * GetKey(void)
Get key value in byte* format.
Definition: qkd-key.cc:242
QKDKeyState_e m_state
The key state.
Definition: qkd-key.h:270
uint64_t GetSizeInBits(void) const
Get the key size in bits.
Definition: qkd-key.cc:209
void MarkRestored()
Mark the key as restored.
Definition: qkd-key.cc:272
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
Definition: qkd-key.h:260
std::string m_key
Definition: qkd-key.h:268
void SetSize(uint64_t sizeInBytes)
Set the key size.
Definition: qkd-key.cc:216
void MarkServed()
Mark the key as served.
Definition: qkd-key.cc:258
std::string GetStateString() const
Get the current state of the key in a string format.
Definition: qkd-key.cc:356
Ptr< UniformRandomVariable > m_random
Definition: qkd-key.h:271
void SwitchToState(QKDKeyState_e state)
Change the state of the key.
Definition: qkd-key.cc:362
void MarkReserved()
Mark the key as reserved.
Definition: qkd-key.cc:280
uint64_t m_sizeInBytes
Definition: qkd-key.h:266
static TypeId GetTypeId(void)
Get the TypeId.
Definition: qkd-key.cc:40
Ptr< QKDKey > Copy(void) const
Copy the key.
Definition: qkd-key.cc:55
std::string m_id
Definition: qkd-key.h:264
Time m_timestamp
Definition: qkd-key.h:269
QKDKey(uint64_t keySize)
Constructor.
Definition: qkd-key.cc:68
std::string ToString(void)
Get the key value.
Definition: qkd-key.cc:235
QKDKeyState_e GetState() const
Get the current state of the key.
Definition: qkd-key.cc:311
uint64_t GetSize(void) const
Get the key size in bytes.
Definition: qkd-key.cc:202
void MarkTransformed()
Mark the key as transformed.
Definition: qkd-key.cc:286
static uint64_t m_globalUid
Definition: qkd-key.h:265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.