summaryrefslogtreecommitdiff
path: root/cipher/cipher-ocb.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2015-07-26 23:39:51 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2015-07-27 11:47:18 +0300
commite950052bc6f5ff11a7c23091ff3f6b5cc431e875 (patch)
tree291e96b0a2ed67cac7f5e8bb5f95ef699ddb1094 /cipher/cipher-ocb.c
parentadbdca0d58f9c06dc3850b95e3455e179c1e6960 (diff)
downloadlibgcrypt-e950052bc6f5ff11a7c23091ff3f6b5cc431e875.tar.gz
Reduce amount of duplicated code in OCB bulk implementations
* cipher/cipher-ocb.c (_gcry_cipher_ocb_authenticate) (ocb_crypt): Change bulk function to return number of unprocessed blocks. * src/cipher.h (_gcry_aes_ocb_crypt, _gcry_aes_ocb_auth) (_gcry_camellia_ocb_crypt, _gcry_camellia_ocb_auth) (_gcry_serpent_ocb_crypt, _gcry_serpent_ocb_auth) (_gcry_twofish_ocb_crypt, _gcry_twofish_ocb_auth): Change return type to 'size_t'. * cipher/camellia-glue.c (get_l): Only if USE_AESNI_AVX or USE_AESNI_AVX2 defined. (_gcry_camellia_ocb_crypt, _gcry_camellia_ocb_auth): Change return type to 'size_t' and return remaining blocks; Remove unaccelerated common code path. Enable remaining common code only if USE_AESNI_AVX or USE_AESNI_AVX2 defined; Remove unaccelerated common code. * cipher/rijndael.c (_gcry_aes_ocb_crypt, _gcry_aes_ocb_auth): Change return type to 'size_t' and return zero. * cipher/serpent.c (get_l): Only if USE_SSE2, USE_AVX2 or USE_NEON defined. (_gcry_serpent_ocb_crypt, _gcry_serpent_ocb_auth): Change return type to 'size_t' and return remaining blocks; Remove unaccelerated common code path. Enable remaining common code only if USE_SSE2, USE_AVX2 or USE_NEON defined; Remove unaccelerated common code. * cipher/twofish.c (get_l): Only if USE_AMD64_ASM defined. (_gcry_twofish_ocb_crypt, _gcry_twofish_ocb_auth): Change return type to 'size_t' and return remaining blocks; Remove unaccelerated common code path. Enable remaining common code only if USE_AMD64_ASM defined; Remove unaccelerated common code. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/cipher-ocb.c')
-rw-r--r--cipher/cipher-ocb.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/cipher/cipher-ocb.c b/cipher/cipher-ocb.c
index bc6fd87f..096975a5 100644
--- a/cipher/cipher-ocb.c
+++ b/cipher/cipher-ocb.c
@@ -260,10 +260,17 @@ _gcry_cipher_ocb_authenticate (gcry_cipher_hd_t c, const unsigned char *abuf,
/* Use a bulk method if available. */
if (abuflen >= OCB_BLOCK_LEN && c->bulk.ocb_auth)
{
- size_t nblks = abuflen / OCB_BLOCK_LEN;
- c->bulk.ocb_auth (c, abuf, nblks);
- abuf += nblks * OCB_BLOCK_LEN;
- abuflen -= nblks * OCB_BLOCK_LEN;
+ size_t nblks;
+ size_t nleft;
+ size_t ndone;
+
+ nblks = abuflen / OCB_BLOCK_LEN;
+ nleft = c->bulk.ocb_auth (c, abuf, nblks);
+ ndone = nblks - nleft;
+
+ abuf += ndone * OCB_BLOCK_LEN;
+ abuflen -= ndone * OCB_BLOCK_LEN;
+ nblks = nleft;
}
/* Hash all full blocks. */
@@ -354,12 +361,17 @@ ocb_crypt (gcry_cipher_hd_t c, int encrypt,
/* Use a bulk method if available. */
if (nblks && c->bulk.ocb_crypt)
{
- c->bulk.ocb_crypt (c, outbuf, inbuf, nblks, encrypt);
- inbuf += nblks * OCB_BLOCK_LEN;
- outbuf += nblks * OCB_BLOCK_LEN;
- inbuflen -= nblks * OCB_BLOCK_LEN;
- outbuflen -= nblks * OCB_BLOCK_LEN;
- nblks = 0;
+ size_t nleft;
+ size_t ndone;
+
+ nleft = c->bulk.ocb_crypt (c, outbuf, inbuf, nblks, encrypt);
+ ndone = nblks - nleft;
+
+ inbuf += ndone * OCB_BLOCK_LEN;
+ outbuf += ndone * OCB_BLOCK_LEN;
+ inbuflen -= ndone * OCB_BLOCK_LEN;
+ outbuflen -= ndone * OCB_BLOCK_LEN;
+ nblks = nleft;
}
if (nblks)