This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

Loading...

From the course by University of Maryland, College Park

Cryptography

417 ratings

This course will introduce you to the foundations of modern cryptography, with an eye toward practical applications.

- Jonathan KatzProfessor, University of Maryland, and Director, Maryland Cybersecurity Center

Maryland Cybersecurity Center

[SOUND].

Â In this lecture, we're going to take a brief detour from the topic of method

Â authentication, to study the important cryptographic primitive of hash functions.

Â Very roughly speaking, a Cryptographic hash function is a function that

Â maps arbitrary length inputs to short, fixed-length outputs.

Â And the output of a hash function is very often called a digest.

Â It turns out that you can consider two classes of hash functions.

Â Either functions that are keyed or functions that are unkeyed.

Â Formally speaking, it turns out that to meaningfully define security

Â properties keyed hash functions are needed.

Â But, in this lecture and throughout the course we're going to be

Â a little bit informal and work with unkeyed hash functions instead.

Â And the reason for doing that is that in practice,

Â hash functions that are used are in fact unkeyed.

Â And so it's easier just to stick to the case of unkeyed hash functions.

Â Let H be a hash function.

Â So again that means that it takes arbitrary length inputs.

Â Here denoted by 0,1*, and

Â produces some fixed-length output, here an output of length and bits.

Â A collision in H is a pair of distinct inputs, x and

Â x prime, whose digests are equal.

Â That is for which H of x is equal to H of x prime.

Â And we'll say that hash function H is collision resistant if it's

Â infeasible to find a collision in H.

Â Now if we give, if we given some hash function H,

Â what's the best generic collision attack that we can have?

Â And this is important because we'd like to understand what value we need for

Â the hash-function output length n.

Â Well, one thing we can observe, is that if we simply compute H of x1, H of x2,

Â H of x3, all the way up to H of x2 n plus 1, for

Â 2 n plus 1, 2 to the n plus 1, distinct inputs.

Â Then we're guaranteed to find a collision.

Â Right, the output length of the hash function is only n bits.

Â That means that there are 2 to the n possible outputs of the hash function.

Â If we evaluate the hash function on 2 to the n plus 1 inputs,

Â then there must be some pair of inputs,

Â that are distinct by construction, which have the same hash value.

Â And so we're guaranteed to find a collision.

Â Is it possible to do better?

Â Well it turns out that it's possible to do much better.

Â And this is, by using a form of attack called a Birthday attack,

Â for a reason we'll explain in a moment.

Â So what you do in this case, for this generic attack,

Â is simply evaluate your hash function H, on 2 to the n over 2, distinct inputs.

Â Now if we do that, what's the probability of a collision?

Â Well now, you're not guaranteed to find a collision, when it could be the case,

Â that all of the hash values you've just computed, turn out to be distinct.

Â But we might hope that with some high probability,

Â we find two inputs that map to the same output.

Â And the probability with which that happens is related to the so

Â called birthday paradox.

Â In the birthday paradox, we ask how many people do we need,

Â in order to have a 50% chance, that some two people share a birthday.

Â And if you haven't seen this before it's worth stopping a moment to think about it.

Â And just to take a a guess or an estimate, as to how many people you think you need,

Â to have in a room or in a group of people say.

Â Such that with at least half probability, some pair of people in that room,

Â share a common birthday.

Â We can analyze both of these problems, by looking at the following balls and

Â bins experiment.

Â So here we have a bunch of bins, and

Â we're going to start throwing balls randomly into these bins.

Â This may look odd if you haven't seen this before, but

Â this is a scenario that's commonly encountered when discussing probability,

Â and when analyzing certain events.

Â Anyway for now let's just imagine we have a bunch of bins and

Â we're going to throw a bunch of balls in those bins.

Â And when we throw a ball, it lands in a uniform bin.

Â The number of bins, we'll denote by capital N.

Â And as I said we start throwing balls into bins.

Â So we throw the first ball, it happens to land into the third bin.

Â We throw the next ball it lands into the second to last bin and so on.

Â And, let's say we keep on doing this.

Â And here, we've managed to get two balls, in the same bin.

Â And if we fix some value for the number of balls, we can ask,

Â well what's the probability that we end up with two balls in the same bin?

Â And I claim that this is related to the two problems we've discussed on

Â the previous slide.

Â If we let the bins denote days of the year, and so we imagine that

Â there are 365 different bins, and we let the balls correspond to people.

Â And imagine that if we pick a random person,

Â their birthday will fall on a random day between January 1st and December 31st.

Â Then the probability with which two people in a room have the same birthday,

Â the probability with,

Â with which they share a birthday, corresponds exactly to the probability.

Â That when we throw a certain number of balls into these 365 bins,

Â that two of the balls end up in the same bin.

Â Turning to the question of hash functions, now we can let the number of bins be 2

Â to the little n, the number of possible outputs of our hash function.

Â And we can let the balls, denote computations of our hash function.

Â Or more precisely,

Â the output value that we obtain, when evaluating the function on some input.

Â And here we're going to make the heuristic assumption,

Â that we can model the hash function as a random function.

Â It turns out that if you don't like that assumption then actually that's

Â the worst case in terms of analyzing the time to collision.

Â And any deviation from random will only,

Â will only make it easier to find collisions.

Â But nevertheless in our analysis we're going to model the hash function as

Â choosing a random output for every input, for every distinct input you feed it.

Â And so again, the question of how many times we

Â have to evaluate the hash function in order to find a collision,

Â comes down to an analysis on this simple balls and bins experiment.

Â And the question we have is how many balls do we need,

Â in order to have a 50% chance of a collision?

Â Well, it turns out that it's possible to prove the following.

