mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-20 17:00:49 +00:00
.
This commit is contained in:
parent
b19634d7e4
commit
2f7d3e655a
@ -18,6 +18,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Packet.hpp"
|
||||
#include "Mutex.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define FORCE_INLINE static __forceinline
|
||||
@ -932,4 +933,16 @@ bool Packet::uncompress()
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t Packet::nextPacketId()
|
||||
{
|
||||
static uint64_t ctr = 0;
|
||||
static Mutex lock;
|
||||
lock.lock();
|
||||
if (unlikely(ctr == 0))
|
||||
Utils::getSecureRandom(&ctr,sizeof(ctr));
|
||||
const uint64_t i = ctr++;
|
||||
lock.unlock();
|
||||
return i;
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
@ -986,7 +986,7 @@ public:
|
||||
ZT_ALWAYS_INLINE Packet() :
|
||||
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
|
||||
{
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Utils::random());
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
||||
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags, cipher ID, and hops
|
||||
}
|
||||
|
||||
@ -1002,7 +1002,7 @@ public:
|
||||
ZT_ALWAYS_INLINE Packet(const Packet &prototype,const Address &dest) :
|
||||
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(prototype)
|
||||
{
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Utils::random());
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
||||
setDestination(dest);
|
||||
}
|
||||
|
||||
@ -1016,7 +1016,7 @@ public:
|
||||
ZT_ALWAYS_INLINE Packet(const Address &dest,const Address &source,const Verb v) :
|
||||
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
|
||||
{
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Utils::random());
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
||||
setDestination(dest);
|
||||
setSource(source);
|
||||
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags and hops
|
||||
@ -1033,7 +1033,7 @@ public:
|
||||
ZT_ALWAYS_INLINE void reset(const Address &dest,const Address &source,const Verb v)
|
||||
{
|
||||
setSize(ZT_PROTO_MIN_PACKET_LENGTH);
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Utils::random());
|
||||
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
||||
setDestination(dest);
|
||||
setSource(source);
|
||||
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags, cipher ID, and hops
|
||||
@ -1047,7 +1047,7 @@ public:
|
||||
* technically different but otherwise identical copies of the same
|
||||
* packet.
|
||||
*/
|
||||
ZT_ALWAYS_INLINE void newInitializationVector() { setAt<uint64_t>(ZT_PACKET_IDX_IV,Utils::random()); }
|
||||
ZT_ALWAYS_INLINE void newInitializationVector() { setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId()); }
|
||||
|
||||
/**
|
||||
* Set this packet's destination
|
||||
@ -1238,6 +1238,8 @@ public:
|
||||
private:
|
||||
static const unsigned char ZERO_KEY[32];
|
||||
|
||||
static uint64_t nextPacketId();
|
||||
|
||||
/**
|
||||
* Deterministically mangle a 256-bit crypto key based on packet
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user