2 * Copyright (C) 2016 The Android Open Source Project
4 * SPDX-License-Identifier: MIT
7 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
8 #error "Never include this file directly, include libavb.h instead."
11 #ifndef AVB_DESCRIPTOR_H_
12 #define AVB_DESCRIPTOR_H_
14 #include "avb_sysdeps.h"
20 /* Well-known descriptor tags.
22 * AVB_DESCRIPTOR_TAG_PROPERTY: see |AvbPropertyDescriptor| struct.
23 * AVB_DESCRIPTOR_TAG_HASHTREE: see |AvbHashtreeDescriptor| struct.
24 * AVB_DESCRIPTOR_TAG_HASH: see |AvbHashDescriptor| struct.
25 * AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE: see |AvbKernelCmdlineDescriptor| struct.
26 * AVB_DESCRIPTOR_TAG_CHAIN_PARTITION: see |AvbChainPartitionDescriptor| struct.
29 AVB_DESCRIPTOR_TAG_PROPERTY,
30 AVB_DESCRIPTOR_TAG_HASHTREE,
31 AVB_DESCRIPTOR_TAG_HASH,
32 AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE,
33 AVB_DESCRIPTOR_TAG_CHAIN_PARTITION,
36 /* The header for a serialized descriptor.
38 * A descriptor always have two fields, a |tag| (denoting its type,
39 * see the |AvbDescriptorTag| enumeration) and the size of the bytes
40 * following, |num_bytes_following|.
42 * For padding, |num_bytes_following| is always a multiple of 8.
44 typedef struct AvbDescriptor {
46 uint64_t num_bytes_following;
47 } AVB_ATTR_PACKED AvbDescriptor;
49 /* Copies |src| to |dest| and validates, byte-swapping fields in the
50 * process if needed. Returns true if valid, false if invalid.
52 * Data following the struct is not validated nor copied.
54 bool avb_descriptor_validate_and_byteswap(
55 const AvbDescriptor* src, AvbDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
57 /* Signature for callback function used in avb_descriptor_foreach().
58 * The passed in descriptor is given by |descriptor| and the
59 * |user_data| passed to avb_descriptor_foreach() function is in
60 * |user_data|. Return true to continue iterating, false to stop
63 * Note that |descriptor| points into the image passed to
64 * avb_descriptor_foreach() - all fields need to be byteswapped!
66 typedef bool AvbDescriptorForeachFunc(const AvbDescriptor* descriptor,
69 /* Convenience function to iterate over all descriptors in an vbmeta
72 * The function given by |foreach_func| will be called for each
73 * descriptor. The given function should return true to continue
74 * iterating, false to stop.
76 * The |user_data| parameter will be passed to |foreach_func|.
78 * Returns false if the iteration was short-circuited, that is if
79 * an invocation of |foreach_func| returned false.
81 * Before using this function, you MUST verify |image_data| with
82 * avb_vbmeta_image_verify() and reject it unless it's signed by a known
83 * good public key. Additionally, |image_data| must be word-aligned.
85 bool avb_descriptor_foreach(const uint8_t* image_data,
87 AvbDescriptorForeachFunc foreach_func,
90 /* Gets all descriptors in a vbmeta image.
92 * The return value is a NULL-pointer terminated array of
93 * AvbDescriptor pointers. Free with avb_free() when you are done with
94 * it. If |out_num_descriptors| is non-NULL, the number of descriptors
95 * will be returned there.
97 * Note that each AvbDescriptor pointer in the array points into
98 * |image_data| - all fields need to be byteswapped!
100 * Before using this function, you MUST verify |image_data| with
101 * avb_vbmeta_image_verify() and reject it unless it's signed by a known
102 * good public key. Additionally, |image_data| must be word-aligned.
104 const AvbDescriptor** avb_descriptor_get_all(const uint8_t* image_data,
106 size_t* out_num_descriptors)
107 AVB_ATTR_WARN_UNUSED_RESULT;
113 #endif /* AVB_DESCRIPTOR_H_ */