util_misc.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 misc functions for verified boot.
  6. */
  7. #ifndef VBOOT_REFERENCE_UTIL_MISC_H_
  8. #define VBOOT_REFERENCE_UTIL_MISC_H_
  9. #include "host_key.h"
  10. #include "vboot_struct.h"
  11. struct rsa_st;
  12. struct vb2_packed_key;
  13. struct vb2_private_key;
  14. /**
  15. * Returns the SHA1 digest of the packed key data as a string.
  16. *
  17. * The returned string is a global static buffer, so each call to this
  18. * overwrites the previous digest string. So don't call this more than once
  19. * per printf().
  20. *
  21. * @param key Key to print digest for
  22. *
  23. * @return A string containing the SHA1 digest.
  24. */
  25. const char *packed_key_sha1_string(const struct vb2_packed_key *key);
  26. /**
  27. * Returns the SHA1 digest of the private key data as a string.
  28. *
  29. * The returned string is a global static buffer, so each call to this
  30. * overwrites the previous digest string. So don't call this more than once
  31. * per printf().
  32. *
  33. * @param key Key to print digest for
  34. *
  35. * @return A string containing the SHA1 digest.
  36. */
  37. const char *private_key_sha1_string(const struct vb2_private_key *key);
  38. /*
  39. * Our packed RSBPublicKey buffer (historically in files ending with ".keyb",
  40. * but also the part of struct vb2_packed_key and struct vb21_packed_key that
  41. * is referenced by .key_offset) has this binary format:
  42. *
  43. * struct {
  44. * uint32_t nwords; // size of RSA key in 32-bit words
  45. * uint32_t N0inv; // -1 / N[0] mod 2^32
  46. * uint32_t modulus[nwords]; // modulus as a little endian array
  47. * uint32_t R2[nwords]; // R^2 as little endian array
  48. * };
  49. *
  50. * This function allocates and extracts that binary structure directly
  51. * from the RSA private key, rather than from a file.
  52. *
  53. * @param rsa_private_key RSA private key (duh)
  54. * @param keyb_data Pointer to newly allocated binary blob
  55. * @param keyb_size Size of newly allocated binary blob
  56. *
  57. * @return 0 on success, non-zero if unable to allocate enough memory.
  58. */
  59. int vb_keyb_from_rsa(struct rsa_st *rsa_private_key,
  60. uint8_t **keyb_data, uint32_t *keyb_size);
  61. #endif /* VBOOT_REFERENCE_UTIL_MISC_H_ */