WEBVTT

0
00:00.810 --> 00:01.750
Hello guys!

1
00:01.860 --> 00:05.220
In this lecture we'll talk about hashes!

2
00:05.220 --> 00:14.130
You'll find them in many areas of computer science. Hashes are a critical part of best art systems digital,

3
00:14.130 --> 00:22.220
signatures, security certificates, blockchain technology cryptocurrencies like Bitcoint and Ethereum

4
00:22.590 --> 00:29.730
or even how the supermarket POS verifies the PIN of your credit card  when you want to pay for

5
00:29.730 --> 00:30.440
something.

6
00:30.970 --> 00:40.240
Let's dive deeper into hashes! A hashing algorithm is a cryptographic function that takes an input, runs it

7
00:40.320 --> 00:49.310
through some magical mathematical processes and then creates a unique output called hash.The output

8
00:49.310 --> 00:58.760
hash is sometimes called message digest checksum or cryptographic fingerprint. The input of the hash

9
00:58.760 --> 01:06.620
function can be literally anything from binary information like a file a packet a single character to

10
01:06.620 --> 01:15.100
a word or a phrase. I'd like to show you a practical example using a Linux machine (since it already has

11
01:15.190 --> 01:20.680
all applications needed to calculate hashes). If you are using Windows

12
01:20.680 --> 01:23.710
you need to install the required tools.

13
01:24.130 --> 01:32.410
So I'm executing sha256sum /etc/passwd


14
01:32.460 --> 01:41.630
Let's take a deeper look at the  command, its argument and its output. The hash function or the hash algorithm

15
01:41.630 --> 01:54.110
used is sha256; sha stands for Secure Hash Algorithm, is pronounced sha, and is in fact a family of more 

16
01:54.110 --> 01:59.020
more hash protocols. Sha256sum

17
01:59.050 --> 02:07.920
is the Linux application, the tool that implements the hash protocol which as I said is sha256.

18
02:10.150 --> 02:19.120
/etc/passwd is the input of the hash function and this string written in hexadecimal or base 16

19
02:19.420 --> 02:29.490
is the hash of the input. We can simply say that sha256 hash of password file is this value,

20
02:30.650 --> 02:38.490
the value you are seeing right now. You should know that all hash algorithms are public. They are like a public

21
02:38.490 --> 02:49.370
math formula that anyone can see and use; for example sha256 is part of a bigger family of hash algorithms

22
02:49.640 --> 02:55.280
called sha-2. You can read more about them even on Wikipedia.

23
02:58.530 --> 03:06.330
Look, this is the pseudo code for a sha256 algorithm; you can implement it in any programming language.

24
03:07.980 --> 03:08.880
It's public!

25
03:11.350 --> 03:20.290
Other well known hash algorithms besides sha-2 are md5 and sha1 which are considered insecure 


26
03:20.560 --> 03:21.760
and obsolete.

27
03:21.760 --> 03:23.820
Let’s see the hash of Linux


28
03:23.840 --> 03:27.050
word calculated with md5 and sha1:

29
03:27.090 --> 03:32.210
echo -n  the word "linux" 

30
03:32.320 --> 03:34.830
You can write anything you want.

31
03:34.900 --> 03:37.260
| md5sum

32
03:37.270 --> 03:48.880
-n is used not to add a new line; by default the echo command ends a new line at the end.

33
03:49.010 --> 03:52.790
I want to calculated the hash only of this word.

34
03:55.570 --> 03:59.230
And the hash calculated using sha1

35
04:02.340 --> 04:03.520
That's the hash.

36
04:03.700 --> 04:04.490
They are written

37
04:04.500 --> 04:12.610
always in hexadecimal numbers; Other very secure and new hash

38
04:12.660 --> 04:25.260
algorithms are sha-3 or Keccak, Blake2b and RIPEMD-160. Blake2b is used by Ethereum 2.0 and RIPEMD-160 

39
04:25.270 --> 04:34.710
is one of the two hash functions used by Bitcoin. And they were never

40
04:34.710 --> 04:46.920
hacked! Another way to calculate a hash is using the openssl command like this:

41
04:46.920 --> 04:53.930
openssl dgst -sha3-256


42
04:53.960 --> 05:00.070
This is the hash algorithm and the file for example  /etc/passwd

43
05:00.280 --> 05:00.880
Okay.

44
05:00.990 --> 05:02.400
This is the hash.

45
05:02.640 --> 05:08.780
This is different than this one because it's another hash algorithm used.

46
05:09.030 --> 05:12.000
Or you can calculate the hash of a string

47
05:12.000 --> 05:12.690
this way:

48
05:13.200 --> 05:25.040
echo -n "linux" | openssl dgst -rmd160

49
05:25.100 --> 05:36.030
That's the hash; you can see a list of all hash algorithms implemented in openssl

50
05:36.190 --> 05:39.670
by executing openssl and then help.

51
05:47.330 --> 05:52.450
These are all hash algorithms implemented in openssl.

52
05:57.020 --> 05:58.660
Let's try another example!

53
05:58.750 --> 06:07.310
Let’s calculate the hash of word “linux” using this time the sha512 algorithm, in different ways:

54
06:07.580 --> 06:08.940
In the first example

55
06:08.990 --> 06:20.320
I'll be using the sha512sum command like this: echo -n "linux" | sha512sum

56
06:20.520 --> 06:25.260
This is the hash; Or using the openssl command.

57
06:32.850 --> 06:44.790
This is the hash! I can also use an online tool to calculate the hash; I am selecting sha512 and the

58
06:44.790 --> 06:46.060
input Linux.

59
06:46.060 --> 06:55.600
And this is the hash and we notice something very important: no matter how we calculate the hash if we

60
06:55.600 --> 07:00.610
use the same algorithm we get the same hash, the same output.

61
07:00.610 --> 07:01.990
Look at this output

62
07:04.640 --> 07:08.210
and look at the same output here.

63
07:08.390 --> 07:16.010
This is one of the properties of hashes which is called determinism and it means that the output of

64
07:16.010 --> 07:19.610
a hash function doesn't change between runs.

65
07:19.610 --> 07:23.400
It's in fact the same mathematical process applied.

66
07:24.300 --> 07:32.220
These hash functions are also called one way functions. Another important property of a hash function

67
07:32.550 --> 07:39.690
is that it's very easy to compute the hash from the given input but infeasible to find out the original

68
07:39.690 --> 07:47.840
input from the resulting hash; or if you have the hash you are seeing right now there is no way to find

69
07:47.840 --> 07:55.790
out what information, what word, file or packet, has given that hash.

70
07:55.790 --> 07:58.660
Note that hashing is not encryption.

71
07:58.700 --> 08:01.540
There is no secret, no key in hashing.