Edexcel International Advanced Level Computer Science, point 12.3.2
Definition
RSA (named after Rivest, Shamir and Adleman) is an asymmetric (public-key) encryption algorithm (3.2.2): it uses a pair of mathematically linked keys, a public key (shared with anyone) and a private key (kept secret). What one key encrypts, only the other can decrypt.
Characteristics
- Asymmetric: two different keys.
- Its security rests on a hard problem: multiplying two large prime numbers is easy, but factorising their product back into the primes is extremely hard for large numbers.
- Slow compared with symmetric ciphers, so it's used for exchanging keys and for digital signatures, not for encrypting large files.
- Key sizes of 2048 bits or more are used today.
Why needed
It solves the key exchange problem (3.2.2): two people who have never met can communicate securely, because the sender only needs the receiver's public key, which isn't secret. It's used in TLS (12.1.2), digital signatures, and secure email.
a. Prime numbers
A prime number is a whole number greater than 1 with exactly two factors: 1 and itself (2, 3, 5, 7, 11, 13, ...). RSA uses two large primes, and , chosen at random and kept secret.
- Multiplying them is fast: .
- Factorising to find and is infeasibly slow for numbers hundreds of digits long.
- is made public, but and are not.
b. Key generation and key exchange
How the keys are made
- Choose two large primes and .
- Calculate .
- Calculate .
- Choose a public exponent with that has no common factor with .
- Calculate the private exponent so that .
- Public key . Private key .
Encrypting and decrypting
where is the message (a number less than ) and is the ciphertext.
A small worked example (using tiny primes, so it can be done by hand)
- , .
- .
- .
- (no common factor with 10).
- , because .
- Public key , private key .
Encrypt : . Work it out in steps: , so , and . So .
Decrypt : . ✓
(Real keys use primes of hundreds of digits, so has over 600 digits: this example is only to show the method.)
Key exchange in practice
- The receiver (a website) generates a key pair and publishes the public key (in a digital certificate, 12.1.2).
- The sender uses that public key to encrypt a symmetric session key and sends it.
- Only the receiver's private key can decrypt it, so both share the session key securely, and then use fast symmetric encryption (such as AES) for the data.
Digital signatures (reverse use)
The sender encrypts a hash of the message with their private key. Anyone can check it with the sender's public key, which proves who sent it and that it wasn't changed.
Benefits
- No shared secret needs to be sent first (solves the key exchange problem).
- Public keys can be published openly.
- Supports digital signatures (authentication and integrity).
- Well studied and widely used.
c. Vulnerabilities
| Weakness | Explanation |
|---|---|
| Small keys | Short keys can be factorised with enough computing power. Keys below 2048 bits aren't safe |
| Poorly chosen primes | If and are close together, or generated with weak random numbers, can be factorised quickly |
| Stolen or leaked private key | Anyone with it can decrypt messages and forge signatures. It must be stored securely |
| Quantum computers | Shor's algorithm could factorise large numbers efficiently, which would break RSA (16.1.3). Quantum-resistant algorithms are being developed |
| Man-in-the-middle attack | If an attacker substitutes their own public key for the real one, they can read the messages. Certificates from trusted authorities prevent this |
| Side-channel attacks | Information leaks from timing or power use while the computer does the maths |
| Slow | Heavy computation, so not used for bulk data, and a risk of overloading servers |
| Implementation bugs | Errors in software (padding mistakes) can expose the data |
Worked example
Task: using , , , find the keys, then encrypt and decrypt it.
- .
- .
- has no common factor with 40. ✓
- : . Try : . ✓ So .
- Public key . Private key .
- Encrypt: .
- Decrypt: , which equals 9 (the calculation is easiest by computer).
Why can an attacker not just work out ? They know and , but to find they need , which needs and , and finding them means factorising . With that's trivial, but with a 2048-bit it is infeasible.
Exam tip: state that RSA's security depends on the difficulty of factorising the product of two large primes. Know which key encrypts and which decrypts (public encrypts, private decrypts, for confidentiality). The specification asks for definition, characteristics and why needed, so focus on those, with key size, quantum computers and stolen private keys as vulnerabilities. You may be asked to complete a diagram of RSA encryption.
Check yourself
What type of encryption is RSA?
Asymmetric (public-key) encryption, using a public key and a private key.
Why is RSA hard to break?
It relies on factorising the product of two very large primes being extremely difficult, even though multiplying them is easy.
Which key does a sender use to encrypt a message to Sam with RSA, and which key decrypts it?
Sam's public key encrypts; Sam's private key decrypts.
Why is RSA usually used to exchange a key instead of encrypting a whole file?
It is slow, so it securely shares a symmetric key and then the faster symmetric encryption handles the data.
Give two vulnerabilities of RSA
Any two of: keys that are too short; poorly chosen primes; theft of the private key; man-in-the-middle with a fake public key; quantum computers.