2017-01-12 Niels Möller <nisse@lysator.liu.se>
+ * tools/nettle-hash.c (find_algorithm): Deleted function.
+ (main): Replaced by call to nettle_lookup_hash.
+
+ * testsuite/meta-hash-test.c (test_main): Use nettle_lookup_hash.
+
* nettle-meta.h (nettle_hashes): New macro, expanding to a call to
nettle_get_hashes. Direct access to the array causes the array
size to leak into the ABI, since a plain un-relocatable executable
void
test_main(void)
{
- int i,j;
+ int i;
int count = sizeof(hashes)/sizeof(*hashes);
for (i = 0; i < count; i++) {
- for (j = 0; NULL != nettle_hashes[j]; j++) {
- if (0 == strcmp(hashes[i], nettle_hashes[j]->name))
- break;
- }
- ASSERT(NULL != nettle_hashes[j]); /* make sure we found a matching hash */
+ /* make sure we found a matching hash */
+ ASSERT(nettle_lookup_hash(hashes[i]) != NULL);
}
- j = 0;
- while (NULL != nettle_hashes[j])
- j++;
- ASSERT(j == count); /* we are not missing testing any hashes */
- for (j = 0; NULL != nettle_hashes[j]; j++)
- ASSERT(nettle_hashes[j]->digest_size <= NETTLE_MAX_HASH_DIGEST_SIZE);
+
+ while (NULL != nettle_hashes[i])
+ i++;
+ ASSERT(i == count); /* we are not missing testing any hashes */
+ for (i = 0; NULL != nettle_hashes[i]; i++)
+ ASSERT(nettle_hashes[i]->digest_size <= NETTLE_MAX_HASH_DIGEST_SIZE);
}
-
alg->name, alg->digest_size, alg->block_size);
};
-static const struct nettle_hash *
-find_algorithm (const char *name)
-{
- const struct nettle_hash *alg;
- unsigned i;
-
- for (i = 0; (alg = nettle_hashes[i]); i++)
- if (!strcmp(name, alg->name))
- return alg;
-
- return NULL;
-}
-
/* Also in examples/io.c */
static int
hash_file(const struct nettle_hash *hash, void *ctx, FILE *f)
die("Algorithm argument (-a option) is mandatory.\n"
"See nettle-hash --help for further information.\n");
- alg = find_algorithm (alg_name);
+ alg = nettle_lookup_hash (alg_name);
if (!alg)
die("Hash algorithm `%s' not supported or .\n"
"Use nettle-hash --list to list available algorithms.\n",