Understanding and testing of the SSL Algorithm Library

Source: Internet
Author: User
Tags md5 hash asymmetric encryption

The SSL Algorithm Library contains three types of algorithms:
Symmetric encryption algorithms: Des, AES, and RC4;
Asymmetric encryption algorithms-RSA and DH;
Information Digest algorithm (one-way hash algorithm)-MD5 and Sha; in SSH, RSA is used to encrypt the Key Exchange Process of SSH V1; and DH is used to encrypt the Key Exchange Process of SSH v2, the DH algorithm is used to obtain the session key, and the DES algorithm is used to encrypt the SSH session process. DES algorithmThe DES algorithm is a symmetric encryption algorithm that uses block encryption to encrypt 64-bit (8 bytes) data blocks each time.
Symmetric encryption algorithms use the same key for encryption/Decryption. They can be divided into block encryption and stream encryption. Block Encryption can be divided into four modes:
1. ECB (Electronic cipher book): in ECB mode, each plaintext block is encrypted independently of other blocks. Although this is more efficient (data block encryption can be performed in parallel), it is vulnerable to attacks because encryption of the same plaintext block always produces the same ciphertext block. This is the basic DES encryption method in the SSL algorithm library.
2. CBC (Cipher Block Chaining): In CBC mode, blocks are continuously encrypted. before encrypting the current plaintext block, use the previous block encryption result to modify the current plaintext block. This process improves some encryption features (for example, the same plaintext block does not generate the same ciphertext block). However, because the encryption process is continuous, the CBC method does not support encryption parallelization. The CBC method uses the initial vector (iv) to start the link process. IV is used to modify the first plaintext block to be encrypted. In the SSL algorithm library, this is the encryption method provided by des for SSL.
3. CFB (Cipher Feedback, password feedback)
4. ofB (output feedback, output feedback) provides two types of DES algorithm Extension: 3DES and desx. 3DES uses the DES algorithm for three-key encryption, which has four methods:
1. DES-EEE3: Use 3 different keys, encryption-encryption in turn.
2. DES-EDE3: Use 3 different keys, encryption-decryption-encryption in turn.
3. DES-EEE3: Use 2 different keys for sequential encryption-encryption, 3rd and 1st use the same key.
4, DES-EDE3: Use 2 different keys, in turn encryption-decryption-encryption, 3rd and 1st use the same key. However, 3DES performs three DES encryption, so its efficiency is only 1/3 of DES. The desx algorithm can not lose efficiency, but also increase the key length.
Desx uses three different keys, and 1st uses the key to perform XOR operations on the block to be encrypted. 2nd uses the key to perform XOR operations on the block that has already been computed by XOR, 3rd use the key for DES encryption. In this way, only one DES encryption is performed, but the key length is the total length of three keys. AES AlgorithmAES is a new symmetric Data Encryption Algorithm in the United States. It is released as a replacement of DES. Compared with DES, it features fast speed and high confidentiality.
AES also uses block encryption. The basic block for AES processing is 128 bits, that is, 16 bytes. The basic block for des processing is 64 bits, that is, 8 bytes.
AES has three key lengths: 128 bits, 192 bits, and 256 bits. Des has a length of 56 bits, and 8 bits are usually 64 bits.
However, the time for AES to come out is not long, and the Registration Algorithm for AES has not been widely used yet. It still takes time to test its actual effect. RC4 algorithmThe RC4 algorithm is usually used for stream encryption with variable key lengths. It features simple and fast algorithms. However, a major RC4 security vulnerability has been discovered and is being gradually replaced by RC5. RSA AlgorithmWe should be familiar with the RSA algorithm. Here we mention PKCS and OAEP. PKCS padding and OAEP padding are two safe padding methods of RSA.
During RSA encryption, each encryption block is encrypted. The encryption block is formatted with a concept of padding. For short, the Padding string is ps, the encrypted block is EB, the encrypted block type is BT, And the plaintext data is D. The EB format is: EB = 00 | BT | PS | 00 | D. PS must consist of K-3-| d | bytes, where k is the length of the modulus. DH AlgorithmThe DH algorithm is usually used for both parties to negotiate the encryption key, and requires the cooperation of the DH negotiation process. The process used for key exchange in SSH. MD5 AlgorithmThe MD5 algorithm is one of the common information digest algorithms (or hash algorithms). Its typical application is to generate an information digest for a piece of information to prevent information tampering. MD5 can convert a byte string of any length into a large integer to compress it into a confidential format.
The MD5 hash value is 128 bits in length.
At present, the MD5 algorithm has been actually cracked. Sha AlgorithmThe Sha algorithm in the SSL Algorithm Library includes Sha and sha1, and sha256, sha384, and sha512.
Sha is an early version of Sha algorithm and has security problems.
Sha1 is widely used. It is also one of common information digest algorithms. Sha1's hash value length is 160 bits, Which is safer than 128bits hash algorithm (such as MD5), but slower.
Currently, sha1 has been cracked by theory (it takes a long time to crack, January 1, 6000)-Haha, Wang Xiaoyun from Shandong, China.
The length of the hash value corresponding to sha256, sha384, and sha512 is 256 bits, 384 bits, and 512 bits. The algorithm library is mainly used to test these seven algorithms. The testing environment is CPU = ppc440, OS = VxWorks, and platform = 6503.

