Gaurav Shah | 431b988 | 2010-02-12 15:54:37 -0800 | [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 | * Utility functions for file and key handling. |
| 6 | */ |
| 7 | |
| 8 | #ifndef VBOOT_REFERENCE_FILE_KEYS_H_ |
| 9 | #define VBOOT_REFERENCE_FILE_KEYS_H_ |
| 10 | |
Gaurav Shah | 5411c7a | 2010-03-31 10:56:49 -0700 | [diff] [blame] | 11 | #include "cryptolib.h" |
Gaurav Shah | 431b988 | 2010-02-12 15:54:37 -0800 | [diff] [blame] | 12 | |
| 13 | /* Read file named [input_file] into a buffer and stores the length into |
| 14 | * [len]. |
| 15 | * |
| 16 | * Returns a pointer to the buffer. Caller owns the returned pointer and |
| 17 | * must free it. |
| 18 | */ |
Gaurav Shah | 456678b | 2010-03-10 18:38:45 -0800 | [diff] [blame] | 19 | uint8_t* BufferFromFile(const char* input_file, uint64_t* len); |
Gaurav Shah | 431b988 | 2010-02-12 15:54:37 -0800 | [diff] [blame] | 20 | |
| 21 | /* Read a pre-processed RSA Public Key from file [input_file]. |
| 22 | * |
| 23 | * Returns a pointer to the read key. Caller owns the returned pointer and |
| 24 | * must free it. |
| 25 | */ |
Gaurav Shah | 23a2f3a | 2010-02-26 15:09:43 -0800 | [diff] [blame] | 26 | RSAPublicKey* RSAPublicKeyFromFile(const char* input_file); |
Gaurav Shah | 431b988 | 2010-02-12 15:54:37 -0800 | [diff] [blame] | 27 | |
Gaurav Shah | 5411c7a | 2010-03-31 10:56:49 -0700 | [diff] [blame] | 28 | /* Returns the appropriate digest for the data in [input_file] |
| 29 | * based on the signature [algorithm]. |
| 30 | * Caller owns the returned digest and must free it. |
| 31 | */ |
| 32 | uint8_t* DigestFile(char* input_file, int sig_algorithm); |
| 33 | |
Gaurav Shah | 08df9b8 | 2010-02-23 16:16:23 -0800 | [diff] [blame] | 34 | /* Helper function to invoke external program to calculate signature on |
| 35 | * [input_file] using private key [key_file] and signature algorithm |
| 36 | * [algorithm]. |
| 37 | * |
| 38 | * Returns the signature. Caller owns the buffer and must Free() it. |
| 39 | */ |
Randall Spangler | 620c38c | 2010-06-17 14:45:22 -0700 | [diff] [blame] | 40 | uint8_t* SignatureFile(const char* input_file, const char* key_file, |
Gaurav Shah | 47b593d | 2010-08-17 15:48:22 -0700 | [diff] [blame] | 41 | unsigned int algorithm); |
Gaurav Shah | 08df9b8 | 2010-02-23 16:16:23 -0800 | [diff] [blame] | 42 | |
Gaurav Shah | 431b988 | 2010-02-12 15:54:37 -0800 | [diff] [blame] | 43 | #endif /* VBOOT_REFERENCE_FILE_KEYS_H_ */ |