When encrypting data that is not an even multiple of the block size, should I send the full last block?

If I am using a block cipher like AES, which has a block size of 128 bits, what if my data is not even multiples of 128 bits? I'm working with data packets and I don't want to resize my packet when encrypting it, but my data is not even a multiple of 128?

Does the AES block cipher allow for the processing of the short final block without resizing my message once it is encrypted?

+2


a source to share


4 answers


This detail depends on the chaining mode you are using. The chaining mode determines how many times you call the AES primitive. and what, for a given input message. The simplest chaining mode is to simply split the input data into sequential 16-byte blocks and encrypt each one independently; this is called the ECB (as "Electronic Code Book"), and is known to have weaknesses (namely, if two input blocks are identical, which is often found in "real life" data, then the two corresponding output blocks will be equal friend, and everyone can see it).

Some chaining modes increase the data, meaning the encrypted message will be slightly larger than the input message. Other chaining modes (like CTR) do not. Almost all secure chaining modes require processing a "seed" which is a piece of data (usually the same size as the block) that should not be secret but should be known to both the sender and the receiver and should be different for each messages. Some modes (like CBC) require an even random IV, while some other modes will be happy with a simple counter. It is generally accepted to send an IV along with an encrypted message. You can also get the IV from the private key itself using a hash function.



These things are complex, and it is difficult to know if you did it right: security cannot be verified; a weak cryptosystem compiles and works just like any other application. It is not recommended to create your own cryptographic protocol. Generally. Using trusted primitives does not guarantee that the result will be safe.

+7


a source


With a block cipher, you need to specify the length of the message to send because of this fact, and then just fill in the unused portion of the last block with random data. You should probably use encryption mode . Not to mention HMAC or some sort of integrity system, depending on what you're using AES for.



AES just says how to encrypt 16 bytes of data per block and nothing else.

+1


a source


The algorithm itself requires each block to be 128 bits, but it really depends on the specific implementation. But what is stopping you from filling your data with zeros to make it slightly out of 128 if that requirement is not automatically supported by implementation?

0


a source


This is really an implementation detail. Although this algorithm will require a full block, your implementation will probably add the last block with zeros or random data.

0


a source







All Articles