avb2.0: add Android Verified Boot 2.0 library
[oweals/u-boot.git] / lib / libavb / avb_chain_partition_descriptor.h
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_CHAIN_PARTITION_DESCRIPTOR_H_
12 #define AVB_CHAIN_PARTITION_DESCRIPTOR_H_
13
14 #include "avb_descriptor.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /* A descriptor containing a pointer to signed integrity data stored
21  * on another partition. The descriptor contains the partition name in
22  * question (without the A/B suffix), the public key used to sign the
23  * integrity data, and rollback index location to use for rollback
24  * protection.
25  *
26  * Following this struct are |partition_name_len| bytes of the
27  * partition name (UTF-8 encoded) and |public_key_len| bytes of the
28  * public key.
29  *
30  * The |reserved| field is for future expansion and must be set to NUL
31  * bytes.
32  */
33 typedef struct AvbChainPartitionDescriptor {
34   AvbDescriptor parent_descriptor;
35   uint32_t rollback_index_location;
36   uint32_t partition_name_len;
37   uint32_t public_key_len;
38   uint8_t reserved[64];
39 } AVB_ATTR_PACKED AvbChainPartitionDescriptor;
40
41 /* Copies |src| to |dest| and validates, byte-swapping fields in the
42  * process if needed. Returns true if valid, false if invalid.
43  *
44  * Data following the struct is not validated nor copied.
45  */
46 bool avb_chain_partition_descriptor_validate_and_byteswap(
47     const AvbChainPartitionDescriptor* src,
48     AvbChainPartitionDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 #endif /* AVB_CHAIN_PARTITION_DESCRIPTOR_H_ */