0% found this document useful (0 votes)
4 views

Unit7_Cryptography

Unit 7 covers various aspects of cryptography, including cybersecurity ethics, symmetric key cryptography, and public key cryptography. It discusses the importance of ethical conduct in cybersecurity, the mechanics of symmetric encryption methods like the Caesar cipher and one-time pad, and introduces public key systems such as RSA. The unit emphasizes the significance of secure communication and the challenges associated with key management and cryptanalysis.

Uploaded by

yeung chunhin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Unit7_Cryptography

Unit 7 covers various aspects of cryptography, including cybersecurity ethics, symmetric key cryptography, and public key cryptography. It discusses the importance of ethical conduct in cybersecurity, the mechanics of symmetric encryption methods like the Caesar cipher and one-time pad, and introduces public key systems such as RSA. The unit emphasizes the significance of secure communication and the challenges associated with key management and cryptanalysis.

Uploaded by

yeung chunhin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Unit 7

Cryptography

Cryptography 7-1
4-Digit Combination Lock

Any two kids together can open the


lock, but any single kid obtains no
information (meaning that he/she
needs to try all 10,000 combinations).

How can it
be done?

Cryptography 7-2
Outline of Unit 7
 7.1 Cybersecurity Ethics
 7.2 Symmetric Key Cryptography
 7.3 Public Key Cryptography
 7.4 Secret Sharing

Cryptography 7-3
Unit 7.1

Cybersecurity Ethics

Cryptography 7-4
What is Ethics?
 Derived from the Greek word “ethos” (ἦθος),
which originally meant “custom” or “habit”.
 A branch of philosophy that is concerned with
human conduct.
 It studies what is morally right or wrong, just
or unjust.

Cryptography 7-5
Code of Ethics
 In work life, ethics is often formulated in formal
codes or standards to which all members of a
profession are held.
 e.g., code of ethics for lawyers, doctors, etc.
 It sets forth values and ethical principles to
which professionals aspire and by which their
actions can be judged.
 It is publicly available and addressed to anyone
with an interest in that organization's activities
and the way it operates.
Cryptography 7-6
The (ISC)² Code of Ethics
 The (ISC)² code of ethics is covered on the
CISSP exam.
 CISSP: Certified Information Systems Security
Professional – a certificate granted by (ISC)²
 Certification holders must adhere to its four
canons during their career.
 Code of Ethics Canons
 Protect society, the common good, necessary From
public trust and confidence, and the highest
infrastructure. standard
 Act honorably, honestly, justly, responsibly, (society) to
and legally. lowest (the
 Provide diligent and competent service to profession)
principals.
 Advance and protect the profession.
Cryptography 7-7
Cybersecurity Ethics
 Ethical issues are at the core of cybersecurity
practices.
 Example:
 Suppose you are a cybersecurity professional.
 You job is to secure a hospital’s network and critical
data from invasion and attack.
 Patients’ privacy, health, or even their survival can
hinge upon your success or failure.
 You are protecting their lives and well beings.

Cryptography 7-8
Hackers
 Black hat hackers
 criminals who break into computer networks with malicious
intent
 White hat hackers
 a.k.a. ethical hackers, penetration testers
 professionals who have permission to identify security flaws in
a system
 Grey hat hackers
 Not necessarily malicious but break into systems without
permission, thus violating laws or ethical standards.
 If vulnerabilities in a system are found, they may report them
to the owner, sometimes requesting a small fee to fix the
problem.
 Watch this (2 min):
 https://www.youtube.com/watch?v=E6S3-XGrZAE

Cryptography 7-9
Unit 7.2

Symmetric Key Cryptography

Cryptography 7-10
Secure Communications
 Bob & Alice want to communicate “securely”
 Trudy (intruder) may intercept, delete, add messages

Alice Bob
channel data, control
messages

data secure secure data


sender receiver

Trudy

Cryptography 7-11
The Language of Cryptography
Alice’s Bob’s
𝐾𝐾𝐴𝐴 encryption 𝐾𝐾𝐵𝐵 decryption
key key

