From e2c1560410591c31b060a245b748a0281a5efc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Thu, 5 Feb 2004 19:39:55 +0100 Subject: [PATCH] * testsuite/arcfour-test.c (test_main): Use test_cipher_stream. * testsuite/testutils.c (test_cipher_stream): New function, that tries dividing the input into varying size blocks before processing. Rev: src/nettle/testsuite/arcfour-test.c:1.3 Rev: src/nettle/testsuite/testutils.c:1.23 Rev: src/nettle/testsuite/testutils.h:1.19 --- testsuite/arcfour-test.c | 8 ++++---- testsuite/testutils.c | 44 ++++++++++++++++++++++++++++++++++++++++ testsuite/testutils.h | 8 ++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/testsuite/arcfour-test.c b/testsuite/arcfour-test.c index 5b1021a8..f4ec523a 100644 --- a/testsuite/arcfour-test.c +++ b/testsuite/arcfour-test.c @@ -4,10 +4,10 @@ int test_main(void) { - test_cipher(&nettle_arcfour128, - HL("01234567 89ABCDEF 00000000 00000000"), - HL("01234567 89ABCDEF"), - H("69723659 1B5242B1")); + test_cipher_stream(&nettle_arcfour128, + HL("01234567 89ABCDEF 00000000 00000000"), + HL("01234567 89ABCDEF"), + H("69723659 1B5242B1")); SUCCESS(); } diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 418faa12..ab7f9259 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -216,6 +216,50 @@ test_cipher_cbc(const struct nettle_cipher *cipher, FAIL(); } +void +test_cipher_stream(const struct nettle_cipher *cipher, + unsigned key_length, + const uint8_t *key, + unsigned length, + const uint8_t *cleartext, + const uint8_t *ciphertext) +{ + unsigned block; + + void *ctx = alloca(cipher->context_size); + uint8_t *data = alloca(length + 1); + + for (block = 1; block <= length; block++) + { + unsigned i; + + memset(data, 0x17, length + 1); + cipher->set_encrypt_key(ctx, key_length, key); + + for (i = 0; i + block < length; i += block) + { + cipher->encrypt(ctx, block, data + i, cleartext + i); + if (data[i + block] != 0x17) + FAIL(); + } + cipher->encrypt(ctx, length - i, data + i, cleartext + i); + if (data[length] != 0x17) + FAIL(); + + if (!MEMEQ(length, data, ciphertext)) + FAIL(); + } + + cipher->set_decrypt_key(ctx, key_length, key); + cipher->decrypt(ctx, length, data, data); + + if (data[length] != 0x17) + FAIL(); + + if (!MEMEQ(length, data, cleartext)) + FAIL(); +} + void test_hash(const struct nettle_hash *hash, unsigned length, diff --git a/testsuite/testutils.h b/testsuite/testutils.h index 2eb02a65..65298b23 100644 --- a/testsuite/testutils.h +++ b/testsuite/testutils.h @@ -60,6 +60,14 @@ test_cipher_cbc(const struct nettle_cipher *cipher, const uint8_t *ciphertext, const uint8_t *iv); +void +test_cipher_stream(const struct nettle_cipher *cipher, + unsigned key_length, + const uint8_t *key, + unsigned length, + const uint8_t *cleartext, + const uint8_t *ciphertext); + void test_hash(const struct nettle_hash *hash, unsigned length, -- GitLab