HomeVideos

Cloudflare’s Lavalamp Obsession

Now Playing

Cloudflare’s Lavalamp Obsession

Transcript

310 segments

0:04

I bet you thought that was pretty

0:05

random, but that is in fact not that

0:07

random. Okay, that was pre-planned. That

0:09

was not that's barely even pseudo

0:11

random. And why this is important

0:12

because today I want to talk about this.

0:14

Yes, this gigantic wall of lava lamps.

0:17

You're probably wondering what what does

0:19

what do all these lava lamps have to do

0:22

with anything? Well, it turns out they

0:24

run a large portion of the internet's

0:27

SSL and TLS encryption. This is in fact

0:30

how Cloudflare does it. And these lava

0:32

lamps are for anybody to see in the

0:35

headquarters front lobby of the

0:37

Cloudflare office. If you go and stand

0:39

in front of it, you can become part of

0:41

encryption, too. A little piece of

0:43

internet lore. That's right. Just you.

0:45

Just you. You little encrypt. You little

0:47

chaotic algorithm. You you know, you're

0:49

just so you're just so chaotic. Anywh

0:51

who, so why does this what is going on

0:53

here? Why are lava lamps being used for

0:56

uh encryption? or how are they actually

0:58

being used for encryption? Well, the

1:00

first thing to know is that random is

1:02

actually really, really hard on a

1:03

computer. Ultimately, a computer breaks

1:05

down to just a series of if statements.

1:08

Even large LLMs that are predicting all

1:10

these amazing tokens at the end of the

1:12

day is just some big gigantic linear

1:14

algebra of if statements just really

1:17

really condensely find as model weights

1:20

and they're like kind of like nebulous

1:22

if statement, you know, like nebulous if

1:23

statements. Anywh who randomness is

1:26

extremely important for secure

1:28

encryption. Each new key that a computer

1:30

uses to encrypt data must be truly

1:32

random so that the attacker won't be

1:34

able to figure out the key and decrypt

1:36

the data. However, computers are

1:38

designed to provide predictable logical

1:40

outputs based on given input. They are

1:42

not designed to produce the random data

1:44

needed for creating unpredictable

1:46

encryption keys. So what Cloudflare

1:48

actually does is it has these lava lamps

1:50

and they're just always running. And

1:51

that's because lava lamps once they get

1:53

heated up to whatever temperature it's

1:54

supposed to be, the lava starts kind of

1:56

like flowing up and sways a little bit,

1:58

becomes a little bally. Sometimes it's

2:00

just like in that weird tube shape.

2:01

Sometimes it's up at the top. They're

2:03

all just kind of different. And since

2:06

there's 100 of them, there's 100 of all

2:08

this continuously changing, continuously

2:11

different amount of data. And so the

2:13

recording came just always taking

2:15

pictures of or always getting data from

2:18

these 100 cloud flare lava lamps. And if

2:21

somebody steps in front of it to

2:23

actually look at it, you become part of

2:25

the picture. Thus, you are some random

2:27

interruption inside of the data. And

2:29

this is actually used to seed the random

2:32

number generation for SSL/TLS.

2:35

And of course, to make it truly random,

2:37

they also use two other Linux computers

2:39

because Linux computers obviously have

2:40

like dev random. They have ability to,

2:42

you know, generate random numbers. They

2:44

actually use two different Linux

2:45

machines, lines, to generate even more

2:48

random numbers and combine all of this

2:51

together to create a truly random

2:53

number. Now, I'm positive there's a lot

2:54

of you right now like, okay, well, why

2:56

can't you just use mathr random? It it

2:57

seems super random to me, right? Well,

3:00

it is random in the sense that it

3:01

randomly is kind of uniformly set out

3:03

inside of the space between 0 to 1, but

3:07

it is predictable. And that's the big

3:09

thing is random numbers for TLS and SSL

3:12

cannot be predictable. So, what do I

3:14

mean predictable? Well, watch this

3:16

little quick video intro. Let me show

3:17

you something wild. I'm going to go

3:18

inside Firefox console, write this code

3:20

snippet, hit enter, and get three random

3:23

numbers. Next, I'm going to go ahead and

3:25

take these numbers and write these into

3:27

this program that I just created. And

3:29

I'm going to hit enter and it's going to

3:31

give me a few more numbers. Now, I will

3:33

go back here and you can see I don't

3:35

have anything else. I have not written

3:36

math.random by myself. But let me run

3:38

this program again. Let's take a look at

3:40

what has happened. So 0.5466 is this

3:42

exact number with the last decimal

3:44

place.

3:45

