summaryrefslogtreecommitdiff
path: root/test/tpm_seed_clear.c
blob: 2077c82e01843afbba619125b04555197d75835a (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Copyright 2023 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "common.h"
#include "ec_commands.h"
#include "system.h"
#include "task.h"
#include "test_util.h"

#ifdef SECTION_IS_RW
#include "fpsensor_state.h"
#endif

#include <stdint.h>
#include <string.h>

test_static const uint8_t default_fake_tpm_seed[] = {
	0xd9, 0x71, 0xaf, 0xc4, 0xcd, 0x36, 0xe3, 0x60, 0xf8, 0x5a, 0xa0,
	0xa6, 0x2c, 0xb3, 0xf5, 0xe2, 0xeb, 0xb9, 0xd8, 0x2f, 0xb5, 0x78,
	0x5c, 0x79, 0x82, 0xce, 0x06, 0x3f, 0xcc, 0x23, 0xb9, 0xe7,
};

test_static const uint8_t zero_fake_tpm_seed[] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

#ifdef SECTION_IS_RO
test_static uint8_t tpm_seed[FP_CONTEXT_TPM_BYTES];
#endif

test_static int test_tpm_seed_before_reboot(void)
{
	if (IS_ENABLED(SECTION_IS_RW)) {
		TEST_ASSERT_ARRAY_EQ(tpm_seed, zero_fake_tpm_seed,
				     FP_CONTEXT_TPM_BYTES);
		memcpy(tpm_seed, default_fake_tpm_seed, FP_CONTEXT_TPM_BYTES);
		TEST_ASSERT_ARRAY_EQ(tpm_seed, default_fake_tpm_seed,
				     FP_CONTEXT_TPM_BYTES);
	}
	return EC_SUCCESS;
}

test_static int test_tpm_seed_after_reboot(void)
{
	if (IS_ENABLED(SECTION_IS_RW)) {
		TEST_ASSERT_ARRAY_EQ(tpm_seed, zero_fake_tpm_seed,
				     FP_CONTEXT_TPM_BYTES);
	}
	return EC_SUCCESS;
}

test_static void run_test_step1(void)
{
	ccprints("Step 1: tpm_seed_clear\n");
	cflush();

	RUN_TEST(test_tpm_seed_before_reboot);

	if (test_get_error_count()) {
		test_reboot_to_next_step(TEST_STATE_FAILED);
	} else {
		test_reboot_to_next_step(TEST_STATE_STEP_2);
	}
}

test_static void run_test_step2(void)
{
	ccprints("Step 2: tpm_seed_clear\n");
	cflush();

	RUN_TEST(test_tpm_seed_after_reboot);

	if (test_get_error_count()) {
		test_reboot_to_next_step(TEST_STATE_FAILED);
	} else {
		test_reboot_to_next_step(TEST_STATE_PASSED);
	}
}

void test_run_step(uint32_t state)
{
	if (state & TEST_STATE_MASK(TEST_STATE_STEP_1)) {
		run_test_step1();
	} else if (state & TEST_STATE_MASK(TEST_STATE_STEP_2)) {
		run_test_step2();
	}
}
int task_test(void *unused)
{
	if (IS_ENABLED(SECTION_IS_RW))
		test_run_multistep();
	return EC_SUCCESS;
}

void run_test(int argc, const char **argv)
{
	test_reset();
	msleep(100); /* Wait for TASK_ID_TEST to initialize */
	task_wake(TASK_ID_TEST);
}