introduction hashfunctions - cimatluis.dominguez/files/urosario-hash.pdf · agenda1...

28
Introduction Hash functions Luis J. Dominguez Perez CRYPTO-CO, Junio 29/Julio 1 de 2016 Luis Dominguez [email protected] Introduction 1/28 1 / 28

Upload: others

Post on 19-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

IntroductionHash functions

Luis J. Dominguez PerezCRYPTO-CO, Junio 29/Julio 1 de 2016

Luis Dominguez [email protected] Introduction 1/281/28

Page 2: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Agenda 1

One-way functions

Hash functions versus MAC functions

Hash functions

Construction

SHA

Luis Dominguez [email protected] Introduction 2/282/28

Page 3: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

One-way functions

DefinitionA function f() is a one-way function if:• y = f(x) is computationally easy, and,• x = f−1(y) is computationally impractical

xeasy−−−−−−−−−−−−−−−−−−−−−→ f(x)

xhard←−−−−−−−−−−−−−−−−−−−−− f(x)

Luis Dominguez [email protected] Introduction 3/283/28

Page 4: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

One-way functions: Examples

• Discrete Logarithm◦ Given x, a, y n, it is easy to compute y = xa mod n; however,

given y, x, y n, finding a is very hard

• Factorisation◦ Given x, and y, it’s easy to compute n = xy; however, given n,

finding the x, and y factors is very hard

• Discrete square root◦ Given x, and n, it’s easy to compute a = x2 mod n; however,

given a, and n, finding x is very hard.

Luis Dominguez [email protected] Introduction 4/284/28

Page 5: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Agenda 2

One-way functions

Hash functions versus MAC functions

Hash functions

Construction

SHA

Luis Dominguez [email protected] Introduction 5/285/28

Page 6: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Hash functions• Hash function◦ Generate fixed size fingerprint from an arbitrary size message◦ There are no involved keys◦ It most be one-way to be useful

• Applications◦ Hash with keys: MAC generation◦ Hash without keys: digital signatures, password files, key stram/

pseudorandom numbers, etc.

• Constructions◦ Iterative hash functions (family of functions MD-4): MD5, SHA-1,

SHA-2, HAVAL, HAS160, etc.◦ Block cipher-based hash functions: MDC (Manipulation Detection

Code)◦ Sponge hash functions, HAIFA, Merkel-Damgård, Conc-permute,

UBI, etc.

Luis Dominguez [email protected] Introduction 6/286/28

Page 7: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Message Authentication Code

• MAC◦ Generate a MAC of a fixed size given a random size message◦ It’s a hash function with key◦ Message origin is authenticated◦ Message integrity is verified◦ The entity is authenticated

• Constructions◦ Hash with key: HMAC◦ Based on encryptors: CBC-MAC◦ Parallelizables: P-MAC

Luis Dominguez [email protected] Introduction 7/287/28

Page 8: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Comparison between hash, and MAC functions

Tamaño arbitrario

mensaje

Función

Hash

hash

Tamaño fijo

Tamaño arbitrario

mensaje

Función

MAC

MAC

Tamaño fijo

• Easy to compute• Compression: random size to fixed size• Function without key versus with a key.

Luis Dominguez [email protected] Introduction 8/288/28

Page 9: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Message authentication using MAC

mensaje

Algoritmo

Llave

Secreta

MAC mensaje

Algoritmo

Llave

Secreta

MAC

K

MAC'

?

YES

NO

K

Luis Dominguez [email protected] Introduction 9/289/28

Page 10: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Digital signature with a hash function

mensaje

Algoritmo

Llave

Pública

Algoritmo

Llave

Pública

?

YES

NO

Función

Hash

hash

Función

Hash

hash

mensaje

Firmante Verificación

Firma

Luis Dominguez [email protected] Introduction 10/2810/28

Page 11: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

MAC, and digital signature

• MAC◦ Generated, and verified by a private key algorithm◦ Message origin authentication, and message integrity◦ Schemes:

• Based on keys: HMAC• Based on encryptors: CBC-MAC

• Digital Signature◦ Generated, and verifies by a private key algorithm◦ Message origin authentication, and message integrity◦ No-repudiation◦ Schemes:

• Hash + Digital signature Algorithm• RSA, DSA, etc. Signatures

Luis Dominguez [email protected] Introduction 11/2811/28

Page 12: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Agenda 3

One-way functions

Hash functions versus MAC functions

Hash functions

Construction

SHA

Luis Dominguez [email protected] Introduction 12/2812/28

Page 13: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Digest function

• Produce digital fingerprints of fixed length from random lengthdocuments

• A small variation in the original text provides a entirelydifferent digital fingerprint◦ Convert passwords to fixed length messages◦ They are used to generate random numbers◦ Provide basic authentication through the use of MACs (Message

autentication code)◦ Basic blocks for digital signatures.

Luis Dominguez [email protected] Introduction 13/2813/28

Page 14: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Digest function - black box

1010101

1010101

0101010

Función

picadilloResumen

n-bits c-bits

The hash function, or digital fingerprint recives a text of undefinedlength (normally, the message is completed with zeros untilmatching a size that can be broken in blocks of specific size), andthe output is of fixed length.

Luis Dominguez [email protected] Introduction 14/2814/28

Page 15: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Digest function - black box 2

Anita lava

la tinah

153ef8eab48

c093c53c27f

8db111701f

anita lava

la tinah

7269bdc195d

266c27154d3

15d2183e83

anita lava

la tinbh

1c5b70d3cd0

0af3aea26a4

7f72a11872

