blob: cf79b64da7367d13e45d5df713af47104b6cb05c [file] [log] [blame]
Eugene Zemtsovc6819dd2019-11-18 20:21:06 -08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright 2019 Google LLC
4 */
5#ifndef _INCFS_INTEGRITY_H
6#define _INCFS_INTEGRITY_H
7#include <linux/types.h>
8#include <linux/kernel.h>
9#include <crypto/hash.h>
10
11#include <uapi/linux/incrementalfs.h>
12
13#include "internal.h"
14
15#define INCFS_MAX_MTREE_LEVELS 8
16#define INCFS_MAX_HASH_AREA_SIZE (1280 * 1024 * 1024)
17
18struct incfs_hash_alg {
19 const char *name;
20 int digest_size;
21 enum incfs_hash_tree_algorithm id;
22
23 struct crypto_shash *shash;
24};
25
26/* Merkle tree structure. */
27struct mtree {
28 struct incfs_hash_alg *alg;
29
30 u8 root_hash[INCFS_MAX_HASH_SIZE];
31
32 /* Offset of each hash level in the hash area. */
33 u32 hash_level_suboffset[INCFS_MAX_MTREE_LEVELS];
34
35 u32 hash_tree_area_size;
36
37 /* Number of levels in hash_level_suboffset */
38 int depth;
39};
40
Eugene Zemtsovc6819dd2019-11-18 20:21:06 -080041struct incfs_hash_alg *incfs_get_hash_alg(enum incfs_hash_tree_algorithm id);
42
Paul Lawrencebc6a70e2020-03-13 12:38:35 -070043struct mtree *incfs_alloc_mtree(struct mem_range signature,
44 int data_block_count);
Eugene Zemtsovc6819dd2019-11-18 20:21:06 -080045
46void incfs_free_mtree(struct mtree *tree);
47
48size_t incfs_get_mtree_depth(enum incfs_hash_tree_algorithm alg, loff_t size);
49
50size_t incfs_get_mtree_hash_count(enum incfs_hash_tree_algorithm alg,
51 loff_t size);
52
53int incfs_calc_digest(struct incfs_hash_alg *alg, struct mem_range data,
54 struct mem_range digest);
55
Eugene Zemtsovc6819dd2019-11-18 20:21:06 -080056#endif /* _INCFS_INTEGRITY_H */