Hello, I think the "transform" part may be causing the issue. It seems you execute transform part n-times, depending on the size of the input data. For this, a different approach may be used:
Performing a Standard HASH Operation, multiple 64 byte input blocks:
1. reset the MDHA using SWR bit
2. MDCR register write
3. MDMR register write
4. write the complete data size to the MDDSR register (for example 256 for four input blocks)
5. poll MDSR[IFL] to check if there is a space available in the FIFO
6. write a longword to the FIFO
7. repeat steps 5 and 6 until the entire block is written
8. set the GO bit
9. wait for MDSR[INT]
This approach gives reliable outputs.
Source code example:
MCF_MDHA_MDCMR = (0 | MCF_MDHA_MDCMR_CI
| MCF_MDHA_MDCMR_RI
| MCF_MDHA_MDCMR_SWR ) ; // do a reset
while (!MCF_MDHA_MDSR & MCF_MDHA_MDSR_RD){} // reset done?
MCF_MDHA_MDCR = 0; // no ints
MCF_MDHA_MDMR = (0 |
MCF_MDHA_MDMR_INIT |
MCF_MDHA_MDMR_ALG); // select MD5 with init
MCF_MDHA_MDDSR = 256; //256 input bytes in total
for(i=0;i<256/4;i++) //move 64 longwords to the fifo
{
//wait until there is a space in the FIFO
while((MCF_MDHA_MDSR & 0x1F0000 ) == 0x10)
{} //do nothing
MCF_MDHA_MDIN = input_data[i]; //move longword to the FIFO
}
MCF_MDHA_MDCMR = MCF_MDHA_MDCMR_GO; // GO
k = MCF_MDHA_MDSR;
/* wait for digest to complete */
while( !( MCF_MDHA_MDSR & MCF_MDHA_MDSR_INT ))
{};
/* Check for errors! */
if ( MCF_MDHA_MDSR & MCF_MDHA_MDSR_ERR)
{
printf("Error during message digest!!!\r\n" );
k = MCF_MDHA_MDISR;
printf("MCF_MDHA_MDISR: 0x%08x\n\r", k);
}