Â When the number above is about n to the one half the square root of n,

Â the probability of a collision is about 50%.

Â What that means is that if we look at the birthday problem,

Â then having 23 people in the room, suffice us to give a 50-50 probability that

Â some pair of people in that room will share a birthday.

Â And this is called a paradox, not because it's actually any paradox, but

Â because the number is much smaller than most people typically expect.

Â Turning to hash functions, this means that if we evaluate the hash function,

Â about 2 to the n over 2 times.

Â Which is the square root of the size of the range of the hash function,

Â which was 2 to the n.

Â Then we expect to find some pair of inputs, that hash to the same output.

Â That is we expect to find a collision with about 50% probability.

Â Now this is much better than what we had before in the trivial attack where we

Â simply evaluate h on 2 to the n plus 1 inputs.

Â We're doing here much better it's a little hard to see because we,

Â the, we're only dividing by half but that value is in the exponent.

Â And so this makes actually a significant difference in terms of

Â the time required to find a hash function collision.

Â Now what this tells us in terms of security, is that if we

Â want security against attackers, running in time, about 2 to the n,

Â then we need the output length of our hash function to be about 2n bits long.

Â So that is if we want, for example, security or

Â collision resistance against attackers running for about 2 to the 80 steps.

Â Then we need to take the output length of our hash func,

Â of our hash function to be about twice times 80, or 160 bits long.

Â And importantly, this is twice the length, that we needed for block cypher keys.

Â So if we want a block cipher to defend against brute force attacks,

Â running in time 2 to the 80.

Â We can use block cipher keys that are exactly 80 bits long.

Â And if there's no better, and there's no better attack,

Â generically speaking, than just trying every key one by one.

Â So that means that if we have an 80 bit block cipher key,

Â we get about 2 to the 80 security, if the block cipher is optimally secured.

Â On the other hand for a hash function,

Â we need the output length of the hash function to be twice that, or 160 bits.

Â And only then do we have a hope of getting security against 2 to the 80

Â time attackers.

Â Of course if there's a weakness in the hash function,

Â then it won't be as secure as we would like it to be.

Â The 160 bits is a lower bound on the length of the hash function output that we

Â need, in order to get the security that we want.

Â In practice, there are a few hash functions you

Â need to be aware of that are very commonly encountered.

Â MD5 was a hash function developed in 1991, and it has a 128-bit output length.

Â The output length alone would be considered too short, for

Â modern day security applications.

Â But independent of that it turns out that MD5 is no longer secure at all.

Â Collisions in MD5 were found in 2004.

Â And since then the time required to find collisions,

Â has only gotten better and better,

Â to the point where now it's possible to find collisions in a number of minutes.

Â And so MD5 should no longer be used.

Â I mention it here only because it does still appear from time to time in legacy

Â code, and you need to be aware of what it is and the fact that it's out there.

Â But you should not be using it in new code that you write.

Â SHA-1, is a standardized hash function introduced in 1995.

Â SHA-1 has a 160-bit output length, and so

Â ideally we can hope that it provides about 80-bit security.

Â Very recently, theoretical analyses have indicated some weaknesses in SHA-1.

Â And although currently no collision attacks on SHA-1 are known,

Â because of these theoretical weaknesses that have been discovered,

Â people have begun migrating away from SHA-1.

Â So even though SHA-1 is still quite common, and

Â you'll find it in lots of code out on the Internet.

Â The tendency nowadays is to begin moving away from SHA-1 toward more recently,

Â more recent hash functions and stronger hash functions.

Â Like SHA-2 and other hash functions we'll talk about next.

Â SHA-2 is in the same design family as SHA-1,

Â and it's also a hash function that's been standardized.

Â And it's available in either 256-bit or 512-bit output lengths.

Â So these already are offering more security than SHA-1 if you

Â assume that they're giving you collision resistance up to the optimal bound.

Â Very importantly, no known weaknesses are, are currently present in SHA-2.

Â And so for that reason,

Â it's generally believed to be safe to use SHA-2 instead of SHA-1, which as

Â we mentioned before had some theoretical weaknesses that have been discovered.

Â So as we were saying a moment ago, many people have begun migrating away from shy,

Â from SHA-1 and replacing usage of SHA-1 with SHA-2.

Â In the last year ,SHA-3 has been introduced.

Â This was a result of a public competition run from 2008 to 2, 2,

Â to 2012, which was run very much the way that the competition for

Â the advanced encryption standard was run.

Â So anybody in the world was allowed to submit a candidate.

Â There was a public selection process in which people would try to attack

Â submissions by different teams.

Â And eventually a winner was chosen by Nist.

Â And standardized as the next generation SHA that is, SHA-3.

Â The name of the submission was Keccak, and so

Â you often hear people refer to it by that name as well.

Â One thing interesting about Keccak,

Â is that its design was very different from the SHA family.

Â In fact, it's different both from MD-5, as well as from SHA-1 and SHA-2.

Â And this was actually a conscious decision on the part of Nist,

Â because they were trying to get a hash function that was constructed in

Â a very different way from the SHA family.

Â So that in case any weaknesses where ever discovered in the future,

Â in the way that SHA was designed,

Â the hope would be that those weaknesses would not be present in Keccak as well.

Â Keccak supports a variety of output lengths ranging from 224 bits to 512 bits,

Â and people can choose which output length they prefer for

Â their particular application.

Â So in this lecture we've

Â just explored a little bit about cryptographic hash functions.

Â And in the next lecture we'll come back to our topic of message authentication, and

Â see how it's possible to use collision resistant hash functions,

Â to obtain message authentication for long messages.

Â Coursera provides universal access to the worldâ€™s best education,
partnering with top universities and organizations to offer courses online.