host_key.c 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Copyright (c) 2011 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 functions for keys.
  6. */
  7. /* TODO: change all 'return 0', 'return 1' into meaningful return codes */
  8. #include <openssl/pem.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include "2sysincludes.h"
  13. #include "2common.h"
  14. #include "2rsa.h"
  15. #include "2sha.h"
  16. #include "host_common.h"
  17. #include "host_misc.h"
  18. #include "vb2_common.h"
  19. #include "vboot_common.h"
  20. int packed_key_looks_ok(const struct vb2_packed_key *key, uint32_t size)
  21. {
  22. struct vb2_public_key pubkey;
  23. if (VB2_SUCCESS != vb2_unpack_key_buffer(&pubkey,
  24. (const uint8_t *)key,
  25. size))
  26. return 0;
  27. if (key->key_version > VB2_MAX_KEY_VERSION) {
  28. /* Currently, TPM only supports 16-bit version */
  29. fprintf(stderr, "%s() packed key invalid version\n", __func__);
  30. return 0;
  31. }
  32. /* Success */
  33. return 1;
  34. }