blob: 018c25d359fc8a546440b07d8fa7d501f980a0cd [file] [log] [blame]
Randall Spanglerd1836442010-06-10 09:59:04 -07001/* 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
8#ifndef VBOOT_REFERENCE_HOST_KEY_H_
9#define VBOOT_REFERENCE_HOST_KEY_H_
10
Randall Spanglerd1836442010-06-10 09:59:04 -070011#include "cryptolib.h"
12#include "utility.h"
13#include "vboot_struct.h"
14
15
16typedef struct rsa_st RSA;
17
18/* Private key data */
19typedef struct VbPrivateKey {
20 RSA* rsa_private_key; /* Private key data */
21 uint64_t algorithm; /* Algorithm to use when signing */
22} VbPrivateKey;
23
24
Bill Richardsona08b5c92010-06-30 21:59:43 -070025/* Read a private key from a .pem file. Caller owns the returned pointer,
Randall Spanglerd1836442010-06-10 09:59:04 -070026 * and must free it with PrivateKeyFree(). */
Bill Richardsona08b5c92010-06-30 21:59:43 -070027VbPrivateKey* PrivateKeyReadPem(const char* filename, uint64_t algorithm);
Randall Spanglerd1836442010-06-10 09:59:04 -070028
29
30/* Free a private key. */
31void PrivateKeyFree(VbPrivateKey* key);
32
Bill Richardsonabf05502010-07-01 10:22:06 -070033/* Write a private key to a file in .vbprivk format. */
34int PrivateKeyWrite(const char* filename, const VbPrivateKey* key);
35
36/* Read a privake key from a .vbprivk file. Caller owns the returned
37 * pointer, and must free it with PrivateKeyFree().
38 *
39 * Returns NULL if error. */
40VbPrivateKey* PrivateKeyRead(const char* filename);
41
42
Randall Spanglerd1836442010-06-10 09:59:04 -070043
Randall Spanglerd1836442010-06-10 09:59:04 -070044/* Allocate a new public key with space for a [key_size] byte key. */
45VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm,
46 uint64_t version);
47
48
Randall Spanglerd55c6452010-06-10 12:43:51 -070049/* Read a public key from a .vbpubk file. Caller owns the returned
50 * pointer, and must free it with Free().
Randall Spanglerd1836442010-06-10 09:59:04 -070051 *
52 * Returns NULL if error. */
Randall Spanglerd55c6452010-06-10 12:43:51 -070053VbPublicKey* PublicKeyRead(const char* filename);
54
55
56/* Read a public key from a .keyb file. Caller owns the returned
57 * pointer, and must free it with Free().
58 *
59 * Returns NULL if error. */
60VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
61 uint64_t version);
62
63
64/* Write a public key to a file in .vbpubk format. */
65int PublicKeyWrite(const char* filename, const VbPublicKey* key);
66
Randall Spanglerd1836442010-06-10 09:59:04 -070067
68#endif /* VBOOT_REFERENCE_HOST_KEY_H_ */