summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2019-10-01 19:56:38 +0200
committerNiels Möller <nisse@lysator.liu.se>2019-10-01 19:56:38 +0200
commita3875d562abde88f258339176575c9ced95d8faa (patch)
tree3b375f844375dff6e810b4cfd201d879d53f6b0b
parentaef6b2aaa65c97ad6f0f0c17c8ea7e1c233828fd (diff)
downloadnettle-a3875d562abde88f258339176575c9ced95d8faa.tar.gz
Improve cfb8 test
* testsuite/testutils.c (test_cipher_cfb8): Reset destination area between tests. Encrypt/decrypt final partial block.
-rw-r--r--ChangeLog3
-rw-r--r--testsuite/testutils.c15
2 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index cdd32dc5..f2a85d01 100644
--- 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.
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index b24b498a..c9f21bab 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -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);