1 /* SPDX-License-Identifier: MIT */
3 * Copyright (C) 2016 The Android Open Source Project
6 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7 #error "Never include this file directly, include libavb.h instead."
10 #ifndef AVB_HASHTREE_DESCRIPTOR_H_
11 #define AVB_HASHTREE_DESCRIPTOR_H_
13 #include "avb_descriptor.h"
19 /* Flags for hashtree descriptors.
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.
26 AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
27 } AvbHashtreeDescriptorFlags;
29 /* A descriptor containing information about a dm-verity hashtree.
31 * Hash-trees are used to verify large partitions typically containing
33 * https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity for more
34 * information about dm-verity.
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.
40 * The |reserved| field is for future expansion and must be set to NUL
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
47 typedef struct AvbHashtreeDescriptor {
48 AvbDescriptor parent_descriptor;
49 uint32_t dm_verity_version;
53 uint32_t data_block_size;
54 uint32_t hash_block_size;
55 uint32_t fec_num_roots;
58 uint8_t hash_algorithm[32];
59 uint32_t partition_name_len;
61 uint32_t root_digest_len;
64 } AVB_ATTR_PACKED AvbHashtreeDescriptor;
66 /* Copies |src| to |dest| and validates, byte-swapping fields in the
67 * process if needed. Returns true if valid, false if invalid.
69 * Data following the struct is not validated nor copied.
71 bool avb_hashtree_descriptor_validate_and_byteswap(
72 const AvbHashtreeDescriptor* src,
73 AvbHashtreeDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
79 #endif /* AVB_HASHTREE_DESCRIPTOR_H_ */