Commit graph

54 commits

Author SHA1 Message Date
bunnie
f720314dc4 add mising dependency on owc-inc feature flag 2026-06-10 14:37:49 +08:00
bunnie
a3e7a9fc9c add note documenting app-keys feature gate 2026-06-08 23:59:32 +08:00
bunnie
9f4421dadd add AppKey implementation
this adds, with a feature-gate, the option for userspace
programs to use & access keys in the APPLICATION data slots.

The implementation bounds-checks the requested indices to ensure
sensitive data in slots around the APPLICATION region cannot
be accessed. Even with corrupted AppKeyOp packets, it shouldn't
be possible to access other slot ranges, but because this code
is so intimate with importan secrets it's recommended to
gate the feature off unless required by the end user application
code.
2026-06-08 23:55:35 +08:00
bunnie
7097164b23 cleanup errant info message 2026-05-06 02:02:05 +08:00
bunnie
44a53e590a move error definition to api crate, fixes hosted ci 2026-04-04 00:08:39 +08:00
bunnie
f2371f49eb add implementation for owc frobbing
by default the knob is not frobbable because frobbing the
knob can lead to potential griefing

more specifically the owc (one way counters) control some
security state. they are all designed to "fail on increment"
but just giving someone a button to increment random counters
gives a DoS vector. So unless you need to open the API it's
recommended to not have it activated.
2026-04-03 23:43:57 +08:00
bunnie
e3408f5346 fix more emulated modes 2026-03-31 01:18:53 +08:00
bunnie
b7826c2ebc flesh out backup register interfaces
- adds API for retrieving & setting the ephemeral key. This is
a key that is erased by a power-on reset, but is preserved between
deep-sleep sleep/wake cycles. It is intended for securing a lock
PIN, and can be up to 192 bits long.

- adds API for checking the warm boot flags, which are also stored
in the backup registers.
2026-03-29 18:04:09 +08:00
bunnie
527f256ec1 add API call to determine if in developer mode 2026-03-26 02:12:11 +08:00
bunnie
f774522e62
remove testing API that never actually worked
there was a thought to speed up CI testing by introducing a
"cheater" routine that allowed us to re-initialize the keystore.
Turns out this doesn't work because it's not possible to fully
revert a system out of developer mode - because, in my infinite
previous-self wisdom, I realized that this is something someone
might try and there is a one-way counter that logs if the
system has *ever* been in developer mode, and that has no
known bypass.

This means that even if you could repopulate the keystore, it
would be cleared on the next boot by merit of the developer
flag being set.

So - we did it the hard way, every single test we have to
re-image the system from scratch. C'est la vie.

Removing this patch eliminates a code path that could later be
abused for unforeseen ill purposes.
2026-02-08 12:55:10 +08:00
bunnie
0aeb9daa37 add a method to force-rewrite keys
This is useful in CI to test various stages of dev-key signed
image vs secret key erase without having to go through a complete
suicide cycle on the chip.

This command is gated behind a feature flag that would only be
invoked for beta testing. I think it's still safe to have even
as a beta-signed feature because the worst you can do with this
is replace existing keys - so it could be used to DoS/brick, but not
leak secrets.
2026-02-04 15:55:34 +08:00
bunnie
b1121daef6 security-relevant: modify collateral test to not panic on failure
The panic on failure causes incompatibility with older boot0's
that don't set up the collateral area correctly.

Make the failure more graceful, but we also promise ourselves
to add CI tests to check for this explicitly, because we can't
just rely on panics to enforce behavior.
2026-01-30 04:01:09 +08:00
bunnie
3f869ca389 bump utralib version for publication 2026-01-29 19:12:00 +08:00
bunnie
b2cf705c59 bump ticktimer version to drop susres dependency 2026-01-28 20:53:57 +08:00
bunnie
10ef6bda02
add information about root key seed to regular sign_image
Three pieces of inforation are leaked about the root seed:

- whether or not the first 64 bits are all 0
- whether or not the first 64 bits are all 3's
- whether if none of the above are true

It's fairly indirect leakage, and I think it is a relatively
minor price to pay for the confidence it gives that some underlying
library behavior didn't accidentally lead to faulty keygen.

Note that these 64 bits are 64 bits out of tens of thousands
of bits that go into the keygen, because the nuisance keys
and the chaff key are all blended together to create the final
derived root key. Thus the security margin on the key is quite
large and even a full disclosure of these 64-bits is a minor
impact on overall security.
2026-01-18 20:52:51 +08:00
bunnie
cc00201774 add collateral erasure check to keystore
in no case should any baochip firmware be holding secret
collateral used by third party firmwares, thus a non-erased
state is a panic
2026-01-18 02:58:32 +08:00
bunnie
4c3d2f677c fix hosted mode 2026-01-16 17:52:00 +08:00
bunnie
2b19c4bd21 add a command for setting the bootwait flag
The keystore is a sensitive server, and the one-way counters
have security-critical propoerties. So instead of revealing a
generic one-way counter API to the world, specific, limited
requests to do things are going to be created for the keystore.

