RSA
Slide deck 10: public-key principles, requirements, the RSA algorithm with worked numbers, and the attacks on RSA.
Prime Numbers & RSA Encryption Algorithm - ComputerphileComputerphile · primes and how RSA works, 15 min
Public Key Cryptography - ComputerphileComputerphile · public-key cryptography in plain words, 6 min
The RSA Encryption Algorithm (1 of 2: Computing an Example)Eddie Woo · a small RSA example: n, phi(n), e, d, 9 min
Public Key Cryptography: RSA EncryptionArt of the Problem · why RSA works: Euler's theorem and modular exponentiation, 16 minPublic-key principlesSearch on YouTube
Private-key cryptographySearch on YouTube
Traditional private / secret / single key cryptography uses one key. The sender and the receiver share that key. If the key is disclosed, the communications are compromised. The scheme is also symmetric, because the parties are equal.
Because both parties hold the same key, the scheme does not protect the sender. The receiver can forge a message and claim that the sender sent it.
Why public keySearch on YouTube
Public-key cryptography uses two keys: a public key and a private key. It is asymmetric, because the parties are not equal. It uses number theory concepts. It complements private-key cryptography. It does not replace it.
Public-key cryptography was developed to address two key issues:
- Key distribution: secure communication without the need to trust a KDC with your key.
- Digital signatures: a method to verify that a message comes intact from the claimed sender.
The public invention is by Whitfield Diffie and Martin Hellman at Stanford University in 1976. The classified community knew the idea earlier.
Two-key cryptographySearch on YouTube
Public-key / two-key / asymmetric cryptography uses two keys:
- A public key. Anybody can know it. It can encrypt messages and verify signatures.
- A related private key. Only the recipient knows it. It decrypts messages and signs (creates) signatures.
It is infeasible to find the private key from the public key. The scheme is asymmetric because the parties that encrypt messages or verify signatures cannot decrypt messages or create signatures.
Think of a mailbox with a slot. Anyone can put a letter in the slot (encrypt with the public key). Only the owner has the key that opens the box (decrypt with the private key).
Encryption with a public keySearch on YouTube
The slide figure "(a) Encryption with public key" shows these steps:
- Bob has a public key ring with the public keys of Joy, Mike, Ted and Alice.
- Bob encrypts the plaintext with Alice's public key (for example, with RSA).
- The transmitted ciphertext is .
- Alice decrypts with her private key : .
Symmetric vs public keySearch on YouTube
| Conventional encryption | Public-key encryption |
|---|---|
| Needed to work | Needed to work |
| 1. The same algorithm with the same key is used for encryption and decryption. | 1. One algorithm is used for encryption and decryption with a pair of keys, one for encryption and one for decryption. |
| 2. The sender and receiver must share the algorithm and the key. | 2. The sender and receiver must each have one of the matched pair of keys (not the same one). |
| Needed for security | Needed for security |
| 1. The key must be kept secret. | 1. One of the two keys must be kept secret. |
| 2. It must be impossible or at least impractical to decipher a message if no other information is available. | 2. It must be impossible or at least impractical to decipher a message if no other information is available. |
| 3. Knowledge of the algorithm plus samples of ciphertext must be insufficient to determine the key. | 3. Knowledge of the algorithm plus one of the keys plus samples of ciphertext must be insufficient to determine the other key. |
Public-key cryptosystemsSearch on YouTube
The "Public-Key Cryptosystems" figure gives secrecy and authentication together. Source A has the key pair . Destination B has the key pair .
Source A Destination B
X --E(PRa)--> Y --E(PUb)--> Z ----> Z --D(PRb)--> Y --D(PUa)--> X- A encrypts with its own private key . This step gives authentication (a signature).
- A encrypts the result with B's public key . This step gives secrecy.
- B decrypts with to get . Then B decrypts with to get .
Uses and requirementsSearch on YouTube
ApplicationsSearch on YouTube
The uses fall into 3 categories:
- Encryption/decryption: provides secrecy.
- Digital signatures: provide authentication.
- Key exchange: of session keys.
Some algorithms are suitable for all uses. Other algorithms are specific to one use.
| Algorithm | Encryption/Decryption | Digital Signature | Key Exchange |
|---|---|---|---|
| RSA | Yes | Yes | Yes |
| Elliptic Curve | Yes | Yes | Yes |
| Diffie-Hellman | No | No | Yes |
| DSS | No | Yes | No |
RSA and ECC do all three. DH deals keys. DSS signs. Diffie-Hellman does only key exchange. DSS does only digital signatures.
RequirementsSearch on YouTube
Public-key algorithms rely on two keys with these properties:
- It is computationally infeasible to find the decryption key from only the algorithm and the encryption key.
- It is computationally easy to encrypt or decrypt messages when the related key is known.
- For some algorithms, either of the two related keys can encrypt, and the other key decrypts.
These requirements are formidable. Only a few algorithms satisfy them.
Trapdoor one-way functionsSearch on YouTube
A public-key scheme needs a trapdoor one-way function. A one-way function is easy in the forward direction and infeasible in the inverse direction:
A trap-door one-way function has these properties:
- is easy, if and are known.
- is easy, if and are known.
- is infeasible, if is known but is not known.
A practical public-key scheme depends on a suitable trap-door one-way function. In RSA, the trapdoor is the factorization of .
Security of public-key schemesSearch on YouTube
A brute-force exhaustive search attack is always possible in theory, as with private-key schemes. But the keys are too large (more than 512 bits). Security relies on a large difference in difficulty between the easy problem (encrypt/decrypt) and the hard problem (cryptanalysis).
The hard problem is known, but it is made too hard to break in practice. This requires very large numbers. Thus public-key schemes are slow compared to private-key schemes.
The RSA algorithmSearch on YouTube
OverviewSearch on YouTube
Rivest, Shamir and Adleman of MIT made RSA in 1977. It is the best known and most widely used public-key scheme. It uses large integers (for example, 1024 bits). Its security comes from the cost of factoring large numbers.
The slide gives the cost of factorization as:
Encryption and decryptionSearch on YouTube
To encrypt a message , the sender gets the recipient's public key and computes:
To decrypt the ciphertext , the owner uses the private key and computes:
The message must be smaller than the modulus . Break a long message into blocks if necessary.
Key setupSearch on YouTube
Each user makes a public/private key pair with these steps:
- Select two large primes at random: , .
- Compute the system modulus . Also compute .
- Select at random the encryption key , where and .
- Solve , with , to find the decryption key .
- Publish the public encryption key: .
- Keep the private decryption key secret: .
Figure 9.5 (The RSA Algorithm) gives the same steps in a table:
| Key generation by Alice | Condition |
|---|---|
| Select | and both prime, |
| Calculate | |
| Calculate | |
| Select integer | ; |
| Calculate | |
| Public key | |
| Private key |
| Step | Plaintext | Ciphertext |
|---|---|---|
| Encryption by Bob with Alice's public key | ||
| Decryption by Alice |
The figure heading says "Decryption by Alice with Alice's Public Key". This is a typo in the figure. Alice decrypts with her private key .
Key setup order: Primes, N, Phi, E, D, Publish, Protect. Pick ; multiply for ; compute ; choose coprime to ; compute ; publish ; protect .
Why RSA worksSearch on YouTube
RSA works because of Euler's theorem:
In RSA, and . The values and are inverses mod . Thus for some integer . Therefore:
, because and .
RSA worked exampleSearch on YouTube
Key setup exampleSearch on YouTube
The slide example has seven steps:
| Step | Compute | Result |
|---|---|---|
| 1 | Select primes | , |
| 2 | ||
| 3 | ||
| 4 | Select with | choose |
| 5 | Find : and | , because |
| 6 | Publish the public key | |
| 7 | Keep the private key secret |
The check: . The prime 7 is not a factor of 160, thus .
Encryption exampleSearch on YouTube
The message is (). Encryption with :
Trace of , with :
| Power | Value computed | Remainder mod 187 |
|---|---|---|
| 88 | 88 | |
| 77 | ||
| 44 | ||
| 66 | ||
Decryption exampleSearch on YouTube
Decryption with :
Square-and-multiply trace for , with :
| Power | Value computed | Remainder mod 187 |
|---|---|---|
| 11 | 11 | |
| 121 | 121 | |
| 55 | ||
| 33 | ||
| 154 |
Multiply the remainders of , , and . Reduce mod 187 after each multiplication.
| Partial product | Computation | Remainder mod 187 |
|---|---|---|
| 55 | ||
| 110 | ||
Round trip: encrypt with . Decrypt with . The recovered value is equal to the message.
Key generation in practiceSearch on YouTube
The users of RSA must:
- Find two primes at random: , .
- Select either or , and compute the other.
An attacker must not be able to find the primes , easily from the modulus . Thus the primes must be sufficiently large. Typically, you guess a candidate and use a probabilistic primality test. The exponents and are inverses, so use the inverse algorithm (extended Euclid) to compute one from the other.
Attacks on RSASearch on YouTube
Attack typesSearch on YouTube
The possible approaches to attack RSA are:
| Attack | Slide description |
|---|---|
| Brute force key search | Infeasible, given the size of the numbers |
| Mathematical attacks | Based on the difficulty of computing , by factoring the modulus |
| Timing attacks | On the running of decryption |
| Chosen ciphertext attacks | Use the properties of RSA |
Factoring problemSearch on YouTube
The mathematical approach takes 3 forms:
- Factor , then compute and then .
- Find directly and compute .
- Find directly.
Timing attacksSearch on YouTube
Paul Kocher developed timing attacks in the mid-1990s. The attack uses timing variations in operations. For example, a multiplication by a small number takes a different time than a multiplication by a large number. IF statements also change which instructions execute.
The attacker infers the operand size from the time taken. In RSA, the attacker uses the time taken in exponentiation. The countermeasures are:
- Use a constant exponentiation time.
- Add random delays.
- Blind the values used in calculations.
Chosen ciphertext attacksSearch on YouTube
RSA is vulnerable to a Chosen Ciphertext Attack (CCA). The attacker chooses ciphertexts and gets the decrypted plaintext back. The attacker chooses the ciphertexts to use the properties of RSA. The results give information that helps cryptanalysis.
The countermeasures are a random pad of the plaintext, or Optimal Asymmetric Encryption Padding (OAEP).
The slide prints "OASP". The standard name is OAEP (Optimal Asymmetric Encryption Padding).
Quick self-testSearch on YouTube
Which two issues did public-key cryptography address?
Key distribution: secure communication without the need to trust a KDC with your key. Digital signatures: proof that a message comes intact from the claimed sender. Diffie and Hellman published the idea at Stanford in 1976.
Classify RSA, Elliptic Curve, Diffie-Hellman and DSS by the 3 public-key uses.
RSA: all three (encryption/decryption, digital signature, key exchange). Elliptic Curve: all three. Diffie-Hellman: key exchange only. DSS: digital signature only.
Give the 3 public-key requirements.
1: It is computationally infeasible to find the decryption key from the algorithm and the encryption key. 2: It is computationally easy to encrypt or decrypt when the related key is known. 3 (for some algorithms): either key of the pair can encrypt, and the other key decrypts.
Define a trap-door one-way function.
is easy if and are known. is easy if and are known. is infeasible if is known but is not known. In RSA the trapdoor is the factorization of .
In the "Public-Key Cryptosystems" figure, which keys does A use, and in which order?
A encrypts with (authentication), then with (secrecy): . B decrypts with and then .
Why are public-key schemes slow compared with private-key schemes?
Security needs a large gap between easy encryption/decryption and hard cryptanalysis. This requires very large numbers (keys larger than 512 bits). Calculations on such large numbers are slow.
Do the RSA key setup with , , .
. . . , because . , .
Show why gives back .
. So . Euler's theorem gives when . Thus .
Encrypt with and decrypt it.
. .
Name the four attack types on RSA and the three timing-attack countermeasures.
Attacks: brute force key search, mathematical attacks (factoring ), timing attacks, chosen ciphertext attacks. Timing countermeasures: constant exponentiation time, random delays, blinding of the values. Paul Kocher developed the timing attack in the mid-1990s.
- Private-key cryptography uses one shared key and does not protect the sender from forgery by the receiver. Public-key cryptography uses a public key (encrypt, verify) and a private key (decrypt, sign).
- Public-key schemes need a trap-door one-way function and very large numbers, so they are slow.
- RSA: choose primes ; ; ; ; . Encrypt . Decrypt .
- Example: , , , , gives . Euler's theorem is the reason that RSA works.
- Attacks: brute force, mathematical (factoring), timing (Kocher), chosen ciphertext (counter with random padding or OAEP).