@@ -183,32 +183,31 @@ static void wc_Stm32_Hash_RestoreContext(STM32_HASH_Context* ctx, word32 algo,
183183 #endif
184184 );
185185
186- /* configure algorithm, mode and data type
187- * mode is HASH_ALGOMODE_HASH or HASH_ALGOMODE_HMAC */
188- HASH -> CR |= (algo | mode | HASH_DATATYPE_8B );
189-
190- /* reset HASH processor */
191- HASH -> CR |= HASH_CR_INIT ;
186+ /* configure algorithm, mode, data type and reset HASH processor.
187+ * INIT must be written in the same register write as the algorithm
188+ * selection — on some STM32 variants (e.g. H753) a separate INIT
189+ * write resets the ALGO bits back to MD5 (0). */
190+ HASH -> CR = (algo | mode | HASH_DATATYPE_8B | HASH_CR_INIT );
192191
193192 /* by default mark all bits valid */
194193 wc_Stm32_Hash_NumValidBits (0 );
195194
196195#ifdef DEBUG_STM32_HASH
197- printf ("STM Init algo %x, mode %x\n" , (unsigned int )algo ,
198- (unsigned int )mode );
196+ printf ("STM Init algo %x, mode %x, CR %lx, SR %lx\n" ,
197+ (unsigned int )algo , (unsigned int )mode ,
198+ HASH -> CR , HASH -> SR );
199199#endif
200200 }
201201 else {
202202 /* restore context registers */
203203 HASH -> IMR = ctx -> HASH_IMR ;
204204 HASH -> STR = ctx -> HASH_STR ;
205- HASH -> CR = ctx -> HASH_CR ;
206205#ifdef STM32_HASH_SHA3
207206 HASH -> SHA3CFGR = ctx -> SHA3CFGR ;
208207#endif
209208
210- /* Initialize the hash processor */
211- HASH -> CR |= HASH_CR_INIT ;
209+ /* Restore CR and initialize in a single write (see init path comment) */
210+ HASH -> CR = ctx -> HASH_CR | HASH_CR_INIT ;
212211
213212 /* continue restoring context registers */
214213 for (i = 0 ; i < HASH_CR_SIZE ; i ++ ) {
0 commit comments