>> Now I'm sure there's a bunch of you

3:46

right now. They're like, "Nah, that guy

3:47

probably cheated. There's just it ain't

3:49

possible to predict this kind of

3:51

randomness." Well, it actually turns out

3:52

no. A lot of random number generators

3:55

you use are actually quite predictable.

3:57

In fact, this became such a problem that

3:59

there was this entire Russian hacking

4:02

casino thing to make millions of dollars

4:04

in which they were able to take a video

4:07

of the game that they were playing. It

4:09

was transmitted back to St. Petersburg.

4:12

The people in St. Petersburg because

4:13

they got a hold of the machines and

4:15

figured out the pseudo random was

4:16

actually not that uh unpredictable

4:19

pseudo random. They are able to watch

4:20

enough of the game play and then go okay

4:23

if you wait until this exact moment you

4:26

will be able to uh tilt the odds into

4:28

your favor. They would send a message.

4:29

It take about a half second to travel

4:31

across the world. It would vibrate in

4:33

someone's phone. They then offset for

4:34

about another $250 milliseconds for a

4:37

person from the vibration to pressing

4:38

the button and that would actually all

4:40

line up and they were able to rake in

4:42

about $250,000

4:44

per week from these broken older

4:47

machines that are spread across the

4:49

world because they were able to

4:51

accurately predict a pseudo random

4:54

number generator. So, this is why it's

4:55

so important because if people were able

4:57

to kind of guess what Cloudflare's next

5:00

set of random numbers are, they could

5:01

end up just being able to inspect

5:03

effectively some portion of the world's

5:06

data going across the internet. That

5:08

means they could do some level of

5:09

decryption that allows them to gain

5:11

access to areas that they should not be

5:13

gaining access to. Just like that Alex

5:15

fellow with the machines, they would be

5:17

able to gamble and probably make

5:19

millions of dollars by stealing people's

5:21

data, being able to break the

5:23

encryption. So having things that are

5:25

extremely random turns out is very

5:27

important for Cloudflare. Now

5:29

specifically this type of random is not

5:31

just called a pseudo random number

5:32

generator. It's actually called a

5:34

cryptographically secure pseudo random

5:36

number generator or a CSRNG.

5:39

It's a type of PRNG that meets a more

5:41

stringent standard making it safer to

5:43

use for cryptography. And it requires

5:45

two kind of you know requirements.

5:47

First, the random number generator has

5:49

to prove that it's unpredictable. And

5:51

second, that an attacker is not able to

5:53

predict its outputs. And that

5:55

[clears throat] is what makes the lava

5:56

lamp so unique. They never take the same

5:58

shape. So if you take all that image

5:59

data, it's just always different. The

6:02

light is reflecting different. The, you

6:04

know, like the saturation, the amount of

6:06

luminosity per pixel is just going to be

6:09

constantly changing under this

6:11

uncalculable number. And that's why it's

6:13

so incredible because when someone does

6:15

walk in front of it, they're just so

6:16

random. They make the CSP RNG

6:20

effectively impossible to guess. But

6:22

Cloudflare actually takes it a step

6:23

further. You're probably asking, well,

6:25

if the lava lamps are the only source

6:26

for a cryptographically secure seed,

6:29

that must mean that if someone were to

6:31

be able to like just put a gigantic sign

6:33

in front of the camera, you would be

6:35

able to effectively kind of circumvent

6:37

Cloudflare's randomness and boom, you

6:39

could guess all the keys, right? Well,

6:40

it turns out that they do even more than

6:43

that. Many operating systems have their

6:45

own sources of random data for use in

6:48

cryptographic seeds. For instance, user

6:50

actions, mouse movements, keyboard

6:51

typing, blah blah blah. Although they

6:53

obtain this data relatively slowly,

6:55

Cloudflare mixes the random data

6:57

obtained from the lava lamps with data

6:58

generated by the Linux operating system

7:00

on two different machines in order to

7:03

maximize entropy when creating

7:04

cryptographic seeds for SSL and TLS

7:07

encryption. So that means even if the

7:09

cameras were to go down, they would

7:11

actually continue to produce very random

7:13

nature. You wouldn't be able to go,

7:15

okay, the cameras are down for the next

7:16

20 minutes. We can guess. It's like, no,

7:17

actually this is still a very, very

7:19

unpredictable and an impossible problem

7:21

to predict. But even more kind of

7:23

interesting, something I did not realize

7:24

until reading this blog, it turns out

7:26

each office kind of has their own unique

7:29

way of doing uh cryptographic data,

7:31

which is it just makes this more fun, I

7:33

