Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
duyuefeng0708
GitHub Repository: duyuefeng0708/Cryptography-From-First-Principle
Path: blob/main/foundations/05-discrete-log-diffie-hellman/README.md
483 views
unlisted

Module 05: The Discrete Logarithm and Diffie-Hellman

View on nbviewer

The hardness assumption that powers key exchange and much of modern crypto.

Prerequisites

Learning Objectives

After completing this module you will:

  1. Understand the discrete logarithm problem and why it is believed to be hard

  2. Implement Diffie-Hellman key exchange from scratch

  3. Analyze the CDH and DDH hardness assumptions and their relationships

  4. Apply baby step giant step and Pohlig-Hellman algorithms to solve discrete logs in weak groups

Explore (SageMath Notebooks)

Work through these notebooks in order:

#NotebookWhat You'll Learn
aThe Discrete Log ProblemWhat the DLP is and why brute force fails for large groups
bPrimitive Roots and GeneratorsFinding and verifying generators of Z_p*
cDiffie-Hellman Key ExchangeThe protocol, step by step, with concrete examples
dComputational Hardness: CDH and DDHCDH, DDH, and the hierarchy of assumptions
eBaby Step Giant StepA time/space tradeoff that solves DLP in O(sqrt(n))
fPohlig-HellmanExploiting smooth group orders to decompose the DLP

Implement (Rust)

Build these from scratch in rust/src/lib.rs:

#FunctionDescription
1discrete_log_bruteBrute force discrete log for small groups
2baby_step_giant_stepBaby step giant step algorithm
3diffie_hellmanCompute a Diffie-Hellman shared secret
4pohlig_hellmanPohlig-Hellman algorithm for smooth order groups
5is_safe_primeTest whether a prime p is safe (p = 2q + 1 with q prime)

Run: cargo test -p dlog-dh

Break

Try these attacks in the break/ folder:

  • Small subgroup attack on DH with an unsafe prime, forcing the shared secret into a small subgroup

  • Pohlig-Hellman on a smooth order group, recovering the secret exponent by solving small DLPs

  • Recover a shared secret from leaked partial bits using lattice or meet in the middle techniques

Connect

See where this shows up in practice (in the connect/ folder):

  • Diffie-Hellman in TLS 1.3 key exchange, where the ephemeral DH handshake establishes session keys

  • DH in the Signal protocol (X3DH), where the extended triple Diffie-Hellman protocol bootstraps end to end encryption


Next: Module 06: Elliptic Curves