plaintext encryption ciphertext: 𝑐𝑐 decryption plaintext: 𝑚𝑚


message: 𝑚𝑚 algorithm algorithm

 Encryption: 𝑐𝑐 = 𝑓𝑓 𝑚𝑚, 𝐾𝐾𝐴𝐴


 Decryption: 𝑚𝑚 = 𝑔𝑔(𝑐𝑐, 𝐾𝐾𝐵𝐵 ):

Cryptography 7-12
Symmetric Key Cryptography

𝐾𝐾𝑆𝑆 𝐾𝐾𝑆𝑆

plaintext encryption ciphertext decryption plaintext


Message: 𝑚𝑚 algorithm algorithm
𝑐𝑐 = 𝑓𝑓(𝑚𝑚, 𝐾𝐾𝑆𝑆 ) 𝑚𝑚 = 𝑔𝑔(𝑐𝑐, 𝐾𝐾𝑆𝑆 )

 The encryption and decryption algorithms (i.e., the


functions 𝑓𝑓 and 𝑔𝑔) are assumed known to the public.
 For many applications, it is difficult to keep the algorithms
as a secret.
 Alice and Bob share the same (symmetric) key: 𝐾𝐾𝑆𝑆
 The key is private (known only by Alice and Bob).

Cryptography 7-13
Caesar Cipher (~58 BC)
 Named after Julius Caesar, who used it in
his private correspondence.
 Each letter in the plaintext is (cyclically)
shifted by a fixed number of positions
down the alphabet.
 e.g. if the shift is 3, a→d, b→e, …, z→c
 The symmetric key 𝐾𝐾𝑆𝑆 is the number of Julius Caesar,
arguably the
shift positions. greatest of the
dictators of
 Decrypt it without knowing 𝐾𝐾𝑆𝑆 !
Rome, ruling
k ecog k ucy k eqpswgtgf from 49 BC to
44 BC.
i came i saw i conquered Cryptography 7-14
Substitution Cipher
 Substitution cipher: replace one thing by another.
 Caesar cipher is a special case of substitution cipher.

 Example: (replace each letter by another)


 plaintext: abcdefghijklmnopqrstuvwxyz

 ciphertext: mnbvcxzasdfghjklpoiuytrewq
 The symmetric key 𝐾𝐾𝑆𝑆 is the mapping.
 Decrypt the ciphertext below using the above key:
nkn s gktc wky mgsbc
bob i love alice
you Cryptography 7-15
Cryptanalysis
 Some English letters
occur more often
than others.
 Monoalphabetic
ciphers are
vulnerable to
frequency analysis
attacks, since the
language feature is
preserved after the Relative frequencies of
substitution. letters in text

Cryptography 7-16
The One-Time Pad (OTP) (1882)
 Motivation:
 In the substitution cipher, every occurrence of an
object is replaced by the same object, which is easy
to break (via statistical analysis) for long messages.
 History:
 First described by Frank Miller in 1882.
 Re-invented by Gilbert Vernam (of AT&T
Corporation) in 1917 and later patented in 1919.
 Its theoretical significance was recognized and
proved by information theorist Claude Shannon in
the 1940s.
Cryptography 7-17
Encryption
 Let n be the length of the plaintext.
 The symmetric key 𝐾𝐾𝑆𝑆 is a list of
𝑛𝑛 random shifts.
 Encryption is by addition mod 26.
 Example:
 number theory is the queen of mathematics
 354123 ...... .. ... ..... .. ...........
 qzqcgu ...... .. ... ..... .. ...........
Note: only the first word is shown.

Cryptography 7-18
Perfect Secrecy
OTP is perfectly (or information-theoretically) secure if
the following four conditions are met:
1. The key is at least as long as the plaintext.
• A major drawback of the scheme. How can sender and receiver
exchange the key (with very long key size)?
2. The key is truly random.
• Hard to achieve in practice. Practical schemes are usually
based on pseudo-random numbers.
3. The key is not reused in whole or in part.
• That’s why it’s called one-time.
4. The key is a secret known only by the sender and
the receiver.
• A condition obviously needed.

