Skip to content

Shrink Optiga PRF SHA256 path#1953

Draft
benma wants to merge 1 commit into
BitBoxSwiss:masterfrom
benma:replace-mbed-sha256
Draft

Shrink Optiga PRF SHA256 path#1953
benma wants to merge 1 commit into
BitBoxSwiss:masterfrom
benma:replace-mbed-sha256

Conversation

@benma
Copy link
Copy Markdown
Collaborator

@benma benma commented Apr 22, 2026

[i teseted this and it works, but it's in draft because I did not check the code yet]

Replace the Optiga crypto PAL implementation with a project-owned PAL file and route the TLS PRF SHA256 implementation through the existing rust_hmac_sha256() firmware symbol instead of mbedTLS's md/sha256 wrapper stack.

The Optiga PAL is the intended integration seam for this, so this keeps the change out of vendored mbedTLS internals. AES-128-CCM stays on mbedTLS exactly as before; only pal_crypt_tls_prf_sha256() is replaced.

In the final linked image this removes the live Optiga mbedTLS digest/SHA256 path entirely:

  • md.c.obj drops out of the dependency chain
  • sha256.c.obj drops out of the dependency chain
  • mbedtls_md_* symbols disappear from the image
  • mbedtls_sha256_* symbols disappear from the image
  • pal_crypt_tls_prf_sha256() itself shrinks from 352 to 228 bytes

Measured on make -j firmware:

  • saved 2008 bytes in build/bin/firmware.bin
  • saved 2008 bytes in .text

This is a better result than the config-only MBEDTLS_SHA256_SMALLER change because it removes the whole live mbedTLS digest wrapper path for Optiga instead of only shrinking the SHA256 compression routine.

Replace the Optiga crypto PAL implementation with a project-owned
PAL file and route the TLS PRF SHA256 implementation through the
existing rust_hmac_sha256() firmware symbol instead of mbedTLS's
md/sha256 wrapper stack.

The Optiga PAL is the intended integration seam for this, so this
keeps the change out of vendored mbedTLS internals. AES-128-CCM
stays on mbedTLS exactly as before; only pal_crypt_tls_prf_sha256()
is replaced.

In the final linked image this removes the live Optiga mbedTLS
digest/SHA256 path entirely:
- md.c.obj drops out of the dependency chain
- sha256.c.obj drops out of the dependency chain
- mbedtls_md_* symbols disappear from the image
- mbedtls_sha256_* symbols disappear from the image
- pal_crypt_tls_prf_sha256() itself shrinks from 352 to 228 bytes

Measured on make -j firmware:
- saved 2008 bytes in build/bin/firmware.bin
- saved 2008 bytes in .text

This is a better result than the config-only MBEDTLS_SHA256_SMALLER
change because it removes the whole live mbedTLS digest wrapper path
for Optiga instead of only shrinking the SHA256 compression routine.
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.

1 participant