|
|
@ -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
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* ********************************************************************** */ |
|
|
|