Georg Brechlin

Problems using the 5275 MDHA for MD5 / HMAC

Discussion created by Georg Brechlin on Aug 19, 2008
Latest reply on Sep 5, 2008 by Martin Latal
Hi,
I am having severe trouble to get the MDHA engine running reliable.
MCU is a 5275.
My code consists of three parts: init, transform and final.
Normal use would be:
init
transform 64 bytes  n times
final

But:
- the result is not always the same though the input is the same
- sometimes MDHA stalls after the GO cmd with status = 0x00000498
Any attempt to change the status=0498 results in an error status.

I appreciate any help!
Kind regards,
Georg Brechlin

#define    MdsrData(k)    (k&0x001F0000)
#define    MdsrBusy(k)    (k&0x00000010)
#define    MdsrHash(k)    (k&0x00000040)
#define    MdsrPad(k)    ((k&0x0000E000)==0x00008000)
#define    MdsrInt(k)    (k&0x00000007)

#define    MdsrHashDone(k)    ((!MdsrBusy(k)) || (MdsrHash(k)) || (MdsrData(k)) || (!MdsrPad(k)) )


init:
    MCF_MDHA_MDCMR = 0x00000001;        // Software Reset
    while (!(MCF_MDHA_MDSR&0x00000008)){}    // still resetting?
    MCF_MDHA_MDCR = 0;    // no Ints
    MCF_MDHA_MDMR = 0x21;    // MD5 Init

transform puts 16 32bit words into the fifo and sets new datasize to 64 bytes
    for (j=16;j;j--)
    {
        d = mdha_byte_to_uint(&k,d);   // fill 32bit word with bytes
        MCF_MDHA_MDIN = k;    // put 32 bit word to fifo
    }

    MCF_MDHA_MDDSR = 64;            //  64 bytes filled in

    k = MCF_MDHA_MDSR;
    // wait for MDSR status:
    // (makes no big difference if waiting or not)
    // - bit hash = 0
    // - bit busy = 1
    // - bits IFL = 0 , Input Fifo Level
    while (MdsrHashDone(k))
    {
        k = MCF_MDHA_MDSR;
    }

final: tell MDHA to calculate the hash

    MCF_MDHA_MDCMR = 0x00000008;    // GO ...

    k = MCF_MDHA_MDSR;
    while ((MdsrBusy(k))||(!MdsrInt(k)))    // wait while BUSY=1 and DONE=0
    {
        k = MCF_MDHA_MDSR;
    }

    // get the result
    md5_transform_erg[0] = MCF_MDHA_MDA0;
    md5_transform_erg[1] = MCF_MDHA_MDB0;
    md5_transform_erg[2] = MCF_MDHA_MDC0;
    md5_transform_erg[3] = MCF_MDHA_MDD0;

    MCF_MDHA_MDCMR = 0x00000004;    // clr Int flag

Outcomes