@@ -252,24 +252,45 @@ static void wc_Stm32_Hash_GetDigest(byte* hash, int digestSize)
252
252
#endif
253
253
}
254
254
255
- static int wc_Stm32_Hash_WaitDone (STM32_HASH_Context * stmCtx )
255
+ static int wc_Stm32_Hash_WaitDataReady (STM32_HASH_Context * stmCtx )
256
256
{
257
257
int timeout = 0 ;
258
258
(void )stmCtx ;
259
259
260
- /* wait until not busy and hash digest / input block are complete */
261
- while ((( HASH -> SR & HASH_SR_BUSY )
260
+ /* wait until not busy and data input buffer ready */
261
+ while ((HASH -> SR & HASH_SR_BUSY )
262
262
#ifdef HASH_IMR_DCIE
263
- || (HASH -> SR & HASH_SR_DCIS ) == 0
263
+ && (HASH -> SR & HASH_SR_DCIS ) == 0
264
264
#endif
265
+ && ++ timeout < STM32_HASH_TIMEOUT ) {
266
+ };
267
+
268
+ #ifdef DEBUG_STM32_HASH
269
+ printf ("STM Wait Data %d, HASH->SR %lx\n" , timeout , HASH -> SR );
270
+ #endif
271
+
272
+ /* verify timeout did not occur */
273
+ if (timeout >= STM32_HASH_TIMEOUT ) {
274
+ return WC_TIMEOUT_E ;
275
+ }
276
+ return 0 ;
277
+ }
278
+
279
+ static int wc_Stm32_Hash_WaitCalcComp (STM32_HASH_Context * stmCtx )
280
+ {
281
+ int timeout = 0 ;
282
+ (void )stmCtx ;
283
+
284
+ /* wait until not busy and hash digest calculation complete */
285
+ while (((HASH -> SR & HASH_SR_BUSY )
265
286
#ifdef HASH_IMR_DINIE
266
287
|| (HASH -> SR & HASH_SR_DINIS ) == 0
267
288
#endif
268
289
) && ++ timeout < STM32_HASH_TIMEOUT ) {
269
290
};
270
291
271
292
#ifdef DEBUG_STM32_HASH
272
- printf ("STM Wait done %d, HASH->SR %lx\n" , timeout , HASH -> SR );
293
+ printf ("STM Wait Calc %d, HASH->SR %lx\n" , timeout , HASH -> SR );
273
294
#endif
274
295
275
296
/* verify timeout did not occur */
@@ -364,7 +385,7 @@ int wc_Stm32_Hash_Update(STM32_HASH_Context* stmCtx, word32 algo,
364
385
365
386
if (wroteToFifo ) {
366
387
/* make sure hash operation is done */
367
- ret = wc_Stm32_Hash_WaitDone (stmCtx );
388
+ ret = wc_Stm32_Hash_WaitDataReady (stmCtx );
368
389
369
390
/* save hash state for next operation */
370
391
wc_Stm32_Hash_SaveContext (stmCtx );
@@ -405,7 +426,7 @@ int wc_Stm32_Hash_Final(STM32_HASH_Context* stmCtx, word32 algo,
405
426
HASH -> STR |= HASH_STR_DCAL ;
406
427
407
428
/* wait for hash done */
408
- ret = wc_Stm32_Hash_WaitDone (stmCtx );
429
+ ret = wc_Stm32_Hash_WaitCalcComp (stmCtx );
409
430
if (ret == 0 ) {
410
431
/* read message digest */
411
432
wc_Stm32_Hash_GetDigest (hash , digestSize );
0 commit comments