blob: 10efc7666c3c1461fddb1f269db68dbc267692cb [file] [log] [blame]
Randall Spangler32a65262011-06-27 10:49:11 -07001/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Randall Spanglerd1836442010-06-10 09:59:04 -07002 * 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
8/* TODO: change all 'return 0', 'return 1' into meaningful return codes */
9
Randall Spanglerd1836442010-06-10 09:59:04 -070010#include <openssl/pem.h>
Randall Spanglerd1836442010-06-10 09:59:04 -070011
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15
Randall Spanglerf7559e42016-06-23 13:45:59 -070016#include "2sysincludes.h"
17#include "2common.h"
18#include "2rsa.h"
19#include "2sha.h"
Randall Spangler32a65262011-06-27 10:49:11 -070020#include "host_common.h"
Randall Spanglerd55c6452010-06-10 12:43:51 -070021#include "host_misc.h"
Randall Spangler98263a12016-06-02 16:05:49 -070022#include "vb2_common.h"
Randall Spanglerd1836442010-06-10 09:59:04 -070023#include "vboot_common.h"
24
Randall Spangler98263a12016-06-02 16:05:49 -070025int packed_key_looks_ok(const struct vb2_packed_key *key, uint32_t size)
Bill Richardsonf16ed872014-08-27 15:37:47 -070026{
Randall Spanglerf7559e42016-06-23 13:45:59 -070027 struct vb2_public_key pubkey;
28 if (VB2_SUCCESS != vb2_unpack_key(&pubkey, (const uint8_t *)key, size))
Randall Spangler98263a12016-06-02 16:05:49 -070029 return 0;
Bill Richardsonf16ed872014-08-27 15:37:47 -070030
Randall Spanglerf7559e42016-06-23 13:45:59 -070031 if (key->key_version > VB2_MAX_KEY_VERSION) {
32 /* Currently, TPM only supports 16-bit version */
33 VB2_DEBUG("%s() - packed key invalid version\n", __func__);
Randall Spangler98263a12016-06-02 16:05:49 -070034 return 0;
35 }
36
37 /* Success */
38 return 1;
Bill Richardsonf16ed872014-08-27 15:37:47 -070039}