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.

In here different byte padding standards are listed as ANSI X.923, ISO 101.26, PKCS7, ISO/IEC 7816-4 and zero padding. All of them seems to apply padding to the last byte blocks. Odds are rare but what happens if the actual data is an integer product of the block size and last bytes conflict with a padding scheme.

For example, for PKCS7 let last 8 bytes be

FF FF FF FF FF FF FF 01

01 may actually be original data or padding. How do we know this? How do we avoid a data loss? (It seems trivial but image formats may become corrupted, because original data size changes.)

share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

Padding is always added, even if the plaintext is a product of the block size. This way the algorithm look for the last byte(s) and can safely interpret it as padding data. In case of alignment to the block size, a full block is added just for padding purposes.

So if your example shows 8 bytes of data and you are using a 64-bit block cipher, a block of eight 08 would be added as padding.

share|improve this answer
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.