Alice chooses a = 6 and Bob chooses b = 15. Compute the public values and the shared key, showing the modular arithmetic.
A cipher is only as safe as its keys. Key management covers how symmetric keys are distributed (KDCs, Needham–Schroeder), how public keys are trusted (certificates, PKI, X.509), and how Diffie–Hellman lets strangers agree on a secret over an open channel.
AES and RSA are, as far as anyone knows, unbreakable when used correctly. Real systems are broken instead through their keys: keys sent in the clear, keys reused for years, keys left on a stolen laptop, or public keys swapped by an impostor. Key management is the set of procedures that create, distribute, store, use, change and destroy keys safely.
Most systems use a key hierarchy. A small number of long-lived master keys (key-encrypting keys, KEKs) are installed by careful, often physical, means. They are used only to protect short-lived session keys (data-encrypting keys, DEKs), which encrypt the actual traffic and are thrown away afterwards.
For two parties A and B to share a secret key, there are four basic options (Stallings' classification):
Options 1 and 2 do not scale beyond a few links. A KDC scales well: each user shares one master key with the KDC, set up once by physical means, and the KDC issues a new session key whenever two users want to talk. Session keys are created on demand and discarded after use.
| Scheme | Long-term keys for N users | Comment |
|---|---|---|
| Every pair shares a key | N(N − 1)/2 | For N = 1,000: 499,500 keys |
| KDC with master keys | N (one per user, shared with the KDC) | Session keys are generated on demand; the KDC must be trusted and kept available |
| Public-key pairs | 2N (N pairs) | Public halves can be published, but need authentication (certificates) |
Roger Needham and Michael Schroeder (1978) designed the classic KDC protocol. A shares master key K_a with the KDC and B shares K_b; N₁ and N₂ are nonces — random numbers used once, which prove freshness.
The replay flaw (Denning and Sacco, 1981). B has no way to tell whether the ticket in message 3 is new. If an attacker ever learns an old session key K_s, they can replay the matching old message 3. B decrypts it, believes it is talking to A, and sends E(K_s, N₂); the attacker, who knows K_s, answers correctly — and impersonates A indefinitely.
Public keys need no secrecy, but they need authenticity: if an impostor can make you believe their public key belongs to your bank, they can read everything you send to the bank. Four approaches exist, from weakest to strongest:
| Method | How it works | Weakness |
|---|---|---|
| Public announcement | Users broadcast their public keys (e-mail signatures, forums, web pages) | Anyone can forge an announcement and pose as someone else |
| Publicly available directory | A trusted organisation keeps a registered {name, public key} directory | The directory is a target; if its keys leak or it is spoofed, entries can be faked |
| Public-key authority | An online authority hands out others' public keys on request, signing each reply with its private key | The authority must be online for every lookup — a bottleneck and single point of failure |
| Public-key certificates | A certificate authority (CA) signs a certificate binding a name to a public key; anyone verifies it offline using the CA's public key | Depends on trusting CAs and on timely revocation — the scalable, standard solution |
Certificates (an idea from Loren Kohnfelder's 1978 thesis) let participants exchange keys directly, without contacting the authority each time. A certificate binds an identity and a public key with an expiry date, all signed by the CA — and only the CA could have produced that signature.
Public keys can then carry symmetric keys. Merkle's simple 1979 scheme — A sends its public key, B returns a session key encrypted under it — is open to a man-in-the-middle who substitutes their own public key. A safer pattern first exchanges nonces encrypted with each other's certified public keys, then sends E(PU_b, E(PR_a, K_s)): only B can unwrap it, and only A could have sealed it.
Diffie–Hellman (Whitfield Diffie and Martin Hellman, 1976, building on ideas of Ralph Merkle) lets two parties who have never met agree on a shared secret over a completely public channel. It is key agreement, not encryption: the agreed number is then used as (or turned into) a symmetric key.
An eavesdropper sees p, g, A and B. To get K she must find a from A = gᵃ mod p — the discrete logarithm problem — which is infeasible for primes of 2,048 bits or more (or for elliptic-curve groups of about 256 bits, as in X25519 / ECDH).
When both sides pick new random secrets for every session (ephemeral Diffie–Hellman, DHE or ECDHE), stealing a server's long-term private key later does not reveal past session keys. This property is forward secrecy, and it is why TLS 1.3 allows only ephemeral (EC)DHE key exchange.
Basic Diffie–Hellman never checks who sent A or B. An active attacker, Mallory, who can intercept and replace messages, can therefore sit in the middle and run one exchange with Alice and another with Bob.
The defence is to authenticate the exchanged values: each side signs its DH public value with a long-term private key whose public half is vouched for by a certificate — the Station-to-Station protocol, TLS's signed ServerKeyExchange and SSH's host-key signature all do this. Pre-shared keys, or comparing key fingerprints over a separate channel (as SSH and messaging apps ask you to), also work.
A public-key infrastructure (PKI) is the set of people, policies and systems that create, distribute, store and revoke certificates. Its main parts:
| X.509 field | Contents |
|---|---|
| Version | 1, 2 or 3 (v3 adds extensions) |
| Serial number | Unique within the issuing CA; used in revocation lists |
| Signature algorithm identifier | Algorithm the CA used to sign, e.g. sha256WithRSAEncryption |
| Issuer name | Distinguished name of the CA that signed it |
| Validity period | Not before / not after dates |
| Subject name | Whom the certificate identifies (person, server, organisation) |
| Subject public-key info | The subject's public key and its algorithm — the thing being certified |
| Issuer / subject unique IDs (v2) | Optional identifiers, rarely used |
| Extensions (v3) | Key usage, basic constraints (is it a CA?), subject alternative names (DNS names), CRL and OCSP locations, policies |
| Signature | The CA's signature over all the fields above |
Chains and trust anchors. A web server's certificate is usually signed by an intermediate CA, whose certificate is signed by a root CA. Root certificates are self-signed and come pre-installed in operating systems and browsers as trust anchors. To validate, the browser checks each signature up the chain to a trusted root, then checks validity dates, the host name (subject alternative name), key usage and revocation status.
Hybrid encryption combines the strengths of both families: public-key cryptography solves key distribution, and symmetric cryptography does the heavy lifting. PGP and S/MIME e-mail, TLS, SSH and encrypted messaging apps all follow this pattern.
Try the problem first, then reveal the working one step at a time.
Alice chooses a = 6 and Bob chooses b = 15. Compute the public values and the shared key, showing the modular arithmetic.
Mallory intercepts the exchange above (p = 23, g = 5, a = 6, b = 15) and uses her own secret m = 3. Find the value she injects and the two keys that result.
A browser connects to https://portal.example.in and receives the server's certificate (issued by "Example Intermediate CA") plus the intermediate's certificate (issued by "Example Root CA"). List what the browser checks before trusting the server's public key.
A housing board connects 50 district offices. Compare the long-term keys needed for (a) pairwise secret keys, (b) a KDC, and (c) public-key pairs with certificates, and recommend a design.
Diffie–Hellman with p = 11 and g = 2: Alice picks a = 3 and Bob picks b = 4. Find A, B and the shared key.
Diffie–Hellman with p = 17 and g = 3, a = 4 and b = 6. Find the values on the wire and the shared key. What exactly would an eavesdropper have to compute to find the key?
Is g = 2 a good generator for Diffie–Hellman with p = 23? List the powers of 2 mod 23 and explain the consequence.
In the Needham–Schroeder protocol, an attacker has recorded an old message 3 and later learned the session key K_s inside it. Describe the attack, and explain how adding a timestamp T to message 3 stops it.
A browser shows four different certificate errors: (a) "certificate has expired", (b) "name mismatch", (c) "issuer not trusted", (d) "certificate revoked". Which X.509 field or check is involved in each?
10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.