In the digital world, secure communication is paramount, especially when dealing with sensitive information over untrusted networks. Cryptography provides the foundation for safeguarding our data and ensuring confidentiality. This blog covers how various cryptographic methods can be combined to perform a secret handshake over untrusted networks. We will define a protocol for a peer-to-peer secret handshake using ECDH, ECDSA, and AES.
Implementation of the Handshake Protocol in Rust (demo below): https://github.com/SubconsciousCompute/handshake-poc

<aside> 💡 If you just need the protocol, you can skip to the “P2P Handshake Protocol” section
</aside>
Key exchange (or key establishment) is a method in cryptography whereby cryptographic keys are exchanged between two parties. Diffie–Hellman is one of the earliest methods of public key exchange. It facilitates two parties with no prior knowledge of each other to jointly establish a shared secret key over an insecure channel. Elliptic-curve Diffie–Hellman (ECDH) is a variant of the Diffie–Hellman protocol that uses elliptic-curve cryptography. Elliptic-curve cryptography allows for smaller keys compared to non-EC cryptography, while providing equivalent security. Here's how the ECDH protocol works between two parties A and B:
This shared secret can be used for symmetric encryption to secure subsequent messages between A and B.
A MITM attack is a type of security breach in which an attacker intercepts and potentially alters communication between two parties who believe they are directly communicating with each other. The attacker positions themselves between the legitimate sender and receiver, secretly relaying, and possibly modifying the exchanged messages. Here's how a party C, secretly positioned between parties A and B, can perform a MITM attack on the ECDH protocol:
The MITM attack on the ECDH protocol is successful because C effectively impersonates both A and B to intercept and manipulate their communication, leading to two separate shared secrets: A-C shared secret and B-C shared secret. However, there are countermeasures available, such as the use of digital signatures.