]> git.sur5r.net Git - u-boot/blob - lib/libavb/avb_hashtree_descriptor.h
3d3e647fe1c675d2c7670cb23efe1742b25c72ca
[u-boot] / lib / libavb / avb_hashtree_descriptor.h
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * SPDX-License-Identifier:     MIT
5  */
6
7 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
8 #error "Never include this file directly, include libavb.h instead."
9 #endif
10
11 #ifndef AVB_HASHTREE_DESCRIPTOR_H_
12 #define AVB_HASHTREE_DESCRIPTOR_H_
13
14 #include "avb_descriptor.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /* Flags for hashtree descriptors.
21  *
22  * AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB: Do not apply the default A/B
23  *   partition logic to this partition. This is intentionally a negative boolean
24  *   because A/B should be both the default and most used in practice.
25  */
26 typedef enum {
27   AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
28 } AvbHashtreeDescriptorFlags;
29
30 /* A descriptor containing information about a dm-verity hashtree.
31  *
32  * Hash-trees are used to verify large partitions typically containing
33  * file systems. See
34  * https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity for more
35  * information about dm-verity.
36  *
37  * Following this struct are |partition_name_len| bytes of the
38  * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then
39  * |root_digest_len| bytes of the root digest.
40  *
41  * The |reserved| field is for future expansion and must be set to NUL
42  * bytes.
43  *
44  * Changes in v1.1:
45  *   - flags field is added which supports AVB_HASHTREE_DESCRIPTOR_FLAGS_USE_AB
46  *   - digest_len may be zero, which indicates the use of a persistent digest
47  */
48 typedef struct AvbHashtreeDescriptor {
49   AvbDescriptor parent_descriptor;
50   uint32_t dm_verity_version;
51   uint64_t image_size;
52   uint64_t tree_offset;
53   uint64_t tree_size;
54   uint32_t data_block_size;
55   uint32_t hash_block_size;
56   uint32_t fec_num_roots;
57   uint64_t fec_offset;
58   uint64_t fec_size;
59   uint8_t hash_algorithm[32];
60   uint32_t partition_name_len;
61   uint32_t salt_len;
62   uint32_t root_digest_len;
63   uint32_t flags;
64   uint8_t reserved[60];
65 } AVB_ATTR_PACKED AvbHashtreeDescriptor;
66
67 /* Copies |src| to |dest| and validates, byte-swapping fields in the
68  * process if needed. Returns true if valid, false if invalid.
69  *
70  * Data following the struct is not validated nor copied.
71  */
72 bool avb_hashtree_descriptor_validate_and_byteswap(
73     const AvbHashtreeDescriptor* src,
74     AvbHashtreeDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif /* AVB_HASHTREE_DESCRIPTOR_H_ */