1 Crypto
1 Crypto
Cryptography (historically)
“…the art of writing or solving codes…”
Private-key cryptography
– aka secret-key / shared-key / symmetric-key
cryptography
Private-key encryption
key key
ciphertext
c
k k
m
c ¬ Enck(m) message/plaintext m := Deck(c)
decryption
encryption
Private-key encryption
• A private-key encryption scheme is defined by a
message space M and algorithms (Gen, Enc, Dec):
– Gen (key-generation algorithm): outputs kÎK
– Enc (encryption algorithm): takes key k and message
mÎM as input; outputs ciphertext c
c ¬ Enck(m)
– Dec (decryption algorithm): takes key k and
ciphertext c as input; outputs m or “error”
m := Deck(c)
For all mÎM and k output by Gen,
Deck(Enck(m)) = m
Kerckhoffs’s principle
• The encryption scheme is not secret
– The attacker knows the encryption scheme
– The only secret is the key
– The key must be chosen at random; kept secret
• k Î K = {0, …, 25}
• To encrypt using key k, shift every letter of the
plaintext by k positions (with wraparound)
• Decryption just does the reverse
helloworldz
ccccccccccc
The shift cipher
• Consider encrypting English text
• Associate ‘a’ with 0; ‘b’ with 1; …; ‘z’ with 25
• k Î K = {0, …, 25}
• To encrypt using key k, shift every letter of the
plaintext by k positions (with wraparound)
• Decryption just does the reverse
helloworldz
ccccccccccc
jgnnqyqtnfb
Modular arithmetic
• x = y mod N if and only if N divides x-y
• [x mod N] = the remainder when x is divided by N
– I.e., the unique value yÎ{0, …, N-1} such that
x = y mod N
• 25 = 35 mod 10
• 25 ≠ [35 mod 10]
• 5 = [35 mod 10]
The shift cipher, formally
• M = {strings over lowercase English alphabet}
• Gen: choose uniform kÎ{0, …, 25}
• Enck(m1…mt): output c1…ct, where
ci := [mi + k mod 26]
• Deck(c1…ct): output m1…mt, where
mi := [ci - k mod 26]
• 0xAF
– 0xAF = 16*A + F = 16*10 + 15 = 175
– 0xAF = 1010 1111
Byte-wise shift cipher
• M = ({0,1}8)* (i.e., strings of bytes)
• Gen: choose uniform kÎK = {0x00, …, 0xFF}
– 256 possible keys
• Enck(m1…mt): output c1…ct, where
ci := mi Å k
• Deck(c1…ct): output m1…mt, where
mi := ci Å k
main(){
FILE *keyfile, *pfile, *cfile;
int i;
unsigned char key, ch;
• Assumptions
– Clearly stated and unambiguous
• Proofs of security
– Move away from design-break-patch cycle
Importance of definitions
• Definitions are essential for the design,
analysis, and sound usage of crypto
Importance of definitions -- design
• Developing a precise definition forces the
designer to think about what they really want
– What is essential and (sometimes more
important) what is not
• Often reveals subtleties of the problem
Importance of definitions -- design
• Threat model
– What (real-world) capabilities the attacker is
assumed to have
Recall
• A private-key encryption scheme is defined by a
message space M and algorithms (Gen, Enc, Dec):
– Gen (key-generation algorithm): generates k
– Enc (encryption algorithm): takes key k and message
m Î M as input; outputs ciphertext c
c ¬ Enck(m)
– Dec (decryption algorithm): takes key k and
ciphertext c as input; outputs m.
m := Deck(c)
Private-key encryption
key key
ciphertext
c
k k
m m := Deck(c)
c ¬ Enck(m) message/plaintext
decryption
encryption
Threat models for encryption
• Ciphertext-only attack
– One ciphertext or many?
• Known-plaintext attack
• Chosen-plaintext attack
• Chosen-ciphertext attack
Goal of secure encryption?
• How would you define what it means for
encryption scheme (Gen, Enc, Dec) over
message space M to be secure?
– Against a (single) ciphertext-only attack
Secure encryption?
• “Impossible for the attacker to learn the key”
– The key is a means to an end, not the end itself
– Necessary (to some extent) but not sufficient
– Easy to design an encryption scheme that
hides the key completely, but is insecure
– Can design schemes where most of the key is
leaked, but the scheme is still secure
Secure encryption?
• “Impossible for the attacker to learn the
plaintext from the ciphertext”
– What if the attacker learns 90% of the plaintext?
Secure encryption?
• “Impossible for the attacker to learn any
character of the plaintext from the ciphertext”
– What if the attacker is able to learn (other)
partial information about the plaintext?
• E.g., salary is greater than $75K
– What if the attacker guesses a character correctly,
or happens to know it?
The right definition
• “Regardless of any prior information the
attacker has about the plaintext, the ciphertext
should leak no additional information about
the plaintext”
– How to formalize?
Perfect secrecy
Probability review
• Random variable: variable that takes on (discrete)
values with certain probabilities
• Pr[C = ‘rqh’] = ?
= Pr[C = ‘rqh’ | M = ‘one’] · Pr[M = ‘one’]
+ Pr[ C = ‘rqh’ | M = ‘ten’] · Pr[M = ‘ten’]
= 1/26 · ½ + 0 · ½ = 1/52
Perfect secrecy (informal)
• “Regardless of any prior information the
attacker has about the plaintext, the ciphertext
should leak no additional information about
the plaintext”
Perfect secrecy (informal)
• Attacker’s information about the plaintext =
attacker knows the distribution of M
• Pr[C = ‘xy’]
= Pr[C = ‘xy’ | M = ‘hi’] · 0.3 + Pr[C = ‘xy’ | M = ‘no’] · 0.2
+ Pr[C=‘xy’ | M=‘in’] · 0.5
= (1/26) · 0.3 + (1/26) · 0.2 + 0 · 0.5
= 1/52
Example 4, continued
• Pr[M = ‘hi’ | C = ‘xy’] = ?
= Pr[C = ‘xy’ | M = ‘hi’] · Pr[M = ‘hi’]/Pr[C = ‘xy’]
= (1/26) · 0.3/(1/52)
= 0.6
¹ Pr[M = ‘hi’]
Conclusion
• The shift cipher is not perfectly secret!
– At least not for 2-character messages
• Correctness:
Deck( Enck(m) ) = k Å (k Å m)
= (k Å k) Å m = m
One-time pad
n bits
key
n bits n bits
message Å ciphertext
Perfect secrecy of one-time pad
• Note that any observed ciphertext can
correspond to any message (why?)
– (This is necessary, but not sufficient, for perfect
secrecy)
• So, having observed a ciphertext, the attacker
cannot conclude for certain which message
was sent
Perfect secrecy of one-time pad
• Fix arbitrary distribution over M = {0,1}n, and
arbitrary m, c Î {0,1}n
• Pr[M = m | C = c] = ?
= Pr[C = c | M = m] · Pr[M = m]/Pr[C = c]
• Pr[C = c]
= Sm’ Pr[C = c | M = m’] · Pr[M = m’]
= Sm’ Pr[K = m’ Å c | M = m’] · Pr[M = m’]
= Sm’ 2-n · Pr[M = m’]
= 2-n
Perfect secrecy of one-time pad
• Fix arbitrary distribution over M = {0,1}n, and
arbitrary m, c Î {0,1}n
• Pr[M = m | C = c] = ?
= Pr[C = c | M = m] · Pr[M = m]/Pr[C = c]
= Pr[K = m Å c | M = m] · Pr[M = m] / 2-n
= 2-n · Pr[M = m] / 2-n
= Pr[M = m]