Symmetric key encryption

aka single key encryption aka conventional encryption.

There are five ingredients  in symmetric key encryption:

1. Plain text – The input. It could be data or text.
2. Encryption algorithm – The algorithm that transforms the plain text into gibberish. It performs substitutions and transformations on the plan text.
3. Secret key – The secret key is also part of the input into the encryption algorithm. The substitutions and transformations generates different output depending on the key.
4. Cipher text -This is the result of the plan text when the encryption algorithm is done with it.
5. Decryption algorithm – This is kind of the encryption algorithm run backwards with the key, which “transforms” the cipher text into plain text.

There are two requirements for an symmetric key encryption algorithm:

1. One should not be able to decipher the cipher text or extract the key even if it’s in possession of other cipher text along with the plain text that produced it.
2. Sender and receiver has to make sure the key is stored and transferred securely. If the attacker knows the key and encryption algorithm it is able to decipher the text.

There are two ways of attacking a cipher:

1. Cryptanalysis: By studying the algorithm and by obtaining some kind of clue of the characteristics of the key, an attacker could guess the key or plain text.
2. Brute forcing: By using computers one could guess keys at an immense rate. A 56-bit key is no longer secure, since it could be brute forced in less than a day.

The most common symmetric key encryption algorithms are block ciphers. Two common block cipher algorithms are AES and DES.

A block cipher is build in iterations. The key is expanded into many keys, and the plain text is split into blocks. Each block is then encrypted with an expanded key.

DES

DES stands for Data Encryption Standard and is an Encryption Scheme. The actual encryption algorithm is referred to as DAE – Data Encryption Standard.

The algorithm itself has survived without any fatal exploits since 1977.

DES uses a 56-bit key which was proven insecure by EFF in 1999 when they built a DES-cracker. It took them three days to crack a key. Therefore, 3DES came to existence.

3DES

3DES is exactly what it sound like –  DES three times over with either two or three unique keys. This strengthens the key from being 56-bit to be 112-bit or even 168-bit.

Since the algorithm in DES is still considered to be secure and with an improved key strength of up to 168-bit, 3DES is considered to be secure.

The only drawback is that 3DES is about three times slower and still has a block size of 64 bit. A larger block size is preferred. It’s also produced in 1977 is does not work very well in software. Thus, AES is preferred over 3DES.

AES

Is the replacement for DES. It stands for Advances Encryption Standard. NIST asked for an algorithm that could use 128-bit, 192-bit or 256-bit keys. It should be suitable for both hardware and software. There will be a more in depth chapter about AES later on.

ECB

The data you want to encrypt is usually not as small as the block size of the encryption algorithm. That is solved by using ECB (electronic codebook), but ECB can leak information that could be used in cryptanalysis. Therefore modes of operation was developed.

Stream cipher

Stream cipher is the alternative to block cipher. A stream cipher could operate down to a single bit.

The stream cipher uses a key generator that it is being fed by. The recipient therefor needs to be able to generate the same key at the same time to decipher the scrambled data when it is received. So with a stream cipher, it is mostly the key generation that is hard to solve. For that, an LFSR is used.

### Message Authentication

MAC – Message Authentication Code

Two people decide they want to start emailing each other. Sven and Torbjörn they’re called. They each got a pet, both named Fido.

Torbjörn and Sven want to make sure that the emails they send to each other doesn’t get tampered with. Thus, they want a MAC.

They decide that they will use a key that is “Fido”, since that is easy to remember for both of them.

When Torbrjörn sends an email to Sven, he runs it trough a program that creates a code that is appended in the end of the email. The code is generated using the key (“Fido”) and the content of the email (“Hej Sven! Läget? MVH Torbjörn!”).

When Sven received the email he reads it. Then he wants to make sure that it wasn’t tampered with along the way.

So he uses the same program as Torbjörn did and runs the email (without the MAC) using the same key as Torbjörn used. The resulting string should be the same as in the footer of the mail he received, or else someone tampered with it.

That’s basically it.

### Hashes

A hash could be used instead of MAC. Then the message and a key is used to produce a hash that is appended to the actual message. The receiver creates a hash from the received message (without the hash) and with the same key, then compares the hashes. If they are the same – the message hasn’t been tampered with.

There are five requirements for a hash, depending what the hash should be used for:

1. It should be possible to produce a hash out of any size of data.
2. It should produce a fixed length of output.
3. It should be easy to compute for any size of data.
4. It should be computationally infeasible to reproduce the original data given only the hash. This is called “one-way” or “preimage resistant“. I.e it should be impossible to “dehash”.
5. It should be computationally infeasible to produce an identical hash from other data given the original message.
6. It should be computationally infeasible to produce an identical hash, even when picking the sources by yourself.

Source

The sixth point defines a secure hash.

### Public key encryption

Public key encryption is asymmetric. That means that it consists of two keys instead of one. Both symmetric- and asymmetric key encryption hold the same level of security – both depends on the length and complexity of the key. Both are vulnerable to brute forcing, as most crypto (even though the time complexity vary).

Public key encryption consists of 6 ingredients:

1. Plain text – As with symmetric key encryption, you need something to encrypt. (Whaaaat!?)
2. Encryption algorithm – An algorithm that transforms the plain text to gibberish.
3. A public and a private key –  In asymmetric encryption you need two keys. One key is for encryption and the other key is for decryption. In symmetric encryption the key is referred to as a secret key, in this case that would be the private key. It’s called a private key to avoid confusion with symmetric encryption, but they’re the same thing essentially.
4. Cipher text – The resulting text when the encryption algorithm is done with the plain text.
5. Decryption algorithm – The algorithm reads the cipher text and decrypts it using the private key and public key, resulting in plain text.

So Alice and Bob want to chat securely using public key encryption so that NSA and FRA can’t read what they’re saying.

Encryption. Bob and Alice generates a public- and a private key each. Bob sends hes public key to Alice and Alice sends her public key to Bob. Then Bob decides he want to send a love-letter to Alice. He writes the letter and encrypts it using Alice public key. When Alice receives the letter, she decrypts the letter using her private key. Then she blushes.

Authenticity and integrity. Bob could also encrypt the letter using hes private key. Then everyone who’s got Bobs public key would be able to decrypt the letter. This way of operation does not provide any secrecy. Instead it provides authenticity and data integrity.

Public key certificate. Since anyone could create a public- and private key and tell people that they are Bob, we need a way to make sure that the public key belongs to the actual Bob. We do this with a Public Key Certificate. The certificate consists of the public key and the user ID. The certificate is then signed by entities that can confirm that the public key is the actual Bob-public key.

– “Hello, I’m Bob. Here is my public key.”

– “Hello “Bob”. Could you prove it?”

– “Sure, here’s a certificate! The Swedish police signed it when they printed my passport.”

– “Great, hello Real-Bob!”

X.509 has come to be the standard protocol of Public Key Encryption. It is used in TLS, SSH and IPsec, amongst other.

### Random- and pseudorandom numbers

A number is considered to be random if:

1. All numbers have the same chance of occurring. I.e. the numbers should occur at about the same frequency.
2. No value should be based on the others in the sequence.

The difference between random- and pseudorandom numbers is that a pseudorandom number not statistically random, but “random enough“.

A True Random Number Generator (TRNG) could for example use unpredictable natural events, such as detecting pulses from ionizing radiation events.

Published inIT-sec