From 08ef50e7fcc976bd4115af3df85532a34becea14 Mon Sep 17 00:00:00 2001 From: Logan oos Even <46396513+Logan007@users.noreply.github.com> Date: Fri, 13 Nov 2020 10:57:01 +0100 Subject: [PATCH] small performance patch for header encryption (#500) --- src/header_encryption.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/header_encryption.c b/src/header_encryption.c index c526726..9777a2a 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -35,12 +35,6 @@ uint32_t packet_header_decrypt (uint8_t packet[], uint16_t packet_len, // to full 128 bit IV memcpy (iv, packet, 12); - // extract time stamp (first 64 bit) and checksum (last 16 bit) blended in IV - speck_he_iv_decrypt (iv, (speck_context_t*)ctx_iv); - *checksum = be16toh (((uint16_t*)iv)[5]); - *stamp = be64toh (((uint64_t*)iv)[0]); - - memcpy (iv, packet, 12); // try community name as possible key and check for magic bytes uint32_t magic = 0x6E326E00; // ="n2n_" @@ -54,12 +48,20 @@ uint32_t packet_header_decrypt (uint8_t packet[], uint16_t packet_len, ) { // decrypt the complete header speck_he (&packet[12], &packet[12], (uint8_t)(test_magic) - 12, iv, (speck_context_t*)ctx); + + // extract time stamp (first 64 bit) and checksum (last 16 bit) blended in IV + speck_he_iv_decrypt (iv, (speck_context_t*)ctx_iv); + *checksum = be16toh (((uint16_t*)iv)[5]); + *stamp = be64toh (((uint64_t*)iv)[0]); + // restore original packet order memcpy (&packet[0], &packet[16], 4); memcpy (&packet[4], community_name, N2N_COMMUNITY_SIZE); + return (1); // successful - } else + } else { return (0); // unsuccessful + } } /* ********************************************************************** */