In this case, the bootwait flag would be convenient to be able
to set from userspace. The motivation for this requirement is
actually continuous integration - a normal human could just
hold down a button while turning on power, but in CI, I don't
have a robotic thumb (or an alternative electrical signal) to
simulate the nerve-pinch on boot.

Previously I was "cheating" and simulating this by nuking the
loader, which effectively forces a bootwait.

However, in production, this is *not possible* because the JTAG
port is sealed off. Thus, this may be the first of a series
of small PRs to incorporate CI tooling that clears up tech
debt like nuking the loader to get into boot wait.
2026-01-16 17:32:12 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
f98dea3097 add missing dependency 2025-12-22 16:51:22 +08:00
bunnie
87dc26d832 update the keystore to ignore the deprecated board type checks 2025-12-18 02:20:44 +08:00
bunnie
d874c3e5c2 commit for version bump 2025-12-16 02:02:37 +08:00
bunnie
b012038c1d
fix argument to hazardous-debug print
this allows us to check that things are being done correctly
in CI.
2025-12-06 00:16:36 +08:00
bunnie
78036d71dc
add code to check the flag
there's a dummy flag checked in, and this code helps check that
the flag is treated correctly during CI testing
2025-12-04 15:10:51 +08:00
bunnie
cdf4a56d76 add backup manager ref in keystore
this claims the backup memory region - eventually we'll do
something with it
2025-11-26 20:48:29 +08:00
bunnie
49dcc7aaa2 add CI telemetry for keystore init 2025-11-19 14:00:59 +08:00
bunnie
22f44f82b9
add debug telemetry to the keystore
this is constructed in a way such that

1. it's gated off in production builds
2. if it was accidentally gated on, there is some security impact
but not a significant loss of security

We do need the telemetry so that during CI we can confirm that things
are actually working. I think the risk of being too buttoned-up
and then accidentally doing something like accidentally never
initializing keys and leaving them all zero is greater than the
risk of accidental partial leakage of information due to a procedural
mix-up in the image signing ceremony.
2025-11-18 23:20:31 +08:00
bunnie
ad116b5af6 reduce leakage during hazardous-debug
in theory, no production images should be signed that have this
feature enabled. But, reducing the amount of leakage just in
case an accident happens and this flag is somehow slipped
into a signed production image.
2025-11-18 22:46:20 +08:00
bunnie
52c5400fca
cleanup debug 2025-11-13 18:36:03 +08:00
bunnie
9213755a6b
move keystore init to userspace
This moves the key store initialization to the key manager
process itself.

It has been tested to work with signed images, and to also
protect the system in case of another process trying to access
the key data as well as in the case of developer keys being
used.
2025-11-13 18:32:04 +08:00
bunnie
315bee22dc add placeholders for ephemeral/volatile data in keystore 2025-11-12 15:26:35 +08:00
bunnie
54f476edd3 fixup hosted mode emulation for baosec 2025-11-08 04:20:30 +08:00
bunnie
792de177b0 implement keystore calls needed for pddb compatibility 2025-11-08 03:52:20 +08:00
bunnie
5de6581698 include chaff output into the hazardous-debug 2025-11-02 10:38:29 +08:00
bunnie
26078dcc7d add keystore to dabao configuration
After some contemplation, we should include the keystore in the
core service set featured by the dabao-xous configuration.

The pros are: any compatibility/sharing of resources
that require access to RRAM, one-way counters, UUIDs, etc.
will either require a wholly separate implementation that is
"insecure" or it could just reuse the baosec work. Furthermore,
as cryptographic accelerators are laid into the keystore,
the APIs become available to the dabao environment

The cons are: more space is used in a space-constrained
dabao environment (roughly 140k "deadweight" at the start, but
as cryptographic APIs get layered in this can grow substantially);
the key slots are "used up" in part by the scheme, which leaves
less key slots available for user-defined purposes.

This is mitigated by the fact that there are a couple thousand
key slots, and so even though we use a couple hundred of them
it's still not the whole range.

Also, the baosec/dabao feature flag can be used to feature-out
cryptographic APIs/accelerators that are too obscure or not
useful for the dabao environment, to "lighten up" the
firmware load.
2025-11-01 22:59:07 +08:00
bunnie
cb6bc4d2c6
add keystore master key derivation
the master key is currently derived from a number of factors:

- the key seed
- chaff keys
- nuisance keys

and then a salt of the uuid/cpid and some info based on the
developer bit is added.

The info addition ensures that the key rotates if developer
mode is entered, so in addition to the key material being
deleted, the info itself is different which should cause
the master key to rotate and "be lost" even if the key
erasure routine is flawed.

