From 24ebf53f1e8a8afa27dcd768339bda70a740bb03 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Tue, 11 Aug 2015 07:22:16 +0300 Subject: Simplify OCB offset calculation for parallel implementations * cipher/camellia-glue.c (_gcry_camellia_ocb_crypt) (_gcry_camellia_ocb_auth): Precalculate Ls array always, instead of just if 'blkn % == 0'. * cipher/serpent.c (_gcry_serpent_ocb_crypt) (_gcry_serpent_ocb_auth): Ditto. * cipher/rijndael-aesni.c (get_l): Remove low-bit checks. (aes_ocb_enc, aes_ocb_dec, _gcry_aes_aesni_ocb_auth): Handle leading blocks until block counter is multiple of 4, so that parallel block processing loop can use 'c->u_mode.ocb.L' array directly. * tests/basic.c (check_ocb_cipher_largebuf): Rename to... (check_ocb_cipher_largebuf_split): ...this and add option to process large buffer as two split buffers. (check_ocb_cipher_largebuf): New. -- Patch simplifies source and reduce object size. Signed-off-by: Jussi Kivilinna --- tests/basic.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/basic.c b/tests/basic.c index c1aa76a7..4ea91a93 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -3153,7 +3153,8 @@ do_check_ocb_cipher (int inplace) static void -check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect) +check_ocb_cipher_largebuf_split (int algo, int keylen, const char *tagexpect, + unsigned int splitpos) { static const unsigned char key[32] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" @@ -3219,7 +3220,14 @@ check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect) goto out_free; } - err = gcry_cipher_authenticate (hde, inbuf, buflen); + if (splitpos) + { + err = gcry_cipher_authenticate (hde, inbuf, splitpos); + } + if (!err) + { + err = gcry_cipher_authenticate (hde, inbuf + splitpos, buflen - splitpos); + } if (err) { fail ("cipher-ocb, gcry_cipher_authenticate failed (large, algo %d): %s\n", @@ -3229,10 +3237,18 @@ check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect) goto out_free; } - err = gcry_cipher_final (hde); + if (splitpos) + { + err = gcry_cipher_encrypt (hde, outbuf, splitpos, inbuf, splitpos); + } if (!err) { - err = gcry_cipher_encrypt (hde, outbuf, buflen, inbuf, buflen); + err = gcry_cipher_final (hde); + if (!err) + { + err = gcry_cipher_encrypt (hde, outbuf + splitpos, buflen - splitpos, + inbuf + splitpos, buflen - splitpos); + } } if (err) { @@ -3267,10 +3283,18 @@ check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect) } /* Now for the decryption. */ - err = gcry_cipher_final (hdd); + if (splitpos) + { + err = gcry_cipher_decrypt (hdd, outbuf, splitpos, NULL, 0); + } if (!err) { - err = gcry_cipher_decrypt (hdd, outbuf, buflen, NULL, 0); + err = gcry_cipher_final (hdd); + if (!err) + { + err = gcry_cipher_decrypt (hdd, outbuf + splitpos, buflen - splitpos, + NULL, 0); + } } if (err) { @@ -3318,6 +3342,18 @@ out_free: } +static void +check_ocb_cipher_largebuf (int algo, int keylen, const char *tagexpect) +{ + unsigned int split; + + for (split = 0; split < 32 * 16; split = split * 2 + 16) + { + check_ocb_cipher_largebuf_split(algo, keylen, tagexpect, split); + } +} + + static void check_ocb_cipher (void) { -- cgit v1.2.1