Crypto Notes
Crypto Notes
Crypto Notes
C ONTENTS
II Perfectly-secret encryption 6
II-A Describing encryption scheme in probability 09/05/2019 . . . . . . . . . . . . . . . . . . . . . . . . . . 6
II-B Formulating Perfect Secrecy 09/05/2019 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
II-B1 Perfect secrecy as conditional probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
II-B2 Perfect secrecy as perfect indistinguishability . . . . . . . . . . . . . . . . . . . . . . . . . . 7
II-C One-time pad 09/10/19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
II-C1 Security of OTP: Is OTP perfectly secret? 09/10/19 . . . . . . . . . . . . . . . . . . . . . . . 7
II-D Are OTP and Perfect Secrecy Useful? (Their Practical Limitations) 09/10/19 . . . . . . . . . . . . . . . 8
II-D1 One-time use of OTP key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
II-D2 Key Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
X TLS (§ 12.7/8) 27
X-A Overview: TLS-HS and TLS-RL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
X-B TLS-HS Design Iteration 1: DHKE under MitM Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . 27
X-C TLS-HS Design Iteration 2: DHKE + Digital Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . 27
X-D TLS-HS Design Iteration 3: PKI and CA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
X-E PKI in practice (Nov. 12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
X-F Certificate Transparency (CT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2
XI Summary 30
References 31
3
I. M ODERN CRYPTOGRAPHY: AN INFORMAL INTRODUCTION
Crypt-o-graphy, as defined in the dictionary, is “the art of writing or solving codes.” In Greek, crypt(o) means “secret”,
graphy means “writing”, logy (as in cryptology) means “study”. This dictionary definition only applies to classic cryptography.
Modern cryptography is different from classic cryptography in two senses: 1. classic cryptography as an art versus modern
cryptography as a science (in a formal treatment), 2. classic cryptography is used in military settings, while modern cryptography
is used in daily life.
The focus of this course is formal study of modern cryptography. To start with, let’s give an informal introduction to the
topic. In the following, we will set up the stage by introducing Private Key Encryption, and focus on introducing the formal
treatment of security in modern cryptography.
4
TABLE I: Security properties and cryptographic primitives
Scenarios Security goals Primitives Security assumption (or source of
security)
“Record-layer” communication on shared secret keys Message confidentiality Private key encryption (SKE) Info-theoretic hardness
Record-layer communication on shared secret keys Message integrity Message authentication code (MAC) Info-theoretic hardness
Record-layer communication on shared secret keys Message confidentiality and integrity Authenticated encryption (AE) Info-theoretic hardness
Sharing secret keys (hand-shaking) Confidentiality of secret keys DH key exchange (DHKE) Computational hardness
Sharing secret keys (hand-shaking) Confidentiality and integrity of secret TLS (MAC) Info-theoretic hardness
keys
Sharing public keys (hand-shaking) Integrity of public keys shared PKI (Digital signatures and CA) Computational hardness and trust to
CA
For data integrity, there are schemes of message authentication code MAC to do record-layer communication (in session).
We can use digital signatures to ensure the authenticity in key-exchange.
For the support of both confidentiality and authenticity, we can use authenticated encryption.
5
E. Precise assumption 09/03/19
Cryptographic constructions are often built on assumptions about computational hardness. For instance, cryptographic hashes
are based on the assumption that the best algorithm to find a hash collision is to brute force scan the hash-input space, which
is hard. We do not know if there is a better algorithm than brute force, but believe there is none. RSA pubic key encryption, or
its security, is based on the assumption that prime factorization is hard or there is no known P algorithm to solve the problem.
The assumptions in a cryptographic construction is a statement that is conjectured to be true but is not proven. In general, a
construction is secure because the only possible algorithms to break the security are assumed to be high computation complexity
(NP). And whether a NP algorithm is really hard to compute relies on the unproven assumption that P 6= N P .
Having the assumption explicitly specified is necessary, as it keeps users aware that the assumption may be proven true/false
in the future which may affect the security (as in the case of MD5). Also, one can compare different constructions (of the same
scheme) built on different assumptions – one should prefer the construction based on a “weaker” and well studied assumption.
k ← G EN(K)
c ← E NC(k, m)
m := D EC(k, c)
Correctness: ∀k ∈ K, m ∈ M, D EC(k, E NC(k, m)) ≡ m
6
2) Perfect secrecy as perfect indistinguishability: The idea of indistinguishability is to consider a message domain of two
values m0 , m1 and to formulate the security by Eve’s inability to distinguish the case that the message (a random variable)
takes one value (m0 ) from the case that it takes the other value (m1 ). By considering two message values m0 , m1 , it simplifies
the setting and security analysis. Informally, one can convey the idea of indistinguishability of perfect secrecy as following:
P RIV K EAV :
C A
m0 , m1 ←M
k ←G EN(K)
b ←{0, 1}
c ←E NC(k, mb )
b′ ←A(c)
The success of a game is defined to be b = b′ , namely
P RIV K = 1.
def
Adversarial advantage is A DV = P r[P RIV K = 1] − 21
Perfect indistinguishability is defined by requiring a zero adversarial advantage, namely A DV = 0.
c := E NC(k, m) = k ⊕ m (3)
m := D EC(k, m) = k ⊕ c
The preliminary of XOR operation is described in § B-A.
1) Security of OTP: Is OTP perfectly secret? 09/10/19:
Theorem 2.1 (Thm §2.9): OTP is perfectly secure. ∀c ∈ C, m ∈ M, P r[M = m|C = c] = P r[M = m]
Proof
P r[C = c|M = m] = P r[E NC (K, m) = c]
= P r[K ⊕ m = c]
1
= P r[K = c ⊕ m] =
2|K| X
P r[C = c] = P r[E NC (K, M ) = c] = P r[E NC (k, m′ ) = c]
∀m′ ∈M,∀k∈K
X X X
= P r[E NC (k, m′ ) = c] = P r[E NC (K, m′ ) = c]
∀m′ ∈M ∀k∈K ∀m′ ∈M
X
P r[C = c] = P r[C = c ∧ M = m′ ] (4)
∀m′ ∈M
X
= P r[C = c|M = m′ ] · P r[M = m′ ]
∀m′ ∈M
1 X 1
= P r[M = m′ ] =
2|K| 2|K|
∀m′ ∈M
7
P r[C=c|M=m]
Due to Bayes’ theorem, P r[M = m|C = c] = P r[C=c] · P r[M = m]
1
2|K|
∴ P r[M = m|C = c] = 1 P r[M = m] = P r[M = m] (5)
2|K|
(Takeaway intuition: P r[M = m|C = c] is about cracking D EC; given C =c, find a k s.t. M =m. And P r[C = c|M = m]
is about E NC; given M =m, find a k s.t. C =c. )
D. Are OTP and Perfect Secrecy Useful? (Their Practical Limitations) 09/10/19
Real-world application: Red phone: During the Cold War, the “red phone” links US president and USSR chairman using
OTP. Stage 1) Before the phone call, a trusted courier working for the US government flies to a preset location to meet a
courier working for the USSR government. During the meeting, they shared the “pad” or one-time key which is usually a long
string printed on papers in a briefcase. Stage 2) Then, during the phone call, the audio stream is encrypted using the shared
pad in the OTP scheme.
1) One-time use of OTP key: An OTP key can only be used for encrypting one message. In other words, OTP with fixed
key is not secure in ciphertext-only attacks with multiple messages.
More specifically,
m1 ⊕ k = c1 (6)
m2 ⊕ k = c2
∴ m1 ⊕ m2 = c1 ⊕ c2
Observing c1 and c2 , Eve can know about m1 ⊕ m2 . Further more, observing c1 , c2 and m1 (e.g., “hello” message in a
handshake), Eve can know about m2 .
2) Key Length:
Theorem 2.2 (Thm §2.10): In any perfectly secure encryption scheme, |K| ≥ |M|.
Proof Fix c, consider a message subspace M (c) where ∀m ∈ M(c), ∃k ∈ K s.t. D EC (c,k)=m. Therefore, |M(c)| ≤ |K|.
To prove the theorem by contradiction, assume |K| < |M|. Thus, |M(c)| < |M|. That is, ∃m′ ∈ M ∧ m′ 6∈ M(c).
P r[M = m′ ] 6= 0 = P r[M = m′ |C = c]
8
First, Eve can mount exhaustive-search attack: 1) In the offline phase, Eve brute-forces the key space K and for each key
encountered say k, she tests if ∀i, E NC(k, mi )? = ci . If so, she stops and claims to find the key. 2) In the online phase, Eve
uses the found key k to decrypt an observed ciphertext c.
In this exhaustive-search attack, Eve runs an algorithm of complexity O(|K|) with success rate 100%.
Second, Eve can make one guess by randomly picking one key, k, from the key space and test the same, that is,
∀i, E NC(k, mi )? = ci .
1
In this one-guess attack, Eve runs a constant-time algorithm with success rate |K| .
As long as we have a small key space |K| ≤ |M|, the scheme is subject to these two attacks. To design a practical and
secure encryption scheme, the idea is to make these two attacks “difficult” to succeed in practice. More specifically, we want
to make it hard to exhaust the key space in the first attack. We also want to make the success rate very small (but not equal
to zero ... ) in the second attack.
More generally, to bypass the limitation of perfect secrecy, we consider two relaxations that are needed: 1. A is
computationally bounded in that she can only run “efficient” algorithms (in the relaxed threat model), and 2. allow a small
adversarial advantage (as the relaxed security goal).
2) Formalizing Computational Security: Security parameter n is the key concept to formalize the notion of the two
relaxations. An efficient adversary can only run a PPT algorithm with respect to n as input length to the algorithm. Note
that PPT stands for probabilistic polynomial-time algorithms; probabilistic algorithms are use to generate keys and model A’s
strategy. Polynomial-time algorithms are those have polynomial-time complexity w.r.t. the input length.
It allows a small adversarial advantage (over the random guess in succeeding the game), formulated as a negligible function
w.r.t. security parameter, NEGL (n). A function NEGL(·) is negligible when ∀x, ∀p(·) where p() is a polynomial function,
NEGL(x) < 1/p(x). For example, NEGL(x) = 1/2x .
Fact: The two relaxations are necessary for the key space to be smaller than message space (|K| < |M|). Why (Exercise
3.12)
The threat model of ciphertext-only attack is formulated by running P RIV K EAV (n),
parameterized with security parameter n (for PPT A) and challenger’s choice of bit b.
Game (computational security) P RIV K EAV (n)
9
P RIV K EAV-MUL (n):
C A
{m0,1 , . . . , m0,t } ←Mt
{m1,1 , . . . , m1,t } ←Mt
k ←G EN(n)
b ←{0, 1}
c1 ←E NC (k, mb,1 )
...
ct ←E NC (k, mb,t )
b′ ←A({c1 , . . . , ct })
Theorem 3.1 (Thm §3.2): Any deterministic encryption scheme can not be indistinguishable (secure) under the multi-
encryption ciphertext-only attacks.
Proof Consider a concrete game P RIV K EAV-MUL : 1. A outputs two message vectors: m ~ 0 = {0l , 0l }, m
~ 1 = {0l , 1l }. 2. upon
′ ′
receiving ~cb = {c0 , c1 }, A’s strategy is that b = 0 when c0 = c1 ; otherwise b = 0. This concrete game always succeed
with probability 1 because deterministic encryption will encrypt 0l and 0l to the same ciphertext, yet 1l and 0l to different
ciphertext (otherwise it can’t decrypt). That is, P r[P RIV K EAV-MUL = 1] = 1.
Message length is assumed to be public information in private-encryption schemes. In practice, message length may be
disclosing sensitive information, like an employee salary being a 5-digit number or a 6-digit number or the number of records
in a patient database may disclose the patients have cough or cancer. In this case, developers are responsible to pad the
messages to the same length.
Here, we use indistinguishability to describe the security. However, the same security can be equivalently defined in a
more semantic way, that is, reflecting the intuition that disclosing ciphertext does not disclose any partial information about
the message. This is called semantic security. Here, semantic security to indistinguishability is like perfect secrecy to perfect
indistinguishability. It is proven semantic security is equivalent to indistinguishability in most encryption/authentication schemes
mentioned in the textbook. Indistinguishability is used as the working definition in this course.
2) CPA security (09/17/19): CPA attacks in the real world: In a shared terminal, Alice uses the computer with her secret
key to send encrypted messages over to the Internet. Alice left without logging herself out. The shared terminal is used by
Eve, where Eve can send messages to the encryption engine (algorithm), yet cannot directly observe Alice’s secret key.
During the Battle of Midway, Japanese military base encrypted message (”Midway”) and telegraphed the ciphertext (”AF”)
to their battleships. US navy intercepts the ciphertext telegram (”AF”) and had an initial guess that ”AF” corresponds to
”Midway”. To confirm the guess (and to convince white house to deploy aircraft carrier), US intelligence sends out a fake
message ”Water shortage on Midway”, intended to be visible to Japanese. By observing ”AF” is mentioned in the next round
of communication, US intelligence now confirms that ”AF” maps to ”Midway.” In this process, US, the eavesdropper, decided
(or influenced) what message got encrypted and can observe the ciphertext.
In both examples, the eavesdropper has the capability in influencing or deciding what message can be encrypted and in
observing the corresponding ciphertext. This ability is formalized in the concept of oracle. In an encryption oracle, A invoke
E NC () function under message m of her choice, yet A cannot know the private key k. Formally stated, A has an “oracle” access
to an encryption scheme iff 1) A can encrypt an arbitrary number of messages, m2 , m3 . . . , and observe their corresponding
ciphertexts. The access to the oracle is adaptive in that A can access it as many times as it wants. 2) A does not directly
observe the private key.
CPA security definition: CPA security (IND-CPA) is defined by P r[P RIV K CPA (n) = 1] − 12 < NEGL(n) where the game
is:
P RIV K CPA (n):
C A
def
m0 , m1 ←AE NC (M) = A ←{(m2 , c2 ), (m3 , c3 ), . . . } ←O(E NC )
k ←G EN(n)
b ←{0, 1}
c ←E NC(k, mb )
b′ ←AE NC (c)
Facts: CPA (for the single message) is equivalent to CPA for multiple encryption (Thm §3.24).
10
Fixed-length CPA-secure encryption can be extended easily to result in an arbitrary-length CPA-secure scheme. Given
a 1-bit CPA-secure encryption E NC, the arbitrary-length encryption, E NC’, is constructed by E NC′ (m1 km2 km3 . . . ) =
E NC(m1 )kE NC(m2 ) . . . . More efficient extension constructions are through the mode of operation (in §3.6).
11
blackbox through adaptively sending an arbitrary number of input message {m} and observing their outputs {O(m)}. The
distinguisher D produces a binary result about what is in the oracle is a generated function (PRF k (·)) or a random function
(f (·)).
Definition 3.3: A keyed function is PRF if ∀ PPT D PRF(·,·),PRF k (·) (1n ), P r[D PRF k (·) (1n ) = 1] − P r[D F(·) (1n ) = 1] <
NEGL(n)
Fact: One-time pad is not a PRF (details see Example §3.26): OTP PRF(k, x) = k⊕x generates function PRF k (·) given a key
k. Suppose an oracle O encapsulating either generated function PRF k (·) or randomly chosen function f (·). Given this oracle,
a distinguisher D(x1 , x2 , y1 = O(x1 ), y2 = O(x2 )) works by returning x1 ⊕ x2 == y1 ⊕ y2 ?1 : 0. Thus, D PRF k (·) (...) ≡ 1
n
with 100% probability, and Df (·) (...) = 1 at probability 1/2 . (The latter can be worked out by an example with n = 1 and
x1 , x2 are one-bit strings). Their difference is 1 − 21n which is not negligible.
Block cipher/Pseudorandom permutation: A permutation is a bijective function (one-to-one mapping). Its input domain is
the same to its output domain. If a PRF generates permutations, it is a pseudorandom permutation generator (or block cipher).
It is defined as PRP : {0, 1}lk , {0, 1}l → {0, 1}l (lk is key length). The security of PRP follows PRF.
Block cipher is a term used in practice for PRP with fixed key length.
Facts: PRF can be used to construct PRG and stream cipher; PRG(s) = F s (1)kF s (2) · · · F s (l). Vice versa, PRG can be
used to construct a PRF with small block length (polynomial number of rows); result of PRG (k) is interpreted as a table of
n rows, thus log(n) block length.
2nn
S1=F(*,*)
n
Key S2=PRF({0,1}n,*)
space
poly(n)
n2^n S3=O(Fk),
2n PRF(*,*)
2 O(F) poly(n)
Fk(*)
Distinguisher
n
Fig. 2: Intuition of PRF: There are two spaces: a space of 2n functions called S1 , and a space of 2n·2 called S2 . S1 is the
space of generated function by PRF(·) and S2 is the space of any function mapping n-bit input to n-bit output.A pseudorandom
function generator requires the distribution of generated function in S1 “looks like” the distribution of random function in S2 ,
through the lens of a PPT distinguisher who can only observes the subset of both S1 and S2 ).
2) OTP-PRF: a CPA-secure construction:
Construction (OTP-PRF): CPA-secure encryption with fixed-length message n:
n n
• G EN(1 ): choose uniform k ∈ {0, 1} and output it.
n n
• E NCk (m ∈ {0, 1} ): choose uniform r ∈ {0, 1} and output the ciphertext
def
c :=hr, c′ = F k (r) ⊕ mi (7)
• D ECk (c = hr, si): output
m :=F k (r) ⊕ c′ (8)
12
and cannot be known in advance. So far, we just talked about fixed-length encryption schemes, like OTP+PRG and OTP+PRF.
They cause problems in the scenario with arbitrary-length long messages.
For instance, consider OTP-PRG (c :=PRG(k) ⊕ m) where PRG is defined as a mapping from 1n to 1l where l is fixed.
It requires l or message length to be fixed before E NC is invoked, which is impossible in the streaming scenarios. Supporting
streamming message is the problem tackled by stream cipher mode of operations (§ IV-A).
For another instance, consider OTP-PRF (c ←PRF k (r) ⊕ mkr) where the ciphertext c has double the length with plaintext
m. For a long message, it is not a good news (for a message of 2 GB, this means the ciphertext of 4 GB). Supporting shorter
ciphertext is the problem tackled by block cipher mode of operations (§ IV-B).
✥
✞✦✜✜✧☞
✗✘
✞✟✠✡☛✡✙✚ ✛✜✢☛✣✤☞
✁✂✄☎✆ ✩✪ ✩✫ ✩✬ ★★★ ✩✭
Fact: In OTP +prg, PRG handles key extension (into the pad) and the mode of operation is about extending fixed-length
message to abitrary length.
2) Synchronized mode: What it is?: For one message m of message blocks m1 m2 . . . mi , it produces a stream of ciphertext
blocks c1 c2 . . . ci :
13
Use case and why it’s called Unsynchronized mode: Alice/Bob encrypting/decrypting mi /ci can just do so by knowning
k, IV i , without any dependency with j 6= i (e.g., no need to know IV j or cj ). In other words, there is no state need to be
maintained across blocks. It is called stateless mode of operation.
B. Security definition
First, let’s look at an example construction of MAC that, intuitively, is not secure. After that, we will describe how to
formulate the security of MAC scheme.
In this example construction, we attempt to use the OTP-PRG encryption for providing authenticity. That is, given
?
c :=PRG(k) ⊕ m, c is (ab)used as t. In V RFYk (m, t), it runs PRG(k) ⊕ t =m. Clearly, this scheme is correct. But intuitively,
it isn’t secure: Flipping a bit in m and c/t results in a valid message,tag pair that passes V RFY. Also, the message-forging A
can work out PRG (k) by t ⊕ m, and then for any forged message m’, forge t′ = (t ⊕ m) ⊕ m′ . This pair of m′ , t′ will pass
V RFY ().
Side-note: In this counter-example, it also says authenticity is not confidentiality. A EAV-secure encryption construction
may not be a good candidate for MAC.
MAC Security: Given Π, A, n, the adaptive chosen-message attack game M AC F ORGE ACMA is
14
ACMA
M AC F ORGE A,Π (n):
C A
n
k ←G EN(1 )
m, t ←AQ(MAC k (·)) (1n )
?
V RFYk (m, t) =1
Note that the oracle in this game O(MAC k ) is the following: Adversary A sends chosen
messages {mi } to the oracle service Q(MACk ) which hides the key k. Given {mi },
Q(MAC k (·)) returns tags {ti }. Given {mi , ti }, A runs a PPT algorithm to produce m and to
forge a tag t.
def
The success of the game is defined as M AC F ORGE ACMA = 1 = V RFYk (m, t) = 1 ∧ m 6∈ Q.
A MAC scheme is existentially unforgeable under the ACMA game M AC F ORGE ACMA when
ACMA
P r[M AC F ORGE Π,A (n) = 1] ≤ NEGL(n) (9)
Fact1: message authentication versus user authentication: message authentication ensures the message Bob receives is the
same with what Alice sends. user authentication means Bob is convinced that the message received is indeed from Alice “the
person”.
Fact2: MAC versus error-correction code (ECC): 1) MAC detects while ECC both detects and recover. 2) MAC handles
malicious message change while ECC handles random change of a small portion of the message. (Exercise XXX)
Fact3: timing attack on V RFY implementation. through side-channel timing info., one can gain advantage in guessing
“correct” tag.
Fact4: MAC is not secure under replay attack.
C. Constructions
1) Fixed-length MAC by PRF:
MAC : t :=PRF k (m)
?
V RFY : t =PRF k (m)
Fact1: Canonical implementation of V RFY: When MAC is deterministic, one can reuse MAC for V RFY.
Security proof
To prove the MAC construction is ACMA-unforgeable, the key technique is to construct a simulation where the distinguisher
D’s view in PRF is simulated by C interacting A in M AC F ORGE ACMA . The simulation is a type of reduction techniques used
to proof security. Figure 4 illustrate the construction.
15
2) Variable-length MAC by CBC-MAC (§ 4.11): Consider variable-length message m = m1 , . . . , ml where each mi is a
block of length n. The CBC-MAC construction is:
(10)
MAC : t0 :=0n
ti :=PRF k (ti−1 ⊕ mi )
t :=tl
?
V RFY : kmk = l ∧ t =MACk (m)
Fact1: CBC-MAC versus CBC-mode encryption: The former uses zero IV (or t0 ) while the latter uses random IV; the
former outputs only tl while the latter outputs all PRF results.
Fact2: arbitrary-length MAC is by using m′ = l, m1 , m2 , . . . ml as the input of fixed-length MAC.
3) Constructions: Construction: enc-then-auth. Given two keys k e and k m , the encryption algorithm is
?
E NCke (m)kMACkm (c). Decryption algorithm is V RFYkm (c, t) =1?D ECke (c) : ⊥.
Fact1: Conceptually, there are other two alternatives: auth-then-enc, and enc-and-auth. It can be easily seen that enc-and-auth
is not secure as tag is revealed which leaks confidentiality.
Fact2: Two keys (k m and k e ) must be independent! Counterexample: E NC is PRF k (mkr) and MAC is PRF −1 k (c).
Fact3: Using authenticated encryption as it is without any state is vulnerable to replay, reorder, reflection attacks.
Maintaining a message counter is the solution.
Fig. 5: Mallory attacking on message ordering by reordering and replay messages between Alice and Bob.
4) Beyond Data Integrity: Replay and reorder attacks: Consider Alice sends a sequence of messages to Bob, as in Figure 5.
Bob wants the messages are received in the correct “order” as sent by Alice.
Even the messages are AE-encrypted, Mallory A can forge the order among messages and pass the verification. Given
messages m1 , m2 , a reorder attacker forwards the messages in different order, say m2 , m1 . In applications of video streaming,
reordering attacks may lead to Bob playing video frames out of order.
Given message m1 , a replay attacker forwards multiple copies of the message m1 , m1 to Bob. In applications such as web
shopping, replaying messages may lead to Bob (amazon.com) charges Alice’s (amazon user) account twice.
AE does not defend replay or reorder attacks. Instead, maintaining a stateful monotonic counter synchronously on Alice and
Bob will fix the problem. Alice will send out E NC(m1 , mcAlice + +); to Bob who runs D EC(c1 , mcBob + +);.
16
VI. H ASH F UNCTIONS (10/08/2019)
A. Scheme
Definition 6.1 (Fixed-length hash h): A fixed-length hash h is a compression function of its input space (called preimage
space) larger than its output space (called digest space).
Definition 6.2 (Variable-length hash H): A variable-length hash H is a compression function: H : {0, 1}∗ → {0, 1}l.
Formally, a variable-length hash function is a scheme of two algorithms, Π (G EN, H):
s ← G EN(1n )
y := H s (x)
Fact1: s is different from encryption key k in: 1) s is not private, 2) s is not chosen uniformly (and generated by G EN ()):
There are “invalid” hash keys where H s (·) is not legitimate.
B. Security
1) Collision Resistance: Collision resistance: collision exists (as long as l′ > l), but it is difficult to find one. Formally,
collision resistance is defined by H ASH C OLL (n):
Security game H ASH C OLL (n) is
C A
n
s ←G EN(1 )
m0 , m1 ←AO(H) (1n )
?
H(m0 ) =H(m1 )
def
H ASH C OLL(n) = 1 = H(m0 ) = H(m1 ) ∧ m0 6= m1
H is a collision-resistant hash function (CR-H ASH) iff. the following holds:
2) Weaker Security: There are weaker security notions that collision resistance.
Second preimage collision resistance: informally, given the first preimage x, it is difficult to find the second preimage x′ ,
s.t., H(x) = H(x′ ).
Onewayness: informally, given the digest y, it is difficult to find a preimage x, s.t., H(x) = y.
C. Generic Attacks
1) Brute-force Attack: Instantiating the adversary in H ASH C OLL gives us collision-finding attacks.
One attack strategy is to iterate through the space of digests 1l (Recall H : {0, 1}L → {0, 1}l). If we try N = 2l + 1 distinct
preimages, 100% chances are that there is at least one collision. This is due to pigeonhole principle (If we put N + 1 pigeons
into N holes, at least one hole will end up with at least two pigeons.)
√ if we want 50% chances to find a collision, how many samples of preimages does an attacker need to try? The answer
But
is N . It leads to birthday attacks. √ l
2) Birthday Attack: In a Birthday attack, the adversary tries just N = 2 / 2 + 1 hash preimages, high chances (50%) are
that she will find a collision among these preimages.
We can play a game in classroom: The teacher wants to find “Birthday collision” among students, that is, two students
having the same day of their Birthdays √ (just the same day in a month). If the teacher samples 32 students, he will find one
for certainty. But if he sample just 32 ≈ 6 students, high chances are he will find students having birthday collisions.
D. Hash-based Primitives
1) MAC domain-extension: Hash-and-MAC: A variable-length MAC, (G EN’,MAC’,V RFY’) is constructed by a fixed-length
MAC, (MAC,V RFY) and a variable-length hash function, (G EN,H). The construction is called Hash-and-MAC:
(12)
′ n n n
G EN (1 ) : k ←{0, 1} , s ←G EN(1 )
t :=MAC′ (m) : MACk (H s (m))
V RFY′ (t, m) : V RFY(t, H s (m))
17
Fact1: In Hash-and-MAC, the resultant MAC’ is a secure variable-length MAC, when H is collision resistant and MAC’
is an MAC.
Fact2: In hash-and-MAC, the “hash” is a var-length hash for domain extension, and the “MAC” is a fixed-length MAC.
2) Hash domain-extension (from h to H): Merkle-Damgard and Merkle trees: Merkle-Damgard construction: arbitrary-
length hash (G EN,H) has arbitrary input length bounded by L < 2n . Fixed-length hash (G EN,h) has input length 2n (w.l.o.g).
Both have output length n. Merkle-Damgard construction constructs (G EN,H) by (G EN,H) as below:
• input x :=x1 , x2 . . . , xB , where each xi is of block length n, and B = L/n.
•
H(x) : y0 :=IV
yi :=hs (yi−1 kxi )
y :=yB
Fact1: CBC vs Merkle-Damgard: in CBC, an iteration is using PRF with ⊕, while in Merkle-Damgard, an interaction is h
with concatenation.
✁✂✄☎
✙✚✛✜✢✣✤✥✦✧★
✆✝ ✞✟ ✠✡
☛☞ ✌ ✫ ✬ ✩✭ ✪
✏ ✑ ✒✓ ✍✎ ✮✯ ✴✵✶
✔✕✖ ✗ ✲✳
✘ ✷
✰✱ ✸
18
E. Hash Applications
Fingerprinting or hash pointer: using H(·) to digest message m, where m can be virus ID (for virus detection), cloud file
(for de-duplicated cloud storage), P2P file (for P2P file lookup)
Merkle tree: MT (m1 , m2 ..., mt ) as domain-extension of H for hashing multiple messages. The application is to digest
multiple files while allowing client to access individual files in cloud storage.
Using hash for fingerprinting and Merkle tree requires the collision resistance of hash functions.
key derivation and password hashing: key derivation is a mapping of non-uniform, high min-entropy distribution to a
uniform distribution. One application is to derive (uniform) key, required by private-key encryption, from non-uniform strings,
such as passwords, bio-metric data, etc.
Using hash for key derivation requires the random-oracle model of hash functions.
19
VII. K EY E XCHANGE (§ 10)
A problem left pending in private-key schemes is how Alice and Bob can establish the private key initially? The first
baseline is that Alice directly sends the generated secret key to Bob. However, this may disclose the secret key to Eve (over
the insecure channel). The second baseline is that Alice distributes the secret key to Bob over an encrypted channel; say with
the key encrypted (but what is the key used for encrypting the key?).
Secure key distribution over an insecure channel is handled by key-exchange protocols. Conceptually, key distribution over
a secure channel (e.g., meet in person) is trivial and has limited applications (only in military settings).
We will talk about two constructions of key exchange; a two-party protocol, DHKE (§ VII-B) and a three-party protocol,
KDC and Needham-Schroeder (§ VII-C). The latter handles key exchange among multiple parties in an open system with
transient interactions.
C A
def
C A , C B joinly run protocol Π, producing transcript T RANS and k = k A = kB
(
k ′ = k , if b = 0
Random bit b ←{0, 1}, Another “key”
k ′ ←1n , if b = 1
b′ ←AP P T (T RANS, k ′ )
EAV def
Success of game KEA,Π = b = b′ .
EAV 1
Security of a KE protocol is defined as P r[KEA,Π ]− 2 < NEGL(n)
Example: The baseline key-exchange by sending out secret key in the clear is unsecured. In this baseline construction,
transcript T RANSis key k. Adversary can then easily have non neglibability adversarial advantage that breaks the KE security
definition.
20
2) Group-theoretic Problems and Hardness: Discrete logarithm: Discrete log is defined by ∀h ∈ Z∗ , there is a unique
x ∈ Z∗ q , s.t. h = g x . x is the discrete log of h.
A DL problem, given Z∗ q with generator g, is to compute x = logq h for a uniform element h ∈ Z∗ .
Fact: A DL problem is a logarithm operation with elements defined in the domain of groups.
DH (Diffie-Hellman) problems: Computational DH, CDH(h1 , h2 , h3 ): Given h1 = gx and h2 = g y , it is hard to compute
h3 = gxy . Given group exponentiation is easy, the hardness of CDHrequires the hardness of DL (if DL is easy, one can obtain
x from g x and compute (g y )x ).
Decisional DH, DDH: Given h3 = CDH(h1 , h2 ), it is hard to decide if it is different from a uniform group element. DDHis
used to prove the security of DH protocol.
3) DHKE: Execution between Alice and Bob:
21
B. Schemes
Scheme: similar to P RIV KE scheme, except that pk, sk ←G EN(1n ).
C. Security Definition
PKE schemes is different from those of PrivKE in that its EAVgame is defined the same to CPAgame.
Security definition(IND-EAV):
D. Domain extension
The ciphertext of multiple message blocks is the concatenation of ciphertext blocks, each produced by encrypting one
message block.
E NC′pk (m1 km2 k...ml ) = E NCpk (m1 )kE NC pk (m2 )k...E NCpk (ml )
22
E. Construction: El Gamal
(15)
n
pk, sk ←G EN(1 ) : G, q, g ←G(n)
def
x ←Zq ( = {1, g1 , g2 , ...g q−1 })
sk = x, G, q, g
def
pk = h( = gx ), G, q, g
c ←E NCpk (m) : pk = h, G, q, g
y ←Zq
def def
c = gy ( = c1 ), hy · m( = c2 )
m′ :=D ECsk (c) : m′ = c2 /c1 x
def
Note that G and (g,q) are two groups. The second group Zq = {1, g, g 2 , ...g q−1 }. The first group G is a subgroup of Zq .
Correctness: m′ = c2 /c1 x = hy · m/(gy )x = (g x )y · m/(gy )x = m.
Security (informal and intuitive): transcript pk = h, G, q, g and c1 = g y , c2 = hy · m is disclosed to Eve. Informally, discrete
log problem prevents Eve from knowing x, y from h = g x , c1 = g y . (Otherwise, knowing x, y, Eve can infer g x ).
Example 11.17: Let q =83 and p = 2q+1 = 167. Let Zq = {1, 2, 3, 4, ...82}. Let G denote the group {h2 mod p|∀h ∈ Zq };
this group is called quadratic residues module p. G is a subgroup of Zp .
Take g = 22 = 4 mod 167 to be the generator. Say the secret key 37 ∈ Z83 . The public key is pk = p, q, g, h =
167, 83, 4, 437 mod 167 = 167, 83, 4, 762
We use p to represent G and g, q to represent Zq .
Say a sender encrypts message m = 65 ∈ G (note 65 = 302 mod 167). If y = 71, ciphertext is 471 mod 167, 7671 · 65
mod 167 = 132, 44.
Compare and contrast: Compare the execution of digital signature in Equation 16 with that of public-key encryption in
Equation ??. We can see that G EN in digital signature runs on the sender while G EN in public-key encryption runs on receiver.
In digital signature, it is like the sender pushes the message to the receiver, while in public-key encryption, it is more like the
receiver pulls the message from the sender.
2 One can write an efficient algorithm to do group exponentiation and calculate 4 ∗ 37 mod 167 = 76.
23
B. Benefits and Distinction of Digital Signatures
1. Easy key distribution and management: Distribute public key instead of private key.
In addition, the number of secret keys a sender maintains in digital signatures is one. Whereas, the number of secret keys
in MAC is N , where N is the number of receivers. The saving in the number of secret keys is significant, for applications
involving a large number of receivers (think about distributing Windows OS patches to millions of Windows users as an
example).
2. Public verifiability: Note that in digital signatures, receiver does not need any secret key to verify the integrity of
message. Using a public key suffices to verify the message authenticity. This property is called public verifiability. It implies
transferability, that is, one receiver who verifies can simply passes public information (i.e., {m, δ}) to the next “receiver” to
verify. There is no need of setting up secret keys in transferring verifiable information, which is unlike MAC.
3. Non-repudiation: The digital signature of message m can be used as an evidence that the sender has signed message m
in the past. In other words, with digital signature, the sender cannot deny the fact that he has signed the message. Because the
sender is the only one who knows the secret/signing key, the digital signature presents itself as a proof of the sender’s signing
action in the past.
By contrast, a MAC tag does not provide non-repudiation and cannot be used as an evidence. A counterexample is the
following: Consider the receiver uses a MAC tag (i.e., t =MAC (m))) as an evidence that the sender has authenticated
message m before. Such evidence is not trustworthy (and a judge cannot take it), because a malicious receiver, knowing the
secret/authentication key, can simply produce t on a message that the sender has not authenticated before.
C. Security Definition
Game S IG -F ORGE A,Π (n):
C A
def
m, δ ←AO(SIGN sk (·)) (pk) = A(pk, Q∗)
b :=V RFYpk (m, δ)
*: Q is defined as the set of message-signature pairs {m′ , δ ′ } where A sends each m′ to the signing oracle
and receives signature δ ′ . Q covers the case that adversary observes the transcript between sender and
receiver (that is, m,δas in the “execution of digital signature”).
def
Successful game: S IG -F ORGE (n) = 1 = b = 1 ∧ m ∈ / Q.
Security definition: P r[S IG -F ORGE (n) = 1] ≤ NEGL(n).
If the hash is collision resistant and fixed-length S IGis unforgeable, the variable-length S IGconstructed by hash-and-sign is
unforgeable.
Counterexample: If the hash is not collision resistant, construct an attack to break the digital signature (or the security
definition in S IG -F ORGE): Adversary observing {m,δ} will find hash collision with m easily. Name the colliding message by
m′ , such that H s (m) = H s (m′ ). Adversary can present {m′ , δ} as the forged message to the receiver. Verification will pass
because V RFY′ (m′ , δ) = V RFY (H s (m′ ), δ) = V RFY(H s (m), δ) = 1.
24
1) Identification scheme: Definition: Protocol execution between Prover (of her secret key sk) and Verifier (of Prover’s
public key pk.
The security of identification scheme is, informally, that given the transcript (I, r, s), the adversary without knowing secret
key sk cannot generate s and use it to fool verifier into accepting.
2) Fiat-Shamir transform:
(I,st) P1(sk)
I
r ✁ pk
r r = H(I, m)
S V(pk, r, S) = I
S P2(sk, st, r)
H(I, m) == r
Vrfy(pk,m,s)
25
Prover(sk) Verifier(pk) (18)
k
k ←Zq ; I = g
I
←
r ←Zq
r
→
s = [rx + k] mod q
s
→
?
Check gs · y −r =I
Authentication
protocol
Auth. Signature
constructed constructed by
by signatures identification
Digital
Signature
Fig. 8: Two perspectives: 1) Authentication protocol constructed by digital signature as primitive, and 2) digital signature
constructed by identification protocols (as in Fiat-Shamir transform)
1) Case: Two-factor authentication: In this game, the authentication server sends a passcode to a user’s registered phone,
as a challenge to the user. The user responds by sending the passcode to the server, as a proof that she has access to the
registered phone.
In general, authentication server sends a challenge and user sends a response. The server verifies the user response (as a
proof) against the challenge.
The response needs to be 1) something that only a legal user can generate and 2) also has to do with the challenge.
2) Case: Public-key based authentication: Public-key based challenge-response protocols are described in the identification
protocol (§ IX-E1).
Baseline design 1: To construct it, one baseline is using digital signature. Consider authentication server Bob and user Alice.
In the first round, the challenge is a random number r picked by Bob. In the second round, the response is a message signed
by Alice’s secret key: S IGN sk (“Alice′′ , r). The server Bob verifies by verifying the signature.
However, this design is not secure, if the man-in-the-middle attacker changes r and Alice, the legitimate user, end up with
signing r′ and get declined by the server.
Baseline design 2: Another baseline construction is using public key encryption. In the first round (for challenge), the
challenge is Bob sends a random number r encrypted by Alice’s public key, that is, E NC pk (r). In the second round, the
response is the plaintext of r sent by Alice. Because only Alice can decrypt the ciphertext challenge. The server simply checks
the equality.
This baseline is not secure, as the adversary can simply changes the plaintext response s = r to any other value, failing
legal user Alice’s authentication.
The secure construction: It uses both public-key encryption and digital signature.
26
Prover(sk) Verifier(pk) (19)
r ←E NCpkA (S IGN skB (“A”,R))
r
←
s ←E NC pkB (S IGN skA (“A”,“B”,R))
s
→
X. TLS (§ 12.7/8)
A. Overview: TLS-HS and TLS-RL
Target scenario: A web browser wants to communicate securely with a web server (identified by its IP address). Using
HTTPS, the network traffic is encrypted by private-key cryptography schemes. TLS or transportation layer security is the
protocol underneath HTTPS: It consists of two phases: an initial hand-shake process (TLS-HS) that establishes shared secret
keys between browser and web server, and a record-layer process (TLS-RL) that uses shared keys to authenticated-encrypt
the messages issued by the applications/users. There are four secret shared keys, each two for communication in a direction.
Different keys are also used for message authentication and encryption, separately. For simplicity/educational purpose, we
consider TLS-HS establishes one shared key between browser and web server.
TLS-HS is secure under M IT M attack, as the adversary cannot forge the signature using A or B’s secret key. In the above
figure, A cannot forge S IGN skA (“g x , pkA ”) without secret key skA .
27
D. TLS-HS Design Iteration 3: PKI and CA
In TLS-HS, the underlying assumption is that A and B (or web browser and server) are identified by their public key. This
causes problems in practice: Consider a web browser connected to a web server for the first time. This web browser can only
receive the public key of the server from the server itself (assuming no other online trusted party). When the web server is
malicious (attempting to impersonate another domain), the web server can simply generate a public key and claims it is bound
to an impersonated domain. In other words, how can a web client establish trust about the server’s identity? Or how can a
client trust the binding between a public key and a web server.
The solution is Public Key Infrastructure (or PKI). In PKI, trusted third party, called certificate authority (CA), exists to issue
certificates on the binding between the domain name of a web server and its pubic key. Formally, a certificate, C ERTCA → S,
is a signed statement that binds the identity of server S to its public key pk S . The certificate is signed by CA’s private key
and verified by its public key. CA, the certificate authority, is fully trusted to the extent that whatever statement it issues is
trusted. A certificate is below:
def
C ERTCA→S = S IGN skCA (binding(“S identity”, “S public-key” pk S )
Fact: A certificate is like a ID card, where the ID card issued by the government (CA) certifies the binding between a
subject’s appearance (server S’s public key) and his identity (S’s identity).
Summary: Overall, bootstrapping trust for secure communications is realized by running three protocols among three parties:
certificate authority CA, server S, and client C. The whole process runs by three protocols at three stages: 1) At the very
beginning, it runs the general PKI protocol as three-party protocol (among S,CA,C) to securely set up environments (distribute
certificates and public keys) for the next stage, 2) At the second stage, it runs the TLS-HS protocol as two party protocol
between S and C to establish the trust and shared keys between them, 3) At the third stage, it runs the TLS-RL (record layer)
protocol between S and C to securely communicate between them using the shared secret keys. In particular, the record-layer
protocol runs private-key authenticated encryption, with sequence numbers and the four private keys (generated in TLS-HS
and used pairwise for encryption and authentication).
Multi-level CA
Root CA R
✁ ✄ ✂
SignSKR( PKX belongs to Visa s office X
| X is a CA )
Regional CA Y Regional CA X
✁ ☎
SignSKX( PKA belongs to
name A | A is non-CA )
Fig. 9: Multi-level CA
Multi-level CA: Practical CAs are hierarchical: there is a root-level CA and multiple regional CAs. Consider Visa as an
example, illustrated as in Figure 9: 1) There are regional offices in Visa. The Visa office in CNY authenticates Niagara Bank.
This is done by issuing certificate like [pk NiagaraBank belongs to name ‘Niagara Bank’]; The certificate is signed by regional
CA’s secret key sk Visa CNY . 2) The job of the root CA is to certificate the authority of regional CAs. This is done by issuing
certificate like [pkVisa CNY belongs to regional CA named by ‘Visa CNY’]; The certificate is signed by root CA’s secret key
sk Visa root .
There are two kinds of “authorities”, CAs and non-CAs (like the bank). A classic attack in multi-level CA is to (mis)use
a non-CA’s secret key to certify another fake non-CA. For instance, in Microsoft’s IE under PKI, a misusing domain owner
signs a certificate of a normal domain name with a fake public key. The security fix for this is to distinguish whether the
public key in a certificate is CA or non-CA.
Organizational PKI: The concept of PKI, relying on authorities to certify users, goes much broader than web applications.
1) VPN is a PKI in the sense that the IT department plays the role of CA and users off campus can use their public keys
to get authenticated. 2) Credit card organization, like Visa, is a PKI that establishes trust between different banks and their
customers. Visa is the CA and banks are the users (so that buyer A in Bank 1 can do business with seller B with account in
Bank 2).
There is a dream of universal PKI that a single CA certifies everything for applications across the board. However, in
practice, the most successful models are organizational, domain-specific PKIs. Why?
Trust and authorities are essentially context-specific. You trust campus IT to the degree of revealing your SUID. But you
don’t trust IT when it comes to revealing your credit card number. You trust amazon.com for credit card. It is hard to find a
universal CA that everybody can place unlimited trust to.
Names: PKI certifies the binding between a public key and a name. But what about the binding between a name and an
actual physical entity (1)? There are other problems regarding names: 2) alias problem that one person has multiple (nick)
28
names, 3) common names in that different people share the same name. In a small town, problem 1) is solved by everybody
knows everybody else. And the name-person binding is solved by sight. Problem 2) and 3) are solved by gossiping. Villagers
can propagate names “Big John” and “Little John” to distinguish two Johns. In a large scale setting, we rely on authorities
to assign name. Like US government assigns SSN to identify different citizen. Email service provider assigns unique email
account for a user. Names and the use of names is context specific (at home he is called John, in workplace, he is called Mr.
Smith). This is another reason context-specific PKI is preferred over universal PKI.
PKI and authorization: PKI certifies the binding between names and public keys. ACL or access-control list stores the
binding between names and permissions. Indirect authorization couples PKI with ACL to solve the authorization based on
public keys. However, the alias problem in names makes it ineffective to join the PKI and ACL; what if the name in PKI is
“John” and name used in ACL is “Mr. Smith”?
Direct authorization directly binds public key with permissions. Without name, the alias problem goes away. However,
without human-readable names, it makes it difficult to audit.
Credential system is a direct authorization method where the binding between public key and permissions is signed. This
sort of certificate makes it easy to transfer permissions. For instance, a file user Alice who has read permission to file X can
transfer her “authority” (file read permission) to another user, Bob, by issuing the following certificate: [pkB is authorized to
read file X]; this certificate is signed with Alice’s secret key skA . The credential system verifies it by 1) verifying the signature
against pkA , 2) checking if user pkA (namely Alice) has read permission to file X.
Low-cost CA
(Let s Encrypt or Keybase)
Authentication
User
server(CA)
Challenge text
29
Log server
to prove that either ST H is a prefix of ST H ′ or ST H ′ is a prefix of ST H. Only when this consistency proof is verified,
there is no fork.
How can CT be attacked: 1. “there is window between when browser uses a cert and monitors check log.” 2. “there may
be no one monitoring a given name”. 3. “lack of gossip in current CT design/implementations”. 4. “privacy/tracking: browsers
asking for proofs from log server”.
XI. S UMMARY
TABLE II: Components in applied cryptography
Scheme/Execution Private-key enc. MAC Public-key enc. Digital sig. Protocols
Security definition EAV,EAV-MUL,KPA,CPA,CCA ACMA CPA ACMA
Construction 3.17, 3.30 PRF El Gamal Schnorr DHKE
Assumption DL DL DL
30
R EFERENCES
[1] J. Katz and Y. Lindell, Introduction to Modern Cryptography . Chapman and Hall/CRC Press, 2007.
[2] R. B. Lee, Security Basics for Computer Architects, ser. Synthesis Lectures on Computer Architecture. Morgan & Claypool Publishers, 2013. [Online].
Available: https://doi.org/10.2200/S00512ED1V01Y201305CAC025
31
A PPENDIX A
R EVIEW: D ISCRETE PROBABILITY (§ A)
A. Introduction and Random Variables
Introductory example: Weather forecast: Tomorrow’s weather is a random variable that takes different values in its domain
(e.g., “rainy”, “sunny”, “cloudy”, etc. This random variable is a distribution today – for each value, there is a probability that
the variable takes the value. But on the day after tomorrow, the variable becomes fixed and its value is determined – only one
value in the domain is bound with 100% chance.
In abstract, we talk about (discrete) random variable R. The random variable R has a domain R which is a finite set of
values r. The variable can take any value in the domain; for each “event” that random variable R takes a value r, denoted as
R ←r, it occurs at a certain probability, denoted as P r[R ←r]. In other words, a random variable is essentially a probability
distribution D defined over the choice of values r ∈ R. A special case is 0/1-random variable whose finite set is simple {0, 1}.
Bayes theorem: Bayes theorem describes the probability of an event E1 , based on prior knowledge of conditions E2 that
might be related to the event. That is, P r[E1 |E2 ] = P r[E 2 |E1 ]
P r[E2 ] ·P r[E1 ]. Here P r[E1 |E2 ] is a conditional probability, namely the
likelihood of event E1 occurring given that another event E2 is true (or occurred). P r[E2 |E1 ] is also a conditional probability,
namely the likelihood of event E2 occurring given that another event E2 is true (or occurred). P r[E1 ] is the probability of
observing event E1 .
B. Statistical Properties
There are several statistical properties describing the distribution of a random variable R. Those include expecta-
tion E XP P [R], variance VAR [R], and entropy E NTROPY [R]. Formally, the expectation of random variable R is
E XP[R] = r P r[R → r] · r. When E XP [R] is known, its bound of the random variable is given by Markov inequality:
P r[r ≤ b] ≤ E XP[R]/b for a given bound b. Note P that here P r[r ≤ b] is short for P r[R → r ∧ r ≤ b].
The variance of random variable R is VAR [R] = r∈R (r − E XP[R])2 , which can be further derived as VAR [R] = VAR [R] =
E XP[R2 ] − E XP[R]2 . Consider, for example, a 0/1 random variable R01 . We have VAR [R01 ] ≤ 1/4 (proof see book). When
VAR [R] is known, we can use Chebyshev bound to describe its probability bound: P r[|R − E[R]| ≥ δ] ≤ VARδ2[R] .
PThe entropy of random variable measures how much uncertain the variable is. Given R, its entropy is E NTROPY [R] =
r∈R −P r[R = r] · log P r[R = r].
Consider, for example, how to generate a random number? A random number is generated by following a uniform distribution.
A uniform distribution takes the same probability for each value in its domain, having the expectation being unbiased (being
the average) and having a high entropy value. Think about toss a biased coin to generate a random number. The random
number is with high entropy (as it is very uncertain which value it will take), but is not uniformly distributed because the
coin head is heavier than tail. A solution to this biased tossing is to toss the coin two times, the random variable takes value
0 when the result is head-tail, it takes value 1 when the result is tail-head. Otherwise, it continues.
def
C OLL(q, N ) = P r[exist a collision in q-balls-in-N -bins]
q2
C OLL(q, N ) ≤
2N
q2
≥
4N
Consider, for example, the real-world
√ birthday problem that polling about 23 people suffices to find two having the same
birthday. That is, when N = 365, q = 365 ≈ 23, C OLL(q, N ) ≤ 12 .
A PPENDIX B
BASIC LOGIC OPERATIONS
A. XOR
The truth table of XOR is in Table III.
XOR has a property that m ⊕ m can be canceled out in an equation.
32
TABLE III: XOR truth table
0 ⊕ 0 0
0 ⊕ 1 1
1 ⊕ 0 1
1 ⊕ 1 0
x ⊕ x 0
0 ⊕ x x
33