All notes

Cryptography notes

1. Symmetric Encryption

Symmetric encryption uses the same cryptographic key for both the encryption of plaintext and the decryption of ciphertext.

Sender      KEY      Ciphertext    KEY      Receiver
   |         |           |          |          | 
"HELLO" ------------> "XZYGH" ------------> "HELLO"
         Encryption            Decryption

It's popular for storing data encrypted with password (key). Examples of popular symmetric algorithms include: AES, DES, Blowfish, RC4. The differences between them are how difficult it is to perform, for example, a known-plaintext attack, chosen-plaintext attack, differential cryptanalysis or linear cryptanalysis.

The main problem of symmetric encryption is potentially vulnerable key distribution. Asymmetric encryption is the solution.

1.1. Known-plaintext attack

Known-plaintext attack is an attack model where the attacker has access to the plaintext and ciphertext. It's performed in order to extract symmetric key. Nowadays, modern symmetric algorithms are virtually immune to these attacks (unless you have bilions of years).

1.2. Differential cryptanalysis

Differential cryptanalysis is the study of how differences in the information input (plaintext) can affect the output (ciphertext). Its main point is to discover where the ciphertext reveals non-random behavior (controlled by the plaintext) and exploit such properties in order to recover the symmetric key.

2. Asymmetric Encryption

Assymetric encryption uses a pair of related keys. The pair of keys is randomly generated by User-A. One of them is arbitrarily chosen to be the private key. Second one is the public key. User-A keeps the private key secret but his public key is published, for example, on his website.

The pair of keys have some certain property: a plaintext encrypted with the private key can be decrypted only with the public key. Adjective private and public doesn't matter in this case because it's an arbitrary choice. It works the same in the opposite way.

Sender     KEY-A     Ciphertext   KEY-B     Receiver
   |         |           |          |          |
"HELLO" ------------> "XZYGH" ------------> "HELLO"
         Encryption            Decryption
 
           KEY-B                  KEY-A     
             |                      |          
"HELLO" ------------> "XZYGH" ------------> "HELLO"

It's not possible to encrypt and decrypt a message with the same key! It's also guaranteed that if you can decrypt a message with the public key it must have been encrypted with the corresponding private key. The content of the message is then not secret (because it can be decrypted with the known public key), but the sender of the message is confirmed (because only the sender has the private key).

How to send an encrypted message using asymmetric encryption? User-A has a pair of keys (Prv-A, Pub-A). User-B has a pair of keys as well (Prv-B, Pub-B).

                        Shared values:
    Prv-A                   Pub-A               Prv-B
                            Pub-B
    User-A                                      User-B     
|'''''''''''|                               |'''''''''''|
|  "HELLO"  |              ,------------->  |  "XYZGH"  |
|           |              |                |           |
|  +Prv-A   |              |                |  -Prv-B   |
|  +Pub-B   |              |                |  -Pub-A   |
| ="XYZGH"  | -------------'                | ="HELLO"  | ---> Message
|,,,,,,,,,,,|                               |,,,,,,,,,,,|

Assymetric encryption ensures couple things:

  1. The message can be decrypted only by User-B. It was encrypted with Pub-B key so only the corresponding Prv-B key can be used to decryption.
  2. The message was sent by User-A and no one else. It can be decrypted only with Pub-A so the Prv-A must be the key that encrypted the message.
  3. The message wasn't changed during the travel. Changing the ciphertext makes it impossible to decrypt.