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

348 ratings

University of Maryland, College Park

348 ratings

Course 3 of 5 in the Specialization Cybersecurity

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 begin our treatment of number theory.

Â Now you might actually be surprised that until this point in the class we

Â haven't had to rely on or to learn any number theory.

Â And the reason you might find that surprising is because my impression is

Â that when people think about cryptography popularly,

Â the first thing that comes to their mind is exactly the number theory.

Â That's kind of the quote, un-quote sexy part of cryptography.

Â However as we've seen in this class so far number theory is not really needed for

Â a lot of important cryptographic applications.

Â And in particular, all of practical private key cryptography is based on

Â things like stream ciphers, block ciphers, and hash functions, that can be

Â constructed analyzed, and reasoned about, without any mention of any number theory.

Â And so I think the point here is that number theory, is, of course, going to be

Â needed, for public key cryptography, but it's not needed for all of cryptography.

Â There's a lot of interesting things you can do without any number theory at all.

Â Having said that of course, it turns out that some kind of

Â number theory does seem to be inherent for any sort of public cryptography.

Â Now we haven't talked about public-key world cryptography yet.

Â We won't talk about it until next week, but this is just sort of a primer for

Â what we're going to need in that setting.

Â The point of this week is to really cover the basics of number theory, very quickly.

Â That is, the goal here is not to give a survey of number theory.

Â It's certainly not to give a comprehensive course on number theory.

Â But only to present the bare minimum that we need for

Â the applications that we're going to study.

Â And for that reason I'm not going to focus particularly on the proofs of a lot of

Â un-underlying concepts and results unless I

Â think that the proof sheds some insight on understanding what's going on.

Â For those that were interested I can recommend several textbooks that can be

Â used to supplement the material and

Â in particular a lot of what we cover here with appropriate proofs.

Â And also some additional details is available in the Cat Lyndel text book.

Â What we're going to talk about in this lecture is algorithmic number theory.

Â And this is actually interesting because very often from a mathematical point of

Â view or from a mathematician's point of view I should say,

Â they're interested in the existence of numbers with certain properties, or

Â in proving that some number has a particular property.

Â But there are very often less interested in the algorithmic efficiency of

Â determining whether or not some number has a given property.

Â In our setting, the computer scientist setting where we're

Â going to ultimately be interested in implementing cryptography.

Â We do have to also take care to think about the algorithmic

Â complexity of determining various properties of numbers, and

Â of computing various interesting things about those numbers.

Â And ultimately, if you're interested in particular in implementing very

Â fast cryptography, a good understanding of

Â these kind of algorithmic considerations is very important.

Â Now one thing that's important to stress,

Â is that when we talk about the efficiency of number theoretic operations,

Â we're always going to be interested in asymptotic complexity, of course.

Â But the asymptotic complexity will be measured in

Â terms of the length of the input.

Â That's always true throughout computer science but

Â it's important to stress it here because it's very often easy to

Â get confused between the magnitude of an input and it's length.

Â And in particular if we have some input integer A then

Â the magnitude of A is itself.

Â If A is equal to 1000 then the magnitude of A is 1000.

Â But the length of that input,

Â the length of A, is the length of the binary representation of A.

Â And I'm going to denote that by these two vertical bars surrounding the integers.

Â So, it's sort of like an extended absolute value sign.

Â So we have these the length of A.

Â The binary representation of a, and

Â the binary representation of an integer is the log of the magnitude of the integer.

Â Right, the number of bits that you need in order to represent some number,

Â is the logarithm of that number's magnitude, and conversely,

Â the magnitude of a number is exponential in its length.

Â And again it's very easy to get these concepts confused when thinking about

Â algorithms but we're going to try very carefully to keep them separate.

Â Now in terms of our study of algorithmic number theory, we're not going to

Â dwell extensively on different algorithms for different computational problems.

Â There's a lot of interesting things to be done there, and as I said it is

Â very important when it comes to efficient implementation of cryptography.

Â But for our purposes what we only want to do, is to

Â be able to distinguish between problems that are easy and problems that are hard.

Â Where for us, easy means that it can be solved in polynomial time.

Â And hard, at least for

Â now, is going to mean that it can't be solved in polynomial time.

Â And so beyond making that kind of a very gross distinction we're not going to

Â be extremely interested in fine tuning the, algorithms that we give or

Â that we discuss, or, the problems we consider.

Â And again, there are several textbooks you can use to supplement the material.

Â Several references you can use if you're ever implementing cryptography and

Â want to find out about the most efficient algorithms for some problem.

Â Before I jump in, I want to just review some notation,

Â regarding modular arithmetic, some of which is a bit idiosyncratic.

Â By a bracket a mod N,