Chaff keys harden against side channel analysis of data
in flight from the RRAM array - under the theory that
the RRAM array is a big, long set of wires (on the order
of mm's) that should make a great target for EM microprobes.
The chaff keys are read out in a random order every boot,
to make it harder to accumulate enough samples to average
out what's going on.

The nuisance keys are just read straight out of the array.
They might be recoverable by side channel analysis, but
their purpose is to make it annoying for a brute-force
read-out of the key array by a microscopist. The location
and size of the nuisance keys are picked to force the attacker
to really dial in their polishing process so that they have
to hit the right layer across the entire chip (or at least
a couple mm's); and then a set of bits are packed closely
together to try and induce as much cross talk on the word
lines, running under the theory that any attack relying
on stray electrons activating the bitlines to enable read-out
are likely to non-selectively activate bitlines, so the
resulting "glow" of the word line is going to be a superposition
of several bits at once. An attacker could, of course, cap
each bit line with a FIB, read the word lines, then uncap/recap
them one by one - but this drives up the cost of the attack
and ensures that it's not just a single imaging run but
will take at least hours if not days for a skilled adversary
with the most modern equipment to extract the data. Furthermore,
the large amount of bits demands that the attacker read out
the data with better than 97% accuracy (the last 3% can be
cleaned by the ECC coded into the array), so mistakes
are costly.

The chaff/nuisance keys are read out where the chaff keys
(which are order-independent) are interleaved with the nuisance
key readout. The chaff keys are read roughly twice, using
a continuous-time algorithm to pick which version of the
chaff key is read, making it a bit harder for sidechannel
analysis to pick out which key is in flight.

It's an attempt at sidechannel hardening, we'll see how it
holds up. Pretty sure there's still some low hanging fruit
in the read-out, it'll be interesting to see what the red
team comes up with.

Hopefully this at least makes the keystore not the low hanging
fruit, and we're back at looking at bootloader/kernel exploits etc.
to do key extraction, which I'm sure there are many; but at
least those can be patched.
2025-10-28 17:29:06 +08:00
bunnie
d2254e2ce4
add HAL to keystore dependencies 2025-10-26 13:37:04 +08:00
bunnie
2a2863c11a
put keystore in charge of enabling preemption
this is done after critical setup is done. it doesn't guarantee
that it has an infinite time slice, but it makes the startup sequence
more deterministic.
2025-10-26 13:35:57 +08:00
bunnie
6dd2a1f554
update dependencies for keystore 2025-10-26 02:00:19 +08:00
bunnie
ba91aa5b58
Add audit code for the keystore
the snippet `attack_keystore()` is left in place along with hints
on how to attack the keystore. Nominally, the attack should fail,
but there are some critical pre-assumptions that can be violated.

I am interested in knowing how robust those assumptions are, so,
documentation and sample code is provided to would-be attackers.

Do me a solid and if you do find a vulnerability, open an issue
ASAP and let me know. Full well aware that some vulns may well
be unpatchable; it is what it is. Hardware is hard, but maybe
we can work together to make it better.
2025-10-26 01:57:06 +08:00
bunnie
dbb0a75118 bump versions
have to absorb a version change due to xous-semver change

might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
2025-10-06 13:23:18 +08:00
bunnie
1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.

Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.

This commit fixes all of the odd names and removes some unmaintained
early targets.
2025-09-18 21:25:51 +08:00
bunnie
75a9373fea fix AES dependencies so that the correct acceleration is enabled
This relies on a trick I was not aware of previously, which is
that transitive dependencies absorb the additive set of features
enabled within a crate.

see

https://doc.rust-lang.org/cargo/reference/features.html#feature-unification

for the full description. but basically by referring to the feature
required in "aes" despite not being used in the crate but pulled
in by aes-gcm-siv, i can ensure that the transitive dependency
is in fact used.

I think this was always there but previously I just didn't understand
it correctly or didn't use it right when I tried to deploy it, but
this time I think I got it right.
2025-09-07 11:50:12 +08:00
bunnie
8c7edaf107 add a "fake" implementation for the keystore
allows us to test pddb crate before final hardware arrives
2025-05-21 18:03:08 +08:00
bunnie
fe190ea4f1 cleanup warning 2025-05-21 10:23:37 +08:00
bunnie
821c6ce47c cleanup dependency tree going down to the cramium-hal layer
remove features that we don't need so as to make the tree as
simple as possible to descend

in particular if we're just pinging the HAL layer for some simple
constants we don't have to pull in the hairball of std targets
2025-05-20 14:38:03 +08:00
bunnie
e2379821e6 republish xous-rs to fix cargo test 2025-05-11 15:36:17 +08:00
bunnie
8a4959056b bump version for xous crate update - commit so we can publish crates 2025-05-11 14:45:24 +08:00
bunnie
2ea777e04f fix key encoding bug; set DNA to "0" in emulation mode
this matches what's done in hosted mode, allowing the analysis
scripts to work on the images generated by this version
2025-05-08 16:02:52 +08:00
bunnie
34a1a33165 fix off-by-one arg error on Dna routine
this is a common api problem because yes, while arg1 is strictly
the second item, previously arg0 was hidden and in the argument
list arg1 took the first place not the second. so i make this
mistake a lot...
2025-05-08 16:01:46 +08:00