34
Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer Science

Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

  • Upload
    others

  • View
    25

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Introduction to Computer SecurityHash Functions and Digital Signatures

Pavel LaskovWilhelm Schickard Institute for Computer Science

Page 2: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Integrity objective in a wide sense

ReliabilityTransmission errorsCorruption of stored data

SecurityManipulation of data in transmissionManipulation of stored data

Page 3: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Integrity checking: a general framework

Compute a “digest” for the original message D = h(M),such that

P(D is corrupt)� P(M is corrupt)

.To check the integrity of a message M′ at a later time,compute D′ = h(M′) and verify that D = D′.

Page 4: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Hash functions

Hash function converts large, variablesize input into small, fixed size output.Applications:

Efficient search (hash tables)Indexing of variable size dataFinding duplicate entriesFinding similar entries

hash

functionkeys

John Smith

Lisa Smith

Sam Doe

Sandra Dee

hashes

00

01

02

03

04

05

:

15

Requirements:Efficiency: less that log2 n comparisonsDeterminism: always maps the same input to the same outputSmall probability of collisionsUniformity: equal probability of output values

Page 5: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Hash function design

Fixed length (numeric) keys:Division method:

h(k) = k mod m

Multiplication method:

h(k) = bm(kA mod 1)c

Variable length keys (e.g. strings):Convert a string into a fixed number (e.g. add up all characters)Compute a hash of a fixed number

Hash function reduces the dimension of the key set:Collisions are unavoidable!

Page 6: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A simple message digest application

Alice Bob

Hashingalgorithm

Message

Messagedigest

Message

Messagedigest

Message

Messagedigest

Hashingalgorithm

Message

Messagedigest

Messagedigest

equal?

Transmit

Page 7: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Insecurity of message digest

Alice Bob

Message A

Message Adigest

Hashingalgorithm

Message B

Message Bdigest

Message Bdigest

equal?

Eve

Message A

Message Adigest

Message B

Message Bdigest

Message B

Message Bdigest

Page 8: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Message authentication code (MAC)

Alice Bob

Hashingalgorithm

Message

Messagedigest

Message

Messagedigest

Message

Messagedigest

Hashingalgorithm

Message

Messagedigest

Messagedigest

equal?

Transmit

Sharedsecret

Sharedsecret

Page 9: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Secure hash function requirements

Compression: h reduces M to a fixed size.For any M, h(M) is easy to compute.Preimage resistance: For any value D, it is computationallyinfeasible to find M such that D = h(M).Second preimage resistance: For any values D and M suchthat D = h(M), it is computationally infeasible to findM′ 6= M such that D = h(M′).Collision resistance: It is computationally infeasible to findany pair M1, M2 such that h(M1) = h(M2).

Page 10: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A birthday paradox

How many people must be in a room for someone to havethe same birthday as you?

(365)How many people must be in a room for some people tohave the same birthday? (23)Probability that n people have different birthdays is:

