summaryrefslogtreecommitdiff
path: root/tests/basic.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2015-02-28 18:04:34 +0200
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2015-02-28 18:04:34 +0200
commit5e66a4f8d5a63f58caeee367433dd8dd32346083 (patch)
treea535c3d472f3f8e501f43b721030aadc8c216ebd /tests/basic.c
parent505decf5369970219ddc9e78a20f97c623957b78 (diff)
downloadlibgcrypt-5e66a4f8d5a63f58caeee367433dd8dd32346083.tar.gz
Fix in-place encryption for OCB mode
* cipher/cipher-ocb.c (ocb_checksum): New. (ocb_crypt): Move checksum calculation outside main crypt loop, do checksum calculation for encryption before inbuf is overwritten. * tests/basic.c (check_ocb_cipher): Rename to ... (do_check_ocb_cipher): ... to this and add argument for testing in-place encryption/decryption. (check_ocb_cipher): New. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'tests/basic.c')
-rw-r--r--tests/basic.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/tests/basic.c b/tests/basic.c
index 869b3818..6ebc0568 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -2781,7 +2781,7 @@ check_ccm_cipher (void)
static void
-check_ocb_cipher (void)
+do_check_ocb_cipher (int inplace)
{
/* Note that we use hex strings and not binary strings in TV. That
makes it easier to maintain the test vectors. */
@@ -3028,7 +3028,18 @@ check_ocb_cipher (void)
err = gcry_cipher_final (hde);
if (!err)
- err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN, plain, plainlen);
+ {
+ if (inplace)
+ {
+ memcpy(out, plain, plainlen);
+ err = gcry_cipher_encrypt (hde, out, plainlen, NULL, 0);
+ }
+ else
+ {
+ err = gcry_cipher_encrypt (hde, out, MAX_DATA_LEN,
+ plain, plainlen);
+ }
+ }
if (err)
{
fail ("cipher-ocb, gcry_cipher_encrypt failed (tv %d): %s\n",
@@ -3075,7 +3086,19 @@ check_ocb_cipher (void)
/* Now for the decryption. */
err = gcry_cipher_final (hdd);
if (!err)
- err = gcry_cipher_decrypt (hdd, out, plainlen, NULL, 0);
+ {
+ if (inplace)
+ {
+ err = gcry_cipher_decrypt (hdd, out, plainlen, NULL, 0);
+ }
+ else
+ {
+ unsigned char tmp[MAX_DATA_LEN];
+
+ memcpy(tmp, out, plainlen);
+ err = gcry_cipher_decrypt (hdd, out, plainlen, tmp, plainlen);
+ }
+ }
if (err)
{
fail ("cipher-ocb, gcry_cipher_decrypt (tv %d) failed: %s\n",
@@ -3130,6 +3153,18 @@ check_ocb_cipher (void)
static void
+check_ocb_cipher (void)
+{
+ /* Check OCB cipher with separate destination and source buffers for
+ * encryption/decryption. */
+ do_check_ocb_cipher(0);
+
+ /* Check OCB cipher with inplace encrypt/decrypt. */
+ do_check_ocb_cipher(1);
+}
+
+
+static void
check_stream_cipher (void)
{
static const struct tv