SE050Sim: applet 3.1.1/7.2.0 personalities and hardware-verified gap fixes - #13
Merged
Merged
Conversation
…ed gaps
Every behavior below was cross-checked against real silicon in the
August 2026 bench sessions: an SE051 (applet 7.2.0) and an SE050C
(applet 3.1.1) driven over raw Se05x_API_* APDUs on the Raspberry Pi
bench, with NIST/RFC vectors where applicable.
SE050_SIM_APPLET selects the personality at runtime (default 7.2.0;
3/3.1.1 for the SE050C). Modelled differences: SELECT/GetVersion
blobs, GetFreeMemory width (U16 vs U32) and values, GetRandom cap
(880 vs 1018 bytes), EC ReadType codes (generic vs curve-specific),
and duplicate CreateECCurve (7.2 refuses 0x6985; 3.x accepts and
silently wipes the curve params).
Fixes applying to both generations:
- MAC surface: HMAC-SHA1/256/384/512 + AES-CMAC, one-shot and
multi-step, generate and validate (was entirely missing, 0x6A86).
- ReadObject on AESKey objects now refused 0x6986 like HMACKey,
regardless of an attached ALLOW_READ policy.
- Cipher mode byte honored: ECB_NOPAD/CBC_NOPAD/CTR implemented and
verified against SP800-38A vectors; unaligned NOPAD input 0x6985.
- Streaming cipher emits output per CipherUpdate with proper chaining
and returns only the remainder at Final.
- Crypto-object lifecycle enforced: CreateCryptoObject required before
Init (0x6985), duplicate create 0x6986; DigestInit now takes the
real wire format (TAG_2 only, algo from the create subtype).
- EC Weierstrass curves are stateful objects: create/set-param/delete/
list with SET=0x02 semantics, keygen requires a fully parameterized
curve. The sim pre-provisions P-192..P-521 so existing hosts keep
working; DeleteAll re-provisions.
- P-521 and P-192 supported end to end (keygen/import/sign/verify/
ECDH); p192 0.13 lacks a sign primitive so signing is implemented
over its arithmetic and tested against its VerifyingKey.
- ECDSA sign/verify enforce input length == algo digest length.
- Missing-object and delete-nonexistent SWs corrected to 0x6985;
binary file bounds enforced (read past end 0x6985, write past end
0x6A80, size immutable); ReadSize reports EC scalar sizes; counter
size fixed at creation with Set/Inc semantics; ReadIDList emits the
TAG_1 more-indicator + TAG_2 ID-list format with type filtering;
GetRandom(0) refused; DigestOneShot hashes the empty message;
WriteUserID refused 0x6985 in plain sessions.
Object store schema extended to {objects, ec_curves} with a fallback
loader for legacy flat-map files.
There was a problem hiding this comment.
Pull request overview
This PR updates the SE050 simulator to match hardware-verified behavior observed on SE050C (applet 3.1.1) and SE051 (applet 7.2.0), including a runtime “applet personality” switch and numerous correctness fixes across object management and crypto operations.
Changes:
- Add applet personality selection (
SE050_SIM_APPLET) to model 3.1.1 vs 7.2.0 deltas (version blobs, GetRandom cap, GetFreeMemory width, EC ReadType codes, CreateECCurve duplicate behavior). - Implement/repair hardware-aligned crypto and object behaviors (MAC surface, AES cipher modes + streaming semantics, curve object lifecycle/state, corrected status words and bounds rules).
- Update persistence schema to include EC curve state with a legacy loader + tests.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SE050Sim/se050-sim/src/object_store/types.rs | Extend curve/type modeling (P-192/P-521, scalar sizing, EC ReadType version dependence, counter size persistence). |
| SE050Sim/se050-sim/src/object_store/mod.rs | Add persistent EC-curve state, new JSON schema + legacy fallback loader, and tests. |
| SE050Sim/se050-sim/src/lib.rs | Export new applet module. |
| SE050Sim/se050-sim/src/handlers/session.rs | Make SELECT response version-dependent via AppletVersion. |
| SE050Sim/se050-sim/src/handlers/rsa.rs | Align missing-object status word handling with hardware behavior. |
| SE050Sim/se050-sim/src/handlers/object_mgmt.rs | Enforce hardware bounds/semantics for Binary/Counter/UserID/AESKey exports; version-dependent ReadType/ReadIDList. |
| SE050Sim/se050-sim/src/handlers/mod.rs | Register new curve and mac handlers. |
| SE050Sim/se050-sim/src/handlers/management.rs | Implement version-dependent GetVersion/GetFreeMemory/GetRandom behavior + tests. |
| SE050Sim/se050-sim/src/handlers/mac.rs | Add HMAC/CMAC one-shot and streaming MAC operations + tests. |
| SE050Sim/se050-sim/src/handlers/ec.rs | Add P-192/P-521 support, enforce ECDSA algo/length contract, and integrate curve-object readiness checks. |
| SE050Sim/se050-sim/src/handlers/digest.rs | Make DigestOneShot accept empty input; make DigestInit use crypto-object subtype wire format. |
| SE050Sim/se050-sim/src/handlers/curve.rs | Implement Create/Param/Delete/List EC curve object lifecycle with version-dependent duplicate-create behavior + tests. |
| SE050Sim/se050-sim/src/handlers/crypto_obj.rs | Enforce duplicate CreateCryptoObject as 0x6986. |
| SE050Sim/se050-sim/src/handlers/aes.rs | Honor cipher mode byte, implement ECB/CBC/CTR + streaming output semantics, and add NIST-vector tests. |
| SE050Sim/se050-sim/src/dispatch.rs | Thread applet personality/version flag through dispatch; route curve + MAC commands. |
| SE050Sim/se050-sim/src/applet.rs | Add AppletVersion personality selection and version-specific constants/encodings. |
| SE050Sim/se050-sim/src/apdu.rs | Add new P2 constants for curve param + MAC operations. |
| SE050Sim/se050-sim/Cargo.toml | Add crypto dependencies needed for new curve/MAC functionality. |
Suppressed comments (2)
SE050Sim/se050-sim/src/handlers/ec.rs:38
- The
pad_hashdoc comment says it "right-pad[s] with zeros", but the implementation truncates longer inputs and left-pads shorter inputs (which matches the inline comment in the body). Please update the comment to match the actual behavior to avoid confusion when reasoning about ECDSA prehash handling.
/// Pad a hash to the curve's scalar size (right-pad with zeros).
/// ECDSA requires the hash to be at least as long as the curve order.
/// When the hash is shorter (e.g., SHA-1 on P-384), it must be padded.
SE050Sim/se050-sim/src/object_store/mod.rs:290
- This test also uses a fixed temp filename (
se050_sim_curve_store_test.json), which can collide when tests run in parallel or when multiple test processes run on the same machine. Make the temp path unique per test run to avoid flakes.
let dir = std::env::temp_dir();
let path = dir.join("se050_sim_curve_store_test.json");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…paths MACInit now requires the crypto object to have been created with the SIGNATURE context (0x03), matching how the SDK creates MAC contexts and how the digest (0x01) and cipher (0x02) handlers already validate theirs. The persistence tests write to per-invocation store paths (pid + nanos) so concurrent cargo test processes cannot interfere through a shared temp file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the August 2026 bench sessions that cross-checked the simulator against real silicon: an SE051 (applet 7.2.0) and an SE050C (applet 3.1.1), probed with raw
Se05x_API_*APDUs and NIST/RFC test vectors. Every behavior change below is traceable to a hardware run on one or both parts.Applet personality (new)
SE050_SIM_APPLETselects the presented part at runtime: unset/7.2.0= SE051 (default, matching what the simulator always advertised),3/3.1.1= SE050C. Modelled differences:03 01 01 6f ff 01 0b07 02 00 3f ff ff ffFixes verified identical on both generations
POLICY_OBJ_ALLOW_READattached.Store schema
Persisted JSON is now
{"objects": {...}, "ec_curves": {...}}with a fallback loader for legacy flat-map store files (covered by tests).Test plan
cargo test -- --test-threads=1: 72 lib + 14 driver integration tests pass, including underSE050_SIM_APPLET=3.1.1.