r/theydidthemath • u/INCOMPLETE_USERNAM • Feb 06 '14
Self Time and energy required to brute-force a AES-256 encryption key.
I did a report on encryption a while ago, and I thought I'd post a bit of it here as it's quite mind-boggling.
AES-256 is the standardized encryption specification. It's used worldwide by everyone from corporations to the US government. It's largest key size is 256 bits. This means that the key, the thing that turns encrypted data into unencrypted data, is string of 256 1s or 0s.
With each character having two possibilities (1 or 0), there are 2256 possible combinations. Typically, only 50% of these need to be exhausted to yield the correct key, so only 2255 need to be guessed. How long would it take to flip through each of the possible keys?
When doing mundane, repetitive calculations (such as brute-forcing or bitcoin mining), the GPU is better suited than the CPU. A high-end GPU can typically do about 2 billion calculations per second (2 gigaflops). So, we'll use GPUs.
Say you had a billion of these, all hooked together in a massively parallel computer system. Together, they could perform at 2e18 flops, or
2 000 000 000 000 000 000 keys per second (2 quintillion)
1 billion gpus @ 2 gigaflops each (2 billion flops)
Since there are 31 556 952 seconds in a year, we can multiply by that to get the keys per year.
*31 556 952
=6.3113904e25 keys per year (~10 septillion, 10 yottaflops)
Now we divide 2255 combinations by 6.3113904e25 keys per year:
2^255 / 6.3113904e25
=9.1732631e50 years
The universe itself only existed for 14 billion (1.4e10) years. It would take ~6.7e40 times longer than the age of the universe to exhaust half of the keyspace of a AES-256 key.
On top of this, there is an energy limitation. The The Landauer limit is a theoretical limit of energy consumption of a computation. It holds that on a system that is logically irreversible (bits do not reset themselves back to 0 from 1), a change in the value of a bit requires an entropy increase according to kTln2, where k is the Boltzmann constant, T is the temperature of the circuit in kelvins and ln2 is the natural log(2).
Lets try our experiment while considering power.
most high-end GPUs take around 150 watts of energy to power themselves at full load. This doesn't include cooling systems.
150 000 000 000 watts (150 gigawatts)
1 billion gpus @ 150 watts
1.5e11 watts
This is enough power to power 50 million american households.
The largest nuclear power reactors (Kashiwazaki-Kariwa) generate about 1 gigawatt of energy.
1.5e11 watts / 1 gigawatt = 150
Therefore, 1 billion GPUs would require 150 nuclear power plant reactors to constantly power them, and it would still take longer than the age of the universe to exhaust half of a AES-256 keyspace.
1 billion GPUs is kind of unrealistic. How about a supercomputer?
The Tianhe-2 Supercomputer is the world's fastest supercomputer located at Sun Yat-sen University, Guangzhou, China. It clocks in at around 34 petaflops.
Tianhe-2 Supercomputer @ 33.86 petaflops (quadrillion flops)
=33 860 000 000 000 000 keys per second (33.86 quadrilion)
3.386e16 * 31556952 seconds in a year
2255 possible keys
2^255 / 1.0685184e24
=1.0685184e24 keys per year (~1 septillion, 1 yottaflop)
=5.4183479e52 years
That's just for 1 machine. Reducing the time by just one power would require 10 more basketball court-sized supercomputers. To reduce the time by x power, we would require 10x basketball court-sized supercomputers. It would take 1038 Tianhe-2 Supercomputers running for the entirety of the existence of everything to exhaust half of the keyspace of a AES-256 key.
Edit: corrections on my grade 12 math.
64
u/christianjackson Feb 06 '14 edited Jul 22 '24
public fanatical berserk bells chase poor dog bear fade melodic
This post was mass deleted and anonymized with Redact
18
u/loopynewt Feb 06 '14
I think the math is very good right up til the very last part.
You're right that it would require a further 10 (well 9 actually but that's a minor point) of the computers to reduce the time by 1 power, but then it would require a further 100 to reduce it by 1 more power, then 1000 for the next power and so forth. So a further 380 computers would not reduce the time down to the length of the universe. You wouldnt even get down 4 powers. You'd need like 1e38 computers to get down to that level. That's the problem with massive numbers like this. When they get past 1e10, we just can't fathom how big they are.
1
u/The_Serious_Account Feb 07 '14
I just want to point out that Landauers principle does not apply to reversible computing, such as quantum computing. But otherwise I enjoyed your post.
3
u/Ulysses6 Feb 06 '14
Relevant xkcd
5
u/ElusiveGuy Feb 06 '14 edited Feb 06 '14
Your calculations have a slight mistake (wrong GPU speed, and ignores dedicated FGPA/ASIC hardware), but, yes, searching through a 256-bit keyspace would take an impossibly long time. That's why algorithm weaknesses and side-channel attacks are a major focus nowadays, rather than brute-forcing. Brute-forcing is only really effective over a small search space, like a user password.
That's a several orders of magnitude too low. Let's take a look at some numbers (they might be off by a bit). These are for single precision FLOPS (floating point operations per second):
Even the cheap RPi SoC GPU can beat your "high-end GPU"! Look, a CPU does so!
Now, this isn't actually indicative of real-world or even encryption performance. Especially since this only addresses single-precision floating-point operations, where double-precision or integer performance may be worse. In fact, (SHA) hashing relies heavily on integer operations, and it seems like AES is too. So integer operations, which don't always correspond to floating-point operations, would be more important.
That's, again, not quite correct, though the examples are. Whether a GPU is more suited or not depends on the nature of the calculation - whether it can be easily parallelised or not (broken into many parts to run at the same time) - many, most, common operations are strictly sequential and perform best on a CPU.It has nothing to do with "mundane" or "repetitive" - a computer has no concept of "mundane", and everything is repetitive.
Also, keep in mind that a GPU is often limited by memory, and anything that necessarily use a large amount of memory (e.g. scrypt) will be inefficient on a GPU. I'm not sure if 256-bit AES fits in this category or not.
Also, a lot of encryption-breaking is done by breaking the key-derivation function, which is usually used to convert a password (usually quite short) to the required key. This avoids the need to brute force such a massive keyspace entirely - which is also a reason most modern KDFs are specifically designed to be difficult for a GPU (e.g. lots of memory, again) See http://crypto.stackexchange.com/a/12870/
Also, consider hardware-accelerated encryption (on CPUs nowadays) and even FPGAs or ASICs designed specifically to break encryption. Those are far more effective. Even then, they probably wouldn't search the whole keyspace in any reasonable time, but still...
2
u/samadams0007 Jun 03 '23
Thanks for sharing INCOMPLET. Loved reading your post and learning new terms such as yottaflop along the way.
Fast forward 9 years and we are in 2023.
The RTX 3090 Ti has 10,752 CUDA cores clocked at 1860 MHz which yields a FP32 performance of 39.99 TFLOPs.
I hope we are still safe if we use a 256 bit AES key (generated with KDF over 1million iterations) with a 128 bit IV to go with it to encrypt/decrypt our precious cargo.
1
u/andersleet Jan 08 '25
nmd
1
u/Interesting-Law-8815 Sep 14 '25
How does it decrypt 256b encryption to recover the key? It supposedly takes 15 billion years to brute force that and this will try to decrypt millions of messages per second? How?
1
u/krogers58 Aug 04 '26
Unless you have encoded your 256 bit AES algorithm yourself, but have used a cut n paste algorithm, of which you have no deep understanding, or worse you 're using an existing encryption program/library, it has backdoors built-in.
-3
u/odoprasm Feb 06 '14
This doesn't take into account the average password is all lowercase letters and less than 10 characters long. So that would reduce the difficulty quite significantly.