1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright (C) 2016 The Android Open Source Project
4 */
5
6#if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7#error "Never include this file directly, include libavb.h instead."
8#endif
9
10#ifndef AVB_HASH_DESCRIPTOR_H_
11#define AVB_HASH_DESCRIPTOR_H_
12
13#include "avb_descriptor.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/* Flags for hash descriptors.
20 *
21 * AVB_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB: Do not apply the default A/B
22 *   partition logic to this partition. This is intentionally a negative boolean
23 *   because A/B should be both the default and most used in practice.
24 */
25typedef enum {
26  AVB_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
27} AvbHashDescriptorFlags;
28
29/* A descriptor containing information about hash for an image.
30 *
31 * This descriptor is typically used for boot partitions to verify the
32 * entire kernel+initramfs image before executing it.
33 *
34 * Following this struct are |partition_name_len| bytes of the
35 * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then
36 * |digest_len| bytes of the digest.
37 *
38 * The |reserved| field is for future expansion and must be set to NUL
39 * bytes.
40 *
41 * Changes in v1.1:
42 *   - flags field is added which supports AVB_HASH_DESCRIPTOR_FLAGS_USE_AB
43 *   - digest_len may be zero, which indicates the use of a persistent digest
44 */
45typedef struct AvbHashDescriptor {
46  AvbDescriptor parent_descriptor;
47  uint64_t image_size;
48  uint8_t hash_algorithm[32];
49  uint32_t partition_name_len;
50  uint32_t salt_len;
51  uint32_t digest_len;
52  uint32_t flags;
53  uint8_t reserved[60];
54} AVB_ATTR_PACKED AvbHashDescriptor;
55
56/* Copies |src| to |dest| and validates, byte-swapping fields in the
57 * process if needed. Returns true if valid, false if invalid.
58 *
59 * Data following the struct is not validated nor copied.
60 */
61bool avb_hash_descriptor_validate_and_byteswap(const AvbHashDescriptor* src,
62                                               AvbHashDescriptor* dest)
63    AVB_ATTR_WARN_UNUSED_RESULT;
64
65#ifdef __cplusplus
66}
67#endif
68
69#endif /* AVB_HASH_DESCRIPTOR_H_ */
70