0
$\begingroup$

I would like to apply CTR mode on a arbitrary length which isn't multiple of block size. Is this possible without applying padding.

In case we apply padding - how does the decryption algorithm know this padding!?

$\endgroup$
  • 1
    $\begingroup$ at least let me know why the down vote! new here!! $\endgroup$ – Nikhil L Sep 21 '17 at 5:06
1
$\begingroup$

In CTR mode, Enc is done as

enter image description here

CT = Enc(k,PT) = Enc(k,ctr) xor PT

The decryption is similar to encryption except you XOR Cipertext(CT) instead of Plaintext(PT).

enter image description here

PT = Dec(k,CT) = Enc(k,ctr) xor CT

So there is no need for plaintext to be multiple of block length and no need of padding because the PT or CT never become the input of the block cipher. Its the counter which is encrypted to generate a random stream and then Xored with plaintext or ciphertext. You can use the required length of generated bit-stream and discard the remaining.

More Details and picture Credit of CTR MODE

$\endgroup$
  • $\begingroup$ Welcome :) u have to process n=((plaintextLength / blockLength )+ 1) blocks using n ctrs, but u will discard the surplus bits of last block. $\endgroup$ – khan Sep 21 '17 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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