guess. The other two main Cloudflare

7:35

offices are in London and Singapore. And

7:38

each office has its own method for

7:39

generating random data from realworld

7:41

inputs. London takes photos of a double

7:44

pendulum system mounted in the office, a

7:47

pendulum connected to a pendulum, the

7:49

movements of which are mathematically

7:51

unpredictable. The Singapore office

7:53

measures the radioactive decay of a

7:55

pellet of uranium. Weird, right? I mean,

7:58

who would who would have who would have

8:00

guessed? There's actually other methods

8:01

that they're using and they're all kind

8:02

of just realworld stuff cuz the real

8:05

world is unpredictable whereas computers

8:07

are just simply predictable. But one

8:09

more kind of might shimalon turnaround

8:12

and all this. It turns out Cloudflare

8:14

not the first company to use lava lamps

8:16

for randomness. Was Cloudflare the first

8:19

company to use lava lamps for

8:20

encryption? No. Surprisingly, a company

8:23

called Silicon Graphics designed a

8:25

similar system called Lava Rand in 1996.

8:29

although the patent has since expired.

8:31

Anyways, this rabbit hole actually goes

8:32

quite a bit deeper. Uh, randomness turns

8:34

out to be actually a very very hard

8:36

problem and a very very important

8:38

problem. So, if you want to, I will have

8:40

links in the description for randomness

8:42

and the a lava random production, the

8:44

nitty-gritty technical details because

8:46

at the end of the day, probably

8:48

something you're never going to have to

8:49

worry about. But it's also just

8:50

something that, you know, it's just

8:51

these are one of those weird things that

8:53

are so interesting cuz my very first

8:55

thought when I saw those lava lamps, I

8:57

just assumed it was like, okay, if the

8:59

lava's high, that's a one. If the lava's

9:01

low, that's a zero. And they use the 100

9:03

to create a 100 bit random string. But

9:05

no, then I was like, okay, well, what

9:06

happens if someone walks in front of it?

9:07

Like does that just become zeros? How

9:09

does this work? I never even thought

9:10

about the fact you just use every single

9:12

pixel from the image. It's like okay,

9:14

they're all so vastly different at

9:16

different at every single moment that it

9:19

just works out like mindblowing stuff

9:21

going on. Of course, I I classic, by the

9:23

way, software engineer. I just think of

9:25

the most complex possible way to do the

9:27

problem when the actual simple answer is

9:29

right in front of me. Hey, just measure

9:31

it all. And I'm like, you could just

9:32

take, you know, it's like a binary

9:33

representation of a 100 bit. [laughter]

9:36

I don't know what's wrong with me. I

9:37

thought this was awesome. If you think

9:38

this is awesome, you know, tell me it

9:40

is. Tell me it's awesome. Tell me, tell

9:42

me something fantastic. Tell me, hey

9:44

girl, tell me about yourself. You come

9:46

come here often. Agen. I forgot the

9:48

whole prime part though. So, just like

9:50

in your head, imagine I said prime and

9:52

then I said all of that and then the

9:54

agen just makes a lot more sense. A gen.

9:58

Hey, do you want to learn how to code?

10:00

Do you want to become a better back-end

10:01

engineer? Well, you got to check out

10:03

boot.dev. Now, I personally have made a

10:05

couple courses from them. I have live

10:06

walkthroughs free available on YouTube

10:08

of the whole course. Everything on

10:10

boot.dev you can go through for free.

10:13

But if you want the gamified experience,

10:15

the tracking of your learning and all

10:16

that, then you got to pay up the money.

10:18

But hey, go check them out. It's

10:19

awesome. Many content creators you know

10:21

and you like make courses there.

10:23

boot.dev/prime for 25% off.

Interactive Summary

The video explains Cloudflare's innovative method for generating truly random numbers, essential for internet security protocols like SSL and TLS encryption. Traditional computers struggle with true randomness, often producing predictable "pseudo-random" outputs. Cloudflare overcomes this by utilizing a wall of lava lamps at its headquarters; cameras capture the continuously changing, chaotic patterns of the lava, providing a source of unpredictable image data. This real-world entropy is combined with additional random inputs from Linux operating systems (including user interactions, mouse movements, and keyboard input) and other physical phenomena like double pendulums (London office) or radioactive decay (Singapore office). This multi-source approach creates a Cryptographically Secure Pseudo Random Number Generator (CSPRNG), ensuring that encryption keys are genuinely unpredictable and protecting sensitive internet data from potential decryption by attackers, as even seemingly random computer-generated numbers can be exploited.

Suggested questions

6 ready-made prompts