2_Authentication&Integrity
2_Authentication&Integrity
1
Outline
2
Secure communication and
message integrity
• What does secure communication entail beyond
private communication?
• Consider a large supermarket chain sending an
email request to purchase 10,000 crates of soda
from a supplier
• Upon receiving order, supplier has to consider:
• Is the order authentic: Did the supermarket chain really
issue the order?
• Are the details of the received order exactly those sent
by the supermarket?
3
Common misconception:
Using encryption for integrity
If ciphertext completely hides the
contents of the message, an
adversary cannot possibly modify an
encrypted message en route – all
that it sees is “random garbage”.
4
Common misconception:
Using encryption for integrity
5
Message Authentication
Codes
• Prevents an adversary from modifying a message
sent by one party to another, without the parties
detecting that a modification has been made.
• Message authentication code (MAC) is an algorithm
applied to a message.
• Input: message, Output: MAC tag, or tag
6
Message Authentication
Codes
Algorithms:
• Gen: takes as input the security parameter 1n and
outputs a uniformly distributed key k:
k Gen(1n)
• MAC: takes as input a key k ∈ {0, 1}n and m ∈ {0,
1}∗, and outputs MAC tag t ∈ {0, 1}∗ :
t MACk(m)
• Verify (Vrfy): takes as input a key k ∈ {0, 1}n , m ∈
{0, 1}∗ and t ∈ {0, 1}∗ , and outputs a bit b ∈ {0, 1}
• For every n,k,m: Vrfyk (m,MACk(m)) = 1
7
Message Authentication
Codes
k k
• m is message to be authenticated
• MAC tag is a cryptographic checksum
• We desire MAC tag to be unforgeable for a new
message (without knowing k).
• Two common methods: CBC-MAC and HMAC
8
Constructing Secure MACs
m, Fk(m)
m PRF: Fk
9
Constructing Variable-length
Secure MACs – Some (bad) Ideas
• Apply a PRF to the first block:
m1 m2 m3
m1 m2 m3
Fk (m1)
• XOR all blocks and apply PRF to result
m1 m2 m3
m1 m2 m3
Fk (m1 ⊕ m2 ⊕ m3)
• Apply a pseudorandom function to each block
separately and output the result
m1 m2 m3
m1 m2 m3
Fk (m1) Fk (m2) Fk (m3)
10
CBC-MAC
11
Hash Functions
m H: Hash H(m)
any message Function digest
12
Collision-resistant Hash
Functions
• Also known as cryptographic hash functions.
• Infeasible for PPT adversary to find a distinct pair of
values x and x′ such that H(x) = H(x′).
• But we are only interested in functions that yield
short output: H: {0, 1}∗ {0, 1}n
• Lower levels of security in hash functions:
• Second-preimage resistance: given x hard to find x′ such
that H(x) = H(x′)
• Preimage resistance (one-way): given y, hard to find x′
such that H(x′) = y
13
Collision-resistant Hash
Functions
• How long should the output be for
• second-preimage resistance
• preimage resistance
• collision resistance?
• Assumption: best attack is random search.
• Assumption: Typically, 128-bit security is well enough.
I.e., not feasible for adversary to run 2128 cycles
• Birthday problem: if q people are in a room, what is the
probability that there exist two people with the same
birthday?
𝑛𝑛⁄
• When 𝑞𝑞 = 𝑂𝑂 2 2 collision probability > 1/2
14
Collision-resistant Hash
Functions
15
Hash Function Construction –
Merkle-Damgård Transform
• Transforms fixed-length collision-resistant hash function (f)
into a general one with arbitrary length inputs.
• If f is collision-resistant hash function, so is the output.
• E.g., MD5, SHA1, SHA2 are constructed via M-D Transform
16
HMAC
17
Using CBC-MAC and HMAC
Which Scenario below describes the right use of MAC?
• Scenario 1:
• Alice and Bob share a secret k.
• Alice creates message m and calculates the MAC function: t =
MACk(m)
• Alice sends MAC tag t to Bob
• Scenario 2:
• Alice and Bob share a secret k.
• Alice creates message m and calculates the MAC function: t =
MACk(m)
• Alice sends MAC tag t and m to Bob
• Bob checks if Vrfyk (m,MACk(m)) = 1
18
Applications of Hash
Functions and MAC
• Message Authentication (obviously )
• Message authentication codes
• Digital signatures
• Hash chains, trees, commitment schemes (next)
• One-time password (not to be confused with one-
time pad) – 2FA
• Time synchronized OTP: use MACk(t)
t: current time or counter, k: shared secret
• Data integrity checks:
• Compare downloaded file against the publisher’s digest
19
Applications of Hash
Functions and MAC
• Storing passwords
• Instead of storing password, store H(password)
• Best practice: store H(password, salt)
• Prevents rainbow table attacks + identical passwords are stored
as different values
Username: Bob
Password: mypass12345 Server stores
H(mypass12345 || salt1), salt1
H(password || salt)
Username: Bob Server stores
Password: mypass12345 H(mypass12345 || salt2), salt2
20
SHA-1 Broken?
21
Obtaining Privacy and
Message Authentication
• We may need both privacy and authentication.
• Idea: Combine secure encryption with secure MAC
• 3 Approaches:
• Encrypt-and-authenticate: encryption and message
authentication are computed and sent separately
• Authenticate-then-encrypt: MAC tag is first computed,
then message and tag are encrypted together
• Encrypt-then-authenticate: message m is first
encrypted, then a MAC tag is computed over the
encrypted message
22
Obtaining Privacy and
Message Authentication
Encrypt-and-authenticate
c = Enc𝑘𝑘1 (m) t = MAC𝑘𝑘2 (m)
m c c t
Authenticate-then-encrypt
t = MAC𝑘𝑘2 (m) c = Enc𝑘𝑘1 (m || t)
m m t c
Encrypt-then-authenticate
c = Enc𝑘𝑘1 (m) t =MAC𝑘𝑘2 (c)
m c c t
23
Obtaining Privacy and
Message Authentication
• Encrypt-and-authenticate is insecure
• Authenticate-and-encrypt
• Secure under CPA (with appropriate selection of encryption
and MAC scheme)
• Insecure under CCA
• Encrypt-then-Authenticate
• Secure against both (as long as used encryption and MAC
schemes are secure)
• We will not dive into details, if interested:
https://eprint.iacr.org/2000/025.pdf
• Another advantage of Encrypt-then-MAC is to avoid
unnecessary decryption for garbage data received.
24
Encryption only vs Encryption
& Authentication
• Most online tasks needs to be encrypted and
authenticated.
• Obvious examples: online purchases and bank
transactions.
• How about when encrypting files on a disk?
• Best practice is to always use encryption and
authentication together.
• Authenticated encryption with associated data (AEAD):
variant of Authenticated Encryption that allows the
message to include associated data = non-confidential
data
25
Digital Signatures
26
Digital Signatures
Algorithms:
• Gen: takes as input the security parameter 1n and
outputs a public key and private key (pk, sk):
(pk, sk) Gen(1n)
• Sign: takes as input private key sk ∈ {0, 1}min n and m ∈
{0, 1}∗, and outputs signature σ:
σ Signsk(m)
• Verify (Vrfy): takes as input public key pk ∈ {0, 1}min n, m
and σ, and outputs a bit b ∈ {0, 1}
• For every n,(pk, sk),m: Vrfypk (m,Signsk(m)) = 1
27
Digital Signatures
sk pk
• Invented in 1977
• 1 year after Diffie-Helman
key exchange
29
Prerequisite: modular arithmetic
• x mod n = remainder of x when divided by n
• facts:
[(a mod n) + (b mod n)] = (a+b) mod n
[(a mod n) - (b mod n)] = (a-b) mod n
[(a mod n) * (b mod n)] = (a*b) mod n
• thus
(a mod n)d = ad mod n
30
RSA: Creating public/private key pair
31
RSA: Encryption, Decryption
0. given (n,e) and (n,d) as computed above
pk sk
thus,
cd (mod n) = (me mod n)d (mod n)
= med (mod n) Use: (a mod n) d mod n = ad mod n
e
bit pattern m m c = me mod n
encrypt:
00001100 12 24832 17
d
c c m = cd mod n
decrypt:
17 481968572106750915091411825223071697 12
34
RSA: Encryption to Digital Signatures
Encsk(Decpk(m)) = Decsk(Encsk(m))
use public key first, use private key first,
followed by private followed by public
key key
result is the same
• Follows directly from modular arithmetic:
(me mod n)d mod n = med mod n
= mde mod n
= (md mod n)e mod n
35
Textbook RSA Signature
Gen: (𝑛𝑛, 𝑒𝑒, 𝑑𝑑) Gen(1n). 𝑝𝑝𝑝𝑝 = 𝑛𝑛, 𝑒𝑒 , 𝑠𝑠𝑠𝑠 = (𝑛𝑛, 𝑑𝑑)
Sign: 𝜎𝜎 ∶= 𝑚𝑚𝑑𝑑 mod 𝑛𝑛 (using 𝑠𝑠𝑠𝑠)
Vrfy: 𝑚𝑚 =? 𝜎𝜎 𝑒𝑒 mod 𝑛𝑛 (using 𝑝𝑝𝑝𝑝)
• Not secure!
• No message attack:
• Choose arbitrary 𝜎𝜎
• Compute 𝑚𝑚 = 𝜎𝜎 𝑒𝑒 mod 𝑛𝑛
• Verification succeeds!
36
Hashed RSA
Gen: (𝑛𝑛, 𝑒𝑒, 𝑑𝑑) Gen(1n). 𝑝𝑝𝑝𝑝 = 𝑛𝑛, 𝑒𝑒 , 𝑠𝑠𝑠𝑠 = (𝑛𝑛, 𝑑𝑑)
Sign: 𝜎𝜎 ∶= 𝐻𝐻(𝑚𝑚)𝑑𝑑 mod 𝑛𝑛 (using 𝑠𝑠𝑠𝑠)
Vrfy: 𝐻𝐻(𝑚𝑚) =? 𝜎𝜎 𝑒𝑒 mod 𝑛𝑛 (using 𝑝𝑝𝑝𝑝)
37
MAC vs Digital Signature
• Both are used for message authentication
• Both are unforgeable
MAC Digital Signature
• Lightweight • Expensive
• Good for unicast • Applicable to multicast
• Requires shared key to • Publicly verifiable
be securely distributed • Non-repudiation
• Requires public key to
be securely distributed
38