Â I'm going to mean the remainder of the integer a when divided by the integer N.

Â So this means you just take, a divided by N.

Â You compute some quotient, which here we don't care about.

Â And you take the remainder.

Â And note, of course, that bracket A mod N,

Â has to lie strictly between 0 and N minus 1.

Â I want to contrast that with the more standard notation that you might be

Â familiar with, namely that A ie equal to B mod N.

Â So A being equal to B mod N means exactly that A and

Â B have the same remainder modulo N.

Â But, the point is that the notation on the left,

Â A equals B mod N, is different from the notation a mod N inside the brackets.

Â Because again, A equals B mod N is expressing something about

Â the relationship between two integers.

Â And A mod N inside the brackets refers to a specific integer in the range of

Â 0 to N minus1, which is the remainder of A when divided by N.

Â Okay. [SOUND] So

Â let's jump in with a our discussion of algori, algorithmic number

Â theory by just briefly noting some basic facts about what can be done efficiently.

Â So if we look at different standard arithmetic operations,

Â we can see that their's actually can be done efficiently.

Â So integer addition for

Â example, can be done efficiently using the standard grade school algorithm.

Â And if you think about how that works, you'll see that it runs in time,

Â essentially linear, in the length of the inputs and the same for subtraction.

Â Multiplication can also be done using a grade school algorithm.

Â The running time now is quadratic rather than liner.

Â And I'll mention that better algorithms are known, but, again, for

Â our purposes, we're just going to be happy with the grade school algorithm because it

Â does run in polynomial time.

Â A little bit more difficult to see, but perhaps not very surprising,

Â is that division with remainder, can be done efficiently.

Â And this in particular means that we can compute bracket A mod N

Â efficiently by just performing the divisions and taking the remainder.

Â For that reason similarly, we can do modular addition,

Â subtraction, multiplication, and reduction efficiently as well.

Â So for example, modular multiplication, would just mean that we have two integers.

Â We want to compute their product, modulus if any N, modulus N if any.

Â [COUGH] And what we can do there is to simply perform the multiplication over

Â the integers and then reduce mod N.

Â And because of those component operations can be

Â done efficiently we know that the entire computation can be done efficiently.

Â What about a more complicated operation, in particular, modular exponentiation?

Â And I focus here on modular exponentiation really for two reasons.

Â First is that it's an important computation that's going to be

Â used all the time in cryptography, and second,

Â because I think it gives a very good illustration of a non trivial algorithm.

Â That is one where the naive algorithm as we'll see does not run in polynomial time,

Â but with a little bit of cleverness you can come up with an algorithm that

Â does run in polynomial time.

Â So lets look at the problem of exponentiation.

Â First of all think about exponentiation over the integers.

Â So here's there's no modular reduction.

Â Let's say we want to compute A to the B, all right, the integer A to the Bth power.

Â Well, let's first consider the size of the result.

Â So the number of bits that we need to specify the result,

Â A to the B, is going to be the order of the logarithm of that,

Â which is the order of the magnitude of B, times the length of A.

Â And what you can see, here, is just writing down the answer

Â can require exponential time, exponential in B, that is.

Â Because the running time, sorry the, the number of bits we need to specify

Â the answer, is going to be linear in the magnitude of B, rather than length of B.

Â So we don't really have any hope of computing integer exponentiation in

Â polynomial time.

Â Fortunately in cryptography we never need to compute integer exponentiation,

Â what we do need instead is modular exponentiation, where we're interested in

Â computing the result of A to the B modulo sum, given modulus N.

Â And note here we don't run into the problem we had before,

Â because the size of the answer here is going to have to be at most the size of N,

Â because the answer has to lie in the interval 0 to N minus 1.

Â So how do we do it?

Â Well the first thing to observe is that a strategy that will not work.

Â If the compute a to the b over the integers.

Â And then reduce the result mod N.

Â That won't work because as we just noted, the the length of the intermediate result,

Â A to the B over the integers cannot even be written down in polynomial space.

Â So, that's not the approach we're going to want to use.

Â Let's consider a, maybe a naive algorithm that we would want to use for

Â computing modular exponentiation.

Â So here, I'm just writing a simple function that takes three arguments, A, B,

Â and N and is meant to compute the result, A to the B, mod N.

Â And we'll assume that B is greater than or equal to 0.

Â We won't worry about negative exponents, for now.

Â They can be handled but it's not important for our purposes.

Â So one natural approach is to just start off with a variable called ans that's

Â going to hold the answer, initialize that to 1.

Â And then for I ranging from 1 to B, what we'll do is we'll simply multiply

Â the current value of the answer by A and then reduce mod N.

Â So this of course is not valid C code.

Â This is meant to just be pseudo code.

Â But what I've indicated here is that we just multiply a into the current answer

