summaryrefslogtreecommitdiff
path: root/reveal.js/cryptographic_primitives.html
blob: 4b2e6fc65304ea8217d9df20d0722034c21f7577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Introduction to cryptographic primitives</title>
    <meta name="author" content="Simeon Simeonov"/>
    <meta name="mobile-web-app-capable" content="yes"/>
    <meta name="mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <link rel="stylesheet" href="dist/reset.css"/>
    <link rel="stylesheet" href="dist/reveal.css"/>

    <!-- <link rel="stylesheet" href="dist/theme/black.css" id="theme"/> -->
    <link rel="stylesheet" href="dist/theme/statnett.css" id="theme"/>

    <!-- Theme used for syntax highlighting of code -->
    <link rel="stylesheet" href="plugin/highlight/monokai.css" id="highlight-theme"/>
    <!-- <link rel="stylesheet" href="plugin/highlight/zenburn.css" id="highlight-theme"/> -->
  </head>

  <body>
    <div class="reveal">
      <!-- Any section element inside of this container is displayed as a slide -->
      <div class="slides">

        <section>
          <h2>Introduction to cryptographic primitives</h2>
          </br>
          <p><small>Simeon Simeonov - TDE</small></p>
        </section>


        <section>
          <h2>What are cryptographic primitives?</h2>
          </br>
          <p>Cryptographic primitives are the most basic building blocks in cryptographic systems and protocols.</p>
          <p>Creating cryptographic routines is very hard, and testing them to be reliable takes a long time, it is essentially never sensible (nor secure) to design a new cryptographic primitive to suit the needs of a new cryptographic system.</p>
          <p>Since algorithms in this field are not only required to be designed well but also need to be tested well by the cryptologist community, even if a cryptographic routine looks good from a design point of view it might still contain errors. Successfully withstanding such scrutiny gives some confidence (in fact, so far, the only confidence) that the algorithm is indeed secure enough to use. Security proofs for cryptographic primitives are generally not available.</p>
          <p>When choosing primitive for a cryptographic system, one should always consider if the primitive:</p>
          <ul>
            <li>is open and can be studied by the community</li>
            <li>is patented</li>
          </ul>
        </section>


        <section>
          <h2>Agenda</h2>
          </br>
          <section id="fragments">
            <ul>
              <span class="fragment"><li>cryptographic hash functions</li></span>
              <span class="fragment"><li>cryptographically secure random generators (the very basics)</li></span>
              <span class="fragment"><li>symmetric ciphers</li></span>
              <span class="fragment"><li>public-key cryptography / asymmetric cryptography</li></span>
            </ul>
          </section>
        </section>


        <section>
          <h2>Cryptographic hash functions</h2>
          <p>A hash function is any function that can be used to map data of arbitrary size to fixed-size values (or a set of fixed-size values)</p>
          <p>Cryptographic hash functions or cryptographically secure hash functions are hash functions with special properties (making them desirable for cryptographic systems)</p>
          <p>(Over)simplified list of desired properties:</p>
          <ul>
            <li>the probability of a particular output result (hash value) <em>n</em>  for a random input string ("message") is 2^(-n) (as for any good hash), so the hash value can be used as a representative of the message</li>
            <li>given a hash value <em>h</em>, it should be difficult to find any message <em>m</em> such that <em>h = hash(m)</em> ("reversing the function")</li>
            <li>given an input <em>m1</em>, it should be difficult to find a different input <em>m2</em> such that <em>hash(m1) = hash(m2)</em> (weak collision resistance)</li>
            <li>it should be difficult to find two different messages <em>m1</em> and <em>m2</em> such that <em>hash(m1) = hash(m2)</em>. Such a pair is called a cryptographic hash collision (strong collision resistance)</li>
            <li>if an input is changed slightly (for example, flipping a single bit), the output changes significantly (avalanche effect) - a property also desired in ciphers</li>
            <li>being fast is always a nice bonus :)</li>
          </ul>
        </section>


        <section>
          <h2>MD5</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>Ronald Rivest</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1992</td>
			  </tr>
			  <tr>
				<td>Digest size</td>
				<td>128 bits (16 bytes)</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>512 bits</td>
			  </tr>
			  <tr>
				<td>Broken?</td>
				<td>Yes (broken collision resistance in 2^18 time)</td>
			  </tr>
			</tbody>
		  </table>
          <p>Still in use in lagacy applications and in applications where collision resistance is not needed</p>
        </section>


        <section>
          <h2>SHA-1 (Secure Hash Algorithm 1)</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>NSA</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1995</td>
			  </tr>
			  <tr>
				<td>Digest size</td>
				<td>160 bits (20 bytes)</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>512 bits</td>
			  </tr>
			  <tr>
				<td>Broken?</td>
				<td>Yes</td>
			  </tr>
			</tbody>
		  </table>
          <p>Still in use. Revision control systems such as <em>Git</em>, <em>Mercurial</em>, and <em>Monotone</em> use <em>SHA-1</em>, not for security, but to identify revisions and to ensure that the data has not changed due to accidental corruption.</p>
        </section>


        <section>
          <h2>SHA-2</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>NSA</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>2001</td>
			  </tr>
			  <tr>
				<td>Digest sizes</td>
				<td>224, 256, 384 or 512 bits</td>
			  </tr>
			  <tr>
				<td>Block sizes</td>
				<td>256 bits (SHA-224 and SHA-256) or 512 bits</td>
			  </tr>
			  <tr>
				<td>Broken?</td>
				<td>No</td>
			  </tr>
			</tbody>
		  </table>
        </section>


        <section>
          <h2>SHA-3</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles van Assche</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>2016</td>
			  </tr>
			  <tr>
				<td>Digest size</td>
				<td>arbitrary</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>variable</td>
			  </tr>
			  <tr>
				<td>Broken?</td>
				<td>No</td>
			  </tr>
			</tbody>
		  </table>
          <p>Based on Keccak - winner of the NIST hash function competition after some controversial adjustments. Very fast and flexible.</p>
        </section>


        <section>
          <h2>BLAKE2</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn and Christian Winnerlein</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>2008 (BLAKE)</td>
			  </tr>
			  <tr>
				<td>Digest size</td>
				<td>up to 64 bytes (BLAKE2b), up to 32 bytes (BLAKE2s)</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>variable (stream)</td>
			  </tr>
			  <tr>
				<td>Broken?</td>
				<td>No</td>
			  </tr>
			</tbody>
		  </table>
          <p>BLAKE2 is based on Daniel J. Bernstein's ChaCha stream cipher and is extremely fast. BLAKE2b and BLAKE2s are specified in RFC 7693.</p>
        </section>


        <section>
          <h2>Application of cryptographic hash functions</h2>
          <p>Cryptographic hash functions are used for many different things in cryptographic systems and protocols. Few examples:</p>
          <ul>
            <li>can be used directly (f.i. sha256sum - part of GNU coreutils)</li>
            <li>message authentication code (MAC)</li>
            <li>password hashing / key derivation</li>
            <li>proof of work</li>
          </ul>
        </section>


        <section>
          <h2>HMAC</h2>
          <p>HMAC (hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and authenticity of a message. An HMAC is a type of keyed hash function that can also be used in a key derivation scheme or a key stretching scheme.</p>
          <p>HMAC can provide authentication using a shared secret instead of using digital signatures with asymmetric cryptography. It trades off the need for a complex public key infrastructure by delegating the key exchange to the communicating parties, who are responsible for establishing and using a trusted channel to agree on the key prior to communication.</p>
          <img src="images/cryptographic_primitives/hmac.svg"></img>
          <p><em>XOR</em> (eXclusive OR) - is a logical operator</p>
          <p>With two inputs, XOR is true if and only if the inputs differ (one is true, one is false)</p>
        </section>


        <section>
          <h2>PBKDF2</h2>
          <p>PBKDF2 (Password-Based Key Derivation Function 2) is a key derivation function with a sliding computational cost, used to reduce vulnerability to brute-force attacks.</p>
          <p>PBKDF2 applies a pseudorandom function, such as <em>HMAC</em>, to the input password or passphrase along with a <em>salt</em> value and repeats the process many times to produce a derived key, which can then be used as a cryptographic key in subsequent operations. The added computational work makes password cracking much more difficult, and is known as <em>key stretching</em>.</p>
          <h4>Demo</h4>
        </section>


        <section>
          <h2>Proof of work</h2>
          <h4>Demo</h4>
        </section>


        <section>
          <h3>Cryptographically secure random generators</h3>
          <p>Most cryptographic applications require random numbers for: generating keys, initialization vectors, nonces (arbitrary numbers that can be used just once), salts, tokens etc, etc.</p>
          <p>The "quality" of the randomness required for these applications varies. For example, creating a <em>nonce</em> in some protocols needs only uniqueness. On the other hand, the generation of a master key requires a higher quality, such as more entropy.</p>
          <p>Entropy is obtained from a high-quality source, generally the operating system's randomness API.</p>
          <p>In practical situations, numbers are needed with more randomness than the available entropy can provide. Also, the processes to extract randomness from a running system are slow in actual practice. In such instances, a cryptographically secure pseudorandom number generator (CSPRNG) can sometimes be used. A CSPRNG can "stretch" the available entropy over more bits.</p>
        </section>


        <section>
          <h3>Cryptographically secure random generators (cont...)</h3>
          <p>CSPRNG must</p>
          <ul>
            <li>pass statistical randomness tests - f.i. given the first k bits of a random sequence, there is no polynomial-time algorithm that can predict the (k+1)th bit with probability of success non-negligibly better than 50%</li>
            <li>be attack resistant - f.i. in the event that part or all of its state has been revealed it should be impossible to reconstruct the stream of random numbers prior to the revelation</li>
          </ul>
          <p>"Practical" CSPRNG schemes not only include an CSPRNG algorithm, but also a way to initialize ("seed") it while keeping the seed secret.</p>
        </section>


        <section>
          <h3>Symmetric-key algorithms / symmetric ciphers</h3>
          <p>Symmetric ciphers use the same cryptographic keys for both the encryption of <em>plaintext</em> and the decryption of <em>ciphertext</em>.</p>
          <p>“Anyone, from the most clueless amateur to the best cryptographer, can create an algorithm that he himself can’t break. It’s not even hard. What is hard is creating an algorithm that no one else can break, even after years of analysis. And the only way to prove that is to subject the algorithm to years of analysis by the best cryptographers around.” - Bruce Schneier</p>
          <p>A "perfect" cipher - the one-time pad has been known since 1882, but is not practically applicable in modern systems:</p>
          <ul>
            <li>generate random stream (pad) with length = len(plaintext)</li>
            <li>ciphertext = plaintext XOR pad</li>
          </ul>
          
          <p>There two types of modern ciphers:</p>
          <ul>
            <li>block ciphers - operate on fixed-length groups of bits, called blocks (padding may be used to the remaining bits)</li>
            <li>stream ciphers - plaintext digits are combined (XORed) with a pseudorandom cipher digit stream (keystream).</li>
          </ul>
        </section>


        <section>
          <h2>DES (Data Encryption Standard)</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designer</td>
				<td>IBM</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1975</td>
			  </tr>
			  <tr>
				<td>Key size</td>
				<td>56 bits</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>64 bits</td>
			  </tr>
			</tbody>
		  </table>
          <p>Not used anymore. 3DES was published in 1981 (with keysize of 112 bits or 168 bits).</p>
        </section>


        <section>
          <h2>Blowfish</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designer</td>
				<td>Bruce Schneier</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1993</td>
			  </tr>
			  <tr>
				<td>Key size</td>
				<td>32-448 bits</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>64 bits</td>
			  </tr>
			</tbody>
		  </table>
          <p>Schneier has stated that "Blowfish is unpatented, and will remain so in all countries. The algorithm is hereby placed in the public domain, and can be freely used by anyone.". Still in use in legacy applications and notably in the <em>bcrypt</em> password hashing function.</p>
        </section>


        <section>
          <h2>AES (Advanced Encryption Standard - Rijndael)</h2>
		  <table>
			<tbody>
			  <tr>
				<td>Designer</td>
				<td>Joan Daemen, Vincent Rijmen</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1998</td>
			  </tr>
			  <tr>
				<td>Key size</td>
				<td>128 bits, 192 bits or 256 bits</td>
			  </tr>
			  <tr>
				<td>Block size</td>
				<td>128 bits</td>
			  </tr>
			</tbody>
		  </table>
          <p>Rijndael was thew winner of the NIST AES selection process. Currently the most widely adopted block cipher (both in hardware and software).</p>
        </section>


        <section>
          <h3>Mode of operation for block ciphers</h3>
          <p>A block cipher by itself is only suitable for the secure cryptographic transformation (encryption or decryption) of one fixed-length group of bits called a block. A mode of operation describes how to repeatedly apply a cipher's single-block operation to securely transform amounts of data larger than a block.</p>
          <img src="images/cryptographic_primitives/modes_of_operation.png" style="width: 30vw;"></img>
        </section>

        
        <section>
          <h3>Galois/counter (GCM)</h3>
          <p>The GCM algorithm provides both data authenticity (integrity) and confidentiality and belongs to the class of authenticated encryption with associated data (AEAD) methods. This means that as input it takes a key <em>K</em>, some plaintext <em>P</em>, and some associated data <em>AD</em>; it then encrypts the plaintext using the key to produce ciphertext <em>C</em>, and computes an authentication tag <em>T</em> from the ciphertext and the associated data (which remains unencrypted). A recipient with knowledge of <em>K</em>, upon reception of <em>AD</em>, <em>C</em> and <em>T</em>, can decrypt the ciphertext to recover the plaintext <em>P</em> and can check the tag <em>T</em> to ensure that neither ciphertext nor associated data were tampered with.</p>
          <img src="images/cryptographic_primitives/GCM.svg" style="width: 12vw;"></img>
        </section>


        <section>
          <h2>Stream ciphers</h2>
          <p> Stream ciphers typically execute at a higher speed than block ciphers and have lower hardware complexity. However, stream ciphers can be susceptible to security breaches, for example, when the same starting state (seed) is used twice.</p>
          <p>Essentially they behave as pseudorandom functions where they key is / is part of the "seed".</p>
          <br/>
          <h4>ChaCha</h4>
		  <table>
			<tbody>
			  <tr>
				<td>Designer</td>
				<td>Daniel J. Bernstein (djb)</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>2008</td>
			  </tr>
			  <tr>
				<td>Key size</td>
				<td>128 bits or 256 bits</td>
			  </tr>
			</tbody>
		  </table>
          <br/>
          <h5>ChaCha20-Poly1305</h5>
          <p><em>ChaCha20-Poly1305</em> is an <em>AEAD</em> algorithm, that combines the <em>ChaCha20</em> stream cipher with the <em>Poly1305</em> message authentication code. It has fast software performance, and without hardware acceleration, is usually faster than <em>AES-GCM</em>.</p>
        </section>


        <section>
          <h3>Public-key cryptography / asymmetric cryptography</h3>
          <p>Asymmetric cryptography makes use pairs of related keys. Each key pair consists of a <em>public key</em> and a corresponding <em>private key</em>. Key pairs are generated with cryptographic algorithms based on mathematical problems termed <em>one-way functions</em>. Security of public-key cryptography depends on keeping the private key secret, while the public key can be openly distributed without compromising security.</p>
          <p>Usually we use public key cryptography for:</p>
          <ul>
            <li>public key encryption - a message is encrypted with the intended recipient's public key. For properly chosen and used algorithms, messages cannot in practice be decrypted by anyone who does not possess the matching private key, who is thus presumed to be the owner of that key and so the person associated with the public key. This can be used to ensure confidentiality of a message.</li>
            <li>digital signatures - a message is signed with the sender's private key and can be verified by anyone who has access to the sender's public key. This verification proves that the sender had access to the private key, and therefore is very likely to be the person associated with the public key. It also proves that the signature was prepared for that exact message, since a signature that passes verification with the public key on one message will not pass verification with the public key on other messages.</li>
          </ul>
        </section>


        <section>
          <h3>RSA</h3>
		  <table>
			<tbody>
			  <tr>
				<td>Designers</td>
				<td>Ron Rivest, Adi Shamir and Leonard Adleman</td>
			  </tr>
			  <tr>
				<td>Published</td>
				<td>1977, patented until 2000 :(</td>
			  </tr>
			</tbody>
		  </table>
          <br/>
          <h4>Using RSA</h4>
          <p>The security of RSA relies on the practical difficulty of factoring the product of two large prime numbers, the "factoring problem". Still the most widely used public key system. A key size of 2048 or 4096 bits should be used. A very good CSPRNG is needed.</p>
          <p>In modern cryptographic systems and protocols (like TLS >= 1.2) RSA is only used for verifying that the client is initiating session with the "right" server. Encryption / decryption is performed using common negotiated key and symmetric ciphers.</p>
          <p><em>Forward secrecy</em> is a desired feature of specific key-agreement protocols that gives assurances that session keys will not be compromised even if long-term secrets used in the session key exchange are compromised, limiting damage. For HTTPS, the long-term secret is typically the private key of the server.</p>
        </section>

        
        <section>
          <h2>Post-quantum cryptography</h2>
          <p>Post-quantum cryptography (PQC), sometimes referred to as quantum-proof, quantum-safe, or quantum-resistant, is the development of cryptographic algorithms (usually public-key algorithms) that are thought to be secure against a cryptanalytic attack by a quantum computer. Most widely-used public-key algorithms rely on the difficulty of one of three mathematical problems: the integer factorization problem, the discrete logarithm problem or the elliptic-curve discrete logarithm problem. All of these problems could be easily solved on a sufficiently powerful quantum computer running Shor's algorithm or even faster and less demanding (in terms of the number of qubits required) alternatives.</p>
        </section>


        <section>
          <h1>Q &amp; A</h1>
        </section>


      </div>
    </div>

    <script src="dist/reveal.js"></script>
    <script src="dist/plugin/zoom.js"></script>
    <script src="dist/plugin/notes.js"></script>
    <script src="dist/plugin/search.js"></script>
    <script src="dist/plugin/markdown.js"></script>
    <script src="dist/plugin/highlight.js"></script>
    <script>
      // Also available as an ES module, see: https://revealjs.com/initialization/
      // import Reveal from 'reveal.js';
      // import RevealZoom from 'reveal.js/plugin/zoom';
      // import RevealNotes from 'reveal.js/plugin/notes';
      // import RevealSearch from 'reveal.js/plugin/search';
      // import RevealMarkdown from 'reveal.js/plugin/markdown';
      // import RevealHighlight from 'reveal.js/plugin/highlight';

      Reveal.initialize({
          controls: true,
          progress: true,
          center: true,
          hash: true,

          // Learn about plugins: https://revealjs.com/plugins/
          plugins: [RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight],
      });
    </script>
  </body>
</html>