8
$\begingroup$

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?

$\endgroup$

2 Answers 2

3
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ 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? $\endgroup$
    – m33lky
    Mar 11, 2012 at 2:48
  • 2
    $\begingroup$ Actually just looking at the diagram at wikipedia there shouldn't be a decryption error, since the last step is an XOR: CFB $\endgroup$
    – m33lky
    Mar 11, 2012 at 2:59
  • 3
    $\begingroup$ @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. $\endgroup$
    – mikeazo
    Mar 11, 2012 at 3:27
  • 1
    $\begingroup$ Very neat mode, why is everyone stuck with CBC? $\endgroup$
    – m33lky
    Mar 11, 2012 at 3:33
  • 4
    $\begingroup$ @m33lky: That is a different question, and an interesting one. $\endgroup$ Mar 11, 2012 at 7:59
5
$\begingroup$

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!).

$\endgroup$
2
  • 2
    $\begingroup$ 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. $\endgroup$ May 30, 2012 at 11:39
  • 1
    $\begingroup$ True, but then you have a non-compliant CFB implementation. $\endgroup$ May 30, 2012 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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