avb_hashtree_descriptor.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_HASHTREE_DESCRIPTOR_H_
  9. #define AVB_HASHTREE_DESCRIPTOR_H_
  10. #include "avb_descriptor.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /* Flags for hashtree descriptors.
  15. *
  16. * AVB_HASHTREE_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_HASHTREE_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
  22. } AvbHashtreeDescriptorFlags;
  23. /* A descriptor containing information about a dm-verity hashtree.
  24. *
  25. * Hash-trees are used to verify large partitions typically containing
  26. * file systems. See
  27. * https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity for more
  28. * information about dm-verity.
  29. *
  30. * Following this struct are |partition_name_len| bytes of the
  31. * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then
  32. * |root_digest_len| bytes of the root digest.
  33. *
  34. * The |reserved| field is for future expansion and must be set to NUL
  35. * bytes.
  36. *
  37. * Changes in v1.1:
  38. * - flags field is added which supports AVB_HASHTREE_DESCRIPTOR_FLAGS_USE_AB
  39. * - digest_len may be zero, which indicates the use of a persistent digest
  40. */
  41. typedef struct AvbHashtreeDescriptor {
  42. AvbDescriptor parent_descriptor;
  43. uint32_t dm_verity_version;
  44. uint64_t image_size;
  45. uint64_t tree_offset;
  46. uint64_t tree_size;
  47. uint32_t data_block_size;
  48. uint32_t hash_block_size;
  49. uint32_t fec_num_roots;
  50. uint64_t fec_offset;
  51. uint64_t fec_size;
  52. uint8_t hash_algorithm[32];
  53. uint32_t partition_name_len;
  54. uint32_t salt_len;
  55. uint32_t root_digest_len;
  56. uint32_t flags;
  57. uint8_t reserved[60];
  58. } AVB_ATTR_PACKED AvbHashtreeDescriptor;
  59. /* Copies |src| to |dest| and validates, byte-swapping fields in the
  60. * process if needed. Returns true if valid, false if invalid.
  61. *
  62. * Data following the struct is not validated nor copied.
  63. */
  64. bool avb_hashtree_descriptor_validate_and_byteswap(
  65. const AvbHashtreeDescriptor* src,
  66. AvbHashtreeDescriptor* dest) AVB_ATTR_WARN_UNUSED_RESULT;
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif /* AVB_HASHTREE_DESCRIPTOR_H_ */