xref: /rk3399_rockchip-uboot/include/android_avb/avb_hashtree_descriptor.h (revision ab608f806ee1d7fa63a18cc035e8ea62b67634e5)
15b69db07SJason Zhu /*
25b69db07SJason Zhu  * Copyright (C) 2016 The Android Open Source Project
35b69db07SJason Zhu  *
45b69db07SJason Zhu  * Permission is hereby granted, free of charge, to any person
55b69db07SJason Zhu  * obtaining a copy of this software and associated documentation
65b69db07SJason Zhu  * files (the "Software"), to deal in the Software without
75b69db07SJason Zhu  * restriction, including without limitation the rights to use, copy,
85b69db07SJason Zhu  * modify, merge, publish, distribute, sublicense, and/or sell copies
95b69db07SJason Zhu  * of the Software, and to permit persons to whom the Software is
105b69db07SJason Zhu  * furnished to do so, subject to the following conditions:
115b69db07SJason Zhu  *
125b69db07SJason Zhu  * The above copyright notice and this permission notice shall be
135b69db07SJason Zhu  * included in all copies or substantial portions of the Software.
145b69db07SJason Zhu  *
155b69db07SJason Zhu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
165b69db07SJason Zhu  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
175b69db07SJason Zhu  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
185b69db07SJason Zhu  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
195b69db07SJason Zhu  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
205b69db07SJason Zhu  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
215b69db07SJason Zhu  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
225b69db07SJason Zhu  * SOFTWARE.
235b69db07SJason Zhu  */
245b69db07SJason Zhu 
255b69db07SJason Zhu /*
265b69db07SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
275b69db07SJason Zhu #error "Never include this file directly, include libavb.h instead."
285b69db07SJason Zhu #endif
295b69db07SJason Zhu */
305b69db07SJason Zhu 
315b69db07SJason Zhu #ifndef AVB_HASHTREE_DESCRIPTOR_H_
325b69db07SJason Zhu #define AVB_HASHTREE_DESCRIPTOR_H_
335b69db07SJason Zhu 
345b69db07SJason Zhu #include <android_avb/avb_descriptor.h>
355b69db07SJason Zhu 
365b69db07SJason Zhu #ifdef __cplusplus
375b69db07SJason Zhu extern "C" {
385b69db07SJason Zhu #endif
395b69db07SJason Zhu 
40*ab608f80SJason Zhu /* Flags for hashtree descriptors.
41*ab608f80SJason Zhu  *
42*ab608f80SJason Zhu  * AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB: Do not apply the default A/B
43*ab608f80SJason Zhu  *   partition logic to this partition. This is intentionally a negative boolean
44*ab608f80SJason Zhu  *   because A/B should be both the default and most used in practice.
45*ab608f80SJason Zhu  */
46*ab608f80SJason Zhu typedef enum {
47*ab608f80SJason Zhu   AVB_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
48*ab608f80SJason Zhu } AvbHashtreeDescriptorFlags;
49*ab608f80SJason Zhu 
505b69db07SJason Zhu /* A descriptor containing information about a dm-verity hashtree.
515b69db07SJason Zhu  *
525b69db07SJason Zhu  * Hash-trees are used to verify large partitions typically containing
535b69db07SJason Zhu  * file systems. See
545b69db07SJason Zhu  * https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity for more
555b69db07SJason Zhu  * information about dm-verity.
565b69db07SJason Zhu  *
575b69db07SJason Zhu  * Following this struct are |partition_name_len| bytes of the
585b69db07SJason Zhu  * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then
595b69db07SJason Zhu  * |root_digest_len| bytes of the root digest.
605b69db07SJason Zhu  *
615b69db07SJason Zhu  * The |reserved| field is for future expansion and must be set to NUL
625b69db07SJason Zhu  * bytes.
63*ab608f80SJason Zhu  *
64*ab608f80SJason Zhu  * Changes in v1.1:
65*ab608f80SJason Zhu  *   - flags field is added which supports AVB_HASHTREE_DESCRIPTOR_FLAGS_USE_AB
66*ab608f80SJason Zhu  *   - digest_len may be zero, which indicates the use of a persistent digest
675b69db07SJason Zhu  */
685b69db07SJason Zhu typedef struct AvbHashtreeDescriptor {
695b69db07SJason Zhu   AvbDescriptor parent_descriptor;
705b69db07SJason Zhu   uint32_t dm_verity_version;
715b69db07SJason Zhu   uint64_t image_size;
725b69db07SJason Zhu   uint64_t tree_offset;
735b69db07SJason Zhu   uint64_t tree_size;
745b69db07SJason Zhu   uint32_t data_block_size;
755b69db07SJason Zhu   uint32_t hash_block_size;
765b69db07SJason Zhu   uint32_t fec_num_roots;
775b69db07SJason Zhu   uint64_t fec_offset;
785b69db07SJason Zhu   uint64_t fec_size;
795b69db07SJason Zhu   uint8_t hash_algorithm[32];
805b69db07SJason Zhu   uint32_t partition_name_len;
815b69db07SJason Zhu   uint32_t salt_len;
825b69db07SJason Zhu   uint32_t root_digest_len;
83*ab608f80SJason Zhu   uint32_t flags;
84*ab608f80SJason Zhu   uint8_t reserved[60];
855b69db07SJason Zhu } AVB_ATTR_PACKED AvbHashtreeDescriptor;
865b69db07SJason Zhu 
875b69db07SJason Zhu /* Copies |src| to |dest| and validates, byte-swapping fields in the
885b69db07SJason Zhu  * process if needed. Returns true if valid, false if invalid.
895b69db07SJason Zhu  *
905b69db07SJason Zhu  * Data following the struct is not validated nor copied.
915b69db07SJason Zhu  */
925b69db07SJason Zhu bool avb_hashtree_descriptor_validate_and_byteswap(
935b69db07SJason Zhu     const AvbHashtreeDescriptor* src,
945b69db07SJason Zhu     AvbHashtreeDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
955b69db07SJason Zhu 
965b69db07SJason Zhu #ifdef __cplusplus
975b69db07SJason Zhu }
985b69db07SJason Zhu #endif
995b69db07SJason Zhu 
1005b69db07SJason Zhu #endif /* AVB_HASHTREE_DESCRIPTOR_H_ */
101