Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 1 | /* |
| 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 Zeh | 30cf14f | 2018-10-23 07:40:08 +0200 | [diff] [blame] | 6 | * Copyright 2018 Siemens AG |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 7 | * |
| 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 Deppenwiese | f18dc5c | 2017-12-14 15:49:32 +0100 | [diff] [blame] | 22 | #include <commonlib/tcpa_log_serialized.h> |
Werner Zeh | 30cf14f | 2018-10-23 07:40:08 +0200 | [diff] [blame] | 23 | #include <commonlib/region.h> |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 24 | #include <vb2_api.h> |
Werner Zeh | 30cf14f | 2018-10-23 07:40:08 +0200 | [diff] [blame] | 25 | |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 26 | #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 | */ |
| 33 | void tcpa_preram_log_clear(void); |
Philipp Deppenwiese | f18dc5c | 2017-12-14 15:49:32 +0100 | [diff] [blame] | 34 | |
| 35 | /** |
Philipp Deppenwiese | f18dc5c | 2017-12-14 15:49:32 +0100 | [diff] [blame] | 36 | * Add table entry for cbmem TCPA log. |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 37 | * @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 Deppenwiese | f18dc5c | 2017-12-14 15:49:32 +0100 | [diff] [blame] | 42 | */ |
Furquan Shaikh | 38f3ffa | 2018-07-31 14:26:39 -0700 | [diff] [blame] | 43 | void tcpa_log_add_table_entry(const char *name, const uint32_t pcr, |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 44 | enum vb2_hash_algorithm digest_algo, |
Furquan Shaikh | 38f3ffa | 2018-07-31 14:26:39 -0700 | [diff] [blame] | 45 | const uint8_t *digest, |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 46 | const size_t digest_len); |
| 47 | |
| 48 | /** |
| 49 | * Dump TCPA log entries on console |
| 50 | */ |
| 51 | void tcpa_log_dump(void *unused); |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Ask vboot for a digest and extend a TPM PCR with it. |
| 55 | * @param pcr sets the pcr index |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 56 | * @param diget_algo sets the digest algorithm |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 57 | * @param digest sets the hash to extend into the tpm |
Philipp Deppenwiese | f849972 | 2018-07-30 01:27:47 +0200 | [diff] [blame] | 58 | * @param digest_len the length of the digest |
| 59 | * @param name sets additional info where the digest comes from |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 60 | * @return TPM_SUCCESS on success. If not a tpm error is returned |
| 61 | */ |
Philipp Deppenwiese | c9b7d1f | 2018-11-10 00:35:02 +0100 | [diff] [blame] | 62 | uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo, |
| 63 | uint8_t *digest, size_t digest_len, |
Philipp Deppenwiese | f849972 | 2018-07-30 01:27:47 +0200 | [diff] [blame] | 64 | const char *name); |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 65 | |
| 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 | */ |
| 70 | uint32_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 | */ |
| 77 | uint32_t tpm_setup(int s3flag); |
| 78 | |
Werner Zeh | 30cf14f | 2018-10-23 07:40:08 +0200 | [diff] [blame] | 79 | /** |
| 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 | */ |
| 86 | uint32_t tpm_measure_region(const struct region_device *rdev, uint8_t pcr, |
| 87 | const char *rname); |
| 88 | |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 89 | #endif /* TSPI_H_ */ |