Skip to content

Conversation

benma
Copy link
Collaborator

@benma benma commented Sep 4, 2025

19 --> 8 optiga security events during a restore.

@benma benma marked this pull request as draft September 4, 2025 13:59
@benma benma changed the title Reduce SC events Reduce SC events during restore Sep 4, 2025
@benma benma marked this pull request as ready for review September 4, 2025 14:28
@benma benma requested a review from NickeZ September 4, 2025 14:39
Copy link
Collaborator

@NickeZ NickeZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the second commit easier to review?

Test against fixtures.
To be below the static function `_retain_seed()` that will be needed later.
Before, `keystore_encrypt_and_store_seed()` (called when
creating/restoring a seed) would always be followed by
`keystore_unlock(<password>)` with the password the user just chose,
so unlock could never fail. The unlocking part costs many secure chip
operations (for stretching the password).

By making the first function already unlock the keystore, we can avoid
calling `keystore_unlock()`, reducing the number of secure chip events
by 5.

This effort is part of mitigating Optiga's throttling mechanism that
kicks in after 133 events - users can run into this by repeatedly
resetting/restoring).
When restoring a wallet, the seed is already known, so no need to do
another `copy_seed()` which is a secure chip security event. This
reduces the number of secure chip operations when restoring.

The hashed seed is retained so it can be compared without storing it
in plaintext.

This effort is part of mitigating Optiga's throttling mechanism that
kicks in after 133 events - users can run into this by repeatedly
resetting/restoring).
verify_seed() after storing a seed currently re-stretches the
password, which needs 5 securechip events.

We can skip that because we still have access to the stretched
password.

If the check succeeds, but there was an error involving the password
or secure chip (e.g. the stretching result was corrupted the first
time), the consequence is that the user won't be able to unlock, but
the seed itself on the MCU, on the backup and retained (encrypted) in
seed is unaffected. That trade-off is good, because a failure
there (securechip returns no error but actually had a corruption)
should be exceedingly rare.

This effort is part of mitigating Optiga's throttling mechanism that
kicks in after 133 events - users can run into this by repeatedly
resetting/restoring).
Copy link
Collaborator

@NickeZ NickeZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@benma benma merged commit 23f192b into BitBoxSwiss:master Sep 22, 2025
35 checks passed
@benma benma deleted the reduce-events branch September 22, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants