Symmetric encryption Algorithm DES, 3DES and AES principle Summary (reprint)

Source: Internet
Author: User
Tags decrypt

1. symmetric encryption Algorithm 1.1 definition

raw data Span style= "font-family: the song Body;" >) and encryption key Span style= "font-family: the song Body;" > (mi yue key and the inverse algorithm of the same algorithm to decrypt the ciphertext, so that it can be restored to readable plaintext. In symmetric cryptographic algorithms, the use of key Only one, both parties use this key to encrypt and decrypt data, which requires the decryption party must know the encryption key beforehand.

1.2 Advantages and disadvantages

Advantages: The algorithm is open, the computational amount is small, the encryption speed is fast, and the encryption efficiency is high.

Disadvantages:

(1) Both sides of the transaction use the same key, the security is not guaranteed.

(2) every pair of users use symmetric encryption algorithm each time, need to use the other people do not know the unique key, which will make the two sides have the number of keys have a geometric growth, Key Management becomes the burden of users. Symmetric encryption algorithm is difficult to use in distributed network system, mainly because of difficulty in Key management and high cost of use.

1.3 commonly used symmetric encryption algorithm

The encryption algorithm based on " symmetric key " mainly includes des, 3DES(TripleDES), AES, RC2, RC4, RC5 and Blowfish . This article only describes the most commonly used symmetric encryption algorithms des, 3DES(TripleDES), and AES.

2.DES Overview

des company on 1975 , Data Mode bytes 64 bit, It is Des also 8 bytes 64 bit, is the data to be encrypted or decrypted; Mode

2.2 Algorithm principle

The DES algorithm transforms the plaintext input block of the decimal bit into a ciphertext output block, which uses a key that is also a bit, and its algorithm is divided into two main steps:

(1) Initial displacement

R0 two parts, Each part of the long 32 bit ... R0 is the two parts after the transposition output, L0 is the output of the left 32 bit, R0 is right 32< Span style= "font-family: the song Body;" > bit, example: set the input value before the change is d1d2d3 ... D64;r0=d57d49 ... D7

(2) Reverse replacement

After the operation of the three iterations, we get L16, R16, this as input, inverse substitution, the inverse permutation is exactly the inverse of the initial permutation, which is the ciphertext output.

2.3 Five grouping modes 2.3.1 EBC mode

Advantages:

1. Simple;

2. facilitates parallel computing;

3. The error will not be transmitted;

Disadvantages:

1. cannot hide the clear text mode;

2. active attacks on plaintext may occur.

2.3.2 CBC mode

CBC mode is also known as the Cipher Group link mode, as follows:

Advantages:

1. not easy to actively attack, security better than the ECB, suitable for transmitting long-length messages, is the standard of SSL,IPSec .

Disadvantages:

1, not conducive to parallel computing;

2, error transmission;

3, need to initialize Vector IV.

2.3.3 CFB mode

The CFB mode is also known as the password feedback mode, as shown in:

Advantages:

1, hide the clear text mode;

2, the group password into the stream mode;

3, can be encrypted in time to transfer less than the packet data.

Disadvantages:

1, not conducive to parallel computing;

2, Error Transmission: A clear text unit damage affects multiple units;

3, the only IV.

2.3.4 OFB mode

The OFB mode is also known as the output feedback mode, as shown in:

Advantages:

1, hide the clear text mode;

2, the group password into the stream mode;

3, can be encrypted in time to transfer less than the packet data.

Disadvantages:

1, not conducive to parallel computing;

2, the active attack on the plaintext is possible;

3, Error Transmission: A clear text unit damage affects multiple units.

2.3.5 CTR mode

The Count mode (CTR mode) encryption is a series of input data blocks ( called counts) that are encrypted, resulting in a series of output blocks that differ from or are ciphertext-plaintext. For the last block of data, it may be a long U- bit local data block, the U -bit will be used for XOR operation, and the remaining b-u bits will be discarded (b represents the length of the block). CTR decryption is similar. This series of counts must differ from each other. The assumed count is expressed as T1, T2, ..., Tn. The CTR mode can be defined as follows:

The CTR encryption formula is as follows:

Cj = Pj XOR Ek (Tj)

C*n = P*n XOR msbu (Ek (Tn)) j = 1, 2 ... n-1;

The CTR decryption formula is as follows:

Pj = Cj XOR Ek (Tj)

P*n = C*n XOR msbu (Ek (Tn)) j = 1, 2 ... n-1;

The AES CTR mode is shown in structure 5 .

Figure 5 mode structure of AES CTR

Fig 5 Structure of AES CTR Mode

Encryption method: The cipher algorithm generates a pseudo-random block stream of bytes, and the pseudo-random code block and the input plaintext are created to produce ciphertext output after the XOR operation. Ciphertext and the same pseudo-random code after the XOR operation can be re-generated plaintext.

CTR mode is widely used in ATM network security and IPSEC applications, and CRT mode has the following characteristics compared to other modes:

hardware efficiency: Allows simultaneous processing of multiple plaintext/ ciphertext.

software efficiency: Parallel computing is allowed, which makes good use of parallel technologies such as CPU pipelining.

preprocessing: The algorithm and the output of the cipher box do not depend on the input of plaintext and ciphertext, so if there is enough secure memory, the encryption algorithm will be just a series of XOR operations, which will greatly improve throughput.

Random Access: The decryption of block I cipher does not depend on the i-1 block cipher, providing high random access capability

provable security: the ability to prove that CTR is at least as safe as other modes (CBC, CFB, OFB, ...) )

Simplicity: Unlike other modes, the CTR mode only requires the implementation of the encryption algorithm, but does not require a decryption algorithm. This simplification is huge for algorithms that are inherently different from AES, such as encryption/decryption.

no padding and can be used effectively as streaming encryption.

2.4 commonly used filling methods

in Java for des, 3DES and AES three symmetric encryption algorithms, often used is nopadding(not filled), zeros Fill (0 fill), Pkcs5padding Fill.

2.4.1 ZerosPadding

Filled with 0 bytes, the result is as follows:

F1 F2 F3 F4 F5 F6 F7 F8// first block

F9 xx xx xx// second block

2.4.2 pkcs5padding

Each populated byte records the total number of bytes populated, with the following results:

F1 F2 F3 F4 F5 F6 F7 F8// first block

F9, and/or second block

Symmetric encryption Algorithm DES, 3DES and AES principle Summary (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.