PKI in Practice
- Abhinav
- Post Quantum Cryptography
- 07 May, 2024
There are several areas of the digital ecosystem where encryption is vital. The purpose of this chapter is to take a step back and see where encryption and cryptography fits in to these applications, what are the deciding factors and what are consequences of encryption being broken.
The Internet
Secure communications are an existential requirement for the internet of today. As far as Alice and Bob are concerned there are two areas where encryption come into the picture.
Scenario 1: Alice enters her password on her phone to login to her profile, the password should be encrypted while it’s on its way to the server for authentication, otherwise, anybody who can listen in can see her password. This problem is solved by implementing protocols such as SSL (Secure Socket Layer) or its’ newer counterpart, TLS (Transport Layer Security). And these protocols make your websites https, where the extra s stands for secure. SSL/TLS reside in the Transport layer of the OSI model and encrypt communications between Alice and the Server so that no middleman can steal the data. SSL and TLS are just protocols, and to implement them, data has to be encrypted with some type of encryption algorithm, RSA, ECC (asymmetric), AES, ChaCha20(symmetric) are some of the algorithms supported by TLS 1.4. Symmetric algorithms compute faster and are lightweight, hence they are preferred for encryption of large amounts of data, however for the secure key-exchange, RSA, Diffie-Hellman or something similar has to be implemented, requiring additional overhead. The point is RSA is still around though it may not be preferred for encrypting actual data, it is widely used for secure key exchange to initiate algorithms like AES.
Scenario 2: Alice sends a WhatsApp message to Bob, the message is encrypted by SSL/TLS between Alice and the server and between the server and Bob when the server routes the message to Bob. But as you may have noticed, the server can see Alice’s message, hence you have to trust WhatsApp that they wont look into your data. That is where end-to-end encryption comes into picture. If end-to-end encryption is implemented, PKI is implemented directly between Alice and Bob, so that even the server will only receive encrypted data.
Email and Digital Signatures
When Alice mails Bob, there are two main security considerations: Firstly, the message should be end-to-end encrypted so that no one can read it other than Bob, and secondly, Bob should have some way of verifying that the message he received actually came from Alice.
For the first part, email security protocols such as PGP, S/MIME, GPG are used which work on PKI. The second part also works on PKI, but a little differently. To understand this we must first go over the concept of a one-way hash function.
A cryptographic hash function is a black box that can ingest a large amount of data and give a unique fixed-length alpha-numeric string as output. The hash value will always be significantly shorter than the message. For example, the SHA-256 hash of any file, regardless of size is always a unique 256 bit value. A good hash function has the following properties:
Even a small change in the input message can result in a drastically different hash value.
For two different messages m1 and m2, the probability that their hashes come out same are infinitesimally small, if this occurs it is called a hash collision. To give an estimate, to perform a collision attack on SHA-256, a popular hashing algorithm, at least 2^128 hashes have to be computed, and with the current state-of-the-art that is estimated to take more time than the age of the universe to compute.
Finding an input string that matches a given hash value (a pre-image) is unfeasible, this is called pre-image resistance.
Modern hash function implementations also add a random ‘salt’ value to the input string to prevent dictionary attacks.
Coming back to Alice and Bob, To ensure that Bob can verify the message came from Alice, the following technique is used:
First Alice encrypts the message using Bob’s public key, then she computes the hash value of the message using a hash function such as SHA-256. Then she encrypts the hash with her private key and appends the encrypted hash value with the encrypted message and sends it over to Bob.
Now Bob first decrypts the message with his private key, then he computes the hash of the message. Then Bob decrypts the hash part of Alice’s message using her public-key. If the hashes match, then Bob knows Alice indeed sent the message. (The interesting point to note here is that for encrypting the hash part Alice used her private key, and so, anyone with her public key can decrypt it!)
Now, anybody with Alice’s public key can decrypt the hash part and see the hash, then what is the point of encrypting it with her private key, after all private key should only be used for decryption not encryption? Can’t Alice just append the hash as is?
No, The point of encrypting the hash part with Alice’s private key is not for security, but instead it is so that Alice cannot deny sending that message to Bob, because her private key was used to encrypt the hash part, also known as signing the message. And this can be verified since Alice’s public key can decrypt the hash, and Bob can independently verify the same hash value by decrypting the original message with his private key and computing the hash! Very cool, I know.
Conclusion
That was a glimpse into how messages are secured over the internet and how we can verify the authenticity of communications. PKI and cryptographic algorithms lie at the heart of all of this infrastructure that we have built up over decades, and in math we trust. I leave it to the reader to imagine the consequences of encryption being broken by an attacker.
Continue Reading Chapter 3: Quantum Computers
Description:
This chapter discusses how quantum computers and quantum algoritms pose a threat to the security of cryptogrphic algorithms. (coming soon)