From: Niels Möller Date: Tue, 1 Oct 2019 17:56:38 +0000 (+0200) Subject: Improve cfb8 test X-Git-Tag: nettle_3.6rc1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3875d562abde88f258339176575c9ced95d8faa;p=thirdparty%2Fnettle.git Improve cfb8 test * testsuite/testutils.c (test_cipher_cfb8): Reset destination area between tests. Encrypt/decrypt final partial block. --- diff --git a/ChangeLog b/ChangeLog index cdd32dc5..f2a85d01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2019-10-01 Niels Möller + * 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);