This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SHA1 issue with TIVAC129

Other Parts Discussed in Thread: EK-TM4C129EXL

Hi all.

Regarding the following discusion :

e2e.ti.com/.../1325145

I have a similar issue with SHA1, in this way: I'm not able to obtain the same hash of my string comparing ti other site SHA1 calculator like:

http://www.sha1-online.com/.

My output is: 83b1df6a4ac9a2a4b5da922fa462e7ada1a58978

but the correct value should be: 6adfb183a4a2c94a2f92dab5ade762a47889a5a1

Below my code:

typedef struct {

uint8_t dataSource[SHA1MD5_VECTOR_LEN];

uint32_t dataLength;

} sha1Md5SourceData;

sha1Md5SourceData sha1md5LocalData;

uint32_t sha1md5LocalResult[5];

main

{

SHA1MD5HashSetMessage( "helloworld" );

SHA1MD5HashGenerate();

SHA1MD5GetHashResult( param2 );

printf("%s", param2);

}

void SHA1MD5HashGenerate( void )

{

SHAMD5Reset(SHAMD5_BASE);

SHAMD5ConfigSet(SHAMD5_BASE, SHAMD5_ALGO_SHA1);

SHAMD5DataProcess( SHAMD5_BASE, (uint32_t *)sha1md5LocalData.dataSource, sha1md5LocalData.dataLength, sha1md5LocalResult );

}

void SHA1MD5HashSetMessage( char *message )

{

memset( sha1md5LocalData.dataSource, 0, SHA1MD5_VECTOR_LEN );

memcpy( sha1md5LocalData.dataSource, message, len );

sha1md5LocalData.dataLength = (uint32_t)strlen( message);

}

Bool SHA1MD5GetHashResult( char *result )

{

sprintf( result, "%08x%08x%08x%08x%08x", sha1md5LocalResult[0],

sha1md5LocalResult[1],

sha1md5LocalResult[2],

sha1md5LocalResult[3],

sha1md5LocalResult[4] );

return (TRUE);

}

 

  • Sorry, adding the correct code for function SHA1MD5HashSetMessage:

    void SHA1MD5HashSetMessage( char *message )
    {
    int len = strlen( message);
    memset( sha1md5LocalData.dataSource, 0, SHA1MD5_VECTOR_LEN );
    memcpy( sha1md5LocalData.dataSource, message, len );
    sha1md5LocalData.dataLength = (uint32_t)len;

    OSConsoleDebug( OS_CONSOLE_LEVEL, osConsoleDebugModule, "SHA1MD5HashSetMessage: " );
    OSConsoleDebug( OS_CONSOLE_LEVEL, osConsoleDebugModule, "%s", sha1md5LocalData.dataSource );
    OSConsoleDebug( OS_CONSOLE_LEVEL, osConsoleDebugModule, ", %d \n", sha1md5LocalData.dataLength );
    }
  • Hello marco,

    We have various examples in the latest version of TivaWare in the folders "/examples/boards/dk-tm4c129x" and "/examples/boards/ek-tm4c129exl". Did you already refer them? Can you try the same test with these examples and see if you still see a mis-match?

    Thanks,
    Sai
  • Yes, I run exactly the same example.

    The main issue is that I cannot reproduce the same result with string.

    I need to manupulate array of char (strings) but using various cast with uint32_t I'm not able to repro the same result of other on line tools.

    Regards,

    Marco

  • Hello Marco,

    Which specific example are you using? Also provide the string that you are using for testing. I can try and see why a mis-match is occurring.

    Thanks,

    Sai

  • I'm using the example:
    C:\ti\TivaWare_C_Series-2.1.1.71\examples\boards\dk-tm4c129x\sha1_hash

    the string is "helloworld" as I specified in the example above.

    Regards,
    Marco
  • Hello Marco,

    The latest TivaWare (v2.1.2.111), has the example "shamd5_hmac_example" in the folder "/examples/boards/ek-tm4c129exl", which handles the strings.

    This example by default supports only HMAC. It can be quickly modified to support HASH operation. The following are the changes I made and got the expected answer:
    * Modify the function "Cmd_algo" to replace the parameter "SHAMD5_ALGO_HMAC_SHA1" with "SHAMD5_ALGO_SHA1" to the TivaWare API "MAP_SHAMD5ConfigSet". Now when the argument "sha1" is passed for the command "algo" (from command line), the module is configured to calculate Hash instead of HMAC.
    * Modify the function "Cmd_hmac" to remove the API call "MAP_SHAMD5HMACKeySet".

    If you don't have the EK-TM4C129EXL LaunchPad, then this example has to be modified to work on DK-TM4C129X.

    Thanks,
    Sai
  • Hello Sai.

    Thank for your support.

    Using the example given, I was able to make my project working fine.

    I think, the issue was relegated into these pieces of code:

    OLD CODE NOT WORKING:

    int SHA1MD5GetHashResult( char *result )

    {

    sprintf( result, "%08x%08x%08x%08x%08x", sha1md5LocalData.dataResult[0],

    sha1md5LocalData.dataResult[1],

    sha1md5LocalData.dataResult[2],

    sha1md5LocalData.dataResult[3],

    sha1md5LocalData.dataResult[4] );

    return (1);

    }

    ----------------------------------------------------------------------------

    ADAPTED CODE AND WORKING:

    int SHA1MD5GetHashResult( char *result )

    {

    char cTmp[4];

    uint32_t ui32Index;

    uint8_t *pui8Ptr;

    strcpy( result, "" );

    pui8Ptr = (uint8_t *)&sha1md5LocalData.dataResult[0];

    for(ui32Index = 0; ui32Index < sha1md5LocalData.dataLength;

    ui32Index++, pui8Ptr++)

    {

    sprintf( cTmp, "%02x", *pui8Ptr);

    strcat( result, cTmp );

    }

    return(1);

    }

    Regards,

    Marco