Home GnuPG

Avoid division by spec->blocksize in cipher mode handlers

Description

Avoid division by spec->blocksize in cipher mode handlers

* cipher/cipher-internal.h (_gcry_blocksize_shift): New.
* cipher/cipher-cbc.c (_gcry_cipher_cbc_encrypt)
(_gcry_cipherp_cbc_decrypt): Use bit-level operations instead of
division to get number of blocks and check input length against
blocksize.
* cipher/cipher-cfb.c (_gcry_cipher_cfb_encrypt)
(_gcry_cipher_cfb_decrypt): Ditto.
* cipher/cipher-cmac.c (_gcry_cmac_write): Ditto.
* cipher/cipher-ctr.c (_gcry_cipher_ctr_crypt): Ditto.
* cipher/cipher-ofb.c (_gcry_cipher_ofb_encrypt)
(_gcry_cipher_ofb_decrypt): Ditto.

Integer division was causing 10 to 20 cycles per call overhead
for cipher modes on x86-64.

  • Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>

Details

Provenance
jukiviliAuthored on Jun 19 2018, 5:34 PM
Parents
rCa69021535b47: Fix CBC-CTS+CBC-MAC flag check
Branches
Unknown
Tags
Unknown