]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Improve cfb8 test
authorNiels Möller <nisse@lysator.liu.se>
Tue, 1 Oct 2019 17:56:38 +0000 (19:56 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Tue, 1 Oct 2019 17:56:38 +0000 (19:56 +0200)
* testsuite/testutils.c (test_cipher_cfb8): Reset destination area
between tests. Encrypt/decrypt final partial block.

ChangeLog
testsuite/testutils.c

index cdd32dc56b1ba765a221e9f4f2f48416f82876ca..f2a85d0133a22a64ab361ce534e32735aa1e1e1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2019-10-01  Niels Möller  <nisse@lysator.liu.se>
 
+       * testsuite/testutils.c (test_cipher_cfb8): Reset destination area
+       between tests. Encrypt/decrypt final partial block.
+
        From Daiki Ueno, fixing bug reported by Stephan Mueller:
        * cfb.c (cfb8_decrypt): Don't truncate output IV if input is
        shorter than block size.
index b24b498a0bae4cf558f567e7f7cd9726f0186285..c9f21bab23462e447e0613c7184ac20c344cf14f 100644 (file)
@@ -442,8 +442,8 @@ test_cipher_cfb8(const struct nettle_cipher *cipher,
   ASSERT (key->length == cipher->key_size);
   ASSERT (iiv->length == cipher->block_size);
 
-  data = xalloc(length);
-  data2 = xalloc(length);
+  data = xalloc(length + 1);
+  data2 = xalloc(length + 1);
 
   for (block = 1; block <= length; block++)
     {
@@ -452,12 +452,16 @@ test_cipher_cfb8(const struct nettle_cipher *cipher,
       cipher->set_encrypt_key(ctx, key->data);
       memcpy(iv, iiv->data, cipher->block_size);
 
+      memset(data, 0x17, length + 1);
       for (i = 0; i + block <= length; i += block)
        {
          cfb8_encrypt(ctx, cipher->encrypt,
                       cipher->block_size, iv,
                       block, data + i, cleartext->data + i);
        }
+      cfb8_encrypt(ctx, cipher->encrypt,
+                  cipher->block_size, iv,
+                  length - i, data + i, cleartext->data + i);
 
       if (!MEMEQ(length, data, ciphertext->data))
        {
@@ -471,15 +475,21 @@ test_cipher_cfb8(const struct nettle_cipher *cipher,
          fprintf(stderr, "\n");
          FAIL();
        }
+      ASSERT (data[length] == 0x17);
+
       cipher->set_encrypt_key(ctx, key->data);
       memcpy(iv, iiv->data, cipher->block_size);
 
+      memset(data2, 0x17, length + 1);
       for (i = 0; i + block <= length; i += block)
        {
          cfb8_decrypt(ctx, cipher->encrypt,
                       cipher->block_size, iv,
                       block, data2 + i, data + i);
        }
+      cfb8_decrypt(ctx, cipher->encrypt,
+                  cipher->block_size, iv,
+                  length - i, data2 + i, data + i);
 
       if (!MEMEQ(length, data2, cleartext->data))
        {
@@ -493,6 +503,7 @@ test_cipher_cfb8(const struct nettle_cipher *cipher,
          fprintf(stderr, "\n");
          FAIL();
        }
+      ASSERT (data[length] == 0x17);
     }
 
   cipher->set_encrypt_key(ctx, key->data);