AES GCM is a version of AES in counter mode, and a counter mode converts a block cipher into a stream cipher. The main advantage of a stream cipher is that we do not have to worry about padding. We get 16 bytes of pseudo random key stream per invocation of the AES encryption function, which gets XOR ed with the plaintext to get the corresponding ciphertext. When reading a file in programming languages like C
or C++
or Python
you can specify the number of bytes to read (choose a multiple of 16), while looping till you reach the end of file. The number of bytes read by these functions successfully can also be checked (let that be called $x$). Suppose you read a file of arbitrary length in blocks of bytes (which is a multiple of 16 ) , there are two possibilities, either the last block read might be exactly your block size (16*n
) or less than it. In either case, you have to invoke the AES encryption function n
times, but you use only, $x$ bytes of the key stream for the XOR with the plaintext.
Aravind A
- 157
- 6