Even a quantum computer cannot break it!


Cryptography 7-19
OTP: Binary Implementation
 Suppose the plaintext 𝑚𝑚 is a bit sequence of
length 𝑛𝑛.
 The symmetric key 𝐾𝐾𝑆𝑆 is a bit sequence of the
same length generated randomly.
 Ciphertext 𝑐𝑐 is obtained by bitwise-XOR between
𝑚𝑚 and 𝐾𝐾𝑆𝑆 , i.e.,
𝑐𝑐 = 𝑚𝑚 ⊕ 𝐾𝐾𝑆𝑆
 Example:
 𝑚𝑚 = 10011101
 𝐾𝐾𝑆𝑆 = 01100101
 𝑐𝑐 = 11111000 (obtained by 𝑚𝑚 ⊕ 𝐾𝐾𝑆𝑆 )
Cryptography 7-20
Hill Cipher (1929)
 A polygraphic substitution cipher,
invented by Lester S. Hill.
 Substitution is performed block by
block (instead of letter by letter).
 A vector of 𝑛𝑛 letters is encrypted
by multiplication with an 𝑛𝑛 × 𝑛𝑛
invertible matrix (mod 26), which
is the secret key.
 Decryption is done by
multiplication with the inverse of
the encryption matrix.
Cryptography 7-21
Example: Encryption Matrix
The plaintext is “ACT”. The encryption matrix.

To ensure decryption
can be done, this
matrix must be
invertible.

SageMath code
R = IntegerModRing(26)
E = Matrix(R,[[6,24,1],[13,16,10],[20,17,15]])
E.is_invertible()

You can use SageMath to verify that the matrix is invertible.


https://sagecell.sagemath.org/
Cryptography 7-22
Example: Encryption
The ciphertext is obtained by

SageMath code

R = IntegerModRing(26)
E = Matrix(R,[[6,24,1],[13,16,10],[20,17,15]])
m = vector(R,[0,2,19])
E * m

Cryptography 7-23
Example: Decryption Matrix
The decryption matrix.

SageMath code

R = IntegerModRing(26)
E = Matrix(R,[[6,24,1],[13,16,10],[20,17,15]])
E.inverse()

Cryptography 7-24
Example: Decryption
The plaintext is obtained by

SageMath code
R = IntegerModRing(26)
E = Matrix(R,[[6,24,1],[13,16,10],[20,17,15]])
m = vector(R,[0,2,19])
c = E * m
D = E.inverse()
D * c

Cryptography 7-25
Remarks on Hill Cipher
 Encryption matrix, 𝐸𝐸, must be invertible.
 According to Cramer’s rule, matrix inverse is
computed by “division by determinant”.
 𝐸𝐸 ≠ 0 (division by zero is undefined)
 𝐸𝐸 is co-prime with the modular base (which can be
guaranteed if the base is chosen as a prime number).

 Matrix multiplication alone is not very secure.


 Vulnerable to known-plaintext attack because a
system of linear equations is easy to solve.
 It is still useful when combining with other non-
linear operations.
Cryptography 7-26
The Enigma Machine (1918) (optional)
 Invented by Arthur Scherbius in 1918,
right at the end of World War I.
 Early models were used commercially
from the early 1920s.
 Adopted by Nazi Germany before and
during World War II.
 Alan Turing, a mathematician, cracked
the code, which shortened the war by
more than two years.
 Enigma machine (12 min):
 https://www.youtube.com/watch?v=G2_Q9
FoD-oQ
Cryptography 7-27
Unit 7.3

Public Key Cryptography

Cryptography 7-28
Symmetric Key vs Public Key
Symmetric key crypto Public key crypto
 radically different
 requires sender and
approach [Diffie-
receiver know a shared Hellman76, RSA78]
secret key  sender, receiver do not
 Q: how to agree on the share secret key
key in the first place  public encryption key
(particularly if never known to all
“met”)?  private decryption key
known only to receiver

