Skip to content

SE050: create ECDH derive target object for applet 7.2 middleware - #10971

Draft
LinuxJedi wants to merge 10 commits into
wolfSSL:masterfrom
LinuxJedi:se050_applet72_ecdh
Draft

SE050: create ECDH derive target object for applet 7.2 middleware#10971
LinuxJedi wants to merge 10 commits into
wolfSSL:masterfrom
LinuxJedi:se050_applet72_ecdh

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

Middleware built for SE05x applet >= 07_02 (required for SE052) derives the ECDH shared secret with Se05x_API_ECDHGenerateSharedSecret_InObject, which requires TLV[TAG_7] to reference an existing HMACKey object sized exactly to the shared secret; otherwise the applet returns SW 0x6985 (conditions not satisfied). The port never created this object, so ECDH offload failed with WC_HW_E on such builds.

Create the derive target as an HMACKey object of the exact secret size before the derive, for both ECC and Curve25519 shared secrets. Read the result back as AES type since sss_se05x_key_store_get_key has no HMAC read case.

Fixes zd#22069

Testing

wolfSSL/simulators#9

Middleware built for SE05x applet >= 07_02 (required for SE052) derives
the ECDH shared secret with Se05x_API_ECDHGenerateSharedSecret_InObject,
which requires TLV[TAG_7] to reference an existing HMACKey object sized
exactly to the shared secret; otherwise the applet returns SW 0x6985
(conditions not satisfied). The port never created this object, so ECDH
offload failed with WC_HW_E on such builds.

Create the derive target as an HMACKey object of the exact secret size
before the derive, for both ECC and Curve25519 shared secrets. Read the
result back as AES type since sss_se05x_key_store_get_key has no HMAC
read case.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes SE050 ECDH offload failures against SE05x applet >= 7.2 middleware by ensuring a correctly-sized derive-target object exists before calling the shared-secret derive APIs.

Changes:

  • Allocate the ECDH derive target as an HMACKey object (instead of Binary) so applet 7.2+ can store the shared secret into an existing object.
  • Pre-create the derive-target object with the exact shared-secret size (ECC and Curve25519) prior to derivation.
  • Read the derived secret back by temporarily treating the object as AES since sss_key_store_get_key() lacks an HMAC read case.

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

Comment thread wolfcrypt/src/port/nxp/se050_port.c Outdated
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m3

  • FLASH: .text +72 B (+0.1%, 122,611 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 200,853 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 181,092 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +104 B, .text -960 B (-0.1%, 771,028 B / 1,048,576 B, total: 74% used)
  • RAM: .bss +192 B (+0.1%, 136,936 B / 262,144 B, total: 52% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +448 B (+0.2%, 213,844 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +256 B (+0.1%, 326,168 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +64 B (+0.1%, 123,355 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 200,853 B / 262,144 B, total: 77% used)

linuxkm-pie

  • Data: __patchable_function_entries +296 B (+1.1%, 26,256 B)

linuxkm-standard

  • Data: __patchable_function_entries +368 B (+0.8%, 48,976 B)

stm32-sim-stm32h753

Align se050_curve25519_shared_secret with the ECC path: set
deriveKeyCreated only after sss_key_store_set_key succeeds, so the
cleanup path cannot erase or free a derive key object whose handle
was never allocated.
Bump SIMULATORS_REF to the simulator commit that supports HMACKey
WriteSymmKey and the applet 7.2 ECDH InObject contract, and run the
test container with SE050_SIM_STRICT_ECDH=1 so the simulator refuses
an ECDH derive whose Tag7 target object was not pre-created. This is
the failure mode seen on SE05x applet >= 7.2 hardware and reproduces
it in CI against the unfixed port.

The pinned simulator commit also consumes the WOLFSSL_EXTRA_CFLAGS
build ARG, so the only-key-id matrix leg now really builds with
-DWOLFSSL_SE050_ONLY_KEY_ID (previously the ARG was not consumed and
the leg silently built the default configuration), and it fixes the
simulator to derive the EC public key on private-only key pair import
so wc_ecc_use_key_id can read the public part back.

Raise the job timeout for cold image rebuilds until the weekend cron
refreshes the registry cache for the new ref.
The previous pin abbreviated to the right commit but the full hash was
invalid, so the simulator checkout step could never resolve it. Pin the
full commit id of the merged simulator change.
Frauschi
Frauschi previously approved these changes Jul 24, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@LinuxJedi

Copy link
Copy Markdown
Member Author

Also fixes ZD#22212

Applet 7.2 denies ReadObject on a symmetric key object that was created
with no policy attached, so the shared secret written into the derive
target by Se05x_API_ECDHGenerateSharedSecret_InObject could not be
exported: sss_key_store_get_key failed with SW 0x6986 (command not
allowed) on SE05x applet >= 7.2 hardware.

Create the derive target with an attached common policy granting read,
write and delete. An attached policy replaces the applet default
entirely, so write (the ECDH engine storing the result) and delete (the
cleanup path) must be granted explicitly alongside read. Guarded by
SSS_HAVE_SE05X_VER_GTE_07_02 so builds against older middleware keep
creating the object with no policy attached.
Bump SIMULATORS_REF to the simulator commit that, in strict mode,
refuses ReadObject on an HMACKey object unless the policy attached at
creation grants POLICY_OBJ_ALLOW_READ. This reproduces the SW 0x6986
derive-target readback failure seen on SE05x applet >= 7.2 hardware
(ZD 22212) and verifies the attached-policy fix in the previous commit.

The pinned commit is wolfSSL/simulators PR wolfSSL#10 and becomes fetchable
from the upstream clone once that PR is merged.
@LinuxJedi

Copy link
Copy Markdown
Member Author

Updated PR with some missing policy pieces.

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LinuxJedi PRB-master-job fails, as SSS_HAVE_SE05X_VER_GTE_07_02 is missing from .wolfssl_known_macro_extras. Otherwise LGTM.

@LinuxJedi
LinuxJedi marked this pull request as draft July 30, 2026 12:39
@LinuxJedi

Copy link
Copy Markdown
Member Author

I need to do further testing before I'm ready to call this good.

Real SE050 hardware (applet 3.1.1, JCOP4) refuses ReadObject on a
symmetric key object created without a read policy just like applet 7.2
does, and pre-7.2 middleware has no way to grant that policy:
sss_policy_common_u can_Read maps to POLICY_OBJ_ALLOW_READ only for
SSS_HAVE_SE05X_VER_GTE_07_02 builds and the symmetric key policy union
has no read flag at all. Switching the derive target to an HMACKey
object unconditionally therefore broke ECDH offload on applet 3.x parts
with SW 0x6986 at the shared secret export.

Restrict the HMACKey target and its attached read policy to
SSS_HAVE_SE05X_VER_GTE_07_02 builds and restore the original Binary
object flow otherwise: no pre-created target, erase before derive, and
the middleware creates the object when storing the derived secret.
Binary objects are readable without an attached policy.

Verified on SE050C (applet 3.1.1) hardware: the ECC and CURVE25519
wolfCrypt tests fail with SW 0x6986 without this change and pass with
it, matching master behavior on the same part. The applet 7.2 path is
unchanged.
Bump SIMULATORS_REF to the simulator commit that refuses ReadObject on
an HMACKey object without POLICY_OBJ_ALLOW_READ in all modes, matching
real hardware on every applet generation as verified on SE050C applet
3.1.1 silicon. With this pin a plain (non-strict) CI run reproduces the
SW 0x6986 readback failure that previously only appeared on hardware,
covering the pre-7.2 Binary derive target fix in the previous commit.

The pinned commit is wolfSSL/simulators PR wolfSSL#11 and becomes fetchable
from the upstream clone once that PR is merged.
The SE050 port now keys the ECDH derive target type and read policy
off the middleware's SSS_HAVE_SE05X_VER_GTE_07_02 feature macro.
The pinned simulator gained an sdk-test fix and review changes; move
SIMULATORS_REF to the final wolfSSL/simulators PR wolfSSL#11 head. Becomes
fetchable from the upstream clone once that PR is merged.
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.

4 participants