Des TestThe test program provides 16 Weak keys (64 currently known), which are not used for testing, but for exclusion and corresponding test data.
1. cbcm Mode
Test data: group 1, initial vector cbc_iv, three keys cbc_key, cbc2_key, cbc3_key, plaintext cbc_data
Test process: the plaintext and initial vectors are used for XOR, 3DES encryption, 3DES decryption, and then the original vectors are used for XOR, and the output and plaintext are compared. All are consistent.
2. ECB Mode
Test data: 34 groups of key data: key_data, plaintext plain_data, and ciphertext cipher_data. A group of key data generates a key.
Test process: Use the key to encrypt the plaintext, compare the output and ciphertext, and then use the same key to decrypt the DES to compare the output and plaintext. All are consistent.
3. Ede ECB Mode
Test data: 34 groups of key data: key_data, plaintext plain_data, and ciphertext cipher_ecb2. A group of key data generates a key.
Test process: Use two keys to encrypt 3des-ede in plaintext, compare the output and ciphertext, And Then decrypt 3des-ede to compare the output and plaintext. All are consistent.
4. CBC Mode
Test data: group 1, initial vector cbc_iv, one key cbc_key, plaintext cbc_data, ciphertext cbc_ OK
Test process: the plaintext and initial vectors are used for XOR, DES encryption, comparison of output and ciphertext, and des decryption using the same key, and then the same or as the initial vector, compare the output and plain text. All are consistent.
5. desx CBC Mode
Test data: group 1, initial vector cbc_iv, three key cbc_key, plaintext cbc_data, ciphertext xcbc_ OK
Test process: Compare the plaintext and initial vectors with the desx encryption method, compare the output and ciphertext, decrypt the desx, and compare the output and plaintext with the initial vector. All are consistent.
6. Ede CBC Mode
Test data: group 1, initial vector cbc_iv, three key cbc_key, plaintext cbc_data, ciphertext cbc3_ OK
Test process: the plaintext and initial vectors are used for XOR, and 3des-ede encryption is performed to compare the output and ciphertext. 3des-ede decryption is performed to compare the output and plaintext with the initial vector. All are consistent.
7. PCBC Mode
It is basically the same as the CBC method, but the calculation method before DES encryption is different.
8. CFB Mode
Cfb8, cff8, cfb32, cfb48, cfb64, and ede_cfb64 were tested.
9. ofB Mode
OfB, ofb64, and ede_ofb64 are tested.
Test results:
1. correctness test: all pass.
2. speed test: the results are relatively stable. The data is as follows:
2.1. Key installation: 298 times per second, with a time consumption of 3.35us.
2.2, DES-ECB stream encryption, for des basic blocks: 353 times per second, each time 2.83us, encryption speed 2.83m Bytes/second.
2.3, DES-CBC block encryption, for 1024 bytes: 2.5 times per second, each time takes us, encryption speed 2.56m Bytes/second.
2.4, DES-EDE-CBC block encryption, for 1024 bytes: 0.89 times per second, each time took 1120us, encryption speed 0.91m Bytes/second.

AES Test Test data:
Six test modes (gfsbox, keysbox, MCT, MT, varkey, and vartxt) from ECB, CBC, CFB, ofB, and AES ), and three key-length (128, 192, 256 bits) test vector files, a total of 4*6*3 = 72 files, each file contains 10-sets of test vectors. The test mainly targets ECB and CBC models.
Test process:
1. Construct an encryption key based on the key data.
2. encrypt the plaintext to obtain the ciphertext. Compare the ciphertext with the known ciphertext.
3. Construct a decryption key based on the key data.
4. decrypt the ciphertext to obtain the plaintext, and compare the plaintext with the known plaintext.
5. If the CBC mode is adopted, the initial vector IV is required. Before encryption, the IV and encrypted data are used for specified operations.
Test notes:
1. If the ECB-MMT mode is adopted, the plaintext and ciphertext given by the test vector will exceed 128 bits of the Basic Block length. In ECB mode, fixed blocks are encrypted and each block is independent. Therefore, plaintext must be divided into fixed bits blocks during encryption. After encryption, during the comparison, BITs ciphertext block data is compared sequentially, and vice versa. In CBC mode, the length of the encrypted data is required.
2. If the CBC mode is used, the encryption function changes the initial vector IV. If you do not pay attention to this, the decryption will fail if the modified IV is sent during decryption. Therefore, you need to save the IV copy in advance and send it to the same IV during encryption/decryption.
Test results:
1. correctness test: all the test vectors about MCT fail, and all others pass.
2. speed test: the results are relatively stable. The data is as follows:
For the 128-bit key
2.1. encryption key installation: 368 times per second, which takes us each time.
2.2. decryption key installation: times per second, which takes 10.18us each time.
2.3, AES-ECB block encryption, for AES basic blocks: 228 times per second, each time takes 4.38us, encryption speed 3.66m Bytes/second.
2.4, AES-CBC block encryption, for AES Basic Block: 182 times per second, each time 5.50us, encryption speed 2.91m Bytes/second.

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.