SH2SC-EDT
Self-Healing Hardware and Software Complex for Encrypted Data Transmission
Loading...
Searching...
No Matches
protocol.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <stdint.h>
14
27const uint8_t MASTER_PSK[32] = {
28 0xA1, 0x3C, 0x7F, 0x04, 0xE8, 0x92, 0x5B, 0xD6,
29 0x3A, 0xFF, 0x01, 0x88, 0x4D, 0x62, 0xC0, 0x19,
30 0x77, 0x2E, 0xB3, 0x55, 0x0C, 0xAD, 0xF1, 0x39,
31 0x6B, 0x84, 0xE0, 0x27, 0x93, 0x5A, 0x1D, 0xCC
32};
33
// end group psk
35
45const uint8_t FLAG_SYN = 0x01;
46const uint8_t FLAG_DAT = 0x02;
47const uint8_t FLAG_FIN = 0x04;
// end group frame_flags
49
54const uint8_t HELLO_NONCE_SIZE = 12u;
55const uint8_t AUTH_TAG_SIZE = 16u;
56const uint8_t TRUNCATED_MAC_SIZE = 8u;
57
63const uint8_t DATA_PAYLOAD_SIZE = 4u;
// end group frame_sizes
65
74const uint8_t SYNC_BYTE_1 = 0xAA;
75const uint8_t SYNC_BYTE_2 = 0x55;
// end group sync_preamble
77
92#pragma pack(push, 1)
94 uint8_t flags;
96};
97#pragma pack(pop)
98
121#pragma pack(push, 1)
123 uint8_t flags;
124 uint16_t seq_num;
125 uint16_t payload[2];
127};
128#pragma pack(pop)
129
135const uint8_t ACK_BYTE = 0x06;
136const uint8_t NACK_BYTE = 0x15;
// end group service_bytes
138
149const uint8_t REST_INDEX = 255;
150
// end group note_encoding
152
157const uint32_t ACK_TIMEOUT_MS = 50UL;
158const uint8_t MAX_RETRIES = 50u;
// end group arq_timing
160
165const uint16_t BAUD_RATE = 9600;
// end group uart_config
const uint32_t ACK_TIMEOUT_MS
Maximum milliseconds TX waits for an ACK before retransmitting.
Definition protocol.h:157
const uint8_t MAX_RETRIES
Retransmission limit per packet; exhausting this triggers suspendSession().
Definition protocol.h:158
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
const uint8_t FLAG_SYN
Session open — HelloPacket carrying the 12-byte CSPRNG nonce.
Definition protocol.h:45
const uint8_t AUTH_TAG_SIZE
Full Poly1305 tag length in bytes (computed internally, not fully transmitted).
Definition protocol.h:55
const uint8_t HELLO_NONCE_SIZE
ChaCha20 IV length in bytes (IETF 96-bit nonce format).
Definition protocol.h:54
const uint8_t DATA_PAYLOAD_SIZE
Byte size of the encrypted payload in a DataPacket.
Definition protocol.h:63
const uint8_t TRUNCATED_MAC_SIZE
Bytes of Poly1305 MAC actually placed on the wire (first 8 of 16).
Definition protocol.h:56
const uint8_t REST_INDEX
Special note index value representing a rest (silence).
Definition protocol.h:149
const uint8_t MASTER_PSK[32]
256-bit (32-byte) Pre-Shared Master Key for ChaCha20-Poly1305 AEAD.
Definition protocol.h:27
const uint8_t NACK_BYTE
Negative acknowledgement — MAC mismatch; TX must retransmit.
Definition protocol.h:136
const uint8_t ACK_BYTE
Positive acknowledgement — MAC verified, note played (or FIN accepted).
Definition protocol.h:135
const uint8_t SYNC_BYTE_2
Second synchronisation byte (preamble marker).
Definition protocol.h:75
const uint8_t SYNC_BYTE_1
First synchronisation byte (preamble marker).
Definition protocol.h:74
const uint16_t BAUD_RATE
UART baud rate in bps (8N1). Chosen for clear bit-width visibility on SimulIDE oscilloscope.
Definition protocol.h:165
Authenticated data packet (FLAG_DAT) and session-close packet (FLAG_FIN).
Definition protocol.h:122
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
uint16_t seq_num
16-bit packet sequence number (little-endian). Part of plaintext AAD.
Definition protocol.h:124
uint8_t mac[TRUNCATED_MAC_SIZE]
First 8 bytes of the Poly1305 authentication tag.
Definition protocol.h:126
Session-open handshake packet (FLAG_SYN).
Definition protocol.h:93
uint8_t nonce[HELLO_NONCE_SIZE]
96-bit session nonce for ChaChaPoly per-packet IV derivation.
Definition protocol.h:95
uint8_t flags
Frame type — must equal FLAG_SYN (0x01).
Definition protocol.h:94