File: test_hash_algs.c

package info (click to toggle)
fsverity-utils 1.6-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ansic: 2,683; sh: 324; makefile: 191
file content (45 lines) | stat: -rw-r--r-- 1,325 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: MIT
/*
 * Test the hash algorithm-related libfsverity APIs.
 *
 * Copyright 2020 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 */

#include "utils.h"

#define SHA256_DIGEST_SIZE 32
#define SHA512_DIGEST_SIZE 64

int main(void)
{
	install_libfsverity_error_handler();

	ASSERT(libfsverity_get_digest_size(0) == -1);
	ASSERT(libfsverity_get_hash_name(0) == NULL);
	ASSERT(libfsverity_find_hash_alg_by_name("bad") == 0);
	ASSERT(libfsverity_find_hash_alg_by_name(NULL) == 0);

	ASSERT(libfsverity_get_digest_size(100) == -1);
	ASSERT(libfsverity_get_hash_name(100) == NULL);

	ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA256) ==
	       SHA256_DIGEST_SIZE);
	ASSERT(!strcmp("sha256",
		       libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA256)));
	ASSERT(libfsverity_find_hash_alg_by_name("sha256") ==
	       FS_VERITY_HASH_ALG_SHA256);

	ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA512) ==
	       SHA512_DIGEST_SIZE);
	ASSERT(!strcmp("sha512",
		       libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA512)));
	ASSERT(libfsverity_find_hash_alg_by_name("sha512") ==
	       FS_VERITY_HASH_ALG_SHA512);

	printf("test_hash_algs passed\n");
	return 0;
}