You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# On the server (Ubuntu VM)
gcc server.c -o server && ./server
# On the client (Kali VM) — ensure file.txt exists
gcc client.c -o client && ./client
2️⃣ AES + Diffie-Hellman (2_AES_DiffieHellman/)
Purpose
Secure file transfer using AES-128-CBC symmetric encryption, with the shared key established via Elliptic Curve Diffie-Hellman (ECDH) key exchange.
Files
File
Role
Description
server_secure.c
Receiver / Decryptor
Generates an ECDH keypair (P-256 curve), exchanges public keys with the client, derives a shared secret, hashes it with SHA-256 to produce a 128-bit AES key, then receives and decrypts the file chunk-by-chunk.
client_secure.c
Sender / Encryptor
Generates its own ECDH keypair, exchanges public keys with the server, derives the same shared AES key, then encrypts and sends the file. Each chunk gets a unique random IV via RAND_bytes().
Cryptographic Details
Component
Algorithm
Key Exchange
ECDH using NIST P-256 (NID_X9_62_prime256v1)
Key Derivation
SHA-256(shared_secret) → first 16 bytes used as AES key
Encryption
AES-128-CBC with per-chunk random IV
Wire Format
[IV (16 bytes)] [cipher_len (4 bytes)] [ciphertext] per chunk
How to Run
# On the server
gcc server_secure.c -o server_secure -lssl -lcrypto && ./server_secure
# On the client — ensure file.txt exists
gcc client_secure.c -o client_secure -lssl -lcrypto && ./client_secure
3️⃣ RSA Encryption (3_RSA_Encryption/)
Purpose
Demonstrate asymmetric (RSA-3072) encryption for sending a short secret message from client to server.
Files
File
Role
Description
rsa_server.c
Key Generator / Decryptor
Generates an RSA-3072 keypair, sends the public key to the client, receives the encrypted message, and decrypts it using the private key.
rsa_client.c
Encryptor
Connects to the server, receives the RSA public key, encrypts a hardcoded secret message, and sends the ciphertext back.
Cryptographic Details
Component
Algorithm
Key Generation
RSA-3072
Padding
OAEP (Optimal Asymmetric Encryption Padding)
Hash (OAEP)
SHA-256
MGF
MGF1-SHA-256
Max Plaintext Size
~318 bytes (384 − 66 bytes OAEP overhead)
How to Run
# On the server
gcc rsa_server.c -o rsa_server -lssl -lcrypto && ./rsa_server
# On the client
gcc rsa_client.c -o rsa_client -lssl -lcrypto && ./rsa_client
4️⃣ Benchmarking (4_Benchmarking/)
Purpose
Compare the encryption/decryption performance of AES-128-CBC (symmetric) vs RSA-3072 (asymmetric) for transferring a 1 KB file, with microsecond-precision timing.
Files
File
Role
Description
aes_client_final.c
AES Sender
Same ECDH + AES-128-CBC flow as Part 2, but wraps the encrypt-and-send loop with gettimeofday() to measure encryption time. Reads from 1kb_file.txt.
aes_server_final.c
AES Receiver
Same ECDH + AES-128-CBC decryption flow, with timing around the receive-and-decrypt loop. Measures decryption time. Saves to received_1kb_aes.txt.
rsa_client_final.c
RSA Sender
Encrypts the 1 KB file in 318-byte chunks (max RSA-3072 payload with OAEP). Measures encryption time. Reads from 1kb_file.txt.
rsa_server_final.c
RSA Receiver
Decrypts each RSA chunk and reconstructs the file. Measures decryption time. Saves to received_1kb.txt.
Benchmark Setup
# Create a 1 KB test file on the client
dd if=/dev/urandom of=1kb_file.txt bs=1024 count=1
⚡ AES is expected to be significantly faster than RSA for file transfer, which is why real-world protocols (TLS, SSH) use RSA/ECDH only for key exchange and AES for data encryption.
⚙️ Prerequisites
GCC compiler
OpenSSL development libraries (libssl-dev)
Two networked machines (e.g., Kali Linux + Ubuntu VMs)
# Install OpenSSL on Debian/Ubuntu
sudo apt install libssl-dev
Note: Update the server IP address (10.0.2.4) in all client files to match your server VM's actual IP.
📋 Summary Table
Part
Encryption
Key Exchange
File Transfer
Benchmarked
1 — Base Transfer
❌ None
N/A
✅ Full file
❌
2 — AES + DH
AES-128-CBC
ECDH (P-256)
✅ Full file
❌
3 — RSA
RSA-3072 OAEP
N/A (direct)
⚠️ Message only
❌
4 — Benchmark
AES-128-CBC & RSA-3072
ECDH / Direct
✅ 1 KB file
✅ (μs timing)
About
A C/C++ client-server application demonstrating secure TCP socket communication, Diffie-Hellman key exchange, AES-128/RSA-3072 encryption, and cryptographic performance benchmarking using OpenSSL.