A cryptographically useful digest function provides totally differentdigests despite minimum changes.

Page 16: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Security requirements of the hash functions - 1• Pre-imagen resistance (one wayness)Given y, it’s computationally unpractical to find any x value,such that y = h(x)

x

h(x)

h

Luis Dominguez [email protected] Introduction 16/2816/28

Page 17: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Security requirements of the hash functions - 2

• Second Pre-imagen resistance (weak resistance to collisions)Given x, it’s computationally unpractical to fond anotherx′ ̸= x, such that h(x) = h(x′)

x1

h(x1)=h(x2)

h

x2=?

Luis Dominguez [email protected] Introduction 17/2817/28

Page 18: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Security requirements of the hash functions - 3• Collision resistance (strong resistance to collisions)It’s computationally unpractical to find two values x, and x suchthat h(x) = h(x′)

x1=?

h(x1)=h(x2)

h

x2=?

Besides being efficiently computable.Luis Dominguez [email protected] Introduction 18/28

18/28

Page 19: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Security requirements of the hash functions - 4

x

h(x)

h

x1

h(x1)=h(x2)

h

x2=? x1=?

h(x1)=h(x2)

h

x2=?

Luis Dominguez [email protected] Introduction 19/2819/28

Page 20: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Agenda 4

One-way functions

Hash functions versus MAC functions

Hash functions

Construction

SHA

Luis Dominguez [email protected] Introduction 20/2820/28

Page 21: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Function constructionMensaje m 10000...0 len

relleno y codificación de longitud

M1 M2 M3 Mt

f f fbn

bn

bn

IV=H0 H1 H2

f

g

bnHt-1

nHt

h(m)

• IV - Initial Vector/Value

• Hi - Chaining variable

• Mi - Input Block

• f - Compression function

• g - optional process

• t - Input Blocks

• b - Bits from Block

• n - Bits from Hash

Page 22: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Function construction - 2

Complete Hash function:• H0 = IV

• Hi = f(Hi−1, Mi)∀1 ≤ i ≤ t

• H(M) = h(Ht)

Luis Dominguez [email protected] Introduction 22/2822/28

Page 23: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

FillingAssuming a fixed length block of 512-bits:

Mensaje m 10000...0 len

Último bloque de 512 bits

64-bitsSea r=|m|mod 512Si 512-r > 64 pad=512-(r+64) bitselse pad=512-r+448 bits

Luis Dominguez [email protected] Introduction 23/2823/28

Page 24: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Agenda 5

One-way functions

Hash functions versus MAC functions

Hash functions

Construction

SHA

Luis Dominguez [email protected] Introduction 24/2824/28

Page 25: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Secure Hash Algorithm• SHA ws designed by the NIST (National Institute of Standardsand Technology), and the NSA (National Security Agency)

• This is the USA’s standard for the DSA (Digital SignatureAlgorithm)

• The algorithm name is SHA, whereas SHS is the standard’sname

• It’s based in MD4, and MD5◦ SHA-0, FIPS PUB 180, 1993◦ SHA-1, FIPS PUB 180-1, 1995

• message bit rotation• used by SSL/TLS, PGP, SSH, S/MIME, and IPSec.

◦ SHA-2, FIPS PUB 180-2, 2001• SHA-224, SHA-256, SHA-384, SHA-512• At the beginning, it wasn’t as popular as SHA-1• (took a while to be used widely)

Luis Dominguez [email protected] Introduction 25/2825/28

Page 26: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

SHA-1 Algorithm

1: Break the D-document in 512 bits blocks, filling with zeros ifnecessary

2: Set the initial h0 . . . h4 values3: loop4: Break one 512 bits block in sixteen 32-bits words.5: Generate eighty 32-bits words from this block6: for i← 0 . . . 79 do7: a← h0, b← h1, c← h2, d← h3, e← h48: Compute f using ⊕, ∧ sobre a, b, c, d, e.9: Mix a, b, c, d, e rotating some bits, by permutation, and add

f , and wi to a10: end forh0 ← h0 + a, h1 ← h1 + b, . . ., h4 ← h4 + e11: end loop12: return h0||h1||h2||h3||h4

Luis Dominguez [email protected] Introduction 26/2826/28

Page 27: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

Initial SHA-1 values• Initial values◦ A = 67452301◦ B = EFCDAB89◦ C = 98BADCFE◦ D = 10325476◦ E = C3D2E1F0

• Constants Kt

◦ t = 0 . . . 19 Kt = 5A827999◦ t = 20 . . . 39 Kt = 6ED9EBA1◦ t = 40 . . . 59 Kt = 8F1BBCDC◦ t = 60 . . . 79 Kt = CA62C1D6

• Boolean function ft

◦ t = 0 . . . 19 ft(B, C, D) = B · C + B̄ ·D◦ t = 20 . . . 39 ft(B, C, D) = B ⊕ C ⊕D◦ t = 40 . . . 59 ft(B, C, D) = B · C + B ·D + C ·D◦ t = 60 . . . 79 ft(B, C, D) = B ⊕ C ⊕D

Luis Dominguez [email protected] Introduction 27/2827/28

Page 28: Introduction Hashfunctions - CIMATluis.dominguez/files/urosario-hash.pdf · Agenda1 One-wayfunctions HashfunctionsversusMACfunctions Hashfunctions Construction SHA LuisDominguez luis.dominguez@cimat.mx

SHA-1 rounds

A B C D E

A B C D E

f

<<<5

<<<30Wt

Kt

Luis Dominguez [email protected] Introduction 28/2828/28