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