blob: 55f883c4814babc6f71807428a8e5d7e31869be0 [file] [log] [blame]
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
5 * Copyright 2018 Facebook Inc.
Werner Zeh30cf14f2018-10-23 07:40:08 +02006 * Copyright 2018 Siemens AG
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#ifndef TSPI_H_
19#define TSPI_H_
20
21#include <security/tpm/tss.h>
Philipp Deppenwiesef18dc5c2017-12-14 15:49:32 +010022#include <commonlib/tcpa_log_serialized.h>
Werner Zeh30cf14f2018-10-23 07:40:08 +020023#include <commonlib/region.h>
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010024#include <vb2_api.h>
Werner Zeh30cf14f2018-10-23 07:40:08 +020025
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010026#define TPM_PCR_MAX_LEN 64
27#define HASH_DATA_CHUNK_SIZE 1024
28
29/**
30 * Clears the pre-RAM tcpa log data and initializes
31 * any content with default values
32 */
33void tcpa_preram_log_clear(void);
Philipp Deppenwiesef18dc5c2017-12-14 15:49:32 +010034
35/**
Philipp Deppenwiesef18dc5c2017-12-14 15:49:32 +010036 * Add table entry for cbmem TCPA log.
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010037 * @param name Name of the hashed data
38 * @param pcr PCR used to extend hashed data
39 * @param diget_algo sets the digest algorithm
40 * @param digest sets the hash extended into the tpm
41 * @param digest_len the length of the digest
Philipp Deppenwiesef18dc5c2017-12-14 15:49:32 +010042 */
Furquan Shaikh38f3ffa2018-07-31 14:26:39 -070043void tcpa_log_add_table_entry(const char *name, const uint32_t pcr,
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010044 enum vb2_hash_algorithm digest_algo,
Furquan Shaikh38f3ffa2018-07-31 14:26:39 -070045 const uint8_t *digest,
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010046 const size_t digest_len);
47
48/**
49 * Dump TCPA log entries on console
50 */
51void tcpa_log_dump(void *unused);
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010052
53/**
54 * Ask vboot for a digest and extend a TPM PCR with it.
55 * @param pcr sets the pcr index
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010056 * @param diget_algo sets the digest algorithm
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010057 * @param digest sets the hash to extend into the tpm
Philipp Deppenwiesef8499722018-07-30 01:27:47 +020058 * @param digest_len the length of the digest
59 * @param name sets additional info where the digest comes from
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010060 * @return TPM_SUCCESS on success. If not a tpm error is returned
61 */
Philipp Deppenwiesec9b7d1f2018-11-10 00:35:02 +010062uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo,
63 uint8_t *digest, size_t digest_len,
Philipp Deppenwiesef8499722018-07-30 01:27:47 +020064 const char *name);
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010065
66/**
67 * Issue a TPM_Clear and reenable/reactivate the TPM.
68 * @return TPM_SUCCESS on success. If not a tpm error is returned
69 */
70uint32_t tpm_clear_and_reenable(void);
71
72/**
73 * Start the TPM and establish the root of trust.
74 * @param s3flag tells the tpm setup if we wake up from a s3 state on x86
75 * @return TPM_SUCCESS on success. If not a tpm error is returned
76 */
77uint32_t tpm_setup(int s3flag);
78
Werner Zeh30cf14f2018-10-23 07:40:08 +020079/**
80 * Measure a given region device and extend given PCR with the result.
81 * @param *rdev Pointer to the region device to measure
82 * @param pcr Index of the PCR which will be extended by this measure
83 * @param *rname Name of the region that is measured
84 * @return TPM error code in case of error otherwise TPM_SUCCESS
85 */
86uint32_t tpm_measure_region(const struct region_device *rdev, uint8_t pcr,
87 const char *rname);
88
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010089#endif /* TSPI_H_ */