1 Introduction - Real-World Cryptography
1 Introduction - Real-World Cryptography
1 Introduction
50 Real-World Cryptography
cancel anytime
NOTE
You can automatically highlight by performing the text selection while keeping the alt /
key pressed.
view how
Of course, it’s not a great protocol as anybody can steal your sword
while you’re napping . . . And so, cryptography is about taking into
account the adversaries who are looking to take advantage of you.
There will be (almost) no scary math formulas. The purpose of this book
is to demystify cryptography, survey what is considered useful
nowadays, and provide intuition about how things around you are built.
This book is intended for curious people, interested engineers,
adventurous developers, and inquisitive researchers. Chapter 1, this
chapter, initiates a tour of the world of cryptography. We will discover
the di erent types of cryptography, which ones matter to us, and how
the world agreed on using these.
livebook features:
discuss
Ask a question, share an example, or respond to another reader. Start a thread by selecting
any piece of text and clicking the discussion icon.
Real-World Cryptography
Let’s imagine that Queen Alice needs to send a letter to Lord Bob, who
lives a few castles away. She asks her loyal messenger to ride his trusty
steed and battle his way through the dangerous lands ahead in order to
deliver the precious message to Lord Bob. Yet, she is suspicious; even
though her loyal messenger has served her for many years, she wishes
the message in transit to remain secret from all passive observers,
including the messenger! You see, the letter most likely contains some
controversial gossip about the kingdoms on the way.
What Queen Alice needs is a protocol that mimics handing the message
to Lord Bob herself with no middlemen. This is quite an impossible
problem to solve in practice unless we introduce cryptography (or
teleportation) into the equation. This is what we ended up doing ages
ago by inventing a new type of cryptographic algorithm—called a
symmetric encryption algorithm (also known as a cipher).
Let’s see how we can use an encryption primitive to hide Queen Alice’s
message from the messenger. Imagine for now that the primitive is a
black box (we can’t see what’s inside or what it’s doing internally) that
provides two functions:
ENCRYPT
DECRYPT
Figure 1.1 The ENCRYPT function takes a message and a secret key
and outputs the encrypted message—a long series of numbers that
look like random noise.
Real-World Cryptography
To make use of this new primitive, Queen Alice and Lord Bob have to
rst meet in real life and decide on what secret key to use. Later, Queen
Alice can use the provided ENCRYPT function to protect a message with
the help of the secret key. She then passes the encrypted message to her
messenger, who eventually delivers it to Lord Bob. Lord Bob then uses
the DECRYPT function on the encrypted message with the same secret
key to recover the original message. Figure 1.3 shows this process.
Figure 1.3 (1) Alice uses the ENCRYPT function with a secret key to
transform her message into noise. (2) She then passes the
encrypted message to her messenger, who will not learn anything
about the underlying message. (3) Once Bob receives the encrypted
message, he can recover the original content by using the DECRYPT
function with the same secret key Alice used.
Real-World Cryptography
During this exchange, all the messenger had was something that looked
random and that provided no meaningful insight into the content of the
hidden message. E ectively, we augmented our insecure protocol into a
secure one, thanks to the help of cryptography. The new protocol makes
it possible for Queen Alice to deliver a con dential letter to Lord Bob
without anyone (except Lord Bob) learning the content of it.
view how
Real-World Cryptography
Hundreds of years have passed and many queens and lords have been
buried. Since then, paper has been abandoned as our primary means of
communication in favor of better and more practical technologies.
Today, we have access to powerful computers as well as the internet.
More practical, sure, but this also means that our previous malicious
messenger has become much more powerful. He is now everywhere: the
Wi-Fi in the Starbucks cafe you’re sitting in, the di erent servers
making up the internet and forwarding your messages, and even in the
machines running our algorithms. Our enemies are now able to observe
many more messages as each request you make to a website might pass
through the wrong wire and become altered or copied in a matter of
nanoseconds without anyone noticing.
Before us, we can see that recent history contains many instances of
encryption algorithms falling apart, being broken by secret state
organizations or by independent researchers, and failing to protect
their messages or accomplish their claims. Many lessons were learned,
and we slowly came to understand how to produce good cryptography.
NOTE
NOTE
Real-World Cryptography
NIST is a United States agency whose role is to de ne standards and
develop guidelines for use in government-related functions
print book as well
$59.99 $35.99
as other public or private organizations. LikepBook
AES, it has
+ eBook + liveBook
standardized many widely used cryptographic audio
primitives.
$24.99 $17.49
If the enemies of Queen Alice and Lord Bob knew exactly how they were
encrypting messages, how is their encryption algorithm secure? The
answer is the secret key! The secrecy of the key makes the protocol
secure, not the secrecy of the algorithm itself. This is a common theme
in this book: all the cryptographic algorithms that we will learn about
and that are used in the real world are most often free to be studied and
used. Only the secret keys used as input to these algorithms are kept
secret. Ars ipsi secreta magistro (an art secret even for the master), said
Jean Robert du Carlet in 1644. In the next section, I will talk about a
totally di erent kind of cryptographic primitive. For now, let’s use
gure 1.4 to organize what we’ve learned so far.
livebook features:
highlight, annotate, and bookmark
Select a piece of text and click the appropriate icon to annotate, bookmark, or highlight
(you can also use keyboard shortcuts - h to highlight, b to bookmark, n to create a
note).
You can automatically highlight by performing the text selection while keeping the alt /
key pressed.
view how
1.4 Asymmetric cryptography: Two keys are
better than one
In our discussion about symmetric encryption, we said that Queen Alice
and Lord Bob rst met to decide on a symmetric key. This is a plausible
scenario, and a lot of protocols actually do work like this. Nonetheless,
this quickly becomes less practical in protocols with many participants:
Real-World Cryptography
do we need our web browser to meet with Google, Facebook, Amazon,
printconnecting
and the other billions of websites before securely book $59.99 $35.99
to those?
pBook + eBook + liveBook
audio $24.99 $17.49
This problem, often referred to as key distribution, has been a hard one
to solve for quite a long time, at least until the discovery in the late
1970s of another large and useful category of cryptographic algorithms
ebook $47.99 $33.59
called asymmetric cryptography or public key cryptography. Asymmetric
pdf + ePub + kindle + liveBook
cryptography generally makes use of di erent keys for di erent
audio $24.99 $17.49
functions (as opposed to a single key used in symmetric cryptography)
or provides di erent points of view to di erent participants. To
illustrate what this means and how public key cryptography helps to set
up trust between people, I’ll introduce a number of asymmetric
primitives in this section. Note that this is only a glance of what you’ll
learn in this book as I’ll talk about each of these cryptographic
primitives in more detail in subsequent chapters.
Real-World Cryptography
Figure 1.5 The rst step of a DH (Dif e-Hellman) key exchange is to
have both participants generate a private key. Inbook
print our analogy,
$59.99 $35.99
Queen Alice chooses a triangle as her private key,
pBook whereas
+ eBook + liveBook Lord
Once they chose their private keys, they both individually combine their
secret shape with the common shape they initially agreed on using (the
square). The combinations result in unique shapes representing their
public keys. Queen Alice and Lord Bob can now exchange their public
keys (hence the name key exchange) because public keys are considered
public information. I illustrate this in gure 1.6.
Because Queen Alice accepts any public key she receives as being Lord
Bob’s public key, I could intercept the exchange and replace it with
mine, which would allow me to impersonate Lord Bob to Queen Alice
(and the same can be done to Lord Bob). We say that a man-in-the-
middle (MITM) attacker can successfully attack the protocol. How do we
x this? We will see in later chapters that we either need to augment
this protocol with another cryptographic primitive, or we need to be
aware in advance of what Lord Bob’s public key is. But then, aren’t we
back to square one?
Previously, Queen Alice and Lord Bob needed to know a shared secret;
now Queen Alice and Lord Bob need to know their respective public
keys. How do they get to know that? Is that a chicken-and-egg problem
all over again? Well, kind of. As we will see, in practice, public key
cryptography does not solve the problem of trust, but it simpli es its
establishment (especially when the number of participants is large).
Let’s stop here and move on to the next section as you will learn more
about key exchanges in chapter 5. We still have a few more asymmetric
cryptographic primitives to uncover (see gure 1.8) to nish our tour of
real-world cryptography.
Now, you and I and everyone who wants can encrypt a message to her
using her public key. In our analogy, imagine that you would insert your
message into the open chest and then close it. Once the chest is closed,
nobody but Queen Alice should be able to open it. The box e ectively
protects the secrecy of the message from observers. The closed box (or
encrypted content) can then be sent to Queen Alice, and she can use her
private key (only known to her, remember) to decrypt it (see gure
1.10).
Alice while they are being sent to her. audio $24.99 $17.49
“What if they forge my signature?” you may ask, and indeed, real
signatures don’t provide much security in the real world. On the other
hand, cryptographic signatures can be used in the same kind of way but
provide a cryptographic certi cate with your name on it. Your
cryptographic signature is unforgeable and can easily be veri ed by
others. Pretty useful compared to the archaic signatures you used to
write on checks!
all our content. all the time.
cancel anytime
ebook $47.99 $33.59
a free eBook each month*
pdf + ePub + kindle + liveBook
Figure 1.12 Lord David already trusts Queen Alice. Because Queen
Alice trusts Lord Bob, can Lord David safely trust Lord Bob as well?
Real-World Cryptography
The result is either true (the signature is valid) or false (the signature is
invalid) as gure 1.14 shows.
Figure 1.14 To verify a signature from Queen Alice, one also needs
the message signed and Queen Alice’s public key. The result is
either validating the signature or invalidating it.
Real-World Cryptography
livebook features:
discuss
Ask a question, share an example, or respond to another reader. Start a thread by selecting
any piece of text and clicking the discussion icon.
cryptography
In 1993, Bruce Schneier released Applied Cryptography (Wiley), a book
targeting developers and engineers who want to build applications that
involve cryptography. Circa 2012, Kenny Paterson and Nigel Smart
started an annual conference called Real World Crypto that targets the
same crowd. But what do applied cryptography and real-world
cryptography refer to? Is there more than one type of cryptography?
livebook features:
highlight, annotate, and bookmark
Select a piece of text and click the appropriate icon to annotate, bookmark, or highlight
(you can also use keyboard shortcuts - h to highlight, b to bookmark, n to create a
note).
You can automatically highlight by performing the text selection while keeping the alt /
key pressed.
view how
1.7 From theoretical to practical: Choose your
own adventure
Sitting on top are cryptanalysts who propose and solve hard mathematical
problems [ . . . ] and at the bottom are software engineers who want to
encrypt some data.
Real-World Cryptography
—Thai Duong (“So you want to roll your own crypto?,” 2020)
print book $59.99 $35.99
pBook + eBook + liveBook
In all the years I’ve spent studying and working with cryptography, I’ve
audio $24.99 $17.49
never noticed a single pattern in which a cryptographic primitive ends
up being used in real-world applications. Things are pretty chaotic.
Before a theoretical primitive gets to be adopted, there’s a long list of
ebook $47.99 $33.59
people who get to handle the primitive and shape it into something
pdf + ePub + kindle + liveBook
consumable and sometimes safer for the public at large. How
audio can I$17.49
$24.99 even
explain that to you?
Have you heard of Choose Your Own Adventure? It’s an old book series
where you got to pick how you want to step through the story. The
principle was simple: you read the rst section of the book; at the end of
the section, the book lets you decide on the path forward by giving you
di erent options. Each option was associated with a di erent section
number that you could skip directly to if you so chose. So, I did the same
here! Start by reading the next paragraph and follow the direction it
gives you.
Where it all begins. Who are you? Are you Alice, a cryptographer? Are you
David, working in the private industry and in need of a solution to your
problems? Or are you Eve, working in a government branch and
preoccupied by cryptography?
You got it! There are many means for a primitive to go real-world. The
best way involves many years of analysis, an implementor-friendly
standard, and good libraries. A worse way involves a bad algorithm with
a poor implementation. In gure 1.16, I illustrate the preferred path.
Figure 1.16 The ideal life cycle for a cryptographic algorithm starts
when cryptographers instantiate a concept in a white paper. For
example, AES is an instantiation of the concept of symmetric
encryption (there are many more symmetric encryption algorithms
out there). A construction can then be standardized: everybody
agrees to implement it a certain way to maximize interoperability.
Then support is created by implementing the standard in different
languages.
Real-World Cryptography
cancel anytime
sitemap
Up next...
2 Hash functions
Hash functions and their security properties
The widely adopted hash functions in use today
Other types of hashing that exist
© 2022 Manning Publications Co.
Real-World Cryptography