Presentation on theme: "Hashes and Message Digests"— Presentation transcript:
1Hashes and Message Digests Nick Feamster CS 6262: Network Security Spring 2009
2Hashes Hash is also called message digest One-way function: d=h(m) but no h’(d)=mCannot find the message given a digestCannot find m1, m2, where d1=d2Arbitrary-length message to fixed-length digestRandomnessany bit in the outputs ‘1’ half the timeeach output: 50% ‘1’ bits
3Hash Algorithm Structure Most important modern hash functions follow the basic structure shown in this figure, Stallings Figure This has proved to be a fundamentally sound structure, and newer designs simply refine the structure and add to the hash code length. Within this basic structure, two approaches have been followed in the design of the compression function, as mentioned previously, which is the basic building block of the hash function.
4Hash and MAC Algorithms Hash Functionscondense arbitrary size message to fixed sizeby processing message in blocksthrough some compression functioneither custom or block cipher basedMessage Authentication Code (MAC)fixed sized authenticator for some messageto provide authentication for messageby using block cipher mode or hash functionNow look at important examples of both secure hash functions and message authentication codes (MACs).Traditionally, most hash functions that have achieved widespread use rely on a compression function specifically designed for the hash function. Another approach is to use a symmetric block cipher as the compression function.MACs also fall into two categories: some use a hash algorithm such as SHA as the core of the MAC algorithm, others use a symmetric block cipher in a cipher block chaining mode.
5Secure Hash Algorithm SHA originally designed by NIST & NSA in 1993 was revised in 1995 as SHA-1US standard for use with DSA signature schemestandard is FIPS , also Internet RFC3174nb. the algorithm is SHA, the standard is SHSbased on design of MD4 with key differencesproduces 160-bit hash valuesrecent 2005 results on security of SHA-1 have raised concerns on its use in future applicationsThe Secure Hash Algorithm (SHA) was developed by the National Institute of Standards and Technology (NIST) and published as a federal information processing standard (FIPS 180) in 1993; a revised version was issued as FIPS in 1995 and is generally referred to as SHA-1. The actual standards document is entitled Secure Hash Standard. SHA is based on the hash function MD4 and its design closely models MD4. SHA-1 produces a hash value of 160 bits. In 2005, a research team described an attack in which two separate messages could be found that deliver the same SHA-1 hash using 2^69 operations, far fewer than the 2^80 operations previously thought needed to find a collision with an SHA-1 hash [WANG05]. This result should hasten the transition to newer, longer versions of SHA.
6Revised Secure Hash Standard NIST issued revision FIPS in 2002adds 3 additional versions of SHASHA-256, SHA-384, SHA-512designed for compatibility with increased security provided by the AES cipherstructure & detail is similar to SHA-1hence analysis should be similarbut security levels are rather higherIn 2002, NIST produced a revised version of the standard, FIPS 180-2, that defined three new versions of SHA, with hash value lengths of 256, 384, and 512 bits, known as SHA-256, SHA-384, and SHA-512. These new versions have the same underlying structure and use the same types of modular arithmetic and logical binary operations as SHA-1, hence analyses should be similar. In 2005, NIST announced the intention to phase out approval of SHA-1 and move to a reliance on the other SHA versions by See Stallings Table12.1 for comparative details of these algorithms.
7Collisions: Birthday Paradox Compute probability of different birthdaysRandom sample of n people (birthdays) taken from k (365) dayskn samples with replacement(k)n=k(k-1)…(k-n+1) sample without replacementProbability of no repetition:p = (k)n/kn 1 - n(n-1)/2k
8How Many Bits for Hash?m bits, takes 2m/2 to find two with the same hash64 bits, takes 232 messages to search (doable)Need at least 128 bits
9Application: Authentication Alice to Bob: challenge rABob to Alice: MD(KAB|rA)Bob to Alice: rBAlice to Bob: MD(KAB|rB)Only need to compare MD results
10Application: MAC Cannot just compute MD(m) MD(KAB|m) Allows concatenation with additional message: MD(KAB|m|m’)MD through chunk n depends on MD through chunks n-1 and the data in chunk nProblem: Arbitrary messages can be concatenated to the originalSolution: Put secret at the end of message:MD(m| KAB)
11Application: Encryption One-time padcompute bit streams using MD, K, and IVb1=MD(KAB|IV), bi=MD(KAB|bi-1), … with message blocksOr mixing in the plaintextsimilar to cipher feedback mode (CFB)b1=MD(KAB|IV), c1= p1 b1b2=MD(KAB| c1), c2= p2 b2
12Application: Secret Key Input Unix password algorithmCompute hash of user password, store the hash (not the password), and compare the hash of user-input password.First 8 bytes of password used to form a secret key.Encrypt 0 with a DES-like algorithm (why not use a “system” key to encrypt the password?).Salt12-bit random number formed from time and process ID.Determine bits to duplicate in the mangler when expanding from 32 to 48 bits.Salt stored with hashed result.
13MD2 128-bit message digest Arbitrary number of bytes of message First pad to multiple of 16 bytesAppend MD2 checksum (16 bytes) to the endThe checksum is almost a MD, but not cryptographically secure by itself.Process whole message
14MD2 Checksum One byte at a time, k 16 steps mnk: byte nk of message cn=(mnk cn-1) cn : 0 41, 1 46, …Substitution on (value of the byte)
15MD2 Final Pass Operate on 16-byte chunks 48-byte quantity q: (current digest|chunk|digestchunk)18 passes of massaging over q,one byte at a time:cn=(cn-1) cn for n = 0, … 47; c-1 = 0 for pass 0; c-1 = (c47 + pass #) mod 256After pass 17, use first 16 bytes as new digest16 8 = 128
16MD5: Message Digest Version 5 input MessageOutput 128 bits Digest
17MD5 Box 512-bit message chunks (16 words) Initial F: (xy)(~x z) 128-bit vectorF: (xy)(~x z)G:(x z) (y ~ z)H:xy zI: y(x ~z)+: binary sumxy: x left rotate y bits128-bit result
18MD5: Padding 1 2 3 4 input Message 512 bit block Padding Initial Value Transformation block by blockFinal OutputOutput 128 bits Digest
19Padding TwistGiven original message M, add padding bits “1000…” such that resulting length is 64 bits less than a multiple of 512 bits.Append (original length in bits mod 264), represented in 64 bits to the padded messageFinal message is chopped 512 bits a block
20MD5 ProcessAs many stages as the number of 512-bit blocks in the final padded messageDigest: 4 32-bit words: MD=A|B|C|DEvery message block contains bit words: m0|m1|m2…|m15Digest MD0 initialized to: A= ,B=89abcdef,C=fedcba98, D=Every stage consists of 4 passes over the message block, each modifying MD
28Basic Steps...Step 4: the 80-step processing of 512-bit blocks – 4 rounds, 20 steps each.Each step t (0 <= t <= 79):Input:Wt – a 32-bit word from the messageKt – a constant.ABCDE: current MD.Output:ABCDE: new MD.
31Basic Logic Functions Only 3 different functions Round Function ft(B,C,D)0 <=t<= 19 (BC)(~B D)20<=t<=39 BCD40<=t<=59 (BC)(BD)(CD)60<=t<=79 BCD
32Twist With Wt’sAdditional mixing used with input message 512-bit blockW0|W1|…|W15 = m0|m1|m2…|m15For 15 < t <80:Wt = Wt-16 Wt-14 Wt-8 Wt-3XOR is a very efficient operation, but with multilevel shifting, it should produce very extensive and random mixing!
33SHA Versus MD5 SHA is a stronger algorithm: Brute-force birthday attacks requires on the order of 280 operations vs. 264 for MD5SHA’s 80 steps and 160-bit hash (vs. 128) requires a little more computation