P̄(n) = 1×(

1− 1365

(1− 2

365

)× . . .×

(1− n− 1

365

)≈

(e−

1365

(e−

2365

)× . . .×

(e−

n−1365

)= e−( 1

365 + 2365 +... n−1

365 ) ≈ e−n2

2·365

Solving for n and equating to 0.5, we obtain:

n =√

2 ln 2 ·√

365 = 22.54

Page 11: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A birthday paradox

How many people must be in a room for someone to havethe same birthday as you? (365)

How many people must be in a room for some people tohave the same birthday? (23)Probability that n people have different birthdays is:

P̄(n) = 1×(

1− 1365

(1− 2

365

)× . . .×

(1− n− 1

365

)≈

(e−

1365

(e−

2365

)× . . .×

(e−

n−1365

)= e−( 1

365 + 2365 +... n−1

365 ) ≈ e−n2

2·365

Solving for n and equating to 0.5, we obtain:

n =√

2 ln 2 ·√

365 = 22.54

Page 12: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A birthday paradox

How many people must be in a room for someone to havethe same birthday as you? (365)How many people must be in a room for some people tohave the same birthday?

(23)Probability that n people have different birthdays is:

P̄(n) = 1×(

1− 1365

(1− 2

365

)× . . .×

(1− n− 1

365

)≈

(e−

1365

(e−

2365

)× . . .×

(e−

n−1365

)= e−( 1

365 + 2365 +... n−1

365 ) ≈ e−n2

2·365

Solving for n and equating to 0.5, we obtain:

n =√

2 ln 2 ·√

365 = 22.54

Page 13: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A birthday paradox

How many people must be in a room for someone to havethe same birthday as you? (365)How many people must be in a room for some people tohave the same birthday? (23)

Probability that n people have different birthdays is:

P̄(n) = 1×(

1− 1365

(1− 2

365

)× . . .×

(1− n− 1

365

)≈

(e−

1365

(e−

2365

)× . . .×

(e−

n−1365

)= e−( 1

365 + 2365 +... n−1

365 ) ≈ e−n2

2·365

Solving for n and equating to 0.5, we obtain:

n =√

2 ln 2 ·√

365 = 22.54

Page 14: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A birthday paradox

How many people must be in a room for someone to havethe same birthday as you? (365)How many people must be in a room for some people tohave the same birthday? (23)Probability that n people have different birthdays is:

P̄(n) = 1×(

1− 1365

(1− 2

365

)× . . .×

(1− n− 1

365

)≈

(e−

1365

(e−

2365

)× . . .×

(e−

n−1365

)= e−( 1

365 + 2365 +... n−1

365 ) ≈ e−n2

2·365

Solving for n and equating to 0.5, we obtain:

n =√

2 ln 2 ·√

365 = 22.54

Page 15: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Brute force attacks

For an ideal hash function with the output size n, it should take

2n operations to stage a second-preimage attack,2n/2 operation to stage a collision attack.

A cryptographic strength of a hash function strongly depends onits output size.

Page 16: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

A simple hash function

x1

+

x2

+

. . .

+

xn

+IV

Fix an initialization value IV.Compute intermediate states

s1 = IV + x1

si = si−1 + xi, ∀i = 2, . . . , n

Output the final state sn as a hash value

Page 17: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Insecurity of a simple hash function

Suppose the digest D is known.The IV can be found by sending the word (0, 0, . . . , 0).Then the message (IV, D, 0, . . . , 0) will produce the hashvalue D: the second preimage property is broken!

Page 18: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

General design of a hash function

f

x1

s1

f

x2

s2. . .

f

xn

snIV

Iterated application of a compression function si ← f (xi, si−1)s0 is initialized to some fixed IVCollision resistance of f implies collision resistance of ahash function (Merkle’s principle).

Page 19: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

MD5 algorithm

Pad a message to a the length 448mod 512, add message length as a64-bit value.Initialize 4 32-bit registers A, B, C, D withpre-defined values.Divide each 512-bit block in 16 words wof length 32; for i = 1 . . . 64, do:

compute A + fi(B, C, D)add Mi = wgi

add Ki = b| sin(i + 1)| · 232cshift left by si positionsAdd B and save in B, C← B, D← C, A← D

F

A B C D

A B C D

M

K

i

i

<<<s

Proceed to the next block using the state A, B, C, D.

Page 20: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Insecurity of MD5

[1996]: H. Dobbertin demonstrated a collision of the compressionfunction of MD5.

[2004]: X. Wang and H. Yu showed a modular differential attack onthe complete MD5 hash function.

[2007]: M. Stevens, A. Lenstra and B. de Weger demonstrated achosen prefix attack: given a prefix P, find suffixes S1 and S2such that MD5 hashes of P||S1 and P||S2 are the same.

[2008]: A. Sotirov et al. generated a rogue X.509 certificate todemonstrate practical consequences of MD5 vulnerability.

Page 21: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

SHA-1 algorithm

160-bit output instead of 128 in MD5; 80rounds per 512-bit block.Similar initialization and overall scheme.16 initial words wi are extended into thetotal of 80 words, one per round:

wi = (wi−3 ⊕wi−8 ⊕wi−14 ⊕wi−16) ≪ 1

Fixed constants and shifts per round.Best known collision attack requires 269

operations, compared to 280 by bruteforce.

A B C D E

A B C D E

<<<5

<<<30

F

Wt

K t

Page 22: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Authentication

The reciever must verify the claimed identity of a sender.The sender cannot deny having sent a message.The reciever cannot have created the message himself.

Page 23: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Symmetric key signatures

Alic

eA,KA(B, P)

TT

P

KB(A, P,KT(A, P))

Bob

Identity of A is proved to T by KA.The fact of A’s sending a message is proved by KT(A, P).B cannot forge having received a message from A becausehe does not know KT.

Page 24: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Public key signatures

Alice’sprivate key,

Kr

A

P

Alice’spublic key,

Ku

A

P

Alice’s computer Bob’s computer

DKr

A(P) EKu

A(DKr

A(P))

Identity of A is proved by B’s being able to encrypt amessage with Ku

A.The fact of A’s sending a message is proved by theexistence of a message decrypted by Kr

A.B cannot forge having received a message from A becausehe cannot produce DKr

A(M).

Page 25: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Digest signatures: DSS

Alice’splaintextmessage

M

SHA-1algorithm H

ElGamalalgorithm

DKr

A(H)

Alice’s privatekey, Kr

A

SenttoBob

For efficiency reasons, public-key decryption is applied to ashort digest of the plaintext message.ElGamal public-key encryption/decryption algorithm is used.

Page 26: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Digest signature application

Alice Bob

Signaturealgorithm

Message

Messagedigest

Message

Messagedigest

Message

Messagedigest

Hashingalgorithm

Message

Messagedigest

Messagedigest

equal?

Transmit

Privatekey

Publickey

Publickey

Page 27: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Digest signature attack

Bob

Signaturealgorithm

Message

Messagedigest

Message

Messagedigest

Message

Messagedigest

Hashingalgorithm

Message

Messagedigest

Messagedigest

equal?

Transmit

Privatekey

Publickey

Publickey

Eve

Page 28: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Public key certificates

A certificate is a binding between an entity name and itspublic key.Certificates are issued by a “certification authority” (CA), atrusted third party.A certificate is generated locally on a computer.To grant a certificate its validity, a CA signes it with its privatekey.Since the CA’s public key is well known everybody can verifythe validity of a certificate.

Page 29: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

The structure of a X.509 certificate

Page 30: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Signature computation

The signature in the X.509 certificate is computed as:

CA<<A>>= K−CA[V, SN, AI, CA, TA, A, K+A ],

whereV : X.509 version

SN : certificate serial numberAI : Algorithm ID

CA : certificate authority nameTA : validity timespan of the certificateA : subject name

K+A : subject public key

Page 31: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Certificate chains

D

B

A C

F

E G

D

C

F

E G

H

If a client trusts a root CA, it uses a top-down trust chain toverify a target certificate:

D<<B>> B<<C>>

If a client trusts a local CA, e.g., G, is must traverse thecertificate hierarchy:

G<<F>> F<<D>> D<<B>> B<<C>>

Page 32: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Rogue certificate authority

An attacker obtains a legitimate (end)certificate GHe creates a rogue certificate H andsigns it with G as a CA

The use of certificates as CA isrestricted by the extension field’basicConstraints’

D

F

E G

H

Page 33: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Rogue certificate authority

An attacker obtains a legitimate (end)certificate GHe creates a rogue certificate H andsigns it with G as a CAThe use of certificates as CA isrestricted by the extension field’basicConstraints’

D

F

E G

H

Page 34: Introduction to Computer Security - uni-tuebingen.de · Introduction to Computer Security Hash Functions and Digital Signatures Pavel Laskov Wilhelm Schickard Institute for Computer

Summary

Integrity of data can be enforced by computing cryptografichash functions (one-way, collision-resistant).Authentication and non-repudiation objectives are attainedby digital signatures that combine public key cryptographywith secure hashing.Binding of digital signatures to entities is achieved by puttingthe relevant information in X.509 certificate issued by atrusted certification authority (CA).