forked from wolfSSL/wolfssl
add macro for trng and gce driver names
This commit is contained in:
@ -27,3 +27,25 @@ The example_server loops looking to accept connections and closes immediatly aft
|
||||
The benchmark example tries to do a TCP connection to SERVER_IP on port 11112 and a TLS connection to SERVER_IP on port 11111 then does wolfCrypt benchmark collection.
|
||||
|
||||
The wolfcryptest runs through all of the unit tests from wolfcrypt/test/test.c
|
||||
|
||||
## Advanced Overriding Driver Name
|
||||
Defaults are set for when accessing the driver but the default names may not always work for an existing project. These are the macros and their defaults that could be mapped to other driver names:
|
||||
|
||||
/* For main SCE open and close */
|
||||
WOLFSSL_SCE_GSCE_HANDLE g_sce
|
||||
|
||||
/* For AES operations */
|
||||
WOLFSSL_SCE_AES256_HANDLE g_sce_aes_256
|
||||
WOLFSSL_SCE_AES192_HANDLE g_sce_aes_192
|
||||
WOLFSSL_SCE_AES128_HANDLE g_sce_aes_128
|
||||
|
||||
/* HASH operations */
|
||||
WOLFSSL_SCE_SHA256_HANDLE g_sce_hash_0
|
||||
|
||||
/* TRNG access */
|
||||
WOLFSSL_SCE_TRNG_HANDLE g_sce_trng
|
||||
|
||||
|
||||
|
||||
An example of remapping a driver name would be the following added to a wolfSSL user_settings.h file:
|
||||
#define WOFSSL_SCE_SHA256_HANDLE my_sce_hash_driver
|
||||
|
@ -792,7 +792,7 @@
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz);
|
||||
}
|
||||
|
||||
@ -828,7 +828,7 @@
|
||||
return WC_HW_E;
|
||||
}
|
||||
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
ByteReverseWords((word32*)outBlock, (word32*)outBlock, sz);
|
||||
if (inBlock != outBlock) {
|
||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz); /* revert input*/
|
||||
@ -842,7 +842,7 @@
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz);
|
||||
}
|
||||
|
||||
@ -873,7 +873,7 @@
|
||||
return WC_HW_E;
|
||||
}
|
||||
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
ByteReverseWords((word32*)outBlock, (word32*)outBlock, sz);
|
||||
if (inBlock != outBlock) {
|
||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz); /* revert input*/
|
||||
@ -2415,7 +2415,7 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
|
||||
#if defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_AES)
|
||||
XMEMCPY((byte*)aes->key, userKey, keylen);
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_BIG) {
|
||||
ByteReverseWords(aes->key, aes->key, 32);
|
||||
}
|
||||
#endif
|
||||
|
@ -2317,13 +2317,18 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG)
|
||||
#include "hal_data.h"
|
||||
|
||||
#ifndef WOLFSSL_SCE_TRNG_HANDLE
|
||||
#define WOLFSSL_SCE_TRNG_HANDLE g_sce_trng
|
||||
#endif
|
||||
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
uint32_t ret;
|
||||
uint32_t blocks;
|
||||
word32 len = sz;
|
||||
|
||||
ret = g_sce_trng.p_api->open(g_sce_trng.p_ctrl, g_sce_trng.p_cfg);
|
||||
ret = WOLFSSL_SCE_TRNG_HANDLE.p_api->open(WOLFSSL_SCE_TRNG_HANDLE.p_ctrl,
|
||||
WOLFSSL_SCE_TRNG_HANDLE.p_cfg);
|
||||
if (ret != SSP_SUCCESS && ret != SSP_ERR_CRYPTO_ALREADY_OPEN) {
|
||||
/* error opening TRNG driver */
|
||||
return -1;
|
||||
@ -2331,8 +2336,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
|
||||
blocks = sz / sizeof(uint32_t);
|
||||
if (blocks > 0) {
|
||||
ret = g_sce_trng.p_api->read(g_sce_trng.p_ctrl, (uint32_t*)output,
|
||||
blocks);
|
||||
ret = WOLFSSL_SCE_TRNG_HANDLE.p_api->read(WOLFSSL_SCE_TRNG_HANDLE.p_ctrl,
|
||||
(uint32_t*)output, blocks);
|
||||
if (ret != SSP_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
@ -2345,14 +2350,15 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
if (len > sizeof(uint32_t)) {
|
||||
return -1;
|
||||
}
|
||||
ret = g_sce_trng.p_api->read(g_sce_trng.p_ctrl, (uint32_t*)tmp, 1);
|
||||
ret = WOLFSSL_SCE_TRNG_HANDLE.p_api->read(WOLFSSL_SCE_TRNG_HANDLE.p_ctrl,
|
||||
(uint32_t*)tmp, 1);
|
||||
if (ret != SSP_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
XMEMCPY(output + (blocks * sizeof(uint32_t)), (byte*)&tmp, len);
|
||||
}
|
||||
|
||||
ret = g_sce_trng.p_api->close(g_sce_trng.p_ctrl);
|
||||
ret = WOLFSSL_SCE_TRNG_HANDLE.p_api->close(WOLFSSL_SCE_TRNG_HANDLE.p_ctrl);
|
||||
if (ret != SSP_SUCCESS) {
|
||||
/* error opening TRNG driver */
|
||||
return -1;
|
||||
|
@ -555,7 +555,7 @@ static int InitSha256(wc_Sha256* sha256)
|
||||
#define XTRANSFORM(S, D) wc_Sha256SCE_XTRANSFORM((S), (D))
|
||||
static int wc_Sha256SCE_XTRANSFORM(wc_Sha256* sha256, const byte* data)
|
||||
{
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_LITTLE)
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_LITTLE)
|
||||
{
|
||||
ByteReverseWords((word32*)data, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
||||
@ -568,7 +568,7 @@ static int InitSha256(wc_Sha256* sha256)
|
||||
return WC_HW_E;
|
||||
}
|
||||
|
||||
if (g_sce.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_LITTLE)
|
||||
if (WOLFSSL_SCE_GSCE_HANDLE.p_cfg->endian_flag == CRYPTO_WORD_ENDIAN_LITTLE)
|
||||
{
|
||||
ByteReverseWords((word32*)data, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
||||
|
@ -229,7 +229,8 @@ int wolfCrypt_Init(void)
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SCE
|
||||
ret = (int)g_sce.p_api->open(g_sce.p_ctrl, g_sce.p_cfg);
|
||||
ret = (int)WOLFSSL_SCE_GSCE_HANDLE.p_api->open(WOLFSSL_SCE_GSCE_HANDLE.p_ctrl,
|
||||
WOLFSSL_SCE_GSCE_HANDLE.p_cfg);
|
||||
if (ret == SSP_ERR_CRYPTO_SCE_ALREADY_OPEN) {
|
||||
WOLFSSL_MSG("SCE already open");
|
||||
ret = 0;
|
||||
@ -293,7 +294,7 @@ int wolfCrypt_Cleanup(void)
|
||||
wolfAsync_HardwareStop();
|
||||
#endif
|
||||
#ifdef WOLFSSL_SCE
|
||||
g_sce.p_api->close(g_sce.p_ctrl);
|
||||
WOLFSSL_SCE_GSCE_HANDLE.p_api->close(WOLFSSL_SCE_GSCE_HANDLE.p_ctrl);
|
||||
#endif
|
||||
#if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \
|
||||
defined(WOLFSSL_IMX6_CAAM_BLOB)
|
||||
|
@ -767,6 +767,12 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
||||
WOLFSSL_LOCAL void wolfSSL_CleanupHandle();
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SCE
|
||||
#ifndef WOLFSSL_SCE_GSCE_HANDLE
|
||||
#define WOLFSSL_SCE_GSCE_HANDLE g_sce
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user