A Discrete-Event Network Simulator
API
ns3::OnionManager Class Reference

Class that manages encryption keys and the encryption and decryption of layers of onion messagess The class is implementing the OnionRouting abstract class with the encryption and decryption methods. More...

#include "onionmanager.h"

+ Inheritance diagram for ns3::OnionManager:
+ Collaboration diagram for ns3::OnionManager:

Public Member Functions

 OnionManager ()
 Default constructor. More...
 
 ~OnionManager ()
 Default destructor. More...
 
virtual void DecryptLayer (unsigned char *innerLayer, unsigned char *onion, uint16_t onionLen, unsigned char *pk, unsigned char *sk) const
 Implementing decryption using the libsodium library. More...
 
virtual void EncryptLayer (unsigned char *ciphertext, unsigned char *message, int len, unsigned char *key) const
 Implementing encryption using the libsodium library. More...
 
void GenerateNewKeyPair (void)
 Generate a new public/private keypair using the libsodium library. More...
 
unsigned char * GetPK (void)
 accessor More...
 
std::string GetPKtoString ()
 accessor More...
 
unsigned char * GetSK (void)
 accessor More...
 
std::string GetSKtoString ()
 accessor More...
 
unsigned char * IpToBuff (uint32_t in)
 Convert an Ipv4 address given as an unsigned integer value to buffer array of 4Bytes. More...
 
void SetPK (unsigned char *pk)
 setter More...
 
void SetSK (unsigned char *sk)
 setter More...
 
unsigned char * StringToUchar (std::string in)
 Convert a string to an array of unsigned chars. More...
 
std::string UcharToString (unsigned char *seq, int len)
 Convert an array of unsigned chars to a std::string. More...
 
- Public Member Functions inherited from ns3::OnionRouting
 OnionRouting ()
 
 OnionRouting (uint16_t keySize, uint16_t sealPadding, uint16_t addressSize)
 
 OnionRouting (uint16_t sealPadding, const uint16_t protocolNumber)
 Constructor – Setup parameters for the creation of onions. More...
 
virtual ~OnionRouting ()
 
void AddressToStream (uint8_t *ip)
 
void AddressToStream (uint8_t *ip)
 Output an ip address to a stream variable, used to LOG the onion message. More...
 
int BuildOnion (uint8_t *cipher, uint8_t **route, uint16_t routeLen, uint8_t **keys, uint8_t *content, uint16_t contentLen)
 
void BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t routeLen)
 Manage construction of the onion ONION_NO_CONTENT. More...
 
void BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t routeLen, uint8_t *endContent, uint16_t endContentLen)
 Manage construction of the onion ONION_ENDCONTENT. More...
 
void BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint8_t **layerContent, uint16_t layerContentLen, uint16_t routeLen)
 Manage construction of the onion ONION_LAYERCONTENT. More...
 
void BuildOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint8_t **layerContent, uint16_t layerContentLen, uint16_t routeLen, uint8_t *endContent, uint16_t endContentLen)
 Manage construction of the onion ONION_LAYERCONTENT_ENDCONTENT. More...
 
int CreateOnion (uint8_t *cipher, uint8_t **route, uint16_t index, uint16_t routeLen, uint8_t **keys, uint8_t *content, uint16_t contentLen)
 
void CreateOnion (uint8_t *cipher, uint8_t **route, uint8_t **keys, uint16_t index, uint16_t routeLen, uint8_t **layerContent, uint16_t layerContentLen, uint8_t *endContent, uint16_t endContentLen)
 Constructs the onion message *. More...
 
virtual void DecryptLayer (uint8_t *innerLayer, uint8_t *onion, uint16_t onionLen, uint8_t *pk, uint8_t *sk) const =0
 
virtual void DecryptLayer (uint8_t *plaintext, uint8_t *ciphertext, uint16_t len, uint8_t *publicKey, uint8_t *secretKey) const =0
 virtual method, implement decryption More...
 
virtual void EncryptLayer (uint8_t *ciphertext, uint8_t *message, int len, uint8_t *key) const =0
 
