Encryption

Encryption is a powerful technology that gives internet a huge potential to realize truly private and escure networks. However, encryption is a complicated topic and it is oftentimes misunderstood. Encryption actually enables three separate but equally important concepts. Encryption

While it is clear that encrypting data will keep that information private, it is not immediately obvious how encryption can ensure that data is unmodified and sent by and to the right person. In the following sections we'll look in to how encryption can accomplish these goals.

Cryptography

Cryptography is an ancient concept that refers to scrambling data in a way that it can only be descrambled by people who have some sort of "key". Today, cryptography is a complex mathematical field based in number theory that seeks to find algorithms to facilitate data encryption. Until the 1970s, most of these algorithms used something called an encryption key. This key was a long number that could be used by the algorithm to scramble and unscramble data. If two people wanted to send a secret message with eachother, they would first agree on an encryption key and then use this key to encipher and decipher their messages. Since only that single key can be used to read their messages, as long as they kept the key secret between themseleves, their messages are secure.

However there is one major flaw with this type of encryption. How do two people decide on a key? In order to make this decision, they most certainly need to communicate with eachother so that they can share their key. But in order to communicate with eachother securely they would already need an encrypted channel. Otherwise, someone would might be able to listen in on their conversation, and determine their secret key before they can even use that key for messaging.

In order to get around this chicken-in-the-egg problem, mathematicians in 1977 developed an ingenious idea. Due to some sophisticated properties of prime numbers, mathematicians discovered that encryption could be performed without sharing a secret key at all! They called this new type of cryptography, public key cryptography.

Public Key Cryptography

Instead of using a single key for encryption, public key cryptography requires both people who want to communicate generate two keys. One of their keys is called their private key. This key is kept secret and shouldn't be shared with anyone, even with the person they are communicating with. Their other key is called the public key. This key can be shared with everyone.

In the first public key cryptosystem developed in 1977, the public and private keys are large (upwards of 512 digits) numbers generated using similarly large primes. Due to the properties of number theory, mathematicians found a way to encrypt a message using one key, such that it could only be decrypted by the other. For instance, if a message is encrypted using someone's public key, then it can only be decrypted by their corresponding private key. If a message is encrypted by someone's private key, it can only be decrypted by someone's public key.

Now comes the ingenious result of this system. If Bob wants to send a secret message to Alice, Bob will encrypt the message using Alice's public key. Then Alice will read it by decrypting using her private key. To respond, Alice can then encrypt her own message using Bob's public key, and Bob can decrypt it using his private key. Since the public keys are readily available to anyone, Bob and Alice will have no trouble encrypting their messages. And since the private keys are always kept secret to the induvidual, Bob will know that only Alice can decrypt his messages and vice versa. At no time did Bob or Alice need to exchange anything secret! They were able to talk to eachother securely without sharing a secret key.

This allows Bob and Alice to keep their messages private, but how does Alice know that the messages she receives are from Bob and not someone impersonating him. After all, anyone has access to her public key, so anyone is able to send encrypted messages to her. There is also another issue, since anyone has access to Alice's public key, it may be possible for them to encrypt their own message for her and insert that into Bob's message or modify Bob's message completely. When Alice decrypts the message, she would have no way to know that the message has been modified.

To get around these issues, instead of encrypting the message to Alice once, Bob will actually encrypt the message twice. First, he'll encrypt the message using Alice's public key so that only she can decrypt it. Then he'll encrypt the message using his own (Bob's) private key. When Alice receives the message then, she'll first try decrypting it with Bob's public key, and then again with her private key. If the message is decrypted properly (it isn't garbled still), then Alice knows that it must have been encrypted using Bob's private key. Since only Bob has access to this key, Alice now knows that Bob himself sent the message! Thus, we Alice and Bob can communicate while ensuring the message remains unmodified and comes from the right person.

There is one last issue. How does Alice know that she is using Bob's public key and not someone else's? It could be possible for someone to trick Alice into using their own public key instead of Bob's. Then when Alice thinks she is talking to Bob, she will actually be talking to someone impersonating him. In a more complex example, a hacker could impersonate Bob when they're talking to Alice and impersonate Alice when they're talking to Bob. Then, this hacker could place themselves in between their messages. When Bob sends a message it will first be decrypted by the hacker and then forwarded to Alice. When Alice responds, the same will happen in reverse. Even as Bob and Alice think they are communicating normally with eachother through what appears to be an encrypted channel, the hacker will be able to see and even alter everything they say. It turns out that this problem is theoretically unavoidable and it is oftentimes known as a man-in-the-middle attack. However, since public keys can be exchanged publicly many people can inspect them and ensure they come from the person who claims to own it. In parctice, man-in-the-middle attacks are difficult and unlikely to compromise existing cryptosystems.

Cryptography In Practice

The first public key cryptosystem relied on the properties of prime numbers and was called RSA after its founders, Rivest, Shamir, and Adleman. Today more complex public key algorithms exist that function based on the properties of elliptic curves. Since these schemes are computationally intensive for encryption and decryption of long messages, they are usually used to securely share a secret key between two parties. Once shared, these parties will use this secret key to encrypt messages between them just like cryptography before the 1970s using a much faster algorithm. To ensure that these messages remain unmodified however, the original public and private keys are used to encypt a short summary of the message called a hash or digest. Once encrypted this summary is called a digital signature that verifies that the long message was unmodified and originated from the correct person. This way, the fast algorithms that use a single secret key can be used to transmit the long messages and the slower public key algorithms are used on the short hashes to ensure the message integrity. The process of determining that initial secret key is also important because if someone can guess the key it won't matter that it has been securely shared. That's where cryptographically secure random number generates and algorithms like the Diffie-Helman key exchange are needed.

Today, almost everything on the internet uses this sort of encryption. Sometimes the terms are a little different. PGP encryption which is used for emails calls public keys certificates. The same is true of SSL, TLS, and VPN encryption which are used to connect to websites. Other encryption schemes like OMEMO which is used for chat will call the public key a fingerprint because it is supposed to identify a particular user. That's why when Gajim asks you to "trust" someone's fingerprint, they are asking you to acknowledge that your recipient's public key actually belongs to the person you think it belongs to. This is important for preventing man-in-the-middle attacks. In practice you usually don't have to worry that such an attack is happening, but to be safe, you can always ask your recipient to read their public key to you and verify that the numbers match.

For voice and video calls one can use SRTP encryption. Unfortunately this method of encryption does not use a public key system so it is susceptible if a hacker intercepts your initial key negotiation messages. However, if you use TLS as your method for connecting to EzIsland on Linphone then this secret key will be sent encrypted using EzIsland's TLS certificates. However this means that you still need to trust EzIsland to avoid modifying or reading this secret key. Another option is to use DTLS encryption which does use public key cryptography so that you can avoid trusting EzIsland (assuming EzIsland is not altering the public key's sent through it). Another option is ZRTP which uses a similar mechanism. However SRTP is most widely supported and is likely sufficient for most cases.