Zero Trust IoT library
Loading...
Searching...
No Matches
ns3 Namespace Reference

Data Structures

class  ZtPolicyEngine
 Implements policy enforcement for Zero Trust security in NS-3 simulations. More...
 
class  ZtTlsHandshake
 Simulates a Zero Trust-based TLS handshake mechanism between NS-3 nodes. More...
 

Functions

std::string EncryptPayload (const std::string &data, const byte *key, std::string &ivOut)
 Encrypts a plaintext string using AES-CBC mode with a randomly generated IV.
 
std::string DecryptPayload (const std::string &cipher, const byte *key)
 Decrypts a ciphertext string encrypted with EncryptPayload.
 
SecByteBlock HexDecodeKey (const std::string &hex)
 Decodes a hex-encoded AES key string into a raw key byte block.
 
std::vector< CryptoPP::byte > HexToBytes (const std::string &hex)
 Converts a hexadecimal string into a byte vector.
 
std::string EncryptPayload (const std::string &data, const CryptoPP::byte *key, std::string &ivOut)
 Encrypts the given plaintext using AES-CBC with a randomly generated IV.
 
std::string DecryptPayload (const std::string &cipher, const CryptoPP::byte *key)
 Decrypts the given ciphertext using AES-CBC.
 
 NS_LOG_COMPONENT_DEFINE ("ZtPolicyEngine")
 
 NS_LOG_COMPONENT_DEFINE ("ZtTlsHandshake")
 

Function Documentation

◆ DecryptPayload() [1/2]

std::string ns3::DecryptPayload ( const std::string &  cipher,
const byte *  key 
)

Decrypts a ciphertext string encrypted with EncryptPayload.

Parameters
cipherThe ciphertext with the IV prepended.
keyThe AES key used for decryption.
Returns
The decrypted plaintext string.

Definition at line 48 of file zt-encryption-utils.cc.

48 {
49 std::string iv = cipher.substr(0, AES::BLOCKSIZE);
50 std::string actualCipher = cipher.substr(AES::BLOCKSIZE);
51
52 std::string recovered;
53 CBC_Mode<AES>::Decryption dec;
54 dec.SetKeyWithIV(key, AES::DEFAULT_KEYLENGTH, (const byte*)iv.data());
55
56 StringSource(actualCipher, true,
57 new StreamTransformationFilter(dec,
58 new StringSink(recovered)
59 )
60 );
61
62 return recovered;
63}
Here is the caller graph for this function:

◆ DecryptPayload() [2/2]

std::string ns3::DecryptPayload ( const std::string &  cipher,
const CryptoPP::byte *  key 
)

Decrypts the given ciphertext using AES-CBC.

Parameters
cipherThe ciphertext with the IV prepended.
keyPointer to the AES key used for decryption.
Returns
The recovered plaintext string.

◆ EncryptPayload() [1/2]

std::string ns3::EncryptPayload ( const std::string &  data,
const byte *  key,
std::string &  ivOut 
)

Encrypts a plaintext string using AES-CBC mode with a randomly generated IV.

Parameters
dataThe plaintext data to encrypt.
keyThe AES key used for encryption.
ivOutReference to store the generated IV.
Returns
The resulting ciphertext with the IV prepended.

Definition at line 22 of file zt-encryption-utils.cc.

22 {
23 AutoSeededRandomPool prng;
24 byte iv[AES::BLOCKSIZE];
25 prng.GenerateBlock(iv, sizeof(iv));
26 ivOut.assign((char*)iv, AES::BLOCKSIZE);
27
28 std::string cipher;
29 CBC_Mode<AES>::Encryption enc;
30 enc.SetKeyWithIV(key, AES::DEFAULT_KEYLENGTH, iv);
31
32 StringSource(data, true,
33 new StreamTransformationFilter(enc,
34 new StringSink(cipher)
35 )
36 );
37
38 return ivOut + cipher; // prepend IV to ciphertext
39}
Here is the caller graph for this function:

◆ EncryptPayload() [2/2]

std::string ns3::EncryptPayload ( const std::string &  data,
const CryptoPP::byte *  key,
std::string &  ivOut 
)

Encrypts the given plaintext using AES-CBC with a randomly generated IV.

Parameters
dataThe plaintext to encrypt.
keyPointer to the AES key used for encryption.
ivOutReference to store the generated IV used during encryption.
Returns
The ciphertext with the IV prepended.

◆ HexDecodeKey()

CryptoPP::SecByteBlock ns3::HexDecodeKey ( const std::string &  hex)

Decodes a hex-encoded AES key string into a raw key byte block.

Converts a hexadecimal string into a raw AES key.

Parameters
hexHexadecimal string representing the AES key.
Returns
A Crypto++ SecByteBlock containing the decoded key.
Parameters
hexThe hex-encoded AES key string.
Returns
A CryptoPP SecByteBlock representing the decoded key.

Definition at line 71 of file zt-encryption-utils.cc.

71 {
72 SecByteBlock key(AES::DEFAULT_KEYLENGTH);
73 StringSource(hex, true,
74 new HexDecoder(new ArraySink(key, key.size())));
75 return key;
76}
Here is the caller graph for this function:

◆ HexToBytes()

std::vector< CryptoPP::byte > ns3::HexToBytes ( const std::string &  hex)

Converts a hexadecimal string into a byte vector.

Parameters
hexThe hexadecimal string to convert.
Returns
A vector of bytes corresponding to the decoded hex string.
Parameters
hexThe hex string to convert.
Returns
A vector of bytes decoded from the hexadecimal input.

Definition at line 84 of file zt-encryption-utils.cc.

84 {
85 std::string decoded;
86 CryptoPP::StringSource(hex, true,
87 new CryptoPP::HexDecoder(
88 new CryptoPP::StringSink(decoded)
89 )
90 );
91
92 return std::vector<CryptoPP::byte>(decoded.begin(), decoded.end());
93}
Here is the caller graph for this function:

◆ NS_LOG_COMPONENT_DEFINE() [1/2]

ns3::NS_LOG_COMPONENT_DEFINE ( "ZtPolicyEngine"  )

◆ NS_LOG_COMPONENT_DEFINE() [2/2]

ns3::NS_LOG_COMPONENT_DEFINE ( "ZtTlsHandshake"  )