Skip to content

SE050Sim: enforce applet 7.2 ECDH InObject target contract - #9

Merged
LinuxJedi merged 2 commits into
wolfSSL:mainfrom
LinuxJedi:se050-strict-ecdh-inobject
Jul 23, 2026
Merged

SE050Sim: enforce applet 7.2 ECDH InObject target contract#9
LinuxJedi merged 2 commits into
wolfSSL:mainfrom
LinuxJedi:se050-strict-ecdh-inobject

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

Per the SE05x IoT applet spec (Se05x_API_ECDHGenerateSharedSecret in the Plug & Trust middleware), the TAG_7 shared-secret target must be an existing HMACKey object sized exactly to the shared secret; otherwise the applet returns SW 0x6985. The simulator previously created the target implicitly, which masked a wolfSSL port bug that fails on real hardware (SE052, or any middleware build for applet >= 07_02).

  • handle_ecdh now requires a pre-existing HMACKey object of exact size and overwrites its value on success
  • add the WriteSymmKey P1_HMAC dispatch route and handler so callers can create the target object
  • update sdk-test ECDH/X25519 tests to the documented pre-create sequence, reading the result back as AES type (the middleware get_key has no HMAC read case)
  • add unit tests covering the strict contract and the HMAC key write

Per the SE05x IoT applet spec (Se05x_API_ECDHGenerateSharedSecret in
the Plug & Trust middleware), the TAG_7 shared-secret target must be an
existing HMACKey object sized exactly to the shared secret; otherwise
the applet returns SW 0x6985. The simulator previously created the
target implicitly, which masked a wolfSSL port bug that fails on real
hardware (SE052, or any middleware build for applet >= 07_02).

- handle_ecdh now requires a pre-existing HMACKey object of exact size
  and overwrites its value on success
- add the WriteSymmKey P1_HMAC dispatch route and handler so callers
  can create the target object
- update sdk-test ECDH/X25519 tests to the documented pre-create
  sequence, reading the result back as AES type (the middleware
  get_key has no HMAC read case)
- add unit tests covering the strict contract and the HMAC key write
@LinuxJedi

Copy link
Copy Markdown
Member Author

Draft because this requires wolfSSL/wolfssl#10971 to be merged (chicken / egg scenario)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SE050 simulator to match the SE05x IoT applet 7.2+ ECDH “InObject” contract by requiring Tag7 to reference a pre-existing, correctly-sized HMACKey object (rather than implicitly creating a binary output), and updates simulator/SDK tests accordingly.

Changes:

  • Enforce Tag7 target existence/type/size for ECDH shared-secret generation and overwrite the existing HMACKey value on success.
  • Add WriteSymmKey P1=HMAC dispatch + handler to allow creating/writing HMACKey objects via the simulator APDU interface.
  • Update SDK-test ECDH and X25519 flows to pre-create the HMACKey target and read the result back via AES read path; add unit tests for the strict Tag7 contract and HMAC write.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
SE050Sim/se050-sim/src/handlers/ec.rs Enforces pre-existing HMACKey Tag7 target for ECDH InObject and adds unit tests for missing/wrong-type/wrong-size/success cases.
SE050Sim/se050-sim/src/handlers/aes.rs Adds a WriteSymmKey(P1=HMAC) handler to store HMACKey objects; includes dispatch-level tests.
SE050Sim/se050-sim/src/dispatch.rs Routes INS_WRITE + P1_HMAC to the new HMAC write handler.
SE050Sim/sdk-test/test_se050.c Updates ECDH and X25519 tests to pre-create an HMAC target object and read the derived secret back as AES.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Three changes to keep wolfSSL and simulators CI green while the applet
7.2 ECDH InObject fix lands in wolfSSL:

- Make the strict ECDH InObject target contract opt-in via the
  SE050_SIM_STRICT_ECDH=1 environment variable. By default a missing
  Tag7 target falls back to the legacy implicit-create Binary behavior
  so wolfSSL builds that predate the fix keep passing. A pre-existing
  HMACKey target gets the exact-size contract in both modes.

- Derive the EC public key when a private-only key pair is imported
  (NIST P-224/P-256/P-384 and Curve25519, matching Ed25519). ReadObject
  returns the public part of an asymmetric object and hosts parse it:
  wc_ecc_use_key_id failed with ASN_PARSE_E on the empty public key.

- Consume WOLFSSL_EXTRA_CFLAGS as a build ARG in Dockerfile.wolfcrypt
  (Pass-B configure and the test binary compiles). wolfSSL CI passes it
  for the WOLFSSL_SE050_ONLY_KEY_ID matrix leg but nothing consumed it,
  so that leg silently built the default configuration.
@LinuxJedi
LinuxJedi marked this pull request as ready for review July 23, 2026 11:20
@LinuxJedi
LinuxJedi merged commit f4ddf5e into wolfSSL:main Jul 23, 2026
21 checks passed
@LinuxJedi
LinuxJedi deleted the se050-strict-ecdh-inobject branch July 23, 2026 11:20
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