A Discrete-Event Network Simulator
API
ns3::OnionRouting Class Referenceabstract

Abstract class for creation and decryption of Onion messages. More...

#include "onion-routing.h"

+ Inheritance diagram for ns3::OnionRouting:
+ Collaboration diagram for ns3::OnionRouting:

Public Types

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 Member Functions

 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)
 
static TypeId GetTypeId (void)
 Register this type. More...
 

Public Attributes

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

Abstract class for creation and decryption of Onion messages.

The OnionRouting abstract class include useful methods for the creation and redirection of Onion Messages. The given class can be used to construct onion messages of the following features:
ONION_NO_CONTENT - onion message including only routing information
example: (((10.1.1.2) 10.1.1.1) 10.1.1.5)10.1.1.3

ONION_ENDCONTENT - onion message including content to be delivered to the last node in the path
example: ((((end_content,0.0.0.0) 10.1.1.2) 10.1.1.1) 10.1.1.5) 10.1.1.3

ONION_LAYERCONTENT - onion message including a content of fixed length (in bytes) in each layer
example: ((((layer_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3

ONION_LAYERCONTENT_ENDCONTENT - onion message including a content of fixed length in each layer and content of arbitrary length to be delivered to the last node in the path
example: ((((end_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3


The given class can be used to construct onion circuits as described in Hiding Routing Information by david M. Goldschlag, Micheal G. Reed, and Paul F. Syverson, May 1996

We designed an abstract class to allow the use of an arbitrary encryption suite, by implementing methods EncryptLayer & DecryptLayer

implementing dummy Encryption/Decryption methods.

The class simulates the use of encryption keys by including them into encryption layers of onion messages. A node deciphering a layer of the onion message will compare its encryption key with the encryption key included in the layer of the onion message. If the two keys match the layer is succesfully deciphered, otherwise the node is not the expected recipient of the onion message and the encryption will fail triggering an error message.

Since dummy encryption keys of 4B are included in each layer of the onion message, the parameter m_sealPadding must be set to at least 4 Bytes. The parameter m_sealPadding is used to emulate additional bytes introduced by a real encryption technique. This parameter is set in the constructor.

Definition at line 29 of file onion-routing.h.

Member Enumeration Documentation

◆ OnionErrno

Enumeration of the possible errors using the class onion-routing.

Enumerator
ERROR_NOTERROR 
ERROR_PROT_NUMBER 
ERROR_ROUTE_TO_SHORT 
ERROR_ENCRYPTION 
ERROR_DECRYPTION 

Definition at line 104 of file onion-routing.h.

Constructor & Destructor Documentation

◆ OnionRouting() [1/3]

ns3::OnionRouting::OnionRouting ( )

Definition at line 27 of file onion-routing.cc.

◆ OnionRouting() [2/3]

ns3::OnionRouting::OnionRouting ( uint16_t  keySize,
uint16_t  sealPadding,
uint16_t  addressSize 
)

Definition at line 43 of file onion-routing.cc.

References m_addressSize, m_keySize, and m_sealPadding.

◆ ~OnionRouting()

ns3::OnionRouting::~OnionRouting ( )
virtual

Definition at line 50 of file onion-routing.cc.

◆ OnionRouting() [3/3]

ns3::OnionRouting::OnionRouting ( uint16_t  sealPadding,
const uint16_t  protocolNumber 
)

Constructor – Setup parameters for the creation of onions.

Parameters
[in]sealPaddingsize increase of the ciphertext in bytes, intorduced by the encryption method
[in]protocolNumbervalue detailing the utilized IP protocol: IPv4–Ipv4L3Protocol::PROT_NUMBER, IPv6–Ipv6L3Protocol::PROT_NUMBER

Definition at line 51 of file onion-routing.cc.

References ERROR_NOTERROR, ERROR_PROT_NUMBER, m_addressSize, m_errno, and m_sealPadding.

Member Function Documentation

◆ AddressToStream() [1/2]

void ns3::OnionRouting::AddressToStream ( uint8_t *  ip)

Definition at line 200 of file onion-routing.cc.

References m_addressSize, and m_onionStream.

Referenced by BuildOnion(), and CreateOnion().

+ Here is the caller graph for this function:

◆ AddressToStream() [2/2]

void ns3::OnionRouting::AddressToStream ( uint8_t *  ip)

Output an ip address to a stream variable, used to LOG the onion message.

Parameters
[in]ipserialized ip address

◆ BuildOnion() [1/5]

int ns3::OnionRouting::BuildOnion ( uint8_t *  cipher,
uint8_t **  route,
uint16_t  routeLen,
uint8_t **  keys,
uint8_t *  content = nullptr,
uint16_t  contentLen = 0 
)

Definition at line 63 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), and m_onionStream.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BuildOnion() [2/5]

void ns3::OnionRouting::BuildOnion ( uint8_t *  cipher,
uint8_t **  route,
uint8_t **  keys,
uint16_t  routeLen 
)

Manage construction of the onion ONION_NO_CONTENT.

The resulting onion message include only routing information and the last hop in the onion path will not recieve content example: (((10.1.1.2) 10.1.1.1) 10.1.1.5)10.1.1.3

Allow the construction of onions of route length > 4, and manage the LOG output

Parameters
[in,out]ciphermemory locations on which the onion message will be stored
[in]routearray of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form
[in]keysarray of encryption keys, keys are stored in the serialized form
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route parameter)

Definition at line 77 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.

+ Here is the call graph for this function:

◆ BuildOnion() [3/5]

void ns3::OnionRouting::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.

The resulting onion message include routing information and the last hop in the onion path recieve the given content
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((end_content,0.0.0.0) 10.1.1.2) 10.1.1.1) 10.1.1.5) 10.1.1.3

Allow the construction of onions of route length > 4, and manage the LOG output

Parameters
[in,out]ciphermemory locations on which the onion message will be stored
[in]routearray of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form
[in]keysarray of encryption keys, keys are stored in the serialized form
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route)
[in]endContentlocation of the content to forward to the last node in the onion message path
[in]endContentLenlength in bytes of the data stored at endContent

Definition at line 105 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.

+ Here is the call graph for this function:

◆ BuildOnion() [4/5]

void ns3::OnionRouting::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.

The resulting onion message include only routing information, and each hop in the route will receive data stored in layerContent
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((layer_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3

Allow the construction of onions of route length > 4, and manage the LOG output

Parameters
[in,out]ciphermemory locations on which the onion message will be stored
[in]routearray of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form
[in]keysarray of encryption keys, keys are stored in the serialized form
[in]layerContentarray of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes
[in]layerContentLenlength in bytes of the data to be stored in each layer of the onion message
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route)

Definition at line 133 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.

+ Here is the call graph for this function:

◆ BuildOnion() [5/5]

void ns3::OnionRouting::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.

The resulting onion message include only routing information, each hop in the route will receive data stored in layerContent, the last hop in the onion path recieve content only data stored in endContent
The zero address – 0.0.0.0 (ipv4) identifies the last hop in the path of the onion message
example: ((((end_content,0.0.0.0) layer_content,10.1.1.2) layer_content,10.1.1.1) layer_content,10.1.1.5)10.1.1.3

Allow the construction of onions of route length > 4, and manage the LOG output

Parameters
[in,out]ciphermemory locations on which the onion message will be stored
[in]routearray of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form
[in]keysarray of encryption keys, keys are stored in the serialized form
[in]layerContentarray of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes
[in]layerContentLenlength in bytes of the data to be stored in each layer of the onion message
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route)
[in]endContentlocation of the content to forward to the last node in the onion message path
[in]endContentLenlength in bytes of the data stored at endContent

Definition at line 160 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), ERROR_NOTERROR, ERROR_ROUTE_TO_SHORT, m_errno, and m_onionStream.

+ Here is the call graph for this function:

◆ CreateOnion() [1/2]

int ns3::OnionRouting::CreateOnion ( uint8_t *  cipher,
uint8_t **  route,
uint16_t  index,
uint16_t  routeLen,
uint8_t **  keys,
uint8_t *  content = nullptr,
uint16_t  contentLen = 0 
)

Definition at line 103 of file onion-routing.cc.

References AddressToStream(), EncryptLayer(), m_addressSize, m_onionStream, m_sealPadding, and OnionLength().

Referenced by BuildOnion(), and CreateOnion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateOnion() [2/2]

void ns3::OnionRouting::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 *.

Parameters
[in,out]ciphermemory on which the onion message will be stored
[in]routearray of ip addresses defining the route of the onion message, ip addresses are stored in the serialized form
[in]keysarray of encryption keys, keys are stored in the serialized form
[in]layerContentarray of of pointers, pointing to data to be stored in a layer of the onion message the data is of fixed length in bytes
[in]layerContentLenlength in bytes of the data to be stored in each layer of the onion message
[in]indexadditional parameter used for the construction of the onion message
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route)
[in]endContentlocation of the content to forward to the last node in the onion message path
[in]endContentLenlength in bytes of the data stored at endContent

Definition at line 185 of file onion-routing.cc.

References AddressToStream(), CreateOnion(), EncryptLayer(), m_addressSize, m_onionStream, m_sealPadding, and OnionLength().

+ Here is the call graph for this function:

◆ DecryptLayer() [1/2]

virtual void ns3::OnionRouting::DecryptLayer ( uint8_t *  innerLayer,
uint8_t *  onion,
uint16_t  onionLen,
uint8_t *  pk,
uint8_t *  sk 
) const
pure virtual

Implemented in ns3::OnionRoutingDummyEncryption.

Referenced by PeelOnion().

+ Here is the caller graph for this function:

◆ DecryptLayer() [2/2]

virtual void ns3::OnionRouting::DecryptLayer ( uint8_t *  plaintext,
uint8_t *  ciphertext,
uint16_t  len,
uint8_t *  publicKey,
uint8_t *  secretKey 
) const
pure virtual

virtual method, implement decryption

Parameters
[in,out]plaintextmemory locations containing the decrypted data
[in]ciphertextmemory locations containing the encrypted data
[in]lenlength in bytes of the ciphertext
[in]publicKeyencryption key
[in]secretKeyencryption key

Implemented in ns3::OnionRoutingDummyEncryption.

◆ EncryptLayer() [1/2]

virtual void ns3::OnionRouting::EncryptLayer ( uint8_t *  ciphertext,
uint8_t *  message,
int  len,
uint8_t *  key 
) const
pure virtual

Implemented in ns3::OnionRoutingDummyEncryption.

Referenced by CreateOnion().

+ Here is the caller graph for this function:

◆ EncryptLayer() [2/2]

virtual void ns3::OnionRouting::EncryptLayer ( uint8_t *  ciphertext,
uint8_t *  plaintext,
int  len,
uint8_t *  key 
) const
pure virtual

virtual method, implement encryption

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

Implemented in ns3::OnionRoutingDummyEncryption.

◆ GetErrno()

enum OnionRouting::OnionErrno ns3::OnionRouting::GetErrno ( void  )

Return the last error code of the OnionErrno enum.

Returns
OnionErrno enum, if != 0 THEN signals ERROR

Definition at line 292 of file onion-routing.cc.

References m_errno.

◆ GetTypeId() [1/2]

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

Definition at line 17 of file onion-routing.cc.

◆ GetTypeId() [2/2]

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

Register this type.

Returns
The object TypeId.

◆ OnionLength() [1/2]

uint16_t ns3::OnionRouting::OnionLength ( uint16_t  routeLen,
uint16_t  contentLen 
)

Definition at line 180 of file onion-routing.cc.

References m_addressSize, and m_sealPadding.

Referenced by CreateOnion(), and ns3::Sink::PrepareOnion().

+ Here is the caller graph for this function:

◆ OnionLength() [2/2]

uint16_t ns3::OnionRouting::OnionLength ( uint16_t  routeLen,
uint16_t  layerContentLen,
uint16_t  endContentLen 
)

Compute the length in bytes of the onion message at given parameters.

Parameters
[in]routeLenthe length of the route that the onion message will travel (equal to the number of ip addresses stored in the route)
[in]layerContentLenlength in bytes of the data to be stored in layers of the onion message
[in]endContentLenlength in bytes of the data stored in the last hop's layer of the onion message


Returns
an integer detailing the length in bytes of the onion message at given parameters

Definition at line 259 of file onion-routing.cc.

References m_addressSize, and m_sealPadding.

◆ PeelOnion() [1/2]

orLayer * ns3::OnionRouting::PeelOnion ( uint8_t *  onion,
uint16_t  onionLen,
uint8_t *  pk,
uint8_t *  sk 
)

Definition at line 158 of file onion-routing.cc.

References DecryptLayer(), ns3::orLayer::innerLayer, ns3::orLayer::innerLayerLen, m_addressSize, m_sealPadding, and ns3::orLayer::nextHopIP.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PeelOnion() [2/2]

orLayer* ns3::OnionRouting::PeelOnion ( uint8_t *  onion,
uint16_t  onionLen,
uint8_t *  publicKey,
uint8_t *  secretKey 
)

Decipher the outer layer of the onion and return details.

Parameters
[in]onionthe onion message
[in]onionLenthe length in bytes of the onion message
[in]publicKeyencryption key
[in]secretKeyencryption key
Returns
orLayer * struct holding onion layer details

Member Data Documentation

◆ m_addressSize

uint16_t ns3::OnionRouting::m_addressSize

size in bytes of the used address type (4-Ipv4, 16-Ipv6)

Definition at line 52 of file onion-routing.h.

Referenced by AddressToStream(), CreateOnion(), OnionLength(), OnionRouting(), and PeelOnion().

◆ m_errno

enum OnionErrno ns3::OnionRouting::m_errno
mutable

error status while using the onion class

Definition at line 320 of file onion-routing.h.

Referenced by BuildOnion(), ns3::OnionRoutingDummyEncryption::DecryptLayer(), GetErrno(), and OnionRouting().

◆ m_keySize

uint16_t ns3::OnionRouting::m_keySize

Definition at line 51 of file onion-routing.h.

Referenced by OnionRouting().

◆ m_onionStream

std::stringstream ns3::OnionRouting::m_onionStream

stringstream used to LOG onion construction

Definition at line 56 of file onion-routing.h.

Referenced by AddressToStream(), BuildOnion(), and CreateOnion().

◆ m_sealPadding

uint16_t ns3::OnionRouting::m_sealPadding

size increase of the ciphertext in bytes, intorduced by the encryption method

Definition at line 50 of file onion-routing.h.

Referenced by CreateOnion(), ns3::OnionRoutingDummyEncryption::DecryptLayer(), ns3::OnionRoutingDummyEncryption::EncryptLayer(), OnionLength(), OnionRouting(), and PeelOnion().


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