Repository navigation
Conversation
With STM32_CRYPTO (on a CRYP that does DES) the des3.c hardware arm defined wc_Des_EcbEncrypt() but no wc_Des3_EcbEncrypt(), so a build with WOLFSSL_DES_ECB failed to link. It also could not decrypt in ECB mode: des3.h maps wc_Des_EcbDecrypt / wc_Des3_EcbDecrypt to the encrypt functions, which works in software because the decryption key schedule is reversed, but the STM32 key setup ignores the direction and the CRYP takes the same key either way, so ECB "decryption" encrypted. - Des3Crypt() takes a mode, like DesCrypt(), and runs TDES-ECB as well as TDES-CBC on all three paths (HAL_V2, CubeMX HAL, StdPeriph). - The STM32 arm defines wc_Des_EcbDecrypt(), wc_Des3_EcbEncrypt() and wc_Des3_EcbDecrypt(), and des3.h declares separate ECB decrypt functions for these builds, as it already does for FREESCALE_MMCAU. - The HAL_V2 paths of DesCrypt() and Des3Crypt() only read the IV back from the CRYP after CBC. ECB does not use the IV registers, so reading them back replaced des->reg with stale contents. Tested with the wolfCrypt test (WOLFSSL_DES_ECB, STM32_HAL_V2) on the STM32Sim STM32F417 target: the DES and 3DES tests, including ECB, pass.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The legacy CubeMX HAL and StdPeriph ECB paths were neither compiled nor run, so vendor API compatibility and behavior need maintainer validation beyond the reported HAL V2 simulator coverage.
No open issues 🎉
What changed in this PR
Adds hardware-backed 3DES ECB support and corrects DES ECB decryption in wolfCrypt’s STM32 crypto backend, building on the CBC fixes in #12079.
Changes:
- Implements 3DES ECB encryption and decryption across STM32 HAL V2, legacy CubeMX HAL, and StdPeriph paths.
- Exposes separate STM32 ECB decrypt functions so hardware receives the correct operation direction.
- Preserves the context’s CBC IV during ECB operations, including on HAL V2.
| File | Description |
|---|---|
wolfssl/wolfcrypt/des3.h |
Declares separate ECB decrypt functions for STM32 hardware with DES support. |
wolfcrypt/src/des3.c |
Adds STM32 3DES ECB support, corrects ECB decryption, and limits IV updates to CBC operations. |
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.
Description
Fixes DES ECB on STM32 hardware crypto (
STM32_CRYPTOon a CRYP that does DES) indes3.c/des3.h. Based on master; follows #12079.wc_Des_EcbEncrypt()but nowc_Des3_EcbEncrypt(), so any build withWOLFSSL_DES_ECBfailed to link (des3_testreferences it).des3.hmapswc_Des_EcbDecrypt/wc_Des3_EcbDecryptto the encrypt functions. That works in software, where a decryption key schedule is reversed, but the STM32SetKeyfunctions ignore the direction and the CRYP takes the same key either way. Sowc_Des_EcbDecrypt()on STM32 hardware encrypted.Changes:
Des3Crypt()takes a mode, likeDesCrypt(), and runs TDES-ECB as well as TDES-CBC on all three paths (STM32_HAL_V2, CubeMX HAL, StdPeriph).wc_Des_EcbDecrypt(),wc_Des3_EcbEncrypt()andwc_Des3_EcbDecrypt(). For these builds,des3.hdeclares separate ECB decrypt functions instead of the macros, as it already does forFREESCALE_MMCAU. Callers inssl_crypto.candevp.calready use the Decrypt names.STM32_HAL_V2paths ofDesCrypt()andDes3Crypt()only read the IV back from the CRYP after CBC. ECB doesn't use the IV registers, so reading them back replaceddes->regwith stale contents.Testing
STM32_HAL_V2,WOLFSSL_DES_ECB): DES and 3DES, includingdes_ecb_testand the 3DES ECB vectors, pass, and so does the rest of the suite. On master the same firmware fails to link onwc_Des3_EcbEncrypt. The F417 target and firmware are in STM32Sim: add STM32F417/F407 targets with RNG fault injection simulators#27, which should merge after this one.STM32_HAL_V2path was built and run. The CubeMX HAL (withoutSTM32_HAL_V2) and StdPeriph ECB branches follow the existing single-DES code, but current STM32CubeF4 no longer ships the old HAL API, and the StdPeriph library isn't available here, so those weren't compiled.Checklist