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_HASH_DESCRIPTOR_H_ 12 #define AVB_HASH_DESCRIPTOR_H_ 13 14 #include "avb_descriptor.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* Flags for hash descriptors. 21 * 22 * AVB_HASH_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_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0), 28 } AvbHashDescriptorFlags; 29 30 /* A descriptor containing information about hash for an image. 31 * 32 * This descriptor is typically used for boot partitions to verify the 33 * entire kernel+initramfs image before executing it. 34 * 35 * Following this struct are |partition_name_len| bytes of the 36 * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then 37 * |digest_len| bytes of the digest. 38 * 39 * The |reserved| field is for future expansion and must be set to NUL 40 * bytes. 41 * 42 * Changes in v1.1: 43 * - flags field is added which supports AVB_HASH_DESCRIPTOR_FLAGS_USE_AB 44 * - digest_len may be zero, which indicates the use of a persistent digest 45 */ 46 typedef struct AvbHashDescriptor { 47 AvbDescriptor parent_descriptor; 48 uint64_t image_size; 49 uint8_t hash_algorithm[32]; 50 uint32_t partition_name_len; 51 uint32_t salt_len; 52 uint32_t digest_len; 53 uint32_t flags; 54 uint8_t reserved[60]; 55 } AVB_ATTR_PACKED AvbHashDescriptor; 56 57 /* Copies |src| to |dest| and validates, byte-swapping fields in the 58 * process if needed. Returns true if valid, false if invalid. 59 * 60 * Data following the struct is not validated nor copied. 61 */ 62 bool avb_hash_descriptor_validate_and_byteswap(const AvbHashDescriptor* src, 63 AvbHashDescriptor* dest) 64 AVB_ATTR_WARN_UNUSED_RESULT; 65 66 #ifdef __cplusplus 67 } 68 #endif 69 70 #endif /* AVB_HASH_DESCRIPTOR_H_ */ 71