Complete cryptographic suite implementing SHA-256, HMAC, HKDF, X25519, and X3DH key agreement protocol. All algorithms implemented from scratch for educational purposes. Includes a web-based demo application with Flask backend and WebAssembly frontend.
Purpose: Validates SHA-256 implementation with long text input.
Test Input: "Monster Mash" song lyrics (277 characters)
Output: 32-byte cryptographic hash
Verification: Consistent hashing of large inputs
Purpose: Tests message authentication with both text and binary inputs.
Test Cases:
- Text: "Monster Mash" lyrics with key "ITS THE MONSTER MASH"
- Binary: 3-byte message with 32-byte binary key
Output: 32-byte HMAC digests
Purpose: Tests key derivation function for cryptographic key generation.
Procedure:
- Extract: Derive PRK (Pseudo-Random Key) from input message
- Expand: Generate 64 bytes OKM (Output Keying Material) using PRK + info
Algorithm: HKDF-SHA256 following RFC 5869
Purpose: Validates Elliptic Curve Diffie-Hellman over Curve25519.
Test Vectors: Standardized test pairs for Alice and Bob
Operations:
- Public key generation from private keys
- Shared secret computation
- Cross-verification between parties
Verification: Both parties compute identical shared secrets
Purpose: Implements Extended Triple Diffie-Hellman key agreement protocol (used in Signal protocol).
Key Types:
- Identity Keys (IK): Long-term key pairs
- Signed Pre-Keys (SPK): Medium-term keys
- Ephemeral Keys (EK): One-time use keys
Protocol: X3DH
Security Properties:
- Forward secrecy through ephemeral keys
- Identity authentication via long-term keys
- Key compromise protection through multiple DH combinations
- SHA-256: NIST-standard cryptographic hash
- HMAC-SHA256: Message authentication code
- HKDF-SHA256: Key derivation function
- X25519: Elliptic curve cryptography
- X3DH: Multi-stage key agreement protocol
A web-based demonstration showcasing the cryptographic protocols in action:
- Web Interface: Terminal-style UI with green/blue themes
- Real-time Messaging: Encrypted message exchange between users
- Session Management: X3DH key agreement and session establishment
- WASM Integration: Cryptographic functions compiled to WebAssembly
- REST API: Flask backend with C library integration
# Build and run the demo application
cd demo && chmod +x compile.sh && ./compile.sh && python3 server.pyImportant: When running in a container, expose port 8000 to access the web interface.
- Access the web interface at
http://localhost:8000 - Register users with
register <username>command - Establish sessions with
session <username>(initiator) andcomplete <username>(responder) - Exchange encrypted messages with
send <username> <message> - Retrieve messages with
getmsgs
gcc -o crypto_test main.c sha256.c X25519.c X3DH.c session_manager.c session_test.c
./crypto_test*** Build by running: ***
docker build ./demo signal_demo
docker run -it --rm -p 8000:8000 signal_demo*** Within container start webser by running: ***
chmod +x ./demo/compile.sh
./demo/compile.sh
python3 ./demo/server.py