Debian Codegraph @

programs/test_hash_algs.c

raw
1 // SPDX-License-Identifier: MIT
2 /*
3 * Test the hash algorithm-related libfsverity APIs.
4 *
5 * Copyright 2020 Google LLC
6 *
7 * Use of this source code is governed by an MIT-style
8 * license that can be found in the LICENSE file or at
9 * https://opensource.org/licenses/MIT.
10 */
11
12 #include "utils.h"
13
14 #define SHA256_DIGEST_SIZE 32
15 #define SHA512_DIGEST_SIZE 64
16
17 int main(void)
18 {
19 install_libfsverity_error_handler();
20
21 ASSERT(libfsverity_get_digest_size(0) == -1);
22 ASSERT(libfsverity_get_hash_name(0) == NULL);
23 ASSERT(libfsverity_find_hash_alg_by_name("bad") == 0);
24 ASSERT(libfsverity_find_hash_alg_by_name(NULL) == 0);
25
26 ASSERT(libfsverity_get_digest_size(100) == -1);
27 ASSERT(libfsverity_get_hash_name(100) == NULL);
28
29 ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA256) ==
30 SHA256_DIGEST_SIZE);
31 ASSERT(!strcmp("sha256",
32 libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA256)));
33 ASSERT(libfsverity_find_hash_alg_by_name("sha256") ==
34 FS_VERITY_HASH_ALG_SHA256);
35
36 ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA512) ==
37 SHA512_DIGEST_SIZE);
38 ASSERT(!strcmp("sha512",
39 libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA512)));
40 ASSERT(libfsverity_find_hash_alg_by_name("sha512") ==
41 FS_VERITY_HASH_ALG_SHA512);
42
43 printf("test_hash_algs passed\n");
44 return 0;
45 }