UDP-based chat client/server example. HMAC keys are exchanged securely via RSA; message integrity is verified with HMAC-SHA256.
-
Start the server first (default port 9999):
./server
-
Start the client (connects to 127.0.0.1:9999):
./client
-
Type a line and press Enter in the client → message is sent to the server and echoed back to the same client.
- Connect
Client sendsINIT→ server replies withKEY_+ RSA public key (PEM). - Key exchange
Client generates a 32-byte HMAC key, encrypts it with the server’s public key, and sendsKEY_+ ciphertext. Server decrypts with its private key and registers that HMAC key for the client. - Chat
Subsequent messages use the formatMSG_+ payload + HMAC-SHA256 (32 bytes). Both server and client verify HMAC before processing.
Max message size 1024 bytes; max payload 1024 − 32 − 4 = 988 bytes.