We'll get into both the mathematics and the practice
of implementing systems using cryptography,
but there's one thing I want to really emphasize,
and make sure that you understand.
Implementing your own cryptography is very challenging,
it's something that is very easy to do incorrectly.
One example of that to keep in mind--
and this is an important thing--
so we often think about programs as black boxes
with inputs and outputs,
and our encryption functions will usually take a key in a message
and produce some ciphertext,
and the implementations we'll show in this class
will be functionally correct,
they'll produce the correct outputs.
They won't be secure,
and the reason they won't be secure is
things aren't really black boxes when we use them.
There's lots of other things that someone
could observe about this.
They could observe how long it takes.
And when you can observe properties
of a function--other than their functional behavior--
other than just their inputs and outputs--
that's called a side channel.
An example of a side channel is timing.
So, the time it takes to run this function could vary,
it could depend on the message or the key.
Most of the code that we're going to write in this class
will have that property.
We're not going to be adding complexity
to our code to worry about things like side channels,
but in terms of implementing things correctly,
that's really important,
and there are lots of ways that code could have side channels.
It could affect what's in the cache of the processor,
and that could be visible in some way,
it could actually affect how much power
your processor uses,
and people have shown ways to break smart cards
by measuring the power consumption as they do encryption
and that gives you some insight into what the key is.
So, this is just an example of the kinds of things
that it's very hard to get right in implementing cryptography.
These are things that, if you were building cryptography
for any important use, you'd have to worry about.
These are things that we are not going to worry about
in most of the code that we write in this class
so you shouldn't view these implementations as secure implementations.
The only reason to implement your own crypto
is for fun and learning.
And that's what we hope you'll get from this class by doing it,
but if you actually want to use cryptography
to protect anything important, well--
you should use a library implementation
that's been carefully vetted,
that's been written in a way to worry about
these kinds of issues like timing side channels,
and that other people have looked at
carefully enough to have some higher level of confidence
that it's correct and secure.
So I want to make sure everyone was paying careful attention
to that last point,
and we'll have a quiz:
Should you use any code from this course
to protect nuclear launch codes?
The answers are no--check the correct answer.