Cryptography 7-29
Public Key Cryptography
𝐾𝐾𝐵𝐵+ Bob’s public
key

𝐾𝐾𝐵𝐵− Bob’s private


key

plaintext encryption ciphertext decryption plaintext


Message: 𝑚𝑚 algorithm algorithm 𝑚𝑚 = 𝑔𝑔(𝑐𝑐, 𝐾𝐾𝐵𝐵− )
𝑐𝑐 = 𝑓𝑓(𝑚𝑚, 𝐾𝐾𝐵𝐵+ )

Additional requirement:
 Given the public key 𝐾𝐾𝐵𝐵+ , it should be (almost)
impossible to compute the private key 𝐾𝐾𝐵𝐵− .
Cryptography 7-30
Practical Use
 The following two-step approach is commonly
used (e.g., in HTTPS):
1) Use public key to privately share a session key
(i.e., a symmetric key)
 Public key crypto has a lot of overhead.
 This step is done only at the beginning of a
communication session.
2) Use symmetric key to encrypt data
 Symmetric key crypto is quicker and uses less
resource.

Cryptography 7-31
RSA Cryptosystem
 By Rivest, Shamir, Adleman
of MIT in 1977.
 Best known and widely used
public-key scheme.
 Use large integers (e.g., 1024
bits) Is factorization
 Security due to the difficulty difficult?
of factoring large numbers.

Cryptography 7-32
RSA Challenge
 Can you factorize the following number
(which has 617 digits, or 2048 bits)?
2519590847565789349402718324004839857142928212620
4032027777137836043662020707595556264018525880784
4069182906412495150821892985591491761845028084891
2007284499268739280728777673597141834727026189637
5014971824691165077613379859095700097330459748808
4284017974291006424586918171951187461215151726546
3228221686998754918242243363725908514186546204357
6798423387184774447920739934236584823824281198163
8150106748104516603773060562016196762561338441436
0383390441495263443219011465754445417842402092461
6515723350778707749817125772467962926386356373289
9121548314381678998850404453640235273819513786365
64391212010397122822120720357
Cryptography 7-33
RSA: Getting Ready
 Message: just a bit pattern
 bit pattern can be uniquely represented by an
integer
 thus, encrypting a message is equivalent to
encrypting a number.
 Example:
 𝑚𝑚 = 10010001 . This message is uniquely
represented by the decimal number 145.
 To encrypt 𝑚𝑚, we encrypt the corresponding
number, which gives a new number (the ciphertext).

Cryptography 7-34
Key Generation
 Bob generates two large distinct random primes,
𝑝𝑝 and 𝑞𝑞.
 Compute 𝑁𝑁 = 𝑝𝑝𝑞𝑞 and 𝜙𝜙 𝑁𝑁 = 𝑝𝑝 − 1 𝑞𝑞 − 1 .
 Choose at random 𝑒𝑒 (with 1 < 𝑒𝑒 < 𝜙𝜙 𝑁𝑁 ) which
is co-prime with 𝜙𝜙 𝑁𝑁 .
 Solve the following equation to find d:
𝑒𝑒𝑒𝑒 ≡ 1 (mod 𝜙𝜙 𝑁𝑁 )
 The inverse of 𝑒𝑒 exists, since 𝑒𝑒 and 𝜙𝜙 𝑛𝑛 are coprime.
 Bob publishes his public key 𝐾𝐾𝐵𝐵+ : (𝑁𝑁, 𝑒𝑒).
 He keeps secret his private key 𝐾𝐾𝐵𝐵− : (𝑁𝑁, 𝑒𝑒).
 Note: 𝑁𝑁 is known by everybody.

