From: Niels Möller Date: Mon, 11 Mar 2013 07:54:36 +0000 (+0100) Subject: Test different alignment for hash input. X-Git-Tag: nettle_2.7_release_20130424~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2152b303a2d144c9cf9ea8594915268d3e76b0a6;p=thirdparty%2Fnettle.git Test different alignment for hash input. --- diff --git a/ChangeLog b/ChangeLog index 80b21856..bfaaa70c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-03-11 Niels Möller + + * testsuite/testutils.c (test_hash): Test different alignments for + the hash input. + 2013-03-08 Niels Möller * armv7/aes-decrypt-internal.asm: New file, 15% speedup. diff --git a/testsuite/testutils.c b/testsuite/testutils.c index b1eb5747..a264b4ca 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -523,6 +523,8 @@ test_hash(const struct nettle_hash *hash, { void *ctx = xalloc(hash->context_size); uint8_t *buffer = xalloc(hash->digest_size); + uint8_t *input; + unsigned offset; ASSERT (digest->length == hash->digest_size); @@ -549,8 +551,25 @@ test_hash(const struct nettle_hash *hash, ASSERT(buffer[hash->digest_size - 1] == 0); + input = xalloc (msg->length + 16); + for (offset = 0; offset < 16; offset++) + { + memset (input, 0, msg->length + 16); + memcpy (input + offset, msg->data, msg->length); + hash->update (ctx, msg->length, input + offset); + hash->digest (ctx, hash->digest_size, buffer); + if (MEMEQ(hash->digest_size, digest->data, buffer) == 0) + { + fprintf(stdout, "hash input address: %p\nGot:\n", input + offset); + print_hex(hash->digest_size, buffer); + fprintf(stdout, "\nExpected:\n"); + print_hex(hash->digest_size, digest->data); + abort(); + } + } free(ctx); free(buffer); + free(input); } void