Commit e2c15604 authored by Niels Möller's avatar Niels Möller

* 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
parent e61f5a9e
......@@ -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();
}
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment