Randall Spangler | d274a2e | 2014-10-23 17:38:18 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2014 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 | */ |
| 6 | |
| 7 | #ifndef VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_ |
| 8 | #define VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_ |
| 9 | |
| 10 | #include "2struct.h" |
| 11 | |
| 12 | /** |
| 13 | * Round up a size to a multiple of 32 bits (4 bytes). |
| 14 | */ |
| 15 | static __inline const uint32_t roundup32(uint32_t v) |
| 16 | { |
| 17 | return (v + 3) & ~3; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Convert a packed key from vboot data format to vboot2 data format. |
| 22 | * |
| 23 | * Intended for use by unit tests. Does NOT validate the original struct |
| 24 | * contents, just copies them. |
| 25 | * |
| 26 | * @param key Packed key in vboot1 format |
| 27 | * @param desc Description of packed key |
Randall Spangler | c0ce70b | 2014-10-31 11:19:14 -0700 | [diff] [blame] | 28 | * @param out_size Destination for size of the newly allocated buffer |
Randall Spangler | d274a2e | 2014-10-23 17:38:18 -0700 | [diff] [blame] | 29 | * @return a newly allocated buffer with the converted key. Caller is |
| 30 | * responsible for freeing this buffer. |
| 31 | */ |
| 32 | struct vb2_packed_key2 *vb2_convert_packed_key2( |
| 33 | const struct vb2_packed_key *key, |
| 34 | const char *desc, uint32_t *out_size); |
| 35 | |
Randall Spangler | c0ce70b | 2014-10-31 11:19:14 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Convert a signature from vboot data format to vboot2 data format. |
| 38 | * |
| 39 | * Intended for use by unit tests. Does NOT validate the original struct |
| 40 | * contents, just copies them. |
| 41 | * |
| 42 | * @param sig Signature in vboot1 format |
| 43 | * @param desc Description of signature |
| 44 | * @param key Key to take algorithms and GUID from. If NULL, those |
| 45 | * fields are left uninitialized. |
| 46 | * @param out_size Destination for size of the newly allocated buffer |
| 47 | * @return a newly allocated buffer with the converted signature. Caller is |
| 48 | * responsible for freeing this buffer. |
| 49 | */ |
| 50 | struct vb2_signature2 *vb2_convert_signature2( |
| 51 | const struct vb2_signature *sig, |
| 52 | const char *desc, |
| 53 | const struct vb2_packed_key2 *key, |
| 54 | uint32_t *out_size); |
| 55 | |
Randall Spangler | b885c3b | 2014-11-01 17:56:46 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Create an unsigned hash signature of the data. |
| 58 | * |
| 59 | * @param data Data to sign |
| 60 | * @param size Size of data in bytes |
| 61 | * @return a newly-allocated signature, which the caller must free, or NULL if |
| 62 | * error. |
| 63 | */ |
| 64 | struct vb2_signature2 *vb2_create_hash_sig(const uint8_t *data, |
| 65 | uint32_t size, |
| 66 | enum vb2_hash_algorithm hash_alg); |
| 67 | |
Randall Spangler | d274a2e | 2014-10-23 17:38:18 -0700 | [diff] [blame] | 68 | #endif /* VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_ */ |