Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

CFB, OFB and other modes are meant for streaming and don't require padding. Are there still limitations such as the text needs to be greater than key length?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

These modes do indeed turn a block cipher into a stream cipher. The output will always be a multiple of the block size, but you can easily truncate the last block of output to match the plaintext size, but any size plaintext will work. In that manner, no padding is required.

share|improve this answer
    
If it simply truncates the last segment, how does it know to correctly decrypt it? I find the name for these block modes deceiving, because there's still a requirement for the data to come in 128/256 bit chunks. Think of it this way: if you get packet fragmentation during transmission you'll get a decryption error, right? –  m33lky Mar 11 '12 at 2:48
2  
Actually just looking at the diagram at wikipedia there shouldn't be a decryption error, since the last step is an XOR: CFB –  m33lky Mar 11 '12 at 2:59
2  
@m33lky, since the key stream is independent of the plaintext, there will be no problems decrypting. To decrypt the last (partial) block, generate the key stream, truncate to appropriate length, and xor. –  mikeazo Mar 11 '12 at 3:27
    
Very neat mode, why is everyone stuck with CBC? –  m33lky Mar 11 '12 at 3:33
3  
@m33lky: That is a different question, and an interesting one. –  Henrick Hellström Mar 11 '12 at 7:59
show 1 more comment

CFB does require padding unless you use a segment size of 1 bit (or 8 bits if your message is byte oriented). Check Section 5.2 in NIST 800-38A:

For the CFB mode, the total number of bits in the plaintext must
be a multiple of a parameter, denoted s, that does not exceed the
block size

OFB indeed does not require any padding.

There are no other limitations on the plaintext (but read very well the requirements about Initialization Vectors!).

share|improve this answer
1  
While these recommendation says CFB should be used with only full blocks/segments, I see nothing in its definition which would prohibit simply truncating the last block/segment to match the plaintext size. –  Paŭlo Ebermann May 30 '12 at 11:39
1  
True, but then you have a non-compliant CFB implementation. –  SquareRootOfTwentyThree May 30 '12 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.