summaryrefslogtreecommitdiff
path: root/tests/vb2_convert_structs.h
blob: 032b5bfb54bfa0e726994564a74efba46499d5ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 */

#ifndef VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_
#define VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_

#include "2struct.h"

/**
 * Round up a size to a multiple of 32 bits (4 bytes).
 */
static __inline const uint32_t roundup32(uint32_t v)
{
	return (v + 3) & ~3;
}

/**
 * Convert a packed key from vboot data format to vboot2 data format.
 *
 * Intended for use by unit tests.  Does NOT validate the original struct
 * contents, just copies them.
 *
 * @param key		Packed key in vboot1 format
 * @param desc		Description of packed key
 * @param out_size	Destination for size of the newly allocated buffer
 * @return a newly allocated buffer with the converted key.  Caller is
 * responsible for freeing this buffer.
 */
struct vb2_packed_key2 *vb2_convert_packed_key2(
				const struct vb2_packed_key *key,
				const char *desc, uint32_t *out_size);

/**
 * Convert a signature from vboot data format to vboot2 data format.
 *
 * Intended for use by unit tests.  Does NOT validate the original struct
 * contents, just copies them.
 *
 * @param sig		Signature in vboot1 format
 * @param desc		Description of signature
 * @param key		Key to take algorithms and GUID from.  If NULL, those
 *			fields are left uninitialized.
 * @param out_size	Destination for size of the newly allocated buffer
 * @return a newly allocated buffer with the converted signature.  Caller is
 * responsible for freeing this buffer.
 */
struct vb2_signature2 *vb2_convert_signature2(
			      const struct vb2_signature *sig,
			      const char *desc,
			      const struct vb2_packed_key2 *key,
			      uint32_t *out_size);

/**
 * Create an unsigned hash signature of the data.
 *
 * @param data		Data to sign
 * @param size		Size of data in bytes
 * @return a newly-allocated signature, which the caller must free, or NULL if
 *	   error.
 */
struct vb2_signature2 *vb2_create_hash_sig(const uint8_t *data,
					   uint32_t size,
					   enum vb2_hash_algorithm hash_alg);

#endif  /* VBOOT_REFERENCE_VB2_CONVERT_STRUCTS_H_ */