Roots now understand encrypted HELLO.

This commit is contained in:
Adam Ierymenko 2024-09-26 19:47:57 -04:00
commit 0ab4e2f750
4 changed files with 57 additions and 11 deletions

View file

@ -135,17 +135,8 @@ public:
while (len >= 16) {
_encryptSW((const uint8_t *)ctr,(uint8_t *)cenc);
ctr[1] = Utils::hton(++bctr);
#ifdef ZT_NO_TYPE_PUNNING
for(unsigned int k=0;k<16;++k)
*(o++) = *(i++) ^ ((uint8_t *)cenc)[k];
#else
*((uint64_t *)o) = *((const uint64_t *)i) ^ cenc[0];
o += 8;
i += 8;
*((uint64_t *)o) = *((const uint64_t *)i) ^ cenc[1];
o += 8;
i += 8;
#endif
len -= 16;
}

View file

@ -447,7 +447,9 @@ public:
ZT_ALWAYS_INLINE unsigned long hashCode() const { return ((unsigned long)_address.toInt() + (unsigned long)_pub.c25519[0] + (unsigned long)_pub.c25519[1] + (unsigned long)_pub.c25519[2]); }
private:
ZT_ALWAYS_INLINE const uint8_t *c25519SecretKey() const { return this->_priv.c25519; }
private:
Address _address;
Type _type;
bool _hasPrivate;

View file

@ -111,6 +111,17 @@
*/
#define ZT_PROTO_FLAG_FRAGMENTED 0x40
/**
* Header flag indicating ephemeral keying and second encryption pass.
*
* If this is set, the packet will have an ephemeral key appended to it its payload
* will be encrypted with AES-CTR using this ephemeral key and the packet's header
* as an IV.
*
* Note that this is a reuse of a flag that has long been deprecated and ignored.
*/
#define ZT_PROTO_FLAG_EXTENDED_ARMOR 0x80
/**
* Verb flag indicating payload is compressed with LZ4
*/
@ -1153,6 +1164,29 @@ public:
b = (b & 0xc7) | (unsigned char)((c << 3) & 0x38); // bits: FFCCCHHH
}
/**
* @return True if packet is encrypted with an extra ephemeral key
*/
inline bool extendedArmor() const
{
return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_EXTENDED_ARMOR) != 0);
}
/**
* Set this packet's extended armor flag
*
* @param f Extended armor flag value
*/
inline void setExtendedArmor(bool f)
{
if (f) {
(*this)[ZT_PACKET_IDX_FLAGS] |= (char)ZT_PROTO_FLAG_EXTENDED_ARMOR;
}
else {
(*this)[ZT_PACKET_IDX_FLAGS] &= (char)(~ZT_PROTO_FLAG_EXTENDED_ARMOR);
}
}
/**
* Get the trusted path ID for this packet (only meaningful if cipher is trusted path)
*