Cryptography 7-35
Encryption and Decryption
1. To encrypt message 𝑚𝑚, Alice uses Bob’s public
key 𝐾𝐾𝐵𝐵+ : 𝑁𝑁, 𝑒𝑒 to compute
𝑐𝑐 = 𝑚𝑚𝑒𝑒 (mod 𝑁𝑁)
 Note that 𝑚𝑚 must be smaller than N (break down
into blocks if necessary).
2. After receiving the ciphertext, Bob uses his
private key 𝐾𝐾𝐵𝐵− : 𝑁𝑁, 𝑒𝑒 to compute
𝑚𝑚′ = 𝑐𝑐 𝑑𝑑 (mod 𝑁𝑁)
magic
𝑚𝑚′ = 𝑚𝑚
happens!
Cryptography 7-36
RSA Toy Example
 Bob chooses 𝑝𝑝 = 5, 𝑞𝑞 = 7.
 Then 𝑁𝑁 = 35, 𝜙𝜙 𝑁𝑁 = 24.
 Suppose 𝑒𝑒 = 5 is chosen (so 𝑒𝑒, 𝜙𝜙 𝑁𝑁 are co-prime)
 Compute 𝑒𝑒 = 5 (by xgcd so that 𝑒𝑒𝑒𝑒 ≡ 1 (mod 𝜙𝜙 𝑁𝑁 ) )
 Encrypt 8-bit message
e e
bit pattern m m c = m mod N
encrypt:
00001100 12 248832 17

c d d
c m’ = c mod N
decrypt:
17 1419857 12
In practice, the numbers are very large.
Fast exponentiation is used instead! Cryptography 7-37
Why does RSA work?
 We want to show that
𝑚𝑚′ ≡ 𝑐𝑐 𝑑𝑑 ≡ 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 mod 𝑁𝑁 ,
or
𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 mod 𝑝𝑝𝑞𝑞 .

 By the corollary of CRT, it suffices to prove that


𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 mod 𝑝𝑝 ,
𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 mod 𝑞𝑞 ,
for all 𝑚𝑚.

Cryptography 7-38
To prove:
Case 1: 𝑚𝑚 ≡ 0 (mod 𝑝𝑝) 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 mod 𝑝𝑝 ∀𝑚𝑚
 It implies 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 0 (mod 𝑝𝑝).
 Hence, 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 (mod 𝑝𝑝).

Case 2: 𝑚𝑚 ≢ 0 (mod 𝑝𝑝) ⟹ 𝑝𝑝 ∤ 𝑚𝑚


 Since 𝑒𝑒𝑒𝑒 ≡ 1 (mod 𝜙𝜙 𝑁𝑁 ), we can write
𝑒𝑒𝑒𝑒 = 1 + 𝑘𝑘𝜙𝜙 𝑁𝑁 for some integer k.
 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚1+𝑘𝑘𝜙𝜙 𝑛𝑛 ≡ 𝑚𝑚 𝑚𝑚𝑝𝑝−1 𝑘𝑘(𝑞𝑞−1) (mod 𝑝𝑝).
 Since 𝑝𝑝 ∤ 𝑚𝑚, by Fermat’s Little Theorem,
𝑚𝑚𝑝𝑝−1 ≡ 1 mod 𝑝𝑝 .
 Hence, 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 (mod 𝑝𝑝).

Similarly, we can show that 𝑚𝑚𝑒𝑒𝑑𝑑 ≡ 𝑚𝑚 (mod 𝑞𝑞).


Q.E.D.
Cryptography 7-39
Why is RSA secure?
 Given the public key (𝑁𝑁, 𝑒𝑒), how hard is it to
determine the private key (𝑁𝑁, 𝑒𝑒)?
 If 𝜙𝜙 𝑁𝑁 is known, 𝑒𝑒 can be determined by solving
𝑒𝑒𝑒𝑒 ≡ 1 mod 𝜙𝜙 𝑁𝑁 .
 Is it hard to determine 𝜙𝜙 𝑁𝑁 from 𝑁𝑁?
 It is well known that factorizing 𝑁𝑁 into 𝑝𝑝𝑞𝑞 for large 𝑁𝑁 is a
very hard problem.
 Suppose 𝜙𝜙 𝑁𝑁 can be determined easily from 𝑁𝑁.
 Then 𝑝𝑝 and 𝑞𝑞 can be obtained by solving the following two
