A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-key.h
Go to the documentation of this file.
1/*
2 * Copyright(c) 2020 DOTFEESA www.tk.etf.unsa.ba
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
9 * Miralem Mehic <miralem.mehic@ieee.org>
10 */
11#ifndef QKD_KEY_H
12#define QKD_KEY_H
13
14#include <stdint.h>
15#include <algorithm>
16#include <stdint.h>
17
18#include "ns3/packet.h"
19#include "ns3/object.h"
20#include "ns3/callback.h"
21#include "ns3/assert.h"
22#include "ns3/ptr.h"
23#include "ns3/simulator.h"
24#include <time.h>
25#include "ns3/nstime.h"
26#include "ns3/traced-callback.h"
27#include "ns3/deprecated.h"
28#include <string>
29#include <iomanip>
30#include <vector>
31#include <bitset>
32/*
33#include <crypto++/iterhash.h>
34#include <crypto++/secblock.h>
35*/
36namespace ns3 {
37
38/**
39 * @ingroup qkd
40 * @brief The QKD key is an elementary class of QKDNetSim. It is used
41 * to describe the key that is established in the QKD process.
42
43 * @noteIn the QKD process, keys are stored as blocks.
44 * Later, some part of the block is taken and used for encryption,
45 * while others remain in the buffer. Operations regarding QKD
46 * Key management(merge, split and other) are under construction.
47 * Each QKDKey is identified using a unique 32 long character identifier.
48 * The key is also marked with the timestamp of its origin, its length,
49 * and the condition in which the key is located. QKDKey can be found
50 * in one of the following states:
51 * INIT - the call for the establishment of the key record is initiated
52 * READY - the key is successfully created and stored
53 * SERVED - the key is served for usage on request
54 * USED - the key is used for cryptographic operations(under construction)
55 * OBSOLETE - the key validity has expired(under construction)
56 * RESTORED - the key is restored for further usage(under construction)
57 */
58class QKDKey : public Object
59{
60 public:
61
62 /**
63 * @brief QKD Key States
64 */
74
75 /**
76 * @brief Get the TypeId
77 *
78 * @return The TypeId for this class
79 */
80 static TypeId GetTypeId();
81
82 /**
83 * @brief Create an empty QKD key of a key size
84 */
85 QKDKey(uint64_t keySize);
86
87 /**
88 * @brief Create an empty QKD key of a key size
89 */
90 QKDKey(std::string keyId, uint64_t keyIdnum, uint64_t keySize);
91
92 QKDKey(std::string keyId, uint64_t keyIdnum, std::string key);
93
94 QKDKey(std::string keyId, std::string key); //KMS key generation!
95
96 std::string GetId() const;
97 void SetId(std::string);
98
99 /**
100 * @brief Help function - Copy key
101 * @return Ptr<QKDKey>
102 */
103 Ptr<QKDKey> Copy() const;
104
105 /**
106 * Return key in byte* which is necessery for encryption or authentication
107 * Convert key from std::String to byte*
108 * @return byte*
109 */
110 uint8_t * GetKey();
111
112 /**
113 * @brief Get QKD key
114 * @return string key
115 */
116 std::string GetKeyString();
117
118 void SetValue(std::string);
119
120 /**
121 * Return key in bits which is necessery for encryption or authentication
122 * @return string
123 */
124 std::string GetKeyBinary();
125
126 /**
127 * @brief Get the size of the key
128 * @return uint64_t
129 */
130 uint64_t GetSize() const;
131
132 /**
133 * @brief Get the size of the key in bits
134 * @return uint64_t
135 */
136 uint64_t GetSizeInBits() const;
137
138 /**
139 * @brief Set the size of the key
140 * @param uint64_t
141 */
142 void SetSize(uint64_t);
143
144 void MarkReady();
145
146 void MarkUsed();
147
148 void MarkRestored();
149
150 void MarkServed();
151
152 void MarkReserved();
153
154 /**
155 * @brief Return the raw key in std::string format and switch to SERVED state
156 * @return std::string
157 */
158 std::string ConsumeKeyString();
159
160 /**
161 * @brief Return the raw key in std::string format
162 * @return std::string
163 */
164 std::string ToString();
165
166 /**
167 * @brief Return random string
168 * @param len length of string to generate
169 * @return string random string
170 */
171 std::string GenerateRandomString(const int len);
172
173 /**
174 * Returns the current state of the key.
175 * @return The current state of the key.
176 */
177 QKDKeyState_e GetState() const;
178
179 /**
180 * Returns the current state of the key in string format.
181 * @return The current state of the key in string format.
182 */
183 std::string GetStateString() const;
184
185 /**
186 * Returns the given state in string format.
187 * @param state An arbitrary state of a key.
188 * @return The given state equivalently expressed in string format.
189 */
190 static std::string GetStateString(QKDKeyState_e state);
191
192 /**
193 * Change the state of the key. Fires the `StateTransition` trace source.
194 * @param state The new state.
195 */
196 void SwitchToState(QKDKeyState_e state);
197
198 /**
199 * Get timestamp of the key
200 * @return Time key timestamp
201 */
203
204 /**
205 * Save details about the QKD module that generated key
206 * @param QKDModuleId.
207 */
208 void SetModuleId(std::string);
209
210 /**
211 * Returns the id of the QKD module that generated key
212 * @return The id of the QKD module that generated key
213 */
214 std::string GetModuleId();
215
216 /// The `StateTransition` trace source.
218
219 protected:
220 std::string m_id; //<! QKDKeyID
221 std::string m_key; //<! QKDKey raw value
222 uint64_t m_size; //<! QKDKey size
223 private:
224 uint64_t m_internalID;
225 static uint64_t m_globalUid; //<! Global static QKDKeyID
226 Time m_timestamp; //<! QKDKey generation timestamp
227 QKDKeyState_e m_state; //!< state of the key
228 std::string m_moduleId; //!< id of QKD module that generated key
229
230 };
231
232} // namespace ns3
233
234#endif /* QKD_KEY_H */
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
The QKD key is an elementary class of QKDNetSim.
Definition qkd-key.h:59
void MarkUsed()
Definition qkd-key.cc:250
std::string GetModuleId()
Returns the id of the QKD module that generated key.
Definition qkd-key.cc:362
Ptr< QKDKey > Copy() const
Help function - Copy key.
Definition qkd-key.cc:45
std::string GetKeyString()
Get QKD key.
Definition qkd-key.cc:147
void SetId(std::string)
Definition qkd-key.cc:181
std::string GenerateRandomString(const int len)
Return random string.
Definition qkd-key.cc:271
void SetModuleId(std::string)
Save details about the QKD module that generated key.
Definition qkd-key.cc:356
Time GetKeyTimestamp()
Get timestamp of the key.
Definition qkd-key.cc:350
static TypeId GetTypeId()
Get the TypeId.
Definition qkd-key.cc:30
std::string ToString()
Return the raw key in std::string format.
Definition qkd-key.cc:220
uint64_t m_internalID
Definition qkd-key.h:224
std::string GetKeyBinary()
Return key in bits which is necessery for encryption or authentication.
Definition qkd-key.cc:162
void MarkReady()
Definition qkd-key.cc:237
QKDKeyState_e
QKD Key States.
Definition qkd-key.h:65
std::string m_moduleId
id of QKD module that generated key
Definition qkd-key.h:228
QKDKeyState_e m_state
state of the key
Definition qkd-key.h:227
void MarkRestored()
Definition qkd-key.cc:257
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
Definition qkd-key.h:217
void SetSize(uint64_t)
Set the size of the key.
Definition qkd-key.cc:201
std::string ConsumeKeyString()
Return the raw key in std::string format and switch to SERVED state.
Definition qkd-key.cc:212
std::string m_key
Definition qkd-key.h:221
std::string GetId() const
Definition qkd-key.cc:175
uint64_t m_size
Definition qkd-key.h:222
uint64_t GetSize() const
Get the size of the key.
Definition qkd-key.cc:187
void MarkServed()
Definition qkd-key.cc:243
std::string GetStateString() const
Returns the current state of the key in string format.
Definition qkd-key.cc:330
void SetValue(std::string)
Definition qkd-key.cc:154
void SwitchToState(QKDKeyState_e state)
Change the state of the key.
Definition qkd-key.cc:336
void MarkReserved()
Definition qkd-key.cc:265
uint64_t GetSizeInBits() const
Get the size of the key in bits.
Definition qkd-key.cc:194
std::string m_id
Definition qkd-key.h:220
Time m_timestamp
Definition qkd-key.h:226
QKDKeyState_e GetState() const
Returns the current state of the key.
Definition qkd-key.cc:288
uint8_t * GetKey()
Return key in byte* which is necessery for encryption or authentication Convert key from std::String ...
Definition qkd-key.cc:227
static uint64_t m_globalUid
Definition qkd-key.h:225
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.