Disclaimer: The purpose of this document is to analyze the common tea algorithms of TX. The reference information is based on the information published on the Internet. The key information is also filtered and there is no attack or leakage.
The simple encryption algorithm tea is so famous in China, probably because Tx is used in a large number of protocols and local data. Many people on the internet even call the Tx encryption algorithm the tea algorithm.
TX algorithm, data block encryption does use the tea (First Generation) algorithm, the key is 16 bytes, each processing of chunk data is 8 bytes (2 32-bit integers), but the number of rounds recommended by the standard tea algorithm is 32 or even 64, TX uses 16 rounds. It should be to speed up.
The TX encryption algorithm is used to process a data stream (buffer) and improve the CBC algorithm (see a blog saying this is an intertwined algorithm, it is very appropriate, most of the translated books are translated into block encryption, but they are hard to understand ). You can think that the symmetric encryption algorithms such as tea are the electronic codebook of the needle ECB and process a fixed-length data block. However, if only the ECB algorithm is used for stream data, there is a huge risk, because the symmetric encryption algorithm is essentially the same original text and key, and the ciphertext obtained must be consistent, simple Block Processing makes it easy to forge ciphertext data (on the Wiki, some people make ECB budgets for an image to compare the original image with the encrypted image, you can still see a lot of information from the ciphertext image ). The CBC algorithm modifies this problem by adding a random number before the ciphertext to generate the initialization vector IV (initialization vector). The ciphertext semi-finished product obtained through the ECB algorithm must be the same as the previous ciphertext, (including IV) obtain the ciphertext from the variance or budget because the random number is inconsistent each time. In this way, you can think that the ciphertext will never be repeated, and the difficulty of such forgery is greatly improved. In addition, the CBC algorithm is based on the ECB, so if your length is not enough to fill a block, it will be completed.
From Wikipedia
The general idea of the txcbc algorithm is that one byte is filled with length + N completed bytes (random number filling) + M-byte salt (random number filling) + data content + verification of K Bytes 0. Fill length = the size of the tea algorithm block 8-(% 8 for non-completion data area length division ), instead of completing the Data Partition length (the completion length of 1 byte + the length of data content + the sum of 0 verification lengths ). For decryption verification, after decryption, check that all the verification fields of K 0 are 0. It may be considered that it is a lot of trouble to forge ciphertext without knowing the key. It should be noted that the first block of this algorithm may contain original data, and its algorithm also encrypts the first block, this is not very consistent with the standard algorithm (standard algorithm IV is meaningless), and since N may be 0, it is necessary to add salt.
Aside from the security of the encryption algorithm, the implementation is somewhat lacking in performance considerations.
First, this algorithm does not take into account the issue of byte alignment in the original data area. (If the length is set to 2, the original data may not be in the alignment position for each processing, this affects some computing performance.
In addition, the tea algorithm is based on two 4-byte integers and does not specify the byte order. The implementation of TX uses network sequence for Internal Computing to consider the consistency of multiple platforms. This is indeed more rigorous, but considering that the service scenario is still x86 Platform in code 99.99%, and the advantages of small x86 headers in Integer Conversion, instead, it is better to directly require that all environments be unified into small-header byte-order operations (that is, to convert the environment in the big-headed byte-order to small-header byte-order operations ). This avoids the consumption of network order conversion in most cases.
In addition, each time an exclusive or exclusive operation is performed on each byte. The above problems are slightly improved, and it is possible to increase the speed by 20%.
Finally, YY considers the security of this algorithm. The tea algorithm is sufficient to meet most requirements. Although tea is a simple encryption algorithm, the algorithm used by Tx has long been cracked, and the source code is also flying. However, the most important security of symmetric encryption lies in the different dynamic keys of each user, not the algorithm itself. In addition, we need to understand that encryption algorithms are mainly used for protocol encryption on the Internet and simple encryption of stored data, what he can really guard against is third-party simulation and intercept packet analysis. For Trojans, they are not in the category of protection against encryption algorithms. For example, the application of cryptography is the processing of packets sent by British agents lurking in the enemy zone of World War II to the local region. It can make the Germans unable to decrypt the packets when they intercept the reports, the Trojan Horse is a German spy that may lurk beside the poster. Of course, the confrontation methods are inconsistent.
References:
The treasure book of cryptography in the past, it is said that this book was a control book and was banned from being exported to China. I personally felt that the translation was a bit messy.
The book password encoding and network security is clearer in some details.
Wikipedia: block password working mode, which is strongly recommended.
See the snow Forum: RTX (TX) Local Password saving tea deformation algorithm and reductor. See the algorithm description and feel the interface reversed by DLL.
Tea and qqtea should also be decompiled.
The article "Study on Security Analysis and Improvement of QQ logon protocol" illustrates the qqtea algorithm and discusses the security issues in the logon protocol. Although I disagree with all his views, but it is indeed a very interesting article.
Many pudn source code is implemented, such as qqtea, which should also be cracked, but download charges.
[The author of this article is fullsail (Yandu hantan). In the spirit of freedom, you can repeat this document in a non-profit situation. For details, refer to the blog link: http://www.cnblogs.com/fullsail. For the Baidu Library, the price of 360doc is doubled]