LPCxpresso55S69 TEE HASH

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCxpresso55S69 TEE HASH

313 Views
Matthias344
Contributor I

Hello,

in a sample project (lpcxpresso55s69_hashcrypt) i saw the HASH mathod so i wanted to use this method in the LPCxpresso55S69_hello_world_s sample project:

 

#define TEST_ASSERT(a)       \
    if (!(a))                \
    {                        \
        PRINTF("error\r\n"); \
        do                   \
        {                    \
        } while (1);         \
    }

#define CRYPTO_TEST_OUT_ARRAY_LEN 0x100
#define CRYPTO_SHA1_OUT_LEN       20
#define CRYPTO_SHA256_OUT_LEN     32
#include "fsl_hashcrypt.h"
void TestSha256(void)
{
    status_t status;
    size_t outLength;
    unsigned int length;
    unsigned char output[32];

    static const uint8_t message[] =
        "Be that word our sign of parting, bird or fiend! I shrieked upstarting"
        "Get thee back into the tempest and the Nights Plutonian shore!"
        "Leave no black plume as a token of that lie thy soul hath spoken!"
        "Leave my loneliness unbroken! quit the bust above my door!"
        "Take thy beak from out my heart, and take thy form from off my door!"
        "Quoth the raven, Nevermore.  ";

    /* Expected SHA-256 for the message. */
    static const unsigned char sha256[] = {0x63, 0x76, 0xea, 0xcc, 0xc9, 0xa2, 0xc0, 0x43, 0xf4, 0xfb, 0x01,
                                           0x34, 0x69, 0xb3, 0x0c, 0xf5, 0x28, 0x63, 0x5c, 0xfa, 0xa5, 0x65,
                                           0x60, 0xef, 0x59, 0x7b, 0xd9, 0x1c, 0xac, 0xaa, 0x31, 0xf7};

    length    = sizeof(message) - 1;
    outLength = sizeof(output);
    memset(&output, 0, outLength);

    /************************ SHA-256 **************************/
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, length, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    TEST_ASSERT(memcmp(output, sha256, outLength) == 0);

    PRINTF("SHA-256 Test pass\r\n");
}

int main(void)
{
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

BOARD_InitPins();
BOARD_BootClockPLL150M();
BOARD_InitDebugConsole();

HASHCRYPT_Init(HASHCRYPT);
TestSha256();
HASHCRYPT_Deinit(HASHCRYPT);

TZM_JumpToNormalWorld(NON_SECURE_START);

while (1){}
}

 

but i always keep getting stuck in the loop (fsl_hashcrypt.c   line: 706)

while (0U == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
{
}

 Could someone help me to solve this problem pls?

THX!

0 Kudos
1 Reply

304 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

I tried on my side but I do not have the same issue. Could you tell me if you have additional configuration? 

Pavel_Hernandez_0-1655227619749.png

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_hashcrypt.h"
#include <string.h>
#include "fsl_power.h"


#define TEST_ASSERT(a)       \
    if (!(a))                \
    {                        \
        PRINTF("error\r\n"); \
        do                   \
        {                    \
        } while (1);         \
    }

#define CRYPTO_TEST_OUT_ARRAY_LEN 0x100
#define CRYPTO_SHA1_OUT_LEN       20
#define CRYPTO_SHA256_OUT_LEN     32

void TestSha256(void)
{
    status_t status;
    size_t outLength;
    unsigned int length;
    unsigned char output[32];

    static const uint8_t message[] =
        "Be that word our sign of parting, bird or fiend! I shrieked upstarting"
        "Get thee back into the tempest and the Nights Plutonian shore!"
        "Leave no black plume as a token of that lie thy soul hath spoken!"
        "Leave my loneliness unbroken! quit the bust above my door!"
        "Take thy beak from out my heart, and take thy form from off my door!"
        "Quoth the raven, Nevermore.  ";

    /* Expected SHA-256 for the message. */
    static const unsigned char sha256[] = {0x63, 0x76, 0xea, 0xcc, 0xc9, 0xa2, 0xc0, 0x43, 0xf4, 0xfb, 0x01,
                                           0x34, 0x69, 0xb3, 0x0c, 0xf5, 0x28, 0x63, 0x5c, 0xfa, 0xa5, 0x65,
                                           0x60, 0xef, 0x59, 0x7b, 0xd9, 0x1c, 0xac, 0xaa, 0x31, 0xf7};

    length    = sizeof(message) - 1;
    outLength = sizeof(output);
    memset(&output, 0, outLength);

    /************************ SHA-256 **************************/
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, length, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    TEST_ASSERT(memcmp(output, sha256, outLength) == 0);

    PRINTF("SHA-256 Test pass\r\n");
}

int main(void)
{

    POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    BOARD_InitBootPins();
    BOARD_BootClockPLL150M();
    BOARD_InitDebugConsole();

    HASHCRYPT_Init(HASHCRYPT);
    TestSha256();
    HASHCRYPT_Deinit(HASHCRYPT);

    while (1)
    {
    }
}

 Best regards,
Pavel

0 Kudos