]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Use nettle_lookup_hash.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 12 Jan 2017 21:03:22 +0000 (22:03 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 12 Jan 2017 21:03:22 +0000 (22:03 +0100)
ChangeLog
testsuite/meta-hash-test.c
tools/nettle-hash.c

index 29b04c016ba9993b56bdf026e463c60aa9b48c8d..788d5133bc9206a2d01c5fd8342f37aefb01fdbe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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
index 0dcd1b9b0b6b0fa55974f15ac71534f84bd005a7..afc715049a62764183464fc7a58f37e2de299eea 100644 (file)
@@ -21,20 +21,16 @@ const char* hashes[] = {
 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);
 }
-  
index fc991ee97ee76d41abd2b6dbd0ef9f679e960f86..d7d4ce2e719d41d158b58f5b6061594accd78e15 100644 (file)
@@ -60,19 +60,6 @@ list_algorithms (void)
            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)
@@ -211,7 +198,7 @@ main (int argc, char **argv)
     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",