Eric Biggers | 5cd90ca | 2020-05-25 13:45:31 -0700 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Private header for libfsverity |
| 4 | * |
| 5 | * Copyright 2020 Google LLC |
| 6 | */ |
| 7 | #ifndef LIB_LIB_PRIVATE_H |
| 8 | #define LIB_LIB_PRIVATE_H |
| 9 | |
| 10 | #include "../common/libfsverity.h" |
| 11 | #include "../common/common_defs.h" |
| 12 | #include "../common/fsverity_uapi.h" |
| 13 | |
| 14 | #include <stdarg.h> |
| 15 | |
| 16 | #define LIBEXPORT __attribute__((visibility("default"))) |
| 17 | |
| 18 | /* hash_algs.c */ |
| 19 | |
| 20 | struct fsverity_hash_alg { |
| 21 | const char *name; |
| 22 | unsigned int digest_size; |
| 23 | unsigned int block_size; |
| 24 | struct hash_ctx *(*create_ctx)(const struct fsverity_hash_alg *alg); |
| 25 | }; |
| 26 | |
| 27 | const struct fsverity_hash_alg *libfsverity_find_hash_alg_by_num(u32 alg_num); |
| 28 | |
| 29 | struct hash_ctx { |
| 30 | const struct fsverity_hash_alg *alg; |
| 31 | void (*init)(struct hash_ctx *ctx); |
| 32 | void (*update)(struct hash_ctx *ctx, const void *data, size_t size); |
| 33 | void (*final)(struct hash_ctx *ctx, u8 *out); |
| 34 | void (*free)(struct hash_ctx *ctx); |
| 35 | }; |
| 36 | |
| 37 | void libfsverity_hash_init(struct hash_ctx *ctx); |
| 38 | void libfsverity_hash_update(struct hash_ctx *ctx, const void *data, |
| 39 | size_t size); |
| 40 | void libfsverity_hash_final(struct hash_ctx *ctx, u8 *digest); |
| 41 | void libfsverity_hash_full(struct hash_ctx *ctx, const void *data, size_t size, |
| 42 | u8 *digest); |
| 43 | void libfsverity_free_hash_ctx(struct hash_ctx *ctx); |
| 44 | |
| 45 | /* utils.c */ |
| 46 | |
| 47 | void *libfsverity_zalloc(size_t size); |
| 48 | void *libfsverity_memdup(const void *mem, size_t size); |
| 49 | |
| 50 | __cold void |
| 51 | libfsverity_do_error_msg(const char *format, va_list va, int err); |
| 52 | |
| 53 | __printf(1, 2) __cold void |
| 54 | libfsverity_error_msg(const char *format, ...); |
| 55 | |
| 56 | __printf(1, 2) __cold void |
| 57 | libfsverity_error_msg_errno(const char *format, ...); |
| 58 | |
| 59 | __cold void |
| 60 | libfsverity_warn_on(const char *condition, const char *file, int line); |
| 61 | |
| 62 | #define WARN_ON(condition) \ |
| 63 | ({ \ |
| 64 | bool c = (condition); \ |
| 65 | \ |
| 66 | if (c) \ |
| 67 | libfsverity_warn_on(#condition, __FILE__, __LINE__); \ |
| 68 | c; \ |
| 69 | }) |
| 70 | |
| 71 | __cold void |
| 72 | libfsverity_bug_on(const char *condition, const char *file, int line); |
| 73 | |
| 74 | #define BUG_ON(condition) \ |
| 75 | ({ \ |
| 76 | bool c = (condition); \ |
| 77 | \ |
| 78 | if (c) \ |
| 79 | libfsverity_bug_on(#condition, __FILE__, __LINE__); \ |
| 80 | c; \ |
| 81 | }) |
| 82 | |
| 83 | #endif /* LIB_LIB_PRIVATE_H */ |