2024-08-13 05:47:59 +00:00
|
|
|
#ifndef TREZORHAL_SECRET_H
|
|
|
|
#define TREZORHAL_SECRET_H
|
2023-07-20 11:20:50 +00:00
|
|
|
|
2024-11-01 11:55:31 +00:00
|
|
|
#include <trezor_types.h>
|
2023-07-20 11:20:50 +00:00
|
|
|
|
2024-08-13 05:47:59 +00:00
|
|
|
#ifdef KERNEL_MODE
|
|
|
|
|
2023-07-20 11:20:50 +00:00
|
|
|
#define SECRET_HEADER_MAGIC "TRZS"
|
|
|
|
#define SECRET_HEADER_LEN 16
|
|
|
|
#define SECRET_OPTIGA_KEY_OFFSET 16
|
|
|
|
#define SECRET_OPTIGA_KEY_LEN 32
|
|
|
|
|
2023-06-28 08:51:30 +00:00
|
|
|
#define SECRET_MONOTONIC_COUNTER_OFFSET 48
|
|
|
|
#define SECRET_MONOTONIC_COUNTER_LEN 1024
|
2024-08-27 10:36:35 +00:00
|
|
|
#define SECRET_MONOTONIC_COUNTER2_OFFSET (SECRET_MONOTONIC_COUNTER_LEN + 48)
|
2023-06-28 08:51:30 +00:00
|
|
|
|
|
|
|
#define SECRET_BHK_OFFSET (1024 * 8)
|
|
|
|
#define SECRET_BHK_LEN 32
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Writes data to the secret storage
|
2024-03-06 14:53:50 +00:00
|
|
|
void secret_write(const uint8_t* data, uint32_t offset, uint32_t len);
|
2023-07-20 11:20:50 +00:00
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Reads data from the secret storage
|
2023-07-20 11:20:50 +00:00
|
|
|
secbool secret_read(uint8_t* data, uint32_t offset, uint32_t len);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Checks if the secret storage has been wiped
|
2023-07-20 11:20:50 +00:00
|
|
|
secbool secret_wiped(void);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Verifies that the secret storage has correct header
|
2024-02-26 08:49:58 +00:00
|
|
|
secbool secret_verify_header(void);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Erases the entire secret storage
|
2023-07-20 11:20:50 +00:00
|
|
|
void secret_erase(void);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Writes the secret header to the secret storage
|
2023-07-20 11:20:50 +00:00
|
|
|
void secret_write_header(void);
|
2023-06-28 08:51:30 +00:00
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Writes optiga pairing secret to the secret storage
|
|
|
|
// Encrypts the secret if encryption is available on the platform
|
|
|
|
// Returns true if the secret was written successfully
|
2024-03-06 14:53:50 +00:00
|
|
|
secbool secret_optiga_set(const uint8_t secret[SECRET_OPTIGA_KEY_LEN]);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Reads optiga pairing secret
|
|
|
|
// Decrypts the secret if encryption is available on the platform
|
|
|
|
// Returns true if the secret was read successfully
|
|
|
|
// Reading can fail if optiga is not paired, the pairing secret was not
|
|
|
|
// provisioned to the firmware (by calling secret_optiga_backup), or the secret
|
|
|
|
// was made unavailable by calling secret_optiga_hide
|
2024-03-06 14:53:50 +00:00
|
|
|
secbool secret_optiga_get(uint8_t dest[SECRET_OPTIGA_KEY_LEN]);
|
|
|
|
|
2024-08-27 07:43:17 +00:00
|
|
|
// Checks if the optiga pairing secret is present in the secret storage
|
|
|
|
secbool secret_optiga_present(void);
|
|
|
|
|
2024-09-05 14:28:28 +00:00
|
|
|
// Checks if the optiga pairing secret can be written to the secret storage
|
|
|
|
secbool secret_optiga_writable(void);
|
|
|
|
|
2024-08-27 07:43:17 +00:00
|
|
|
// Erases optiga pairing secret from the secret storage
|
|
|
|
void secret_optiga_erase(void);
|
|
|
|
|
2024-04-05 07:14:56 +00:00
|
|
|
// Regenerates the BHK and writes it to the secret storage
|
2023-06-28 08:51:30 +00:00
|
|
|
void secret_bhk_regenerate(void);
|
|
|
|
|
2024-04-04 14:33:39 +00:00
|
|
|
// Prepares the secret storage for running the firmware
|
|
|
|
// Provisions secrets/keys to the firmware, depending on the trust level
|
|
|
|
// Disables access to the secret storage until next reset, if possible
|
|
|
|
// This function is called by the bootloader before starting the firmware
|
|
|
|
void secret_prepare_fw(secbool allow_run_with_secret, secbool trust_all);
|
2024-08-13 05:47:59 +00:00
|
|
|
|
2024-09-25 14:40:47 +00:00
|
|
|
// Prepares the secret storage for running the boardloader and next stages
|
|
|
|
// Ensures that secret storage access is enabled
|
|
|
|
// This function is called by the boardloader
|
|
|
|
void secret_init(void);
|
|
|
|
|
2024-08-13 05:47:59 +00:00
|
|
|
#endif // KERNEL_MODE
|
|
|
|
|
|
|
|
// Checks if bootloader is locked, that is the secret storage contains optiga
|
|
|
|
// pairing secret on platforms where access to the secret storage cannot be
|
|
|
|
// restricted for unofficial firmware
|
|
|
|
secbool secret_bootloader_locked(void);
|
|
|
|
|
|
|
|
#endif // TREZORHAL_SECRET_H
|