Score:0

Can we determine the size of n-bytes before encryption by AES-128?

sk flag

I am writing a program in python to encrypt files. This program takes subsequent 1024*1024 (1 mebibyte) chunks of data from a file and encrypts it using AES-128. This is performed in a loop until all the data in the file is encrypted. The issue is that the size of each 1 mebibyte of data is increased when it gets encrypted.

What I need is a way to determine the new chunk size for each 1 mebibyte after its gets encrypted .

Score:1
in flag

Yes, you can determine the amount that your file will grow, i.e. how much the ciphertext will expand compared to the plaintext. However, that's less determined by the block cipher than that it is determined by the block cipher mode of operation.

Very often CBC mode encryption is the default mode of operation on low level cryptographic API's. In that case - because your chunk of data is a multiple of the AES block size (16 bytes) - the ciphertext expansion is one full block of 16 bytes. If the IV is prefixed before the ciphertext then it will grow with another 16 bytes. The calculation for CBC padding size is N - (L % N) where N is the block size and L is the plaintext chunk size, both in bytes.

Other modes such as counter (CTR) mode don't use padding, but they may still store an IV or nonce with the ciphertext. Authenticated ciphertext such as AES-GCM may also store an authentication tag to provide message integrity and authenticity.

Of course, if you are using a high level API or protocol then all bets are off; you should take a look into the protocol to find out how much the files get expanded.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.