Key Length and Security
Why a longer key means a larger keyspace, how many guesses a brute-force attack needs on average, the cost of longer keys, and why key lengths only compare within one algorithm.
1Keyspace grows by doubling
Longer keys produce larger keyspaces. For binary keys, an n-bit key has a keyspace of 2n: each bit has two choices, so every added bit doubles the number of possible keys.
2How many guesses on average
An adversary using software to guess an n-bit key will find it, on average, after 2n ÷ 2 = 2n−1 guesses. The right key is equally likely to be anywhere in the search, so on average the search ends halfway through. The worst case is all 2n.
A real test: a program picked 2,000 random 12-bit keys and searched for each one from 0 upward.
| Measure | Result |
|---|---|
| Keyspace | 212 = 4,096 |
| Predicted average, 2n−1 | 2,048 guesses |
| Measured average | 2,060 guesses |
| Fastest and slowest searches | 2 and 4,095 guesses |
At a trillion guesses per second, here is the average search time:
| Key length (bits) | Keyspace | Average guesses | Average time |
|---|---|---|---|
| 8 | 28 = 256 | 27 | less than a second |
| 16 | 216 = 65,536 | 215 | less than a second |
| 56 | 256 = 7.2 × 1016 | 255 | about 10 hours |
| 128 | 2128 = 3.4 × 1038 | 2127 | about 5.4 × 1018 years |
| 256 | 2256 = 1.2 × 1077 | 2255 | about 1.8 × 1057 years |
3Longer keys cost time
Longer keys are more secure, but they also require more time to encrypt and decrypt. AES-256 runs 14 rounds of scrambling per block instead of AES-128's 10. For RSA the cost grows much faster: doubling an RSA key from 2048 to 4096 bits makes each decryption several times slower, which matters on a busy server or a small device.
4Recommendations keep rising
Processing power and efficiency keep improving, so software guesses keys faster every year. Key-length recommendations for both symmetric and asymmetric algorithms are therefore periodically increased.
| Then | What happened | Now |
|---|---|---|
| 56-bit DES keys were the U.S. standard from 1977 | In 1998 a purpose-built machine found a DES key in 56 hours | AES with 128-bit or longer keys |
| 512-bit RSA keys were common in the 1990s | A 512-bit RSA key was broken in 1999 | 2048-bit RSA is the minimum; 3072 or more for long-term secrets |
5Compare within one algorithm
Key-length comparison is only valid for keys of the same algorithm.
- An AES 256-bit key is more secure than an AES 128-bit key.
- An RSA 4096-bit key is more secure than an RSA 2048-bit key.
- RSA and AES keys cannot be compared directly. RSA keys must be much longer because attackers do not search every possible RSA key; they use math shortcuts. A 2048-bit RSA key is not sixteen times stronger than a 128-bit AES key.
An n-bit key has 2n possible values, and a brute-force search needs 2n−1 guesses on average. Longer keys are more secure but slower, recommended lengths rise as computers get faster, and lengths only compare within the same algorithm.
6Worked examples
A 20-bit key
A practice cipher uses a 20-bit key. What is its keyspace, and how many guesses does brute force need on average?
- 1Keyspace: 220 = 1,048,576.
- 2Average: 219 = 524,288 guesses.
How much bigger?
How many times larger is the keyspace of a 64-bit key than a 60-bit key?
- 1Each extra bit doubles the keyspace.
- 2Four extra bits: 24 = 16.
RSA versus AES
A student says, “RSA-2048 is far more secure than AES-256, because 2048 is bigger than 256.” Evaluate the claim.
- 1Key lengths only compare within the same algorithm.
- 2RSA and AES are attacked in completely different ways, so their bit counts do not measure the same thing.
Long-term records
A hospital must keep encrypted records private for 30 years. Its policy allows AES-128 or AES-256. Which should it choose, and what is the cost?
- 1Computers will keep getting faster, and recommendations rise over time.
- 2A 30-year secret needs a large safety margin: AES-256.
- 3The cost is more time to encrypt and decrypt, which modern servers handle easily.
7Common mistakes
Adding one bit doubles it. Going from 128 to 256 bits multiplies the keyspace by 2128.
The average brute-force search needs half of that: 2n−1 guesses.
Only compare AES to AES or RSA to RSA.
Faster computers push recommendations up. A key length that was fine years ago may not be now.
“A 256-bit AES key has 2256 possible values, so a brute-force attack needs 2255 guesses on average, far more than any computer can try. It is more secure than a 128-bit AES key but takes somewhat longer to encrypt and decrypt.”
Give the keyspace, the average number of guesses, and the trade-off, and compare only within one algorithm.