simultaneous equations:
• 𝑁𝑁 = 𝑝𝑝𝑞𝑞,
• 𝜙𝜙 𝑁𝑁 = 𝑝𝑝 − 1 𝑞𝑞 − 1 = 𝑝𝑝𝑞𝑞 − 𝑝𝑝 − 𝑞𝑞 + 1.
 Hence, it is hard to determine 𝜙𝜙 𝑁𝑁 from 𝑁𝑁.

Cryptography 7-40
Exercise
Use the RSA algorithm to encrypt the message 𝑚𝑚
represented by the decimal number 32 with 𝑁𝑁 = 85
and 𝑒𝑒 = 61.
a) Compute the ciphertext, 𝑐𝑐. me ( mod N )
-

b) Factorize 𝑁𝑁 and check your answer in (a) by


decryption. c

• In practice, N is a very large number, so factorization is


extremely time consuming.

Cryptography 7-41
Solution

(a) Encryption (b) Decryption


𝑐𝑐 = 𝑚𝑚𝑒𝑒 mod 𝑛𝑛 = 3261 mod 85 𝑁𝑁 = 𝑝𝑝 × 𝑞𝑞 85 = 5 × 17.
322 ≡ 4 mod 85 ϕ 𝑁𝑁 = 𝑝𝑝 − 1 𝑞𝑞 − 1
324 ≡ 16 mod 85 = 4 × 16 = 64.
328 ≡ 1 mod 85 𝑒𝑒𝑒𝑒 ≡ 1 mod 64
61𝑒𝑒 ≡ 1 mod 64 ⇒ 𝑒𝑒 = 21.
3216 ≡ 1 mod 85
𝑚𝑚 = 𝑐𝑐 𝑑𝑑 mod 𝑛𝑛
3232 ≡ 1 mod 85
= 221 mod 85
= 25 4 2 mod 85
3232 3216 328 324 32 mod 85
= (324 ) 2 mod 85
= 16 × 32 mod 85 = 2.
= 16 × 2 = 32
Cryptography 7-42
Unit 7.4

Secret Sharing

Cryptography 7-43
4-Digit Combination Lock

Key Idea: Two points determine a line.

Suppose the lock’s


combination is 6965.

slope = 6965, y-intercept (generated randomly)

Cryptography 7-44
Secret Sharing Scheme
 Let 𝑝𝑝 = 10007 (any prime number greater than 10,000)
 Pick a random number from 0, 1, … , 𝑝𝑝 − 1 .
 Define the line 𝐿𝐿 by
𝑦𝑦 ≡ 6965𝑥𝑥 + 30 (mod 10007)

 Give the kids the following points on 𝐿𝐿:


 Alice: (1, 6995)
 Bob: (2, 3953)
 Claire: (3, 911)
 Daniel: (4, 7876)

Cryptography 7-45

How to Open the Lock?
 Suppose Alice and Claire want to open the lock.
 Alice: (1, 6995), Claire: (3, 911)

 The slope of the line through their point is


911 − 6995 −6084
≡ (mod 10007)
3−1 2

 Note that 2−1 ≡ 5004 (mod 10007).


 Hence,
−6084 × 5004 ≡ 6965 (mod 10007)
They can open the lock!
Cryptography 7-46
Recommended Reading
 Chapter 11, J. H. Silverman, A Friendly
Introduction to Number Theory, 4th ed.,
Pearson, 2013.

 Section 8.2, J. Kurose and K. Ross,


Computer Networking: a top-down
approach, 6th ed., Prentice Hall, 2010.

 Chapter 7, J. S. Kraft and L. C.


Washington, Elementary Number
Theory, CRC Press, 2015.

Cryptography 7-47
Supplementary Materials on Enigma
(optional)

 Flaw in the Enigma (11 min):


 https://www.youtube.com/watch?
v=V4V2bpZlqx8

 The Imitation Game


 A movie based on the biography of
Alan Turing
 Trailer (2.5 min):
https://www.youtube.com/watch?
v=aG4-C4bGAw4

Cryptography 7-48

You might also like