From 144839a8db524cf1397c2f72e604a30211d33a66 Mon Sep 17 00:00:00 2001 From: Tetsuya Yoshizaki Date: Fri, 19 Jan 2018 06:23:16 +0000 Subject: [PATCH] ltc: ctr: update pt and ct after acceleration Problem occurs in the condition of the following case: 1st decryption: Decrypt a ciphertext whose length is a multiple of the block size (16B) (len = n * block_size) 2nd decryption: Decrypt the continuing ciphertext whose length is not a multiple of the block size (len = m * block_size + l) In this case accel_ctr_encrypt() is firstly used at the 2nd decryption. If pt and ct are not updated, the top (l = len % block_size) bytes of decryption result are sometimes destroyed. From: Tetsuya Yoshizaki Signed-off-by: Tetsuya Yoshizaki Signed-off-by: Victor Chong (cherry picked from commit d1d3ae2d1e705f36e7d313aa4a9b61c0a146ee44) --- src/modes/ctr/ctr_encrypt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modes/ctr/ctr_encrypt.c b/src/modes/ctr/ctr_encrypt.c index ecc7b01..7319cf5 100644 --- a/src/modes/ctr/ctr_encrypt.c +++ b/src/modes/ctr/ctr_encrypt.c @@ -53,6 +53,8 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) { return err; } + pt += (len / ctr->blocklen) * ctr->blocklen; + ct += (len / ctr->blocklen) * ctr->blocklen; len %= ctr->blocklen; }