virtual void EncryptLayer (uint8_t *ciphertext, uint8_t *plaintext, int len, uint8_t *key) const =0
 virtual method, implement encryption More...
 
enum OnionErrno GetErrno (void)
 Return the last error code of the OnionErrno enum. More...
 
uint16_t OnionLength (uint16_t routeLen, uint16_t contentLen)
 
uint16_t OnionLength (uint16_t routeLen, uint16_t layerContentLen, uint16_t endContentLen)
 Compute the length in bytes of the onion message at given parameters. More...
 
orLayerPeelOnion (uint8_t *onion, uint16_t onionLen, uint8_t *pk, uint8_t *sk)
 
orLayerPeelOnion (uint8_t *onion, uint16_t onionLen, uint8_t *publicKey, uint8_t *secretKey)
 Decipher the outer layer of the onion and return details. More...
 

Static Public Member Functions

static TypeId GetTypeId (void)
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::OnionRouting
static TypeId GetTypeId (void)
 
static TypeId GetTypeId (void)
 Register this type. More...
 

Private Attributes

unsigned char m_publickey [crypto_box_PUBLICKEYBYTES]
 the public encryption key More...
 
unsigned char m_secretkey [crypto_box_SECRETKEYBYTES]
 the secret encryption key More...
 

Additional Inherited Members

- Public Types inherited from ns3::OnionRouting
enum  OnionErrno {
  ERROR_NOTERROR, ERROR_PROT_NUMBER, ERROR_ROUTE_TO_SHORT, ERROR_ENCRYPTION,
  ERROR_DECRYPTION
}
 Enumeration of the possible errors using the class onion-routing. More...
 
- Public Attributes inherited from ns3::OnionRouting
uint16_t m_addressSize
 size in bytes of the used address type (4-Ipv4, 16-Ipv6) More...
 
enum OnionErrno m_errno
 error status while using the onion class More...
 
uint16_t m_keySize
 
std::stringstream m_onionStream
 stringstream used to LOG onion construction More...
 
uint16_t m_sealPadding
 size increase of the ciphertext in bytes, intorduced by the encryption method More...
 

Detailed Description

Class that manages encryption keys and the encryption and decryption of layers of onion messagess The class is implementing the OnionRouting abstract class with the encryption and decryption methods.

Definition at line 47 of file onionmanager.h.

Constructor & Destructor Documentation

◆ OnionManager()

ns3::OnionManager::OnionManager ( )

Default constructor.

Definition at line 41 of file onionmanager.cc.

◆ ~OnionManager()

ns3::OnionManager::~OnionManager ( )

Default destructor.

Definition at line 45 of file onionmanager.cc.

Member Function Documentation

◆ DecryptLayer()

void ns3::OnionManager::DecryptLayer ( unsigned char *  innerLayer,
unsigned char *  onion,
uint16_t  onionLen,
unsigned char *  pk,
unsigned char *  sk 
) const
virtual

Implementing decryption using the libsodium library.

Parameters
[in,out]innerLayermemory on which the inner onion layer will be stored
[in]onionmemory locations containing the data to be decrypted
[in]lenlength in bytes of the onion
[in]pkpointer to the public encryption key
[in]skpointer to the secret encryption key

Definition at line 65 of file onionmanager.cc.

◆ EncryptLayer()

void ns3::OnionManager::EncryptLayer ( unsigned char *  ciphertext,
unsigned char *  message,
int  len,
unsigned char *  key 
) const
virtual

Implementing encryption using the libsodium library.

implement onion routing class

Parameters
[in,out]ciphertextmemory on which the ciphertext will be stored
[in]mesagememory locations containing the data to be encrypted
[in]lenlength in bytes of the plaintext
[in]keypointer to the encryption key

Definition at line 55 of file onionmanager.cc.

◆ GenerateNewKeyPair()

void ns3::OnionManager::GenerateNewKeyPair ( void  )

Generate a new public/private keypair using the libsodium library.

handling encryption keys

