K038 / Asymmetric encryption, signatures and key exchange
Diffie-Hellman
Diffie-Hellman (DH) is an asymmetric key-agreement method for establishing a shared secret between two parties.
CRYPTOGRAPHY LAB / K038
Cryptography Lab · Diffie-Hellman
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
DH (p=23, g=5)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- Diffie-Hellman (DH) is an asymmetric key-agreement method for establishing a shared secret between two parties. Source document ↗
- Classification and reversibility
- Key agreement; use the shared secret for symmetric-key derivation rather than directly. Source document ↗
- Key or secret requirements
- Each party keeps a secret integer below p; p, g and public values A/B are public. Source document ↗
- Operating principle and structure
- Agree on p,g; calculate/exchange A,B with secrets x,y; B^x and A^y yield the same shared key k. Source document ↗
- Key size, block size and parameters
- Finite-field DH requires prime p and other parameters; p should be at least 2048 bits. Source document ↗
- Security strength and recommendation
- NIST plans to deprecate quantum-vulnerable public-key algorithms after 2030 and disallow after 2035; DH needs PQ transition. Source document ↗
- Known attacks and vulnerabilities
- Raw unauthenticated DH is vulnerable to man-in-the-middle attacks. Source document ↗
- Standards and certification
- NIST SP 800-56A Rev.3 specifies finite-field/elliptic-curve DH and MQV key establishment. Source document ↗
- Typical uses
- Establish session keys via ephemeral DH/ECDH in TLS and IKE. Source document ↗
- Implementations, libraries and tools
- Windows CNG supports DH key pair generation through BCryptOpenAlgorithmProvider and related APIs. Source document ↗
- Decryption or decoding
- DH itself has no decryption or decoding; derive symmetric keys for subsequent ciphertext decryption/authentication. Source document ↗
- Advantages
- Computes a shared secret over an untrusted channel without transmitting any of the secret itself. Source document ↗
- Limitations and cautions
- Static key exchange lacks forward secrecy and is considered poor practice. Source document ↗
- Distinguishing encryption, encoding and hashing
- DH is key agreement, not encryption/encoding/hashing; derive keys with a KDF rather than using raw shared secret. Source document ↗
Practical examples
Example
Alice and Bob exchange public parameters and values, compute the same shared secret using their private values, derive a symmetric key via KDF for later encryption/decryption and authentication.
Procedure
Choose standard finite-field parameters or curve; generate ephemeral key pairs and exchange only public keys; compute shared secret from peer public and own private key; derive session key via KDF; encrypt/decrypt with that symmetric key. DH itself has no decryption.
Scenario
Use ephemeral ECDH/DH in TLS/IKE handshakes for session keys, then symmetric encryption of application data. Authenticate public-key exchange with certificates or authenticated channel to prevent MITM.
Pitfalls and alternatives
Authenticate peers with certificates, signatures or PSK. Static DH/ECDH lacks forward secrecy; use KDF, not raw shared secret as key. Use standard parameters, safe sizes/curves and consider post-quantum migration.
References
- Diffie-Hellman Key Agreement - PyCryptodome ↗
- 22C:169 Notes, Lecture 27 ↗
- Diffie-Hellman Key ↗
- Diffie–Hellman key exchange ↗
- NIST IR 8547 Final: Post-Quantum Deadlines Become Vendor Requirements ↗
- Diffie-Hellman - Crypto++ Wiki ↗
- SP 800-56A Rev. 3, Recommendation for Pair-Wise Key-Establishment Schemes Using Discrete Logarithm Cryptography | CSRC ↗
- Public-Key Based Key-Establishment: SP 800-56 Series ↗
- Diffie-Hellman Keys - Win32 apps | Microsoft Learn ↗
- RFC 10015: Deprecating Obsolete Key Exchange Methods in TLS 1.2 and DTLS 1.2 ↗