Repository navigation
SE050Sim: accept 0x81 TLV lengths in commands - #28
Merged
Merged
Conversation
parse_tlvs() only took the short and 0x82 length forms and answered a 0x81 LL length with 0x6A80. Plug&Trust's tlvSet_u8buf() uses 0x81 for every 128..255 byte value, so wolfSSL's SE050 hash offload failed on its first 128-byte DigestUpdate chunk. Decode the length in a parse_length() helper that takes the short, 0x81 and 0x82 forms, including longer than needed ones such as 81 00, which the real applet accepts. The response encoder stays on short / 0x82. On an SE051 (applet 7.2.0) GetRandom, ReadObject and DigestOneShot answer with 0x82 HH LL at every value size tested (16 to 869 bytes, including 128 to 255), so the part never sends 0x81 there. Plug&Trust parses all three forms; the Rust se050 crate used by the integration tests only parses short and 0x82. Add unit tests for the short, 0x81 and 0x82 forms, non-minimal lengths, mixed TLVs, truncated input, invalid length bytes and the encoder's 127/128/255/256 boundaries.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the TLV parser’s expanded length support.
No open issues 🎉
What changed in this PR
This PR updates SE050Sim’s command TLV parser to accept 0x81 lengths, enabling Plug&Trust’s 128–255-byte values and resolving the reported wolfSSL hash-offload failure.
Changes:
- Adds a length-decoding helper supporting short,
0x81, and0x82forms, including non-minimal encodings, while preserving malformed-input errors. - Adds tests for length boundaries, mixed encodings, truncation, and unsupported length forms.
- Documents the existing response-encoding behavior without changing its output.
| File | Description |
|---|---|
SE050Sim/se050-sim/src/tlv.rs |
Adds command-length decoding support and regression tests; documents unchanged response encoding. |
Review effort: Balanced
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.
SE050Sim rejected command TLVs that use the one-byte extended length form (
81 LL) with SW 0x6A80. Plug&Trust'stlvSet_u8buf()uses that form for every 128..255 byte value, so wolfSSL's SE050 hash offload (WOLFSSL_SE050_HASH) failed on its first 128-byte DigestUpdate chunk. Found while testing wolfSSL/wolfssl#12318.How it was validated
81 LLin commands: DigestOneShot with42 81 C8and 200 bytes returns 0x9000 and the correct SHA-256.81 LLin a response. GetRandom (64 to 300 bytes), DigestOneShot, ReadIDList and ReadObject (16 to 869 bytes) all answered41 82 HH LL, including at 128..255 bytes. Only a 1-byte flag (ReadIDList "more") used the short form.cargo testpasses (109 unit, 14 integration, 14 SCP03).Dockerfile.wolfcryptagainst wolfSSL with the PR above:-DWOLFSSL_SE050_HASH -DWOLFSSL_SE050_CRYPT: PASS. 795 commands carried a43 81TAG_3, for example DigestUpdate42 02 00 01 43 81 80plus 128 bytes, answered90 00. Before this change that run needed a locally patched simulator. (Built with--disable-rng-autolockto avoid an unrelated fork-test deadlock in that wolfSSL branch.)Changes
parse_tlvs()decodes lengths through a newparse_length()helper that takes the short,81 LLand82 HH LLforms, including longer than needed ones such as81 00, which the real applet accepts. Truncated input is stillTooShort;0x80and0x83and up are stillInvalidLength.82 HH LL) and now documents why it never emits81 LL: silicon doesn't, and the Rustse050crate used by the integration tests (LinuxJedi/nxp-se050sim-compat) only parses short and 0x82 and loops forever on any other length byte.No other place in the simulator decodes TLV lengths; the T=1, policy and TCP framing lengths are separate formats.