meta-hash-test.c 965 Bytes
Newer Older
1
#include "testutils.h"
2
#include "nettle-internal.h"
3
#include "nettle-meta.h"
4
5
/* For NETTLE_MAX_HASH_CONTEXT_SIZE */
#include "sha3.h"
6
7
8
9
10

const char* hashes[] = {
  "md2",
  "md4",
  "md5",
11
  "ripemd160",
12
13
14
15
  "sha1",
  "sha224",
  "sha256",
  "sha384",
16
17
18
19
20
  "sha512",
  "sha3_224",
  "sha3_256",
  "sha3_384",
  "sha3_512",
21
22
};

23
void
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
test_main(void)
{
  int i,j;
  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 */
  }
  j = 0;
  while (NULL != nettle_hashes[j])
    j++;
  ASSERT(j == count); /* we are not missing testing any hashes */
39
  for (j = 0; NULL != nettle_hashes[j]; j++) {
40
    ASSERT(nettle_hashes[j]->digest_size <= NETTLE_MAX_HASH_DIGEST_SIZE);
41
42
    ASSERT(nettle_hashes[j]->context_size <= NETTLE_MAX_HASH_CONTEXT_SIZE);
  }
43
}