Today we use cryptography in almost everywhere. From surfing the web over https, to working remotely over ssh. However, many of us do not appreciate the subtleties of crypto primitives, and the lack of correct and updated resources leads to design and development of vulnerable applications. In this talk, we cover the building block of modern crypto, and how to develop secure applications in Python.
10. 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<e<f(n) (public, chosen)
– d = e-1
mod f(n) (private, calculated)
• D(E(M)) = Med
mod n = M kf(n)+1
= M (Euler’s theorem)
10
11. 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
11
12. 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’) such that, h(m) = h(m’)
– Collisions: It is computationally difficult to find any two
messages m, m’ (m ≠ m’) such that, h(m) = h(m’)
• Examples
– Recommended Hash Algorithm (SHA-2, SHA-3) by NIST
– SHA-1: output 160 bits being phased out
– MD2, MD4, and MD5 by Ron Rivest [RFC1319, 1320, 1321]
12