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_HASH_DESCRIPTOR_H_ 325b69db07SJason Zhu #define AVB_HASH_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 hash descriptors. 41*ab608f80SJason Zhu * 42*ab608f80SJason Zhu * AVB_HASH_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_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0), 48*ab608f80SJason Zhu } AvbHashDescriptorFlags; 49*ab608f80SJason Zhu 505b69db07SJason Zhu /* A descriptor containing information about hash for an image. 515b69db07SJason Zhu * 525b69db07SJason Zhu * This descriptor is typically used for boot partitions to verify the 535b69db07SJason Zhu * entire kernel+initramfs image before executing it. 545b69db07SJason Zhu * 555b69db07SJason Zhu * Following this struct are |partition_name_len| bytes of the 565b69db07SJason Zhu * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then 575b69db07SJason Zhu * |digest_len| bytes of the digest. 585b69db07SJason Zhu * 595b69db07SJason Zhu * The |reserved| field is for future expansion and must be set to NUL 605b69db07SJason Zhu * bytes. 61*ab608f80SJason Zhu * 62*ab608f80SJason Zhu * Changes in v1.1: 63*ab608f80SJason Zhu * - flags field is added which supports AVB_HASH_DESCRIPTOR_FLAGS_USE_AB 64*ab608f80SJason Zhu * - digest_len may be zero, which indicates the use of a persistent digest 655b69db07SJason Zhu */ 665b69db07SJason Zhu typedef struct AvbHashDescriptor { 675b69db07SJason Zhu AvbDescriptor parent_descriptor; 685b69db07SJason Zhu uint64_t image_size; 695b69db07SJason Zhu uint8_t hash_algorithm[32]; 705b69db07SJason Zhu uint32_t partition_name_len; 715b69db07SJason Zhu uint32_t salt_len; 725b69db07SJason Zhu uint32_t digest_len; 73*ab608f80SJason Zhu uint32_t flags; 74*ab608f80SJason Zhu uint8_t reserved[60]; 755b69db07SJason Zhu } AVB_ATTR_PACKED AvbHashDescriptor; 765b69db07SJason Zhu 775b69db07SJason Zhu /* Copies |src| to |dest| and validates, byte-swapping fields in the 785b69db07SJason Zhu * process if needed. Returns true if valid, false if invalid. 795b69db07SJason Zhu * 805b69db07SJason Zhu * Data following the struct is not validated nor copied. 815b69db07SJason Zhu */ 825b69db07SJason Zhu bool avb_hash_descriptor_validate_and_byteswap(const AvbHashDescriptor* src, 835b69db07SJason Zhu AvbHashDescriptor* dest) 845b69db07SJason Zhu AVB_ATTR_WARN_UNUSED_RESULT; 855b69db07SJason Zhu 865b69db07SJason Zhu #ifdef __cplusplus 875b69db07SJason Zhu } 885b69db07SJason Zhu #endif 895b69db07SJason Zhu 905b69db07SJason Zhu #endif /* AVB_HASH_DESCRIPTOR_H_ */ 91