host_signature.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright (c) 2010 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.
  6. */
  7. #ifndef VBOOT_REFERENCE_HOST_SIGNATURE_H_
  8. #define VBOOT_REFERENCE_HOST_SIGNATURE_H_
  9. #include "host_key.h"
  10. #include "utility.h"
  11. #include "vboot_struct.h"
  12. struct vb2_private_key;
  13. struct vb2_signature;
  14. /**
  15. * Initialize a signature struct.
  16. *
  17. * @param sig Structure to initialize
  18. * @param sig_data Pointer to signature data buffer (after sig)
  19. * @param sig_size Size of signature data buffer in bytes
  20. * @param data_size Amount of data signed in bytes
  21. */
  22. void vb2_init_signature(struct vb2_signature *sig, uint8_t *sig_data,
  23. uint32_t sig_size, uint32_t data_size);
  24. /**
  25. * Allocate a new signature.
  26. *
  27. * @param sig_size Size of signature in bytes
  28. * @param data_size Amount of data signed in bytes
  29. *
  30. * @return The signature or NULL if error. Caller must free() it.
  31. */
  32. struct vb2_signature *vb2_alloc_signature(uint32_t sig_size,
  33. uint32_t data_size);
  34. /**
  35. * Copy a signature.
  36. *
  37. * @param dest Destination signature
  38. * @param src Source signature
  39. *
  40. * @return VB2_SUCCESS, or non-zero if error. */
  41. int vb2_copy_signature(struct vb2_signature *dest,
  42. const struct vb2_signature *src);
  43. /**
  44. * Calculate a SHA-512 digest-only signature.
  45. *
  46. * @param data Pointer to data to hash
  47. * @param size Length of data in bytes
  48. *
  49. * @return The signature, or NULL if error. Caller must free() it.
  50. */
  51. struct vb2_signature *vb2_sha512_signature(const uint8_t *data, uint32_t size);
  52. /**
  53. * Calculate a signature for the data using the specified key.
  54. *
  55. * @param data Pointer to data to sign
  56. * @param size Length of data in bytes
  57. * @param key Private key to use to sign data
  58. *
  59. * @return The signature, or NULL if error. Caller must free() it.
  60. */
  61. struct vb2_signature *vb2_calculate_signature(
  62. const uint8_t *data, uint32_t size,
  63. const struct vb2_private_key *key);
  64. /**
  65. * Calculate a signature for the data using an external signer.
  66. *
  67. * @param data Pointer to data to sign
  68. * @param size Length of data in bytes
  69. * @param key_file Name of file containing private key
  70. * @param key_algorithm Key algorithm
  71. * @param external_signer Path to external signer program
  72. *
  73. * @return The signature, or NULL if error. Caller must free() it.
  74. */
  75. struct vb2_signature *vb2_external_signature(const uint8_t *data,
  76. uint32_t size,
  77. const char *key_file,
  78. uint32_t key_algorithm,
  79. const char *external_signer);
  80. #endif /* VBOOT_REFERENCE_HOST_SIGNATURE_H_ */