Â and then increment B.

Â And we're going to avoid the problem that we had on the previous slide.

Â Of first computing A to the B and then reducing modular N.

Â Because you'll notice here that we're reducing modular N at every step.

Â So every time we multiply, we're going to then reduce.

Â And so the value of Ns at any point during the computation,

Â is going to be strictly in the range of 0 to N minus 1.

Â So we do this for a total of B iterations of the loop, and

Â then we return the answer.

Â This will indeed give the right result, but

Â what's the running time of the algorithm?

Â Well, it's easy to see here that the inner loop is going to be running for

Â a total of B times.

Â And that is not, efficient.

Â That is not polynomial time.

Â Because we would like an algorithm that runs in time polynomial in the length of B

Â not in the magnitude of B.

Â And again here we have a loop running for a number of steps linear in

Â the magnitude of B, so this is not going to qualify as an efficient algorithm.

Â What kind of approach could we use to get a more efficient algorithm,

Â to get in particular a polynomial kind of algorithm?

Â Well it's easiest to think about the problem if we assume for

Â simplicity that B is a power of 2.

Â So let's say that B equals 2 to the K for some integer K.

Â If you kind of unwrap the proceeding algorithm or

Â maybe just view it in a different way.

Â You can see that the preceding algorithm roughly corresponds to

Â performing B multiplications of A.

Â That is, to computing A times A, times A again, times A again, et cetera, for

Â A total of 2 to the K minus 1 multiplications.

Â But a better way to do the computation.

Â Would be to first square A, right to just compute A times A,

Â take that result and square it again.

Â Take that and square that, and keep going until you've done a total of K squarings.

Â Or K minus 1 squarings I guess.

Â So, that would give a much better algorithm.

Â Then the former one because we have k

Â squarings versus two to the k minus one multiplications.

Â And again, the important thing to note here is that k is order of log of B,

Â which means that K is order of the length of B.

Â So what we have here in the second case is an algorithm that's running in

Â time linear, in the length of B.

Â So of course this only works when B is a power of two.

Â But as we'll see in the next slide we can modify this approach even when B

Â is not a power of 2.

Â So here is the algorithm.

Â So again we're going to have an algorithm taking as input A, B, and N.

Â And we're going to again assume that B is greater than or equal to 0.

Â What we'll do here is to initialize two variables.

Â One called X and one called T.

Â We'll initialize X to a and T to 1.

Â And then while B is greater than 0 we do the following.

Â So first of all we check if B is odd.

Â If B is odd we then compute a within a set T equal to T times X mod N.

Â And we reduce B by 1.

Â Then we compute X equals X squared And B is equal to B divided by 2.

Â So note that in this point the algorithm must be even because if it

Â were odd at the beginning of the loop then in the previous step we checked that it

Â was odd and so we subtracted 1.

Â We keep doing this as long as B is greater than 0, and then finally return t.

Â Now it's a bit difficult, perhaps, to be convinced that this is working.

Â But you can prove that the algorithm works by looking at, or

Â by showing that the algorithm satisfies the following invariant.

Â And the invariant is, that the answer, the correct answer that you're looking for

Â is always equal to T times X to the B amount N.

Â And that's certainly true at the beginning of the algorithm when we

Â initialized the variables because then X is equal to A and T is equal to 1.

Â And indeed A to the B amount N is exactly the answer we're looking for.

Â And then you can check throughout the loop.

Â That if B is even for example,

Â then what we end up doing is squaring the value of X and reducing B in half.

Â And so X to the b mod N, or t times x to the b mod N,

Â is of course equal to T to the X squared, to the B over 2 mod N.

Â Just algebra.

Â And similarly, if B is odd, we then shift a factor of X into T, and reduce B by 1.

Â And you can write down on paper and easily verify that the invariant is satisfied.

Â At the end of the algorithm, B is equal to 0, and

Â so the correct answer is given by exactly T.

Â And T is a value that we return.

Â What's the running time here?

Â Well the important thing to note is that in every execution of the inner loop.

Â The value of B is decreased by at least half.

Â And that means that the number of iterations of the inner loop is going to

Â be 0 of log B, which is linear in the length of B.

Â In each iteration of the inner loop,

Â we perform some computation that can be done in time polynomial, in, A, B and N.

Â And so without getting into too much of a fine grained analysis we can see that

Â the overall running time of the algorithm is indeed polynomial in the length

Â of it's three inputs.

Â In the next lecture we'll spend some more time on modular arithmetic.

Â And we'll also introduce the very important notion of an abstract group

Â that will allow us to think in a more clean away about various of

Â the manipulations that we're going to be doing and

Â that we're going to use for crypt, for cryptography.

Â See you next time.

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