avb_hash_descriptor.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
  25. #error "Never include this file directly, include libavb.h instead."
  26. #endif
  27. #ifndef AVB_HASH_DESCRIPTOR_H_
  28. #define AVB_HASH_DESCRIPTOR_H_
  29. #include "avb_descriptor.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* Flags for hash descriptors.
  34. *
  35. * AVB_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB: Do not apply the default A/B
  36. * partition logic to this partition. This is intentionally a negative boolean
  37. * because A/B should be both the default and most used in practice.
  38. */
  39. typedef enum {
  40. AVB_HASH_DESCRIPTOR_FLAGS_DO_NOT_USE_AB = (1 << 0),
  41. } AvbHashDescriptorFlags;
  42. /* A descriptor containing information about hash for an image.
  43. *
  44. * This descriptor is typically used for boot partitions to verify the
  45. * entire kernel+initramfs image before executing it.
  46. *
  47. * Following this struct are |partition_name_len| bytes of the
  48. * partition name (UTF-8 encoded), |salt_len| bytes of salt, and then
  49. * |digest_len| bytes of the digest.
  50. *
  51. * The |reserved| field is for future expansion and must be set to NUL
  52. * bytes.
  53. *
  54. * Changes in v1.1:
  55. * - flags field is added which supports AVB_HASH_DESCRIPTOR_FLAGS_USE_AB
  56. * - digest_len may be zero, which indicates the use of a persistent digest
  57. */
  58. typedef struct AvbHashDescriptor {
  59. AvbDescriptor parent_descriptor;
  60. uint64_t image_size;
  61. uint8_t hash_algorithm[32];
  62. uint32_t partition_name_len;
  63. uint32_t salt_len;
  64. uint32_t digest_len;
  65. uint32_t flags;
  66. uint8_t reserved[60];
  67. } AVB_ATTR_PACKED AvbHashDescriptor;
  68. /* Copies |src| to |dest| and validates, byte-swapping fields in the
  69. * process if needed. Returns true if valid, false if invalid.
  70. *
  71. * Data following the struct is not validated nor copied.
  72. */
  73. bool avb_hash_descriptor_validate_and_byteswap(const AvbHashDescriptor* src,
  74. AvbHashDescriptor* dest)
  75. AVB_ATTR_WARN_UNUSED_RESULT;
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* AVB_HASH_DESCRIPTOR_H_ */