Slide 1

Slide 1 text

Common Crypto Pitfalls Amirali Sanatinia asanatinia

Slide 2

Slide 2 text

Cryptography • Cryptography is ubiquitous today • From mobile phones to wireless connections • Supported in almost every programming language • It is even embedded in the CPUs • It is not hard to do crypto right but …

Slide 3

Slide 3 text

Crypto Failures

Slide 4

Slide 4 text

Hashing Functions • Input: long message • Output: short block (called hash or message digest) • Desired properties: – Pre-image: Given a hash h it is computationally infeasible to find a message m that produces h – Second preimage: Given message m, it is computationally infeasible to find a message m’, (m ≠ m’) s.t., h(m) = h(m’) – Collisions: It is computationally difficult to find any two messages m, m’ (m ≠ m’) such that, h(m) = h(m’)

Slide 5

Slide 5 text

Hashing (cont.) • Examples – Recommended Hash Algorithm (SHA-2, SHA-3) by NIST – SHA2: 224, 256, 384, or 512 bits digests – SHA-1: output 160 bits being phased out, shattered – MD2, MD4, and MD5 by Ron Rivest [RFC1319, 1320, 1321]

Slide 6

Slide 6 text

Encryption Models Encryption Algorithm Decryption Algorithm Encryption Key Decryption Key Message Destination Plaintext Ciphertext Plaintext Symmetric encryption: Asymmetric encryption: Public key Shared key Shared key Private key

Slide 7

Slide 7 text

Symmetric vs. Asymmetric Encryption • Symmetric algorithms are much faster – In the order of a 1000 times faster • Symmetric algorithms require a shared secret – Impractical if the communicating entities don’t have another secure channel • Both algorithms are combined to provide practical and efficient secure communication – E.g., establish a secret session key using asymmetric crypto and use symmetric crypto for encrypting the traffic

Slide 8

Slide 8 text

Advanced Encryption Standard (AES) • Also known as Rijndael • Part of NIST competition • Requirements – Fast in software and hardware – Block size: 128; Key size: 128, 192 and 256 • Joan Daemen and Vincent Rijmen • First published in 1998 • FIPS 197 on November 26, 2001 • Other candidates: Mars, RC6, Serpent, Twofish

Slide 9

Slide 9 text

Block Cipher Mode of Operation • AES works on a block of data (128 bits) • To encrypt a large message, each block needs to be encrypted • Different modes of encrypting the blocks – Electronic Codebook (ECB) – Cipher Block Chaining (CBC) – Counter (CTR)

Slide 10

Slide 10 text

ECB source: wikipedia

Slide 11

Slide 11 text

CBC source: wikipedia

Slide 12

Slide 12 text

CTR source: wikipedia

Slide 13

Slide 13 text

ECB vs. CBC Original ECB CBC

Slide 14

Slide 14 text

Bit Flipping Attack • Change encryption of m 1 to encryption of m 2 without the knowledge of the key k • In certain modes of operation (e.g., CBC) • Ci = Ek (Pi ⊕ Ci-1 ) • C0 = IV • Pi = DK (Ci ) ⊕ Ci-1 • C0 = IV • IVj = IVj ⊕ Pj ⊕ t

Slide 15

Slide 15 text

Hash-based Message Authentication Code source: wikipedia

Slide 16

Slide 16 text

Encrypt then MAC source: wikipedia

Slide 17

Slide 17 text

source: wikipedia Encrypt and MAC

Slide 18

Slide 18 text

source: wikipedia MAC then Encrypt

Slide 19

Slide 19 text

Galois Counter Mode (GCM) source: wikipedia

Slide 20

Slide 20 text

Case of Adobe source: nakedsecurity

Slide 21

Slide 21 text

Case of Adobe (cont.) source: nakedsecurity

Slide 22

Slide 22 text

Case of Adobe (cont.) source: nakedsecurity

Slide 23

Slide 23 text

Case of Adobe (cont.) source: nakedsecurity

Slide 24

Slide 24 text

Password Storage • Use salt • Use adaptive one-way functions – Password-Based Key Derivation Function 2 (PBKDF2) • Key = PBKDF2(PRP, password, salt, iterations, key length) – scrypt – bcrypt

Slide 25

Slide 25 text

RSA • One of the first practical public crypto systems • Designed by Ron Rivest, Adi Shamir, and Leonard Adleman • First published in 1977 • Was patented until September 2000 • Based on the hardness of factoring problem and modular arithmetic

Slide 26

Slide 26 text

Textbook RSA • E(M) = Me mod n = C (Encryption) • D(C) = Cd mod n = M (Decryption) • RSA parameters and basic (not secure) operations: – p, q, two big prime numbers (private, chosen) – n = pq, f(n) = (p-1)(q-1) (public, calculated) – e, with gcd(f(n), e) = 1, 1

Slide 27

Slide 27 text

Example of RSA • Keys generation: – p = 5; q = 11 => n = 55 – e = 3 => d = 27 • Because ed = 1 mod (p-1)(q-1) – Public key: (e, n); Private Key: (d, n) • Encryption – M = 2 – Encryption(M) = Me mod n = 8 – Decryption(8) = 8d mod n = 2

Slide 28

Slide 28 text

Optimal Asymmetric Encryption Padding (OAEP) • Textbook RSA is not IND-CPA secure • M 1 =M 2 → E(M 1 ) = E(M 2 ) • We use Optimal Asymmetric Encryption Padding (OAEP)

Slide 29

Slide 29 text

OAEP source: wikipedia

Slide 30

Slide 30 text

RSA Public Key (Salt Stack)

Slide 31

Slide 31 text

No Encryption Fake Ransom ware

Slide 32

Slide 32 text

Cost of Crypto

Slide 33

Slide 33 text

Cost of Crypto (cont.) source: Cloudflare

Slide 34

Slide 34 text

Cryptography in Action (SHA2)

Slide 35

Slide 35 text

Cryptography in Action (AES Encryption/Decryption)

Slide 36

Slide 36 text

Cryptography in Action (RSA Key Generation)

Slide 37

Slide 37 text

Cryptography in Action (RSA Encryption/Decryption)

Slide 38

Slide 38 text

Takeaways • Don’t invent your own crypto algorithm • Don’t implement your own crypto library • Doing crypto in a right way is not difficult

Slide 39

Slide 39 text

Thank You! Questions?