From db527b6759115065f1f0fc8dbfbc402e237a68eb Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 20 May 2021 16:56:08 +0200 Subject: [PATCH] Optimised announces to 151 bytes --- RNS/Destination.py | 5 +---- RNS/Identity.py | 12 ++++++------ RNS/Packet.py | 1 + docs/source/understanding.rst | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index f788e48..f4798ad 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -156,10 +156,7 @@ class Destination: signature = self.identity.sign(signed_data) - # TODO: Check if this could be optimised by only - # carrying the hash in the destination field, not - # also redundantly inside the signed blob as here - announce_data = self.hash+self.identity.get_public_key()+random_hash+signature + announce_data = self.identity.get_public_key()+random_hash+signature if app_data != None: announce_data += app_data diff --git a/RNS/Identity.py b/RNS/Identity.py index 489105d..2bd697d 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -149,16 +149,16 @@ class Identity: if packet.packet_type == RNS.Packet.ANNOUNCE: RNS.log("Validating announce from "+RNS.prettyhexrep(packet.destination_hash), RNS.LOG_DEBUG) destination_hash = packet.destination_hash - public_key = packet.data[10:Identity.KEYSIZE//8+10] - random_hash = packet.data[Identity.KEYSIZE//8+10:Identity.KEYSIZE//8+20] - signature = packet.data[Identity.KEYSIZE//8+20:Identity.KEYSIZE//8+20+Identity.KEYSIZE//8] + public_key = packet.data[:Identity.KEYSIZE//8] + random_hash = packet.data[Identity.KEYSIZE//8:Identity.KEYSIZE//8+10] + signature = packet.data[Identity.KEYSIZE//8+10:Identity.KEYSIZE//8+10+Identity.KEYSIZE//8] app_data = b"" - if len(packet.data) > Identity.KEYSIZE//8+20+Identity.KEYSIZE//8: - app_data = packet.data[Identity.KEYSIZE//8+20+Identity.KEYSIZE//8:] + if len(packet.data) > Identity.KEYSIZE//8+10+Identity.KEYSIZE//8: + app_data = packet.data[Identity.KEYSIZE//8+10+Identity.KEYSIZE//8:] signed_data = destination_hash+public_key+random_hash+app_data - if not len(packet.data) > Identity.KEYSIZE//8+20+Identity.KEYSIZE//8: + if not len(packet.data) > Identity.KEYSIZE//8+10+Identity.KEYSIZE//8: app_data = None announced_identity = Identity(create_keys=False) diff --git a/RNS/Packet.py b/RNS/Packet.py index 25917e9..8ee68a3 100755 --- a/RNS/Packet.py +++ b/RNS/Packet.py @@ -186,6 +186,7 @@ class Packet: self.packed = True self.update_hash() + def unpack(self): self.flags = self.raw[0] self.hops = self.raw[1] diff --git a/docs/source/understanding.rst b/docs/source/understanding.rst index a34371b..7190eea 100644 --- a/docs/source/understanding.rst +++ b/docs/source/understanding.rst @@ -672,8 +672,8 @@ Binary Packet Format wire size including all fields. - Path Request : 33 bytes - - Announce : 323 bytes - - Link Request : 141 bytes + - Announce : 151 bytes + - Link Request : 182 bytes - Link Proof : 205 bytes - Link RTT packet : 86 bytes - Link keepalive : 14 bytes \ No newline at end of file