Skip to content

Commit d189d8a

Browse files
committed
document deviation from RFC
1 parent d01041e commit d189d8a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/MeshCore.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@
1717
#define PATH_HASH_SIZE 1
1818

1919
// V2 (ChaCha20-Poly1305)
20+
// RFC 8439 specifies 256-bit key, 96-bit nonce, 128-bit tag
21+
// We deviate from RFC in two ways to minimize LoRa airtime:
22+
//
23+
// 1. NONCE COMPRESSION: Transmit 4-byte counter, derive 12-byte nonce via SHA256(key || counter)
24+
// Security: Equivalent to full nonce - SHA256 output is indistinguishable from random
25+
//
26+
// 2. TAG TRUNCATION: Use 64-bit tag instead of 128-bit (RFC says "MUST NOT" truncate)
27+
// Security: Forgery probability 1 in 2^64 (vs 2^128). Acceptable for mesh because:
28+
// - Attacker must be in radio range for each attempt
29+
// - Each attempt consumes airtime and is detectable
30+
// - Online brute force at 1000 msg/sec = 292 million years
31+
// - No known attacks reduce this below brute force
32+
//
33+
// Trade-off: 8 bytes saved per packet vs. reduced forgery resistance margin
2034
#define CHACHA_KEY_SIZE 32
2135
#define CHACHA_NONCE_SIZE 12 // Internal nonce size (derived from counter + key)
2236
#define CHACHA_COUNTER_SIZE 4 // Transmitted counter size (full nonce derived via SHA256)
23-
#define CHACHA_TAG_SIZE 8 // 64-bit tag: sufficient for mesh network (2^64 forgery resistance)
37+
#define CHACHA_TAG_SIZE 8 // 64-bit tag (RFC specifies 128-bit, see rationale above)
2438

2539
#define MAX_PACKET_PAYLOAD 184
2640
#define MAX_PATH_SIZE 64

0 commit comments

Comments
 (0)