[PATCH 09/10] des: reduce CTR bulk counter carry handling to 16 bits

Jussi Kivilinna jussi.kivilinna at iki.fi
Fri Jul 24 20:50:16 CEST 2026


* cipher/des.c (_gcry_3des_ctr_enc): Use cipher_block_add_be16.
(do_tripledes_setkey): Assign ctr16be_enc bulk op.
--

3DES CTR increment used full-width cipher_block_add. Under ctr16be_enc
contract generic ctr code splits work at low 16-bit overflow, so low
16-bit addition suffices.

Moves 3DES off transitional ctr_enc alias.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/des.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cipher/des.c b/cipher/des.c
index 4b3f9a1e..c28fcf5a 100644
--- a/cipher/des.c
+++ b/cipher/des.c
@@ -911,7 +911,7 @@ _gcry_3des_ctr_enc(void *context, unsigned char *ctr, void *outbuf_arg,
       outbuf += DES_BLOCKSIZE;
       inbuf  += DES_BLOCKSIZE;
       /* Increment the counter.  */
-      cipher_block_add(ctr, 1, DES_BLOCKSIZE);
+      cipher_block_add_be16(ctr, 1, DES_BLOCKSIZE);
     }
 
   wipememory(tmpbuf, sizeof(tmpbuf));
@@ -1250,7 +1250,7 @@ do_tripledes_setkey ( void *context, const byte *key, unsigned keylen,
   memset (bulk_ops, 0, sizeof(*bulk_ops));
   bulk_ops->cbc_dec =  _gcry_3des_cbc_dec;
   bulk_ops->cfb_dec =  _gcry_3des_cfb_dec;
-  bulk_ops->ctr_enc =  _gcry_3des_ctr_enc;
+  bulk_ops->ctr16be_enc =  _gcry_3des_ctr_enc;
 
   tripledes_set3keys ( ctx, key, key+8, key+16);
 
-- 
2.53.0




More information about the Gcrypt-devel mailing list