In CFB mode, the previous ciphertext packet is sent back to the input of the cryptographic algorithm. The so-called feedback, which refers to the meaning of the return input, as shown:
In the ECB mode and CBC mode, the plaintext packet is encrypted by the cipher algorithm, whereas in the CFB mode, the plaintext packet is not encrypted directly by the cipher algorithm.
We can see the difference between the CBC mode and the CFB model, in CBC mode, there are two steps between the plaintext group and the cipher algorithm, whereas in the CFB mode, there is only XOR between the plaintext group and the cipher group.
Advantages of the CFB model:
1. Clear text mode is hidden
2. Block password conversion to stream mode
3. Data that is smaller than the packet can be encrypted in time
Disadvantages of the CFB model:
1. Not conducive to parallel computing
2. Error transfer: A clear text unit damage affects multiple units
3. The only IV
The attack on the CFB model comes from a book of Graphic cryptography Techniques:
The encryption of the CFB mode:
#include <string. H>#defineInch#defineOut//Suppose that the encryption is grouped into a group of 4 bytesvoidEncrypt (inChar*lpszdata, inChar*lpszkey, outChar*lpszendata) { inti =0; for(i =0; I <4; i++) {Lpszendata[i]= Lpszdata[i] ^Lpszkey[i]; }}voidDecrypt (inChar*lpszdata, inChar*lpszkey, outChar*lpszdedata) { inti =0; for(i =0; I <4; i++) {Lpszdedata[i]= Lpszdata[i] ^Lpszkey[i]; }}intMainintargcChar*argv[]) { CharSzdata[] ="Hello world!"; Charszendata[ -] = {0}; Charszdedata[ -] = {0}; Char*lpszkey ="1234"; inti =0; CharSziv[] ="9999"; printf ("Original data:%s\r\n", Szdata); while(true) { if(strlen (szdata + i) = =0) { Break; } //block encryption with previous ciphertextEncrypt (Sziv, Lpszkey, Sziv); //Group XOR operation with clear text//because of their own encryption is also different or, so do not write separately with the ciphertext group XOR functionEncrypt (Szdata +I, Sziv, Sziv); memcpy (Szendata+ I, Sziv,4); I+=4; } printf ("post-encrypted data:%s\r\n", Szendata); memcpy (Sziv,"9999",4); I=0; Charszpreendata[8] = {0}; while(true) { if(strlen (szendata + i) = =0) { Break; } memcpy (Szpreendata, Szendata+ I,4); //block encryption with the previous ciphertext, note that this is encryption, not decryption!!!!!!!!!!!!!!Encrypt (Sziv, Lpszkey, Sziv); //XOR operation with ciphertext group is clear//because of their own encryption is also different or, so do not write separately with the ciphertext group XOR functionEncrypt (Szendata + i, Sziv, Szdedata +i); memcpy (Sziv, Szpreendata,4); I+=4; } printf ("post-decryption data:%s\r\n", Szdedata); return 0;}
Raw data: Hello world!
Encrypted data: @nfa |:] "u/
Decrypted data: Hello world!
Block cipher mode: CFB Mode (ciphertext feedback mode)