Public key cryptography: which key does what
Public key cryptography gives each person two linked keys: one to publish and one to keep. It is like a letterbox in a front door: anyone can push a letter in, and only the householder can take letters out. This removes the need to share a secret key in advance. No background beyond symmetric encryption is assumed. Knowing exactly which of the four keys is used for which job is the most tested fact in cryptography.
By the end of this unit you will be able to:
- Explain how a public key and a private key work together
- Choose the right key for confidentiality, for proof of origin, and for both together
- Tell apart RSA, Diffie-Hellman, ElGamal, DSA and elliptic curve cryptography
- Calculate the keys a group needs with public key cryptography and compare the result with symmetric keys
- Put the four attacks in order by what the attacker holds, from ciphertext only to chosen ciphertext
A tip-off for a journalist she has never met
An illustrative example
A hospital porter wants to send documents to a journalist at a national newspaper. They have never met and cannot meet. Anything the porter posts or emails might be opened on the way.
The journalist's page on the newspaper's website ends with a long block of letters and numbers headed "my public key". It has been there for years, in plain view, for anyone to copy.
How can something published to the whole world let one stranger send a message that only the journalist can read?
A letterbox anyone can post into
A letterbox has a slot and a door. The slot is open to the street: anyone can post a letter. The door has a lock, and only the householder has its key. Posting needs nothing secret. Collecting does.
Asymmetric cryptography, also called public key cryptography, works the same way. Each person or system has a key pair: two keys created together and linked by mathematics.
- Public key
- The public key is given to anyone who asks. It can be printed on a website. It is the slot.
- Private key
- The private key never leaves its owner and is never shared with anyone. It is the key to the door.
Whatever one key of the pair does, only the other key of the same pair can undo. Working out the private key from the public key is possible in theory and would take longer than anyone has.
The sender and the recipient use different keys, which is why the method is called . In both use the same one.
Two keys: one use for secrecy, one for proof
A key pair can be used in two directions, and each direction does a different job.
| Goal | The sender uses | The recipient uses |
|---|---|---|
| Confidentiality: only the recipient can read it | The recipient's public key, to | The recipient's own private key, to |
| Proof of origin: it came from the sender | The sender's own private key, to sign | The sender's public key, to check the signature |
| Both together | The sender's private key to sign, then the recipient's public key to encrypt | The recipient's private key to decrypt, then the sender's public key to check |
Secrecy uses the recipient's keys; proof uses the sender's
Read this figure as text
A key pair can be used in two directions, and each direction does a different job. A private key is only ever used by its owner and never leaves the owner.
- Confidentiality: the sender encrypts with the recipient's public key, and only the recipient's own private key can decrypt, so only the recipient can read the message.
- Proof of origin: the sender signs with the sender's own private key, and the recipient checks the signature with the sender's public key, so the message can only have come from the sender.
- Both together: the sender signs with the sender's private key, then encrypts with the recipient's public key. The recipient decrypts with the recipient's private key, then checks with the sender's public key.
- Encrypting with your own private key hides nothing, because everyone has the matching public key. It proves who the message came from.
Using a private key on a message produces a . Anyone can check it, and only the key's owner could have made it.
A private key is only ever used by its owner. To keep a secret, use the recipient's public key. To prove who sent it, use the sender's private key.
Common misconception
“Encrypting a message with my private key keeps it secret.”
Everyone has the matching public key, so everyone can read it. Using a private key proves who the message came from. It hides nothing.
The algorithms and the hard problems behind them
Each public key rests on a calculation that is quick in one direction and impractical to reverse. Multiplying two very large prime numbers takes a moment. Finding the two primes from their product, called factoring, takes longer than is practical. A second such problem is the discrete logarithm: undoing a particular kind of repeated multiplication.
| Algorithm | Hard problem | Used for |
|---|---|---|
| RSA | Factoring | Encryption and signatures |
| Diffie-Hellman | Discrete logarithm | Agreeing a shared . It does not encrypt or sign |
| ElGamal | Discrete logarithm | Encryption and signatures |
| DSA (Digital Signature Algorithm) | Discrete logarithm | Signatures only. No longer approved for new signatures |
| Elliptic curve cryptography (ECC) | Discrete logarithm on the points of a curve | Key agreement and signatures, with much shorter keys |
Elliptic curve cryptography gives the same strength with far smaller keys. An elliptic curve key of 256 bits is rated equal to an RSA key of 3,072 bits and to a 128-bit AES key. Small keys suit phones, payment cards and other small devices.
Public key operations are much slower than symmetric ones. They are used on small items, such as a key or a short check value, and not on whole files.
Counting keys: 2n
Each person needs one key pair, however many people they deal with. A group of n people needs 2n keys.
| People | Symmetric: n(n-1)/2 | Public key: 2n |
|---|---|---|
| 10 | 45 | 20 |
| 100 | 4,950 | 200 |
| 1,000 | 499,500 | 2,000 |
A new member adds two keys and nobody else has to change anything. Public keys can be sent openly, so the old problem of delivering a secret key disappears.
A new problem replaces it. The porter must be sure the key on the web page really is the journalist's, and has not been swapped for an impostor's. That question is answered by .
Chosen plaintext and chosen ciphertext
Two attacks give the attacker more than a known- attack does. In both the attacker can use the cryptosystem, without knowing the key.
In a chosen-plaintext attack the attacker picks plaintexts, has them encrypted and studies the results. With public key cryptography this is always possible, because the encrypting key is public. If a reply can only be YES or NO, the attacker encrypts both words with the public key and compares each result with the intercepted . Sound public key encryption therefore mixes random padding into every message, so that the same plaintext never encrypts the same way twice.
In a chosen-ciphertext attack the attacker picks ciphertexts, has them decrypted, and learns something from each result. The system need not hand back the plaintext. A server that answers "badly formed message" to some ciphertexts and not to others is leaking a little each time. A well-known attack of this kind against an older way of padding RSA messages recovered secrets through a very large number of such questions.
An attack is called adaptive when the attacker chooses each new question in the light of the answers so far.
The defences against chosen ciphertext are to use current padding for RSA, to use so that altered ciphertext is rejected unread, and to return the same error whatever went wrong.
Two research methods carry related names. Linear works from large amounts of known plaintext. Differential cryptanalysis works from chosen pairs of plaintext that differ in a set way.
The ladder of what the attacker holds
The four attacks form a ladder. Each rung gives the attacker more than the one below, so each is easier to carry out and harder to arrange.
| Attack | The attacker holds | Everyday picture |
|---|---|---|
| Ciphertext only | Intercepted ciphertext and nothing else | A coded note copied from a noticeboard |
| Known plaintext | Ciphertext with its matching plaintext | The coded note and, later, the announcement it contained |
| Chosen plaintext | The power to have chosen plaintexts encrypted | Getting the clerk to encode messages of the attacker's choosing |
| Chosen ciphertext | The power to have chosen ciphertexts decrypted, or to see how the system reacts | Handing the clerk altered notes and watching which ones are refused |
A cipher is judged against the top rung. A modern cipher is expected to resist an attacker who can do all four.
Worked example: Keys for a firm of 25 people
A firm of 25 people wants every member of staff to be able to exchange private messages with every other.
- With symmetric keys, every pair needs its own: 25 × 24 ÷ 2 = 300 keys. Each person holds 24.
- With public key cryptography, each person has one pair: 2 × 25 = 50 keys. Each person guards one private key.
- A twenty-sixth person joins. Symmetric: 25 new keys, each delivered secretly to two people. Public key: one new pair, and the new public key is published.
- A person leaves. Symmetric: their 24 keys are withdrawn from 24 colleagues. Public key: one key pair is withdrawn.
Public key cryptography needs 50 keys where symmetric needs 300, and joining or leaving touches one person's keys.
A question, worked through
A partner at a law firm must email a draft contract to a client. The client's instruction is that nobody else may read it, and that the client must be able to tell it came from the partner and nobody else. Both hold key pairs and each has the other's public key. The firm's IT supplier suggests that the partner should encrypt the contract with her own private key, since that is "encrypted and proves it is from her".
Which use of the keys BEST meets both of the client's requirements?
Decide on your answer, then open the reasoning
- The question asks for two goals at once: confidentiality, and proof that the partner sent it.
- Rule out c. Anyone holding the partner's public key can undo what her private key did. It shows origin and gives no secrecy.
- Rule out b. A signature must be made with a key that only the signer holds. The client's public key is held by everyone.
- Between a and d: d gives confidentiality, because only the client's private key can decrypt. It gives no proof of origin, since anyone could have used the client's public key.
- Option a does both: the partner's private key proves origin, and the client's public key keeps the contract secret.
Answer: A. Sign with the partner's private key, then encrypt with the client's public key
Choosing between good answers
- A question asks which key keeps a message secret
- it is the recipient's public key to encrypt and the recipient's private key to decrypt.
- A question asks which key proves who sent a message
- it is the sender's private key to sign and the sender's public key to check.
- An option has anyone using another person's private key
- reject it. A private key is only ever used by its owner.
- A question asks which attack lets the attacker submit data to be decrypted
- it is chosen ciphertext. If the attacker submits data to be encrypted, it is chosen plaintext.
- A small device needs public key cryptography with short keys
- choose elliptic curve cryptography.
Check your understanding
4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.
These questions are drafts that no named reviewer has approved yet.
Question 1 of 4
What to remember
- Each party has a public key to publish and a private key to keep. What one does, only the other undoes.
- For secrecy: encrypt with the recipient's public key. For proof of origin: sign with the sender's private key.
- RSA rests on factoring. Diffie-Hellman, ElGamal and DSA rest on discrete logarithms. Elliptic curves give equal strength with shorter keys.
- A group of n needs 2n keys with public key cryptography and n(n-1)/2 with symmetric keys.
- Public key operations are slow, so they are used on small items such as keys.
- The ladder: ciphertext only, known plaintext, chosen plaintext, chosen ciphertext. Each rung gives the attacker more.
Say it from memory
What can the attacker do in a chosen-ciphertext attack, and how does it differ from chosen plaintext?
The attacker picks ciphertexts, has them decrypted or watches how the system reacts to them, and uses the results to recover a key or another message. In chosen plaintext the attacker picks plaintexts and has them encrypted. Chosen ciphertext is the top rung of the ladder. Defences: current RSA padding, authenticated encryption and uniform error messages.
In asymmetric cryptography, what are the public key and the private key, and how are they linked?
Each party has a key pair created together and linked by mathematics. The public key is given to anyone who asks. The private key never leaves its owner. Whatever one key of the pair does, only the other key of the same pair can undo.
Which key does a sender use to keep a message secret, and which to prove it came from them?
To keep it secret, the sender encrypts with the recipient's public key, and the recipient decrypts with their own private key. To prove origin, the sender signs with their own private key, and the recipient checks with the sender's public key. A private key is only ever used by its owner.
Which hard problem does RSA, Diffie-Hellman and elliptic curve cryptography each rest on, and what key sizes give equal strength?
RSA rests on factoring. Diffie-Hellman rests on the discrete logarithm and only agrees a shared secret key. Elliptic curve cryptography rests on the discrete logarithm on the points of a curve. A 256-bit elliptic curve key is rated equal to a 3,072-bit RSA key and a 128-bit AES key.
How many keys does a group of n people need with public key cryptography, and what new problem replaces key delivery?
2n keys: one key pair each, however many people they deal with. Ten people need 20 keys, against 45 symmetric keys. The new problem is being sure a public key really belongs to its named owner and has not been swapped for an impostor's, which certificates answer.
Order the four attacks by what the attacker holds, from least to most.
Ciphertext only: intercepted ciphertext and nothing else. Known plaintext: ciphertext with its matching plaintext. Chosen plaintext: the power to have chosen plaintexts encrypted. Chosen ciphertext: the power to have chosen ciphertexts decrypted, or to see how the system reacts. A modern cipher is expected to resist all four.
Sources
- NIST IR 8105: Report on Post-Quantum Cryptography, NISTRSA, Diffie-Hellman and elliptic curve systems resting on integer factorisation or the discrete logarithm problem.
- RFC 8017: PKCS #1: RSA Cryptography Specifications Version 2.2, IETFThe chosen-ciphertext attack on the older RSA encryption padding and the requirement to support the newer padding scheme in new applications.
- RFC 2631: Diffie-Hellman Key Agreement Method, IETFDiffie-Hellman as a key agreement algorithm by which two parties reach a shared secret.
- FIPS 186-5: Digital Signature Standard (DSS), NISTRSA and elliptic curve algorithms approved for digital signatures, and DSA no longer approved for generating them.
- NIST SP 800-57 Part 1 Rev. 5: Recommendation for Key Management, NISTAn elliptic curve key of 256 bits, an RSA key of 3,072 bits and AES-128 each rated at 128 bits of security strength.