Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 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 | |
| 8 | #ifndef VBOOT_REFERENCE_HOST_KEY_H_ |
| 9 | #define VBOOT_REFERENCE_HOST_KEY_H_ |
| 10 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 11 | #include "cryptolib.h" |
| 12 | #include "utility.h" |
| 13 | #include "vboot_struct.h" |
| 14 | |
| 15 | |
| 16 | typedef struct rsa_st RSA; |
| 17 | |
| 18 | /* Private key data */ |
| 19 | typedef struct VbPrivateKey { |
| 20 | RSA* rsa_private_key; /* Private key data */ |
| 21 | uint64_t algorithm; /* Algorithm to use when signing */ |
| 22 | } VbPrivateKey; |
| 23 | |
| 24 | |
Bill Richardson | a08b5c9 | 2010-06-30 21:59:43 -0700 | [diff] [blame] | 25 | /* Read a private key from a .pem file. Caller owns the returned pointer, |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 26 | * and must free it with PrivateKeyFree(). */ |
Bill Richardson | a08b5c9 | 2010-06-30 21:59:43 -0700 | [diff] [blame] | 27 | VbPrivateKey* PrivateKeyReadPem(const char* filename, uint64_t algorithm); |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 28 | |
| 29 | |
| 30 | /* Free a private key. */ |
| 31 | void PrivateKeyFree(VbPrivateKey* key); |
| 32 | |
Bill Richardson | abf0550 | 2010-07-01 10:22:06 -0700 | [diff] [blame] | 33 | /* Write a private key to a file in .vbprivk format. */ |
| 34 | int 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. */ |
| 40 | VbPrivateKey* PrivateKeyRead(const char* filename); |
| 41 | |
| 42 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 43 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 44 | /* Allocate a new public key with space for a [key_size] byte key. */ |
| 45 | VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm, |
| 46 | uint64_t version); |
| 47 | |
| 48 | |
Randall Spangler | d55c645 | 2010-06-10 12:43:51 -0700 | [diff] [blame] | 49 | /* Read a public key from a .vbpubk file. Caller owns the returned |
| 50 | * pointer, and must free it with Free(). |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 51 | * |
| 52 | * Returns NULL if error. */ |
Randall Spangler | d55c645 | 2010-06-10 12:43:51 -0700 | [diff] [blame] | 53 | VbPublicKey* 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. */ |
| 60 | VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm, |
| 61 | uint64_t version); |
| 62 | |
| 63 | |
| 64 | /* Write a public key to a file in .vbpubk format. */ |
| 65 | int PublicKeyWrite(const char* filename, const VbPublicKey* key); |
| 66 | |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 67 | |
| 68 | #endif /* VBOOT_REFERENCE_HOST_KEY_H_ */ |