mirror of
https://github.com/openharmony/third_party_fsverity-utils.git
synced 2026-07-01 10:05:35 -04:00
5cd90ca608
From the 'fsverity' program, split out a library 'libfsverity'.
Currently it supports computing file measurements ("digests"), and
signing those file measurements for use with the fs-verity builtin
signature verification feature.
Rewritten from patches by Jes Sorensen <jsorensen@fb.com>.
I made a lot of improvements, e.g.:
- Separated library and program source into different directories.
- Drastically improved the Makefile.
- Added 'make check' target and rules to build test programs.
- In the shared lib, only export the functions intended to be public.
- Prefixed global functions with "libfsverity_" so that they don't cause
conflicts when the library is built as a static library.
- Made library error messages be sent to a user-specified callback
rather than always be printed to stderr.
- Keep showing OpenSSL error messages.
- Stopped abort()ing in library code, when possible.
- Made libfsverity_digest use native endianness.
- Moved file_size into the merkle_tree_params.
- Made libfsverity_get_hash_name() just return the static strings.
- Made some variables in the API uint32_t instead of uint16_t.
- Shared parse_hash_alg_option() between cmd_enable and cmd_sign.
- Lots of other fixes.
(Folded in a couple Makefile fixes from Jes.)
Reviewed-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Utility functions for programs
|
|
*
|
|
* Copyright 2018 Google LLC
|
|
*/
|
|
#ifndef PROGRAMS_UTILS_H
|
|
#define PROGRAMS_UTILS_H
|
|
|
|
#include "../common/libfsverity.h"
|
|
#include "../common/common_defs.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
void *xmalloc(size_t size);
|
|
void *xzalloc(size_t size);
|
|
void *xmemdup(const void *mem, size_t size);
|
|
char *xstrdup(const char *s);
|
|
|
|
__printf(1, 2) __cold void error_msg(const char *format, ...);
|
|
__printf(1, 2) __cold void error_msg_errno(const char *format, ...);
|
|
__printf(1, 2) __cold __noreturn void fatal_error(const char *format, ...);
|
|
__cold __noreturn void assertion_failed(const char *expr,
|
|
const char *file, int line);
|
|
|
|
#define ASSERT(e) ({ if (!(e)) assertion_failed(#e, __FILE__, __LINE__); })
|
|
|
|
struct filedes {
|
|
int fd;
|
|
char *name; /* filename, for logging or error messages */
|
|
};
|
|
|
|
bool open_file(struct filedes *file, const char *filename, int flags, int mode);
|
|
bool get_file_size(struct filedes *file, u64 *size_ret);
|
|
bool full_read(struct filedes *file, void *buf, size_t count);
|
|
bool full_write(struct filedes *file, const void *buf, size_t count);
|
|
bool filedes_close(struct filedes *file);
|
|
|
|
bool hex2bin(const char *hex, u8 *bin, size_t bin_len);
|
|
void bin2hex(const u8 *bin, size_t bin_len, char *hex);
|
|
|
|
#endif /* PROGRAMS_UTILS_H */
|