host_signature2.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. *
  5. * Host-side functions for verified boot key structures
  6. */
  7. #ifndef VBOOT_REFERENCE_HOST_SIGNATURE2_H_
  8. #define VBOOT_REFERENCE_HOST_SIGNATURE2_H_
  9. #include "2struct.h"
  10. struct vb2_private_key;
  11. struct vb21_signature;
  12. /**
  13. * Get the digest info for a hash algorithm
  14. *
  15. * @param hash_alg Hash algorithm
  16. * @param buf_ptr On success, points to the digest info
  17. * @param size_ptr On success, contains the info size in bytes
  18. * @return VB2_SUCCESS, or non-zero error code on failure.
  19. */
  20. int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
  21. const uint8_t **buf_ptr,
  22. uint32_t *size_ptr);
  23. /**
  24. * Sign data buffer
  25. *
  26. * @param sig_ptr On success, points to a newly allocated signature.
  27. * Caller is responsible for calling free() on this.
  28. * @param data Pointer to data to sign
  29. * @param size Size of data to sign in bytes
  30. * @param key Private key to use to sign data
  31. * @param desc Optional description for signature. If NULL, the
  32. * key description will be used.
  33. * @return VB2_SUCCESS, or non-zero error code on failure.
  34. */
  35. int vb21_sign_data(struct vb21_signature **sig_ptr,
  36. const uint8_t *data,
  37. uint32_t size,
  38. const struct vb2_private_key *key,
  39. const char *desc);
  40. /**
  41. * Calculate the signature size for a private key.
  42. *
  43. * @param size_ptr On success, contains the signature size in bytes.
  44. * @param key Key to calculate signature length from.
  45. * @param desc Optional description for signature. If NULL, the
  46. * key description will be used.
  47. * @return VB2_SUCCESS, or non-zero error code on failure.
  48. */
  49. int vb21_sig_size_for_key(uint32_t *size_ptr,
  50. const struct vb2_private_key *key,
  51. const char *desc);
  52. /**
  53. * Calculate the total signature size for a list of keys.
  54. *
  55. * @param size_ptr On success, contains the signature size in bytes.
  56. * @param key_list List of keys to calculate signature length from.
  57. * @param key_count Number of keys.
  58. * @return VB2_SUCCESS, or non-zero error code on failure.
  59. */
  60. int vb21_sig_size_for_keys(uint32_t *size_ptr,
  61. const struct vb2_private_key **key_list,
  62. uint32_t key_count);
  63. /**
  64. * Sign object with a key.
  65. *
  66. * @param buf Buffer containing object to sign, starting with
  67. * common header
  68. * @param sig_offset Offset in buffer at which to store signature. All
  69. * data before this in the buffer will be signed.
  70. * @param key Key to sign object with
  71. * @param desc If non-null, description to use for signature
  72. */
  73. int vb21_sign_object(uint8_t *buf,
  74. uint32_t sig_offset,
  75. const struct vb2_private_key *key,
  76. const char *desc);
  77. /**
  78. * Sign object with list of keys.
  79. *
  80. * @param buf Buffer containing object to sign, starting with
  81. * common header
  82. * @param sig_offset Offset to start signatures. All data before this
  83. * in the buffer will be signed.
  84. * @param key_list List of keys to sign object with
  85. * @param key_count Number of keys in list
  86. */
  87. int vb21_sign_object_multiple(uint8_t *buf,
  88. uint32_t sig_offset,
  89. const struct vb2_private_key **key_list,
  90. uint32_t key_count);
  91. #endif /* VBOOT_REFERENCE_HOST_SIGNATURE2_H_ */