34 NS_OBJECT_ENSURE_REGISTERED (OnionRouting);
36 NS_LOG_COMPONENT_DEFINE (
"onionrouting");
42 static TypeId tid = TypeId (
"ns3::OnionRouting")
44 .SetGroupName (
"OnionRouting");
57 if (protocolNumber == Ipv4L3Protocol::PROT_NUMBER)
61 else if (protocolNumber == Ipv6L3Protocol::PROT_NUMBER)
67 NS_LOG_WARN (
"The given (IP) protocol number is not valid.");
84 NS_LOG_LOGIC (
"Route is too short, need at least 3 intermediate hops.");
90 NS_LOG_INFO (
"Start creation of the onion");
94 CreateOnion (cipher,route,keys, routeLen, routeLen,
nullptr, 0,
nullptr, 0);
105 OnionRouting::BuildOnion (uint8_t * cipher, uint8_t ** route, uint8_t ** keys, uint16_t routeLen, uint8_t * endContent, uint16_t endContentLen)
112 NS_LOG_LOGIC (
"Route is too short, need at least 3 intermediate hops.");
118 NS_LOG_INFO (
"Start creation of the onion");
122 CreateOnion (cipher,route,keys, routeLen, routeLen,
nullptr, 0, endContent, endContentLen);
133 OnionRouting::BuildOnion (uint8_t * cipher, uint8_t ** route, uint8_t ** keys, uint8_t ** layerContent, uint16_t layerContentLen, uint16_t routeLen)
140 NS_LOG_LOGIC (
"Route is too short, need at least 3 intermediate hops.");
146 NS_LOG_INFO (
"Start creation of the onion");
150 CreateOnion (cipher,route,keys, routeLen, routeLen, layerContent, layerContentLen,
nullptr, 0);
160 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)
167 NS_LOG_LOGIC (
"Route is too short, need at least 3 intermediate hops.");
172 NS_LOG_INFO (
"Start creation of the onion");
176 CreateOnion (cipher,route,keys, routeLen, routeLen, layerContent, layerContentLen, endContent, endContentLen);
185 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)
192 if (index <= 2 && (endContentLen != 0 || layerContentLen != 0))
200 if (endContentLen != 0)
225 if (layerContentLen != 0)
243 uint8_t * innerLayer =
new uint8_t[onionLen - (
m_sealPadding)];
245 DecryptLayer (innerLayer,onion,onionLen,publicKey,secretKey);
261 routeLen = routeLen - 1;
262 if (endContentLen == 0 && layerContentLen == 0)
266 else if (endContentLen == 0)
294 NS_LOG_FUNCTION (
this);
307 NS_FATAL_ERROR (
"Seal padding must be at least 4-Bytes");
315 static TypeId tid = TypeId (
"ns3::OnionRoutingDummyEncryption")
317 .SetGroupName (
"OnionRouting");
325 Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
326 uint32_t key = x->GetInteger (0,UINT32_MAX);
340 memcpy (ciphertext, &key[0], 4);
343 ciphertext[4 + i] = 0;
351 for (
int i = 0; i < 4; ++i)
353 if (onion[i] != pk[i])
355 NS_LOG_INFO (
"Messge corrupted or not for this node");