Definition at line 81 of file onionmanager.cc.

References m_publickey, and m_secretkey.

Referenced by ns3::Sink::StartApplication(), and ns3::SensorNode::StartApplication().

+ Here is the caller graph for this function:

◆ GetPK()

unsigned char * ns3::OnionManager::GetPK ( void  )

accessor

Returns
Return the pointer to the public key

Definition at line 88 of file onionmanager.cc.

References m_publickey.

Referenced by ns3::SensorNode::ProcessOnionHead().

+ Here is the caller graph for this function:

◆ GetPKtoString()

std::string ns3::OnionManager::GetPKtoString ( )

accessor

Returns
Return the public key as a string

Definition at line 103 of file onionmanager.cc.

References m_publickey.

Referenced by ns3::SensorNode::Handshake(), and ns3::Sink::StartApplication().

+ Here is the caller graph for this function:

◆ GetSK()

unsigned char * ns3::OnionManager::GetSK ( void  )

accessor

Returns
Return the pointer to the secret key

Definition at line 96 of file onionmanager.cc.

References m_secretkey.

Referenced by ns3::SensorNode::ProcessOnionHead().

+ Here is the caller graph for this function:

◆ GetSKtoString()

std::string ns3::OnionManager::GetSKtoString ( )

accessor

Returns
Return the secret key as a string

Definition at line 111 of file onionmanager.cc.

References m_secretkey.

Referenced by ns3::Sink::StartApplication().

+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::OnionManager::GetTypeId ( void  )
static

Register this type.

Returns
The object TypeId.

Definition at line 34 of file onionmanager.cc.

◆ IpToBuff()

unsigned char * ns3::OnionManager::IpToBuff ( uint32_t  in)

Convert an Ipv4 address given as an unsigned integer value to buffer array of 4Bytes.

Parameters
[in]inan Ipv4 address given as an unsigned integer value
Returns
the pointer to the array of 4Bytes

Definition at line 155 of file onionmanager.cc.

Referenced by ns3::Sink::PrepareOnion().

+ Here is the caller graph for this function:

◆ SetPK()

void ns3::OnionManager::SetPK ( unsigned char *  pk)

setter

Parameters
[in]pkpointer to the public encryption key

Definition at line 119 of file onionmanager.cc.

References m_publickey.

◆ SetSK()

void ns3::OnionManager::SetSK ( unsigned char *  sk)

setter

Parameters
[in]pkpointer to the secret encryption key

Definition at line 126 of file onionmanager.cc.

References m_secretkey.

◆ StringToUchar()

unsigned char * ns3::OnionManager::StringToUchar ( std::string  in)

Convert a string to an array of unsigned chars.

Other methods.

Parameters
[in]ina std::string
Returns
the pointer to the array of unsigned chars

Definition at line 138 of file onionmanager.cc.

Referenced by ns3::Sink::PrepareOnion(), and ns3::SensorNode::ProcessOnionHead().

+ Here is the caller graph for this function:

◆ UcharToString()

std::string ns3::OnionManager::UcharToString ( unsigned char *  seq,
int  len 
)

Convert an array of unsigned chars to a std::string.

Parameters
[in]seqan array of unsigned chars
[in]lenthe length of the seq the array of unsigned chars
Returns
a std::string

Definition at line 147 of file onionmanager.cc.

Referenced by ns3::SensorNode::ProcessOnionHead(), and ns3::Sink::SendOnion().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_publickey

unsigned char ns3::OnionManager::m_publickey[crypto_box_PUBLICKEYBYTES]
private

the public encryption key

Definition at line 191 of file onionmanager.h.

Referenced by GenerateNewKeyPair(), GetPK(), GetPKtoString(), and SetPK().

◆ m_secretkey

unsigned char ns3::OnionManager::m_secretkey[crypto_box_SECRETKEYBYTES]
private

the secret encryption key

Definition at line 192 of file onionmanager.h.

Referenced by GenerateNewKeyPair(), GetSK(), GetSKtoString(), and SetSK().


The documentation for this class was generated from the following files: