Subject: STSAFE-A110 Local Envelope Unwrap fails with STSAFEA_CRYPTO_LIB_ISSUE (0x20) when using STSAFEA_ENCRYPTION_RESPONSE — Wrap succeeds wit
Hi,
I'm integrating an STSAFE-A110 with stsafe-a-openssl-engine V2.0.0 on a Linux/aarch64 host (Jetson AGX Orin, Ubuntu 22.04, OpenSSL 3.0.2), communicating over I2C. I've resolved a number of earlier issues (wrong I2C bus, OpenSSL 3.0 API migration, host key pairing) and now have Host Key programming, Local Envelope key generation, Product Data query, Life Cycle State query, and Command Authorization Configuration query all succeeding against the physical chip.
Current issue: StSafeA_WrapLocalEnvelope and StSafeA_UnwrapLocalEnvelope behave asymmetrically.
My chip's Command Authorization Configuration reports:
- Command
0x0E(Wrap Local Envelope):CommandAC = 0x03(MAC),HostEncryptionFlags = 0x02(command encryption) - Command
0x0F(Unwrap Local Envelope):CommandAC = 0x03(MAC),HostEncryptionFlags = 0x01(response encryption)
Calling Wrap with STSAFEA_MAC_HOST_CMAC, STSAFEA_ENCRYPTION_COMMAND succeeds and returns a plausible 488-byte wrapped envelope.
Calling Unwrap on that same output with STSAFEA_MAC_HOST_CMAC, STSAFEA_ENCRYPTION_RESPONSE fails with STSAFEA_CRYPTO_LIB_ISSUE (0x20), reported by StSafeA_DataDecryption in stsafea_crypto.c.
What I've isolated so far:
inlenpassed toStSafeA_UnwrapLocalEnvelopeis correct (488 =ENVELOPE_SIZE + 8).StSafeA_AES_ECB_Encrypt(computing the initial value) andStSafeA_AES_CBC_Decryptboth report success (status 0x00) at the OpenSSL layer.- However, the resulting "decrypted" buffer contains no valid
0x80padding marker anywhere near the expected offset — the tail bytes look like random noise, not a padded 480-byte envelope. So the CBC decrypt call succeeds mechanically but produces incorrect plaintext, which then failsStSafeA_DataDecryption's padding-marker validation. - The host CMAC sequence counter (
pStSafeA->HostMacSequenceCounter) is freshly re-queried from the chip viaStSafeA_GetHostMacSequenceCounterimmediately before each CMAC-flagged command, so it isn't stale between the Wrap and Unwrap calls. aHostCipherKeyis a static array, unmodified between the two calls.- The
ComputeInitialValuedirection enum values look correct per the source (C_ENCRYPTION = 2,R_ENCRYPTION = 3).
I found a similar-sounding symptom in this thread (different command, EstablishKey, but same STSAFEA_ENCRYPTION_RESPONSE + STSAFEA_CRYPTO_LIB_ISSUE-adjacent behavior), where the resolution involved personalization profile (SPL02 vs SPL03) and a prerequisite pairing step from the X-CUBE-SAFEA1 example: [link to that thread]
Questions:
- Does Local Envelope Unwrap (response-encrypted) require a pairing/session step beyond basic host key programming (
HostKeyPresenceFlagconfirmed = 1) — similar to what's needed for EstablishKey with STSAFEA_ENCRYPTION_RESPONSE on SPL03 profiles? - Is there a known issue with
ComputeInitialValue's IV construction specifically for theR_ENCRYPTIONcase in this library version? - Could you point me to documentation on the exact IV/counter semantics expected for response decryption, so I can verify against my host-side implementation?
Happy to share my ST Product Number / PersoId from a Product Data query if that helps identify my personalization profile.
Thanks in advance for any guidance.
