Skip to content

Commit bbace5a

Browse files
authored
Merge pull request #10494 from LinuxJedi/STM32MP13-SHAKE
Fix SHAKE with STM32MP13 and add simulator
2 parents e2d3b63 + ecdf170 commit bbace5a

2 files changed

Lines changed: 54 additions & 9 deletions

File tree

.github/workflows/stm32-sim.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ concurrency:
1515

1616
# Build the STM32 software simulator (https://github.com/wolfSSL/simulators,
1717
# STM32Sim/ subdirectory) and run the wolfCrypt test suite on emulated
18-
# STM32H753 (Cortex-M7) and STM32U585 (Cortex-M33) hardware. Replaces the
19-
# previous Renode-based STM32H753 workflow and adds U5/PKA coverage.
18+
# STM32H753 (Cortex-M7), STM32U585 (Cortex-M33), and STM32MP135 (Cortex-A7)
19+
# hardware. Replaces the previous Renode-based STM32H753 workflow and adds
20+
# U5/PKA + MP135 (SHA3/SHAKE on HASH1) coverage.
2021
#
2122
# Dockerfile.wolfcrypt reads wolfSSL from /opt/wolfssl at runtime via a
2223
# bind mount, so unlike se050-sim.yml / stsafe-a120-sim.yml no Dockerfile
2324
# patching is required - we just mount the PR checkout.
25+
#
26+
# The simulators repo is pinned via SIMULATORS_REF so the MP135 SHAKE-
27+
# enabling sed patch below has a known anchor in user_settings.h. Bump
28+
# the pin when simulators changes are needed.
29+
30+
env:
31+
SIMULATORS_REF: 840da2f4a28a9e3027c127da38d758ded902d926
2432

2533
jobs:
2634
stm32_sim:
@@ -36,14 +44,33 @@ jobs:
3644
script: run-wolfcrypt-h7.sh
3745
- chip_label: U585
3846
script: run-wolfcrypt-u5.sh
47+
- chip_label: MP135
48+
script: run-wolfcrypt-mp135.sh
3949
steps:
4050
- name: Checkout wolfSSL (PR source)
4151
uses: actions/checkout@v4
4252
with:
4353
path: wolfssl
4454

4555
- name: Clone STM32 simulator
46-
run: git clone --depth 1 https://github.com/wolfSSL/simulators simulators
56+
run: |
57+
git clone https://github.com/wolfSSL/simulators simulators
58+
cd simulators && git checkout "$SIMULATORS_REF"
59+
60+
# The MP135 firmware in the simulators repo currently disables SHAKE
61+
# in user_settings.h with a comment pointing at the wolfSSL build
62+
# break that this PR resolves. Once the simulators repo refreshes
63+
# that file, this patch step becomes a no-op (the grep below will
64+
# still pass) - drop it then.
65+
- name: Enable SHAKE in MP135 firmware user_settings.h
66+
if: matrix.chip_label == 'MP135'
67+
working-directory: simulators/STM32Sim/firmware/wolfcrypt-test-mp135
68+
run: |
69+
sed -i 's|^#define WOLFSSL_SHA3$|#define WOLFSSL_SHA3\n#define WOLFSSL_SHAKE128\n#define WOLFSSL_SHAKE256|' user_settings.h
70+
# Fail fast if the anchor line drifted - better than silently
71+
# building with SHAKE off and "passing" without exercising it.
72+
grep -q '^#define WOLFSSL_SHAKE128$' user_settings.h
73+
grep -q '^#define WOLFSSL_SHAKE256$' user_settings.h
4774
4875
- uses: docker/setup-buildx-action@v3
4976

wolfcrypt/src/sha3.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@
7676
#include <wolfcrypt/src/misc.c>
7777
#endif
7878

79+
/* Gates the non-WOLFSSL_SHA3_SMALL software Keccak primitives
80+
* (hash_keccak_r, BlockSha3, InitSha3, Sha3Update, Sha3Final and the
81+
* Load64* helpers). Compiled when:
82+
* - No HW SHA-3 backend is selected (the original baseline), OR
83+
* - STM32 HW SHA-3 is selected and SHAKE is enabled - SHAKE on STM32MP13
84+
* runs in software because the HASH peripheral's SHAKE support is
85+
* fixed-length and does not match wolfSSL's variable-length / iterative
86+
* SqueezeBlocks API. SHA-3 still uses the HASH peripheral.
87+
*
88+
* Note: the WOLFSSL_SHA3_SMALL branch earlier in this file defines its
89+
* own hash_keccak_r and BlockSha3 unconditionally inside its #ifdef
90+
* block, so this macro only controls the non-SMALL implementation. */
91+
#if (!defined(STM32_HASH_SHA3) && !defined(PSOC6_HASH_SHA3)) || \
92+
(defined(STM32_HASH_SHA3) && \
93+
(defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)))
94+
#define WC_SHA3_SW_KECCAK
95+
#endif
96+
7997
#if FIPS_VERSION3_GE(6,0,0)
8098
const unsigned int wolfCrypt_FIPS_sha3_ro_sanity[2] =
8199
{ 0x1a2b3c4d, 0x00000016 };
@@ -320,7 +338,7 @@ void BlockSha3(word64* s)
320338
*/
321339
#define ROTL64(a, n) (((a)<<(n))|((a)>>(64-(n))))
322340

323-
#if !defined(STM32_HASH_SHA3) && !defined(PSOC6_HASH_SHA3)
341+
#ifdef WC_SHA3_SW_KECCAK
324342
/* An array of values to XOR for block operation. */
325343
static const word64 hash_keccak_r[24] =
326344
{
@@ -555,7 +573,7 @@ do { \
555573
while (0)
556574
#endif /* SHA3_BY_SPEC */
557575

558-
#if !defined(STM32_HASH_SHA3) && !defined(PSOC6_HASH_SHA3)
576+
#ifdef WC_SHA3_SW_KECCAK
559577
/* The block operation performed on the state.
560578
*
561579
* s The state.
@@ -581,11 +599,11 @@ void BlockSha3(word64* s)
581599
s[0] ^= hash_keccak_r[i+1];
582600
}
583601
}
584-
#endif /* WOLFSSL_SHA3_SMALL */
585-
#endif /* STM32_HASH_SHA3 */
602+
#endif /* WC_SHA3_SW_KECCAK */
603+
#endif /* !WOLFSSL_SHA3_SMALL */
586604
#endif /* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
587605

588-
#if !defined(STM32_HASH_SHA3) && !defined(PSOC6_HASH_SHA3)
606+
#ifdef WC_SHA3_SW_KECCAK
589607
#if defined(BIG_ENDIAN_ORDER)
590608
static WC_INLINE word64 Load64Unaligned(const unsigned char *a)
591609
{
@@ -929,7 +947,7 @@ static int Sha3Final(wc_Sha3* sha3, byte padChar, byte* hash, byte p, word32 l)
929947

930948
return 0;
931949
}
932-
#endif
950+
#endif /* WC_SHA3_SW_KECCAK */
933951
#if defined(STM32_HASH_SHA3)
934952

935953
/* Supports CubeMX HAL or Standard Peripheral Library */

0 commit comments

Comments
 (0)