SH2SC-EDT
Self-Healing Hardware and Software Complex for Encrypted Data Transmission
Loading...
Searching...
No Matches
DataPacket Struct Reference

Authenticated data packet (FLAG_DAT) and session-close packet (FLAG_FIN). More...

#include <protocol.h>

Data Fields

uint8_t flags
 Frame type — FLAG_DAT (0x02) for data; FLAG_FIN (0x04) for teardown. Part of plaintext AAD.
 
uint16_t seq_num
 16-bit packet sequence number (little-endian). Part of plaintext AAD.
 
uint16_t payload [2]
 ChaCha20-encrypted payload: [0] = note_index, [1] = duration_ms.
 
uint8_t mac [TRUNCATED_MAC_SIZE]
 First 8 bytes of the Poly1305 authentication tag.
 

Detailed Description

Authenticated data packet (FLAG_DAT) and session-close packet (FLAG_FIN).

Carries one encrypted note authenticated with a truncated Poly1305 MAC. The seq_num field resides in the plaintext AAD so both nodes can independently derive the per-packet nonce without decrypting the payload:

packetNonce[0..11] = s_sessionNonce[0..11]
packetNonce[10] ^= (seq_num >> 8) & 0xFF
packetNonce[11] ^= (seq_num) & 0xFF
static uint8_t s_sessionNonce[HELLO_NONCE_SIZE]
96-bit session nonce generated once per button press by sendHelloPacket().
uint16_t seq_num
16-bit packet sequence number (little-endian). Part of plaintext AAD.
Definition protocol.h:124

Wire layout (15 bytes, preceded by 2-byte sync preamble = 17 bytes total):

Byte 0 : flags (FLAG_DAT=0x02 or FLAG_FIN=0x04) ─┐ 3-byte plaintext AAD
Bytes 1–2 : seq_num (uint16_t, little-endian) ─┘ (authenticated, NOT encrypted)
Bytes 3–6 : payload[2] — ChaCha20 ciphertext {note_index, duration_ms}
Bytes 7–14 : mac[8] — first 8 bytes of Poly1305 tag
const uint8_t FLAG_FIN
Session close — instructs RX to teardown the current session.
Definition protocol.h:47
const uint8_t FLAG_DAT
Data frame — DataPacket carrying an encrypted note (index + duration).
Definition protocol.h:46
uint16_t payload[2]
ChaCha20-encrypted payload: [0] = note_index, [1] = duration_ms.
Definition protocol.h:125
uint8_t flags
Frame type — FLAG_DAT (0x02) for data; FLAG_FIN (0x04) for teardown. Part of plaintext AAD.
Definition protocol.h:123
uint8_t mac[TRUNCATED_MAC_SIZE]
First 8 bytes of the Poly1305 authentication tag.
Definition protocol.h:126
Note
Any bit-flip in flags or seq_num causes MAC verification to fail and the packet is discarded with a NACK response.

Carries one encrypted note authenticated with a truncated Poly1305 MAC. The seq_num field resides in the plaintext AAD so both nodes can independently derive the per-packet nonce without decrypting the payload:

packetNonce[0..11] = s_sessionNonce[0..11]
packetNonce[10] ^= (seq_num >> 8) & 0xFF
packetNonce[11] ^= (seq_num) & 0xFF

Wire layout (15 bytes, preceded by 2-byte sync preamble = 17 bytes total):

Byte 0 : flags (FLAG_DAT=0x02 or FLAG_FIN=0x04) — plaintext AAD byte 0
Bytes 1–2 : seq_num (uint16_t, little-endian) — plaintext AAD bytes 1-2
Bytes 3–6 : payload[2] — ChaCha20 ciphertext {note_index, duration_ms}
Bytes 7–14 : mac[8] — first 8 bytes of Poly1305 tag
Note
Any bit-flip in flags or seq_num causes MAC verification to fail and the packet is discarded with a NACK response.

Definition at line 122 of file protocol.h.

Field Documentation

◆ flags

uint8_t DataPacket::flags

Frame type — FLAG_DAT (0x02) for data; FLAG_FIN (0x04) for teardown. Part of plaintext AAD.

Definition at line 123 of file protocol.h.

Referenced by authenticateAndPlay(), sendFinPacket(), and sendPacket().

◆ mac

uint8_t DataPacket::mac

First 8 bytes of the Poly1305 authentication tag.

Definition at line 126 of file protocol.h.

Referenced by authenticateAndPlay(), processFinPacket(), sendFinPacket(), and sendPacket().

◆ payload

uint16_t DataPacket::payload

ChaCha20-encrypted payload: [0] = note_index, [1] = duration_ms.

Definition at line 125 of file protocol.h.

Referenced by authenticateAndPlay(), processFinPacket(), sendFinPacket(), and sendPacket().

◆ seq_num

uint16_t DataPacket::seq_num

16-bit packet sequence number (little-endian). Part of plaintext AAD.

Definition at line 124 of file protocol.h.

Referenced by authenticateAndPlay(), processFinPacket(), sendFinPacket(), and sendPacket().


The documentation for this struct was generated from the following files: