- In this lesson, lesson 4.3
we're gonna talk about hashing and digital signatures.
Now, the objective of hashing is to prove integrity, right?
We wanna prove
that a message has not changed in transmission.
And the way it works is
that the hashing process produces a visual representation
of a data set that can be used for comparative purposes.
Now, that output, that visual representation
has lots of different names.
Sometimes it's known as a hash,
sometimes it's known as a message digest.
Sometimes it's known as a fingerprint.
Sometimes it's referred to as the hash value.
Now, hashing can be used to validate
that the message wasn't changed in transmission.
It can be used to verify that a file has not been altered
and it can be used to verify
that a forensic clone is the exact same
as the original media.
But in all cases
what we're trying to do is prove integrity right?
That the message
or the data set or the file has not changed.
So let's talk through the hashing process.
We take a variable length input.
We can take anything from three words, two words,
one word to a full novel.
It's a variable length input and we're going to put it
through a hash function or a hash algorithm.
And then we're going to have the output.
Now the output being the hash, hash value,
message digest, fingerprint, whatever you wanna call it.
But here's some of the key characteristics of that output.
Unique, one-way, fixed length output.
Unique means that the output will always be unique
to that input.
Now, I can put that input
through the same hash function a million times.
It'll end up with the same output.
But if I make any change, the slightest change
whatsoever then the output will be different.
So it's always uniquely tied to the input.
One way means that we can go
from that clear text to this visual representation
to this hash fingerprint message digest.
But we can't go from this hash fingerprint message digest
back to the original.
It's not like encryption where we're transforming plain text
to cipher text and back. Right?
There is no transformation.
Someone once explained it to me
as you can make chicken nuggets from a chicken
but you really can't make a chicken
from chicken nuggets, right?
It's a one-way process.
And then it's a fixed length output.
So the various hash functions will have a specific length
that their output is so unique, one-way,
fixed length output.
Now, in order to be secure
a cryptographic hash function has to meet three criteria.
One, the output must not be reversible means
that one-way representation,
two, a variable length input must produce
a fixed length output.
And three, the output must be unique to the input.
Now, if a hash function ever ends up producing
the same value for two different inputs, the result is known
as a collision and that hash process, right
or that hash function is no longer useful to us.
Now, there are three hash functions you wanna recognize.
Message Digest, you'll see it abbreviated as MD,
Secure Hash Algorithm.
You'll see that abbreviated as SHA, S H A
and then RIPEMD.
The MD4 was developed by Ron Rivest
of RSA fame in 1990 and it has been broken.
The MD5, which is still in use
has been subject to collision attacks.
And for cryptographic purposes, it is considered broken
however, it's sometimes used for non-cryptographic purposes.
Secure hash algorithm, SHA was developed by the NSA,
the National Security Agency here in the United States.
Now, SHA-1 is subject to collision attacks.
Remember, collision attack
is when we could have different output for the same input.
But secure versions include the SHA-2
and the SHA-3 families.
Then RIPEMD-160 is a cryptographic hash function
that is based on the Merkle-Damgard construction.
And it is actually what's used in the Bitcoin standard.
So how do we generate this fingerprint
or hash or message digest, whatever we're calling it?
Well, we use a hash calculator.
So in this case, I just access to hash calculator online.
You can do bring one, use one online.
You can have one locally.
And what you're gonna do is you're gonna put your input
in or your input of any length.
So I just put the Gettysburg Address
beginning of it, four score
and seven years ago, our fathers brought forth
on this continent a new nation conceived in liberty
and dedicated to the proposition that all men
are created equal.
Now it says, what kind of checksum do you want?
Really what kind of hash do you want?
MD5, SHA-1, SHA-256 and I chose SHA-256.
And then where it says string hash,
that's the visual representation, right?
Now, I can't go from that
if I just said that back to my four score
and seven years ago.
That's the visual representation
but it is unique to that input.
So what if I do this again?
What if I take the same exact string?
Four score and seven years ago
our fathers brought forth to this continent
a new nation conceived in liberty and dedicated
to the proposition that all men are created equal.
But I make one change.
I take that first word and instead of capital F,
lowercase O U R, I did capital F, capital O, capital U
and capital R.
No change to the content, just change
in this case to the capitalization, still using SHA-256.
And if you look, you'll see
that the visual representation, right now ends in,
well it's a completely different number,
but just to make it easier
you can see it's ending down at the bottom at D85.
So made any change.
If I changed spacing, change capitalization,
change punctuation or of course if I changed any
of the words or even one single letter,
the output would be different.
So here's how we use our message digest in action.
Alice is gonna put a message to a hashing algorithm
and she's gonna generate a message digest or a hash value.
Remember, what is Alice trying to accomplish here?
She wants to make sure that when a message gets to Bob,
Bob knows the message wasn't changed in transmission.
So she's going to send the plain text message
'cause we're not looking at confidentiality here.
We only care about integrity right now.
So send the the message and that message digest to Bob.
And you might have seen a message digest,
some point you might have gotten one that
underneath a signature line you see kind of a block
of letters and numbers.
That would be that message digest.
So Alice sends the message and the message digest to Bob.
Bob receives that clear text message
and the message digest.
Bob is gonna put the message
through the same hashing algorithm, right?
So whatever Alice used, Bob is gonna use,
it's gonna the same through the same hashing algorithm.
And he's gonna generate a message digest
or a hash value, right?
So now he's got the one that Alice sent him
and the one he created.
And he is gonna compare the two.
And what's he gonna know?
Well, if the message digests are the same
he knows that the message was not changed in transmission.
He can trust the integrity of the message.
But if the message digests are different
then he knows that the message was modified in transmission.
And that's how we use hashing to verify integrity.
Now, there are some hash extensions.
There's what's known as a hash MAC or an HMAC.
A hash MAC message, authentication code or HMAC
is a hash value that actually includes a symmetric key.
So you take the, whatever the the value is
whatever the string is that you wanna hash
and you throw in a symmetric key.
Ah, so that's interesting.
Why would you do that?
Well, if you control both sides, right?
The HMAC can't be reproduced without knowing the key.
So you have to also get that symmetric key somehow.
So the HMAC provides integrity
and data origin authentication.
You know where it came from.
The HMAC is used by cryptographic protocols such
as TLS and IPsec, both of which we'll be talking
about a little bit later on to verify the integrity
of transmitted data during secure communications.
The other hash extension that is used pretty frequently
are salts or salting.
Salts are just random values that are appended
to the input to negate the value of a rainbow table.
Rainbow tables are just pre-computed hashes.
So someone said, okay
I'm gonna take 10,000 common dictionary words.
I'm gonna put them through SHA-256,
I'm gonna see what the hash is
and now I'll have their visual representation.
So if I ever capture a hash, I can say, oh
was it in my table?
And I'll know what it is
if I'm the bad guy doing that obviously, right?
The rainbow tables are publicly available tables
of those pre-computed hashes.
So now let's turn our attention in digital signatures.
The objective of a digital signature is to prove integrity
and non-repudiation, right.
Integrity, a message hasn't changed.
And non-repudiation means
that the signer can't deny sending the message.
And conversely, the receiver can trust
that the message came from that name signer.
So a digital signature.
All right, get ready for this is a message digest
that's been encrypted using the sender's private key.
Now, we're not encrypting the message digest
'cause we're trying to keep anything secret
about the message digest.
Remember, the message digest is a bunch of gobbly-cook.
Why are we encrypting it with the sender's private key?
Because who should have the sender's private key?
Only the sender.
What's the corresponding key to the sender's private key?
Sender's public key which is freely distributed.
So if we can decrypt a message digest
with the sender's public key, right the corresponding key
we know who the message came from.
Now, digital signatures require two algorithms
a hashing algorithm and a digital signature algorithm.
So again, often used RSA,
right defacto commercial standard works
with both encryption and digital signatures.
Or DSA, digital signature algorithm, which is published
by NIST, the National Institute of Standards and Technology
in cooperation with the NSA, the National Security Agency
and it is the US Government Digital Signature standard.
Now let's walk through digital signatures in action.
Alice is gonna put a message for hashing algorithm
and he's gonna generate a message digest or a hash function.
Alice is gonna encrypt that message digest
with her private key.
She's gonna send the plain text message
and that encrypted message digest to Bob.
Bob receives the message and the encrypted message digest.
Bob is gonna decrypt the message digest using
the corresponding key to Alice's private key,
which is Alice's public key.
And if he can decrypt, right the message digest
it proves authenticity.
It proves that it came from Alice, right, non-repudiation.
Then Bob is gonna take that plain text message.
He's gonna put it
through the same hashing algorithm that Alice used.
He's gonna generate a message digest.
And just like we saw before
he'll compare the two message digests.
If they're the same, he knows that the message
wasn't modified in transmission, proving integrity.
And if they're different
he knows the message was modified in transmission.
In this lesson, we talked about hashing
and digital signatures, hashing to prove integrity
and digital signatures to prove non-repudiation
and authenticity.
We know who the message came from.
That sender can't deny sending it.
We can trust that they were the ones that sent the message.
So hashing and digital signatures.
And that brings us to a three-second challenge.
Now you ready? All right.
A unique fixed length representation of data.
This is the thing I said had multiple names to it.
What is this?
One, two, three.
A hash, a fingerprint, a message digest
all of those would work.
Number two, the term used to describe
when a hash function produces the same output
for two different inputs?
This is when we have a, this is a problem.
One, two, three that's known as a collision.
Number three, a hash value that includes a symmetric key.
So we add the symmetric key in with the hash value.
Said it was used by TLS and IPsec.
That's gonna be a Hashed Message Authentication Code,
we just call it an HMAC all the time.
Number four, random values appended
to the input to negate the value of a rainbow table.
One, two, three.
That's gonna be salts.
And lastly number five,
key used to decrypt an encrypted message digest.
So if I get sent an encrypted message digest
what key should I use to decrypt it?
Think about that for a sec.
One, two, three.
I'm going to use the sender's public key
because the sender's always gonna encrypt the message digest
with their private key because only the sender
should have their private key.
So the correspondent of the mathematically related key
will be the sender's public key.
Okay, that brings us to a security-in-action
about secure communication.
The local police department needs to communicate regularly
with the Department of Homeland Security
about national security issues.
Confidentiality, integrity and sender authenticity
are equally important to both parties.
So here's my question to you.
What cryptographic processes and associated algorithms
are you gonna recommend?
Confidentiality, integrity and sender authenticity.
What a great time to put me on pause, write some notes
and then come on back
and we'll talk about your recommendations.
So our recommended processes would be encryption
for confidentiality, hashing, right for integrity
and digital signatures for sender authenticity.
Now for encryption, we're probably gonna wanna use AES
for confidentiality.
That's current US Government standard.
For hashing, we'll use the SHA-2 or the SHA-3 family
for message integrity and for digital signatures
because this is government, right the US government
we're going to use DSA, the digital signature algorithm.
So digital signatures using DSA for non-repudiation.
Do all that.
You'll have confidentiality, integrity
and sender authenticity.
If you can do that,
well that's definitely security-in-action.
All right, let's go to our Word Cloud.
It's a bunch here.
You know what to do.
Make sure that you can define all of these terms.
You know what they mean, you know how to use them.
And once you're there, then come on over to the next lesson.
We'll be talking about digital certificates.
See you there.