summaryrefslogtreecommitdiff
path: root/firmware/lib/region-fw.c
blob: e2c6488a1fac7e2d91dc38190f77e5230d4ba241 (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
/* Copyright (c) 2013 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.
 *
 * High-level firmware API for loading and verifying rewritable firmware.
 * (Firmware portion)
 */

#include "sysincludes.h"

#include "bmpblk_header.h"
#include "region.h"
#include "gbb_access.h"
#include "gbb_header.h"
#include "load_kernel_fw.h"
#include "utility.h"
#include "vboot_api.h"
#include "vboot_struct.h"

static VbError_t VbGbbReadKey(VbCommonParams *cparams, uint32_t offset,
			      VbPublicKey **keyp)
{
	VbPublicKey hdr, *key;
	VbError_t ret;
	uint32_t size;

	ret = VbRegionReadData(cparams, VB_REGION_GBB, offset,
			       sizeof(VbPublicKey), &hdr);
	if (ret)
		return ret;

	/* Deal with a zero-size key (used in testing) */
	size = hdr.key_offset + hdr.key_size;
	if (size < sizeof(hdr))
		size = sizeof(hdr);
	key = VbExMalloc(size);
	ret = VbRegionReadData(cparams, VB_REGION_GBB, offset, size, key);
	if (ret) {
		VbExFree(key);
		return ret;
	}

	*keyp = key;
	return VBERROR_SUCCESS;
}

VbError_t VbGbbReadRootKey(VbCommonParams *cparams, VbPublicKey **keyp)
{
	return VbGbbReadKey(cparams, cparams->gbb->rootkey_offset, keyp);
}

VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams, VbPublicKey **keyp)
{
	return VbGbbReadKey(cparams, cparams->gbb->recovery_key_offset, keyp);
}