Dominik Farhan

Hash functions

function h:{0,1}{0,1}bh:\{0,1\}^* \rightarrow \{0,1\}^b, ideally indistinguishable from a random function.

Merkle-Damgard construction

compression function f:{0,1}b×{0,1}b{0,1}bf:\{0,1\}^b\times\{0,1\}^b \rightarrow \{0,1\}^b.

Now we have the following structure:

MD structure, Davidgothberg, Public domain, via Wikimedia Commons

if ff is collision-resistant then hh is collision-resistant.

proof

h(x1,,xn)=h(x1,,xn)h(x_1,\dots,x_n) = h(x_1, \dots, x_{n'})

length-extension: this is why it’s different from random function. Knowing the hash of a prefix helps us construct the hash of the whole message.


Length-extension property in practice, board from the 6th lecture, by Martin Mareš, http://mj.ucw.cz/vyuka/2021/kry/.

Attacks on hash functions

A nice presentation on various attacks.

For even more info I recommend Martin Mareš's notes or boards.

Davies-Meyer construction from a block cipher

Use block cipher to create compression function as f(x,y)=Ey(x)yf(x,y) = E_y(x) \oplus y XOR is needed otherwise we could get f(x,y)=Ey(x)=Ez(Dz(Ey(x)))=f(z,Dz(Ey(x)))f(x,y) = E_y(x) = E_z(D_z(E_y(x))) = f(z, D_z(E_y(x)))

Also, note that using this construction with arbitrary cipher is dangerous. For example, DES’s complementarity property makes creating collisions easy.

MD5 (Rivest)

The result has 128128b, due to birthday paradox the security level is 6464b which is weak.

Since 2004 we are able to produce collisions easily but it is not yet invertible.

The structure is Merkle-Damgard.

SHA-1 (NSA)

160160b output.

The structure is Merkle-Damgard.

We can produce collisions but it is not that easy (Google was needed to do it).

SHA-2 (NSA)

family of functions. Similar to SHA-1 but stronger and slower. No serious weaknesses were found at the time of writing this.

SHA-224224, 256256, 384384, 512512.

SHA-3 (NIST competition)

family of functions

Sponge construction


Sponge construction, http://sponge.noekeon.org/, CC BY 3.0, via Wikimedia Commons

security level is min(r/2,c/2)min(r/2, c/2) due to the inner collision attack.

inner collision attack

you feed in zeros and wait till the “lower” (capacity) part repeats (2c/22^{c/2} steps needed). This gives us messages when one is a prefix of the other. The last block of the longer message si then set so that the “upper” (rate) part is the same as the “upper” part for the prefix message.

based on Keccak 16001600 bit permutation.

SHA-3

SHAKE can be used as PRNG

Merkle trees

A convenient way to hash databases or anything where some part of the data changes often.

The structure of the tree must be hashed to output, otherwise, some extension or truncation attacks are possible.

Message Authentication Codes (MACs)

functions to generate and verify signatures.

Security

can be defined like this: the attacker possesses a signing oracle and wants to produce a correct signature on a message that was not presented to the oracle

HMAC

today pretty much THE way to do MACs.

h(x)=h(akh(bkx))h(x) = h(a \oplus k || h(b \oplus k || x))

basically three keys but a,ba, b are some fixed constants.

Combining with encryption

MAC and encrypt

MACs are the same for the same messages no matter what we do in encryption, horrible.

MAC then encrypt

used to be believed to be the best but there are a lot of padding oracle attacks. Some workarounds use stream cipher to avoid timing attacks.

Encrypt then MAC

The best approach today.

CBCMac

The last block is used as a signature. Needs a fixed IV, otherwise one could flip bits in the first block of the cipher. Not very popular.

This construction is secure when the cipher is ideal and the message length is fixed.

Also, we can’t use the same key for MAC and encryption.

Using CBCMac and CBC encryption with the same key is a lot of fun.

Shanon-secure MACs

Given a known pair of x and sign(x) all signatures of x’ different from x are equally probable for a random key.

one-time key

requires keys 22 times the size of the message, so unusable in practice.

2-independence

H={hkkK}\mathbb{H} = \{h_k| k\in \mathbb{K}\} x1,x2X,x1x2,y1,y2Y:Pr[h(x1)=y1&h(x2)=y2]=1Y2\forall x_1, x_2 \in X, x_1\neq x_2, y_1, y_2\in Y: Pr[h(x_1) = y_1 \& h(x_2) = y_2] = \frac{1}{|Y|^2}
Shanon security with MACs, board from the 7th lecture, by Martin Mareš, http://mj.ucw.cz/vyuka/2021/kry/.

GCM and Poly1305

A nice Youtube video.