blob: 032b5bfb54bfa0e726994564a74efba46499d5ca [file] [log] [blame]
Randall Spanglerd274a2e2014-10-23 17:38:18 -07001/* 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 */
15static __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 Spanglerc0ce70b2014-10-31 11:19:14 -070028 * @param out_size Destination for size of the newly allocated buffer
Randall Spanglerd274a2e2014-10-23 17:38:18 -070029 * @return a newly allocated buffer with the converted key. Caller is
30 * responsible for freeing this buffer.
31 */
32struct vb2_packed_key2 *vb2_convert_packed_key2(
33 const struct vb2_packed_key *key,
34 const char *desc, uint32_t *out_size);
35
Randall Spanglerc0ce70b2014-10-31 11:19:14 -070036/**
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 */
50struct 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 Spanglerb885c3b2014-11-01 17:56:46 -070056/**
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 */
64struct vb2_signature2 *vb2_create_hash_sig(const uint8_t *data,
65 uint32_t size,
66 enum vb2_hash_algorithm hash_alg);
67
Randall Spanglerd274a2e2014-10-23 17:38:18 -070068#endif /* VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_ */