mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 02:37:28 +02:00
DCP port: Fixed AES, aligned key for the HW module
This commit is contained in:
@ -50,9 +50,11 @@
|
|||||||
#include "fsl_dcp.h"
|
#include "fsl_dcp.h"
|
||||||
|
|
||||||
#ifndef SINGLE_THREADED
|
#ifndef SINGLE_THREADED
|
||||||
|
#define dcp_lock_init() wolfSSL_CryptHwMutexInit()
|
||||||
#define dcp_lock() wolfSSL_CryptHwMutexLock()
|
#define dcp_lock() wolfSSL_CryptHwMutexLock()
|
||||||
#define dcp_unlock() wolfSSL_CryptHwMutexLock()
|
#define dcp_unlock() wolfSSL_CryptHwMutexUnLock()
|
||||||
#else
|
#else
|
||||||
|
#define dcp_lock_init() do{}while(0)
|
||||||
#define dcp_lock() do{}while(0)
|
#define dcp_lock() do{}while(0)
|
||||||
#define dcp_unlock() do{}while(0)
|
#define dcp_unlock() do{}while(0)
|
||||||
#endif
|
#endif
|
||||||
@ -126,6 +128,7 @@ static int dcp_get_channel(void)
|
|||||||
if (dcp_status[i] == 0) {
|
if (dcp_status[i] == 0) {
|
||||||
dcp_status[i]++;
|
dcp_status[i]++;
|
||||||
ret = dcp_channels[i];
|
ret = dcp_channels[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dcp_unlock();
|
dcp_unlock();
|
||||||
@ -161,6 +164,7 @@ static int dcp_key_slot(int ch)
|
|||||||
int wc_dcp_init(void)
|
int wc_dcp_init(void)
|
||||||
{
|
{
|
||||||
dcp_config_t dcpConfig;
|
dcp_config_t dcpConfig;
|
||||||
|
dcp_lock_init();
|
||||||
dcp_lock();
|
dcp_lock();
|
||||||
DCP_GetDefaultConfig(&dcpConfig);
|
DCP_GetDefaultConfig(&dcpConfig);
|
||||||
|
|
||||||
@ -211,8 +215,11 @@ int DCPAesInit(Aes *aes)
|
|||||||
void DCPAesFree(Aes *aes)
|
void DCPAesFree(Aes *aes)
|
||||||
{
|
{
|
||||||
dcp_free(aes->handle.channel);
|
dcp_free(aes->handle.channel);
|
||||||
|
aes->handle.channel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned char aes_key_aligned[16] __attribute__((aligned(0x10)));
|
||||||
int DCPAesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
|
int DCPAesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
|
||||||
int dir)
|
int dir)
|
||||||
{
|
{
|
||||||
@ -227,10 +234,12 @@ int DCPAesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
|
|||||||
if (len != 16)
|
if (len != 16)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
if (aes->handle.channel == 0) {
|
if (aes->handle.channel == 0) {
|
||||||
return BAD_FUNC_ARG;
|
if (DCPAesInit(aes) != 0)
|
||||||
|
return WC_HW_E;
|
||||||
}
|
}
|
||||||
dcp_lock();
|
dcp_lock();
|
||||||
status = DCP_AES_SetKey(DCP, &aes->handle, key, 16);
|
memcpy(aes_key_aligned, key, 16);
|
||||||
|
status = DCP_AES_SetKey(DCP, &aes->handle, aes_key_aligned, 16);
|
||||||
if (status != kStatus_Success)
|
if (status != kStatus_Success)
|
||||||
status = WC_HW_E;
|
status = WC_HW_E;
|
||||||
else {
|
else {
|
||||||
@ -328,11 +337,6 @@ int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wc_InitSha256(wc_Sha256* sha256)
|
|
||||||
{
|
|
||||||
return wc_InitSha256_ex(sha256, NULL, INVALID_DEVID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DCPSha256Free(wc_Sha256* sha256)
|
void DCPSha256Free(wc_Sha256* sha256)
|
||||||
{
|
{
|
||||||
if (sha256)
|
if (sha256)
|
||||||
|
Reference in New Issue
Block a user