Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 5781

SHA-256 generation didn't works on the S7

$
0
0

Hi

I want to  use the hash S7 function.

I starts with the sha2_example function:

static uint32_t    sha256InitialValue[8] =
{
    0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
    0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};

/* padded message buffer (for message string "abc") */
static uint32_t  InputMessage[16] =
{
    0x61626380, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000018
};

/* expected output sha1 message digest */
static uint32_t ExpectedMD[8] =
{
    0xBA7816BF, 0x8F01CFEA, 0x414140DE, 0x5DAE2223,
    0xB00361A3, 0x96177A9C, 0xB410FF61, 0xF20015AD
};

static uint32_t InputMessageLen = 16;


/* The example below shows usage for the SHA1 driver.
 * The example below computes the sha2 hash for an input message "abc".
 */
void sha2_example (void)
{
    ssp_err_t iret;
    int i = 0;

    uint32_t OutputMD[8];

    /* configure the SHA256 driver */
    iret = (ssp_err_t) g_sce_hash_sha256.p_api->open(g_sce_hash_sha256.p_ctrl, g_sce_hash_sha256.p_cfg);
    if(iret != SSP_SUCCESS)
    {
        printf("ERROR open [%d]\r\n", iret);
        return;
    }

    /* initialize the sha2 hash value */
    memcpy(OutputMD, sha256InitialValue, 32);

    /* process the input message data and update the sha2 hash value
       64-byte blocks from the input message are processed
    */
    iret = (ssp_err_t) g_sce_hash_sha256.p_api->hashUpdate(g_sce_hash_sha256.p_ctrl,InputMessage, InputMessageLen, OutputMD);
    if(iret != SSP_SUCCESS)
    {
        printf("ERROR hashUpdate [%d]\r\n", iret);
        return;
    }

    /* close the sha2 driver */
    iret = (ssp_err_t) g_sce_hash_sha256.p_api->close(g_sce_hash_sha256.p_ctrl);
    if(iret != SSP_SUCCESS)
    {
        printf("ERROR close [%d]\r\n", iret);
        return;
    }

    printf("\n\rSHA2 Input Message\n\r");
    printf("InputMessage[%d] = ", InputMessageLen);
    for(i=0; i < InputMessageLen; i++)
    {
        printf(" 0x%08x,", InputMessage[i]);
    }
    printf("\n");
    printf("OutputMD[%d] = ", 8);
    for(i=0; i < 8; i++)
    {
        printf(" 0x%08x,", OutputMD[i]);
    }
    printf("\n");
    printf("ExpectedMD[%d] = ", 8);
    for(i=0; i < 8; i++)
    {
        printf(" 0x%08x,", ExpectedMD[i]);
    }
    printf("\n");

    /* check if the sha2 value returned matches the expected value */
    if (memcmp(OutputMD, ExpectedMD, 32) != 0)
    {
        printf("! SHA2 hashing failed !\n\r");
    }
}

But I've got a bad result !

OutputMD[8] =  0xa94b467f, 0x38048650, 0x785dc28a, 0x8679266a, 0x41aed18a, 0x0fb178b4, 0x95f3b17f, 0x2e9a21d3,

 

Nobody have the same problem ?

Thanks


Viewing all articles
Browse latest Browse all 5781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>