2023-08-23 13:42:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
|
|
|
*
|
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TREZORHAL_OPTIGA_H
|
|
|
|
#define TREZORHAL_OPTIGA_H
|
|
|
|
|
2024-11-01 11:55:31 +00:00
|
|
|
#include <trezor_types.h>
|
|
|
|
|
2023-10-02 17:16:55 +00:00
|
|
|
#include "optiga_common.h"
|
2024-07-02 19:33:53 +00:00
|
|
|
#include "storage.h"
|
2023-08-23 13:42:16 +00:00
|
|
|
|
|
|
|
#define OPTIGA_DEVICE_CERT_INDEX 1
|
|
|
|
#define OPTIGA_DEVICE_ECC_KEY_INDEX 0
|
|
|
|
|
2024-06-26 08:09:38 +00:00
|
|
|
typedef enum _optiga_pin_result {
|
|
|
|
OPTIGA_PIN_SUCCESS = 0, // The operation completed successfully.
|
|
|
|
OPTIGA_PIN_INVALID, // The PIN is invalid.
|
|
|
|
OPTIGA_PIN_COUNTER_EXCEEDED, // The PIN try counter limit was exceeded.
|
|
|
|
OPTIGA_PIN_ERROR, // Optiga processing or communication error.
|
|
|
|
} optiga_pin_result;
|
2023-08-23 13:42:16 +00:00
|
|
|
|
2024-06-26 08:09:38 +00:00
|
|
|
typedef enum _optiga_sign_result {
|
|
|
|
OPTIGA_SIGN_SUCCESS = 0, // The operation completed successfully.
|
|
|
|
OPTIGA_SIGN_INACCESSIBLE, // The signing key is inaccessible.
|
|
|
|
OPTIGA_SIGN_ERROR, // Invalid parameters or Optiga processing or
|
|
|
|
// communication error.
|
|
|
|
} optiga_sign_result;
|
2023-10-02 17:18:11 +00:00
|
|
|
|
2023-09-19 12:24:56 +00:00
|
|
|
// Size of secrets used in PIN processing, e.g. salted PIN, master secret etc.
|
|
|
|
#define OPTIGA_PIN_SECRET_SIZE 32
|
|
|
|
|
2024-06-26 08:09:38 +00:00
|
|
|
optiga_sign_result __wur optiga_sign(uint8_t index, const uint8_t *digest,
|
|
|
|
size_t digest_size, uint8_t *signature,
|
|
|
|
size_t max_sig_size, size_t *sig_size);
|
2023-08-23 13:42:16 +00:00
|
|
|
|
2023-09-30 09:37:31 +00:00
|
|
|
bool __wur optiga_cert_size(uint8_t index, size_t *cert_size);
|
2023-08-23 13:42:16 +00:00
|
|
|
|
2023-09-30 09:37:31 +00:00
|
|
|
bool __wur optiga_read_cert(uint8_t index, uint8_t *cert, size_t max_cert_size,
|
|
|
|
size_t *cert_size);
|
2023-08-23 13:42:16 +00:00
|
|
|
|
2024-06-25 09:23:25 +00:00
|
|
|
bool __wur optiga_read_sec(uint8_t *sec);
|
|
|
|
|
2024-07-09 12:30:18 +00:00
|
|
|
void optiga_set_sec_max(void);
|
|
|
|
|
2023-09-30 09:37:31 +00:00
|
|
|
bool __wur optiga_random_buffer(uint8_t *dest, size_t size);
|
2023-09-08 09:19:06 +00:00
|
|
|
|
2024-07-02 19:33:53 +00:00
|
|
|
bool __wur optiga_pin_set(optiga_ui_progress_t ui_progress,
|
2024-06-26 08:09:38 +00:00
|
|
|
uint8_t stretched_pin[OPTIGA_PIN_SECRET_SIZE]);
|
2023-09-19 12:24:56 +00:00
|
|
|
|
2024-07-02 19:33:53 +00:00
|
|
|
uint32_t optiga_estimate_time_ms(storage_pin_op_t op);
|
|
|
|
|
2024-06-26 08:09:38 +00:00
|
|
|
optiga_pin_result __wur
|
2024-07-02 19:33:53 +00:00
|
|
|
optiga_pin_verify(optiga_ui_progress_t ui_progress,
|
2024-06-26 08:09:38 +00:00
|
|
|
uint8_t stretched_pin[OPTIGA_PIN_SECRET_SIZE]);
|
2024-06-13 12:17:11 +00:00
|
|
|
|
2024-06-26 08:09:38 +00:00
|
|
|
optiga_pin_result __wur
|
2024-07-02 19:33:53 +00:00
|
|
|
optiga_pin_verify_v4(optiga_ui_progress_t ui_progress,
|
2024-06-26 08:09:38 +00:00
|
|
|
const uint8_t pin_secret[OPTIGA_PIN_SECRET_SIZE],
|
|
|
|
uint8_t out_secret[OPTIGA_PIN_SECRET_SIZE]);
|
2023-09-19 12:24:56 +00:00
|
|
|
|
2024-06-26 09:09:07 +00:00
|
|
|
bool __wur optiga_pin_get_rem_v4(uint32_t *ctr);
|
2024-06-13 16:24:09 +00:00
|
|
|
|
2024-06-26 09:09:07 +00:00
|
|
|
bool __wur optiga_pin_get_rem(uint32_t *ctr);
|
2023-10-02 18:24:25 +00:00
|
|
|
|
2024-06-26 09:09:07 +00:00
|
|
|
bool __wur optiga_pin_decrease_rem_v4(uint32_t count);
|
2024-06-13 16:24:09 +00:00
|
|
|
|
2024-06-26 09:09:07 +00:00
|
|
|
bool __wur optiga_pin_decrease_rem(uint32_t count);
|
2023-10-02 18:24:25 +00:00
|
|
|
|
2023-08-23 13:42:16 +00:00
|
|
|
#endif
|