hc
2024-08-16 a24a44ff9ca902811b99aa9663d697cf452e08ef
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
46
47
48
49
50
51
52
53
54
55
56
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright 2019 Google LLC
 */
#ifndef _INCFS_INTEGRITY_H
#define _INCFS_INTEGRITY_H
#include <linux/types.h>
#include <linux/kernel.h>
#include <crypto/hash.h>
 
#include <uapi/linux/incrementalfs.h>
 
#include "internal.h"
 
#define INCFS_MAX_MTREE_LEVELS 8
#define INCFS_MAX_HASH_AREA_SIZE (1280 * 1024 * 1024)
 
struct incfs_hash_alg {
   const char *name;
   int digest_size;
   enum incfs_hash_tree_algorithm id;
 
   struct crypto_shash *shash;
};
 
/* Merkle tree structure. */
struct mtree {
   struct incfs_hash_alg *alg;
 
   u8 root_hash[INCFS_MAX_HASH_SIZE];
 
   /* Offset of each hash level in the hash area. */
   u32 hash_level_suboffset[INCFS_MAX_MTREE_LEVELS];
 
   u32 hash_tree_area_size;
 
   /* Number of levels in hash_level_suboffset */
   int depth;
};
 
struct incfs_hash_alg *incfs_get_hash_alg(enum incfs_hash_tree_algorithm id);
 
struct mtree *incfs_alloc_mtree(struct mem_range signature,
               int data_block_count);
 
void incfs_free_mtree(struct mtree *tree);
 
size_t incfs_get_mtree_depth(enum incfs_hash_tree_algorithm alg, loff_t size);
 
size_t incfs_get_mtree_hash_count(enum incfs_hash_tree_algorithm alg,
                   loff_t size);
 
int incfs_calc_digest(struct incfs_hash_alg *alg, struct mem_range data,
           struct mem_range digest);
 
#endif /* _INCFS_INTEGRITY_H */