avb_hash_descriptor.h 2.0 KB

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