forked from wolfSSL/wolfssl
add macro for trng and gce driver names
This commit is contained in:
@ -1,29 +1,51 @@
|
|||||||
|
|
||||||
## Building wolfSSL For DK-S7G2
|
## Building wolfSSL For DK-S7G2
|
||||||
|
|
||||||
- First physically toggle the ENET1 and JTAG switch to on with the DK-S7G2 board.
|
- First physically toggle the ENET1 and JTAG switch to on with the DK-S7G2 board.
|
||||||
- Open e2studio and set the workspace to be wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/
|
- Open e2studio and set the workspace to be wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/
|
||||||
- Create a Synergy library project named wolfssl "File->New->Synergy C/C++ Project", "Renesas Synergy C Library Project" then "Next", set wolfssl as the "Project Name" then "Next", set Board to "S7G2 DK" then "Next", finally select the BSP radius and click "Finish"
|
- Create a Synergy library project named wolfssl "File->New->Synergy C/C++ Project", "Renesas Synergy C Library Project" then "Next", set wolfssl as the "Project Name" then "Next", set Board to "S7G2 DK" then "Next", finally select the BSP radius and click "Finish"
|
||||||
- Copy configuration.xml and .project from wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/ into the wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl directory
|
- Copy configuration.xml and .project from wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl-template-project/ into the wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfssl directory
|
||||||
- (optional but necessary for production) Add TRNG support by clicking on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > TRNG Driver on r_sce_trng". Then comment out WOLFSSL_SCE_NO_TRNG define in wolfssl project src/user_settings.h
|
- (optional but necessary for production) Add TRNG support by clicking on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > TRNG Driver on r_sce_trng". Then comment out WOLFSSL_SCE_NO_TRNG define in wolfssl project src/user_settings.h
|
||||||
- (optional SHA acceleration) Add HASH support by clicking on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > HASH Driver on r_sce_hash". Then uncomment WOLFSSL_SCE_NO_HASH define in wolfssl project src/user_settings.h
|
- (optional SHA acceleration) Add HASH support by clicking on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > HASH Driver on r_sce_hash". Then uncomment WOLFSSL_SCE_NO_HASH define in wolfssl project src/user_settings.h
|
||||||
- (optional AES acceleration) Add the stacks for AES128, AES192, and AES256. Click on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > AES Driver on r_sce_aes". Add three one for each key size and rename them to g_sce_aes_256, g_sce_aes_192, and g_sce_aes_128. Changing each to ECB chaining mode and the key length that matches the name.
|
- (optional AES acceleration) Add the stacks for AES128, AES192, and AES256. Click on Threads tab and highlight HAL/Common click "New Stack > Driver > Crypto > AES Driver on r_sce_aes". Add three one for each key size and rename them to g_sce_aes_256, g_sce_aes_192, and g_sce_aes_128. Changing each to ECB chaining mode and the key length that matches the name.
|
||||||
- Generate the changes by clicking on "Generate Project Content"
|
- Generate the changes by clicking on "Generate Project Content"
|
||||||
- Exclude src/wolfcrypt/port and all src/wolfcrypt/*.S and src/wolfcrypt/*.asm files from the build
|
- Exclude src/wolfcrypt/port and all src/wolfcrypt/*.S and src/wolfcrypt/*.asm files from the build
|
||||||
- Exclude src/wolfcrypt/evp.c, src/wolfcrypt/misc.c and src/wolfssl/bio.c
|
- Exclude src/wolfcrypt/evp.c, src/wolfcrypt/misc.c and src/wolfssl/bio.c
|
||||||
- Set the Preprocessor define in wolfssl proejct to have WOLFSSL_USER_SETTINGS. Right click on wolfssl project "Properties -> C/C++ Build -> GNU ARM Cross C Compiler -> Preprocessor" add WOLFSSL_USER_SETTINGS under "Defined symbols"
|
- Set the Preprocessor define in wolfssl proejct to have WOLFSSL_USER_SETTINGS. Right click on wolfssl project "Properties -> C/C++ Build -> GNU ARM Cross C Compiler -> Preprocessor" add WOLFSSL_USER_SETTINGS under "Defined symbols"
|
||||||
- Set include to wolfssl directory. Right click on project "Properties -> C/C++Build -> GNU ARM Cross Compiler -> Includes". Add "${ProjDirPath}/../../../../.." and "${ProjDirPath}/../"
|
- Set include to wolfssl directory. Right click on project "Properties -> C/C++Build -> GNU ARM Cross Compiler -> Includes". Add "${ProjDirPath}/../../../../.." and "${ProjDirPath}/../"
|
||||||
- Build wolfssl by right clicking on wolfssl project and selecting "Build Project"
|
- Build wolfssl by right clicking on wolfssl project and selecting "Build Project"
|
||||||
|
|
||||||
## Example Projects and Building
|
## Example Projects and Building
|
||||||
|
|
||||||
- Create a new Synergy project "Renesas Synergy C Project Using Synergy Library"
|
- Create a new Synergy project "Renesas Synergy C Project Using Synergy Library"
|
||||||
- Set it to use the wolfssl library
|
- Set it to use the wolfssl library
|
||||||
- Copy in the .cproject, .project and source file from the template desired i.e. wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/
|
- Copy in the .cproject, .project and source file from the template desired i.e. wolfssl-X.X.X/IDE/Renesas/e2studio/DK-S7G2/wolfcrypttest-template/
|
||||||
- Right click on the created project and select "Build Project"
|
- Right click on the created project and select "Build Project"
|
||||||
|
|
||||||
The example_server loops looking to accept connections and closes immediatly after a successful connection was made.
|
The example_server loops looking to accept connections and closes immediatly after a successful connection was made.
|
||||||
|
|
||||||
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 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
|
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;
|
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);
|
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -828,7 +828,7 @@
|
|||||||
return WC_HW_E;
|
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);
|
ByteReverseWords((word32*)outBlock, (word32*)outBlock, sz);
|
||||||
if (inBlock != outBlock) {
|
if (inBlock != outBlock) {
|
||||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz); /* revert input*/
|
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz); /* revert input*/
|
||||||
@ -842,7 +842,7 @@
|
|||||||
{
|
{
|
||||||
uint32_t ret;
|
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);
|
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,7 +873,7 @@
|
|||||||
return WC_HW_E;
|
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);
|
ByteReverseWords((word32*)outBlock, (word32*)outBlock, sz);
|
||||||
if (inBlock != outBlock) {
|
if (inBlock != outBlock) {
|
||||||
ByteReverseWords((word32*)inBlock, (word32*)inBlock, sz); /* revert input*/
|
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)
|
#if defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_AES)
|
||||||
XMEMCPY((byte*)aes->key, userKey, keylen);
|
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);
|
ByteReverseWords(aes->key, aes->key, 32);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2317,13 +2317,18 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG)
|
#elif defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_TRNG)
|
||||||
#include "hal_data.h"
|
#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)
|
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||||
{
|
{
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
uint32_t blocks;
|
uint32_t blocks;
|
||||||
word32 len = sz;
|
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) {
|
if (ret != SSP_SUCCESS && ret != SSP_ERR_CRYPTO_ALREADY_OPEN) {
|
||||||
/* error opening TRNG driver */
|
/* error opening TRNG driver */
|
||||||
return -1;
|
return -1;
|
||||||
@ -2331,8 +2336,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
|
|
||||||
blocks = sz / sizeof(uint32_t);
|
blocks = sz / sizeof(uint32_t);
|
||||||
if (blocks > 0) {
|
if (blocks > 0) {
|
||||||
ret = g_sce_trng.p_api->read(g_sce_trng.p_ctrl, (uint32_t*)output,
|
ret = WOLFSSL_SCE_TRNG_HANDLE.p_api->read(WOLFSSL_SCE_TRNG_HANDLE.p_ctrl,
|
||||||
blocks);
|
(uint32_t*)output, blocks);
|
||||||
if (ret != SSP_SUCCESS) {
|
if (ret != SSP_SUCCESS) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2345,14 +2350,15 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
if (len > sizeof(uint32_t)) {
|
if (len > sizeof(uint32_t)) {
|
||||||
return -1;
|
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) {
|
if (ret != SSP_SUCCESS) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
XMEMCPY(output + (blocks * sizeof(uint32_t)), (byte*)&tmp, len);
|
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) {
|
if (ret != SSP_SUCCESS) {
|
||||||
/* error opening TRNG driver */
|
/* error opening TRNG driver */
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -555,7 +555,7 @@ static int InitSha256(wc_Sha256* sha256)
|
|||||||
#define XTRANSFORM(S, D) wc_Sha256SCE_XTRANSFORM((S), (D))
|
#define XTRANSFORM(S, D) wc_Sha256SCE_XTRANSFORM((S), (D))
|
||||||
static int wc_Sha256SCE_XTRANSFORM(wc_Sha256* sha256, const byte* data)
|
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((word32*)data, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||||
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
||||||
@ -568,7 +568,7 @@ static int InitSha256(wc_Sha256* sha256)
|
|||||||
return WC_HW_E;
|
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((word32*)data, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||||
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
ByteReverseWords(sha256->digest, sha256->digest, WC_SHA256_DIGEST_SIZE);
|
||||||
|
@ -229,7 +229,8 @@ int wolfCrypt_Init(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_SCE
|
#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) {
|
if (ret == SSP_ERR_CRYPTO_SCE_ALREADY_OPEN) {
|
||||||
WOLFSSL_MSG("SCE already open");
|
WOLFSSL_MSG("SCE already open");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -293,7 +294,7 @@ int wolfCrypt_Cleanup(void)
|
|||||||
wolfAsync_HardwareStop();
|
wolfAsync_HardwareStop();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WOLFSSL_SCE
|
#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
|
#endif
|
||||||
#if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \
|
#if defined(WOLFSSL_IMX6_CAAM) || defined(WOLFSSL_IMX6_CAAM_RNG) || \
|
||||||
defined(WOLFSSL_IMX6_CAAM_BLOB)
|
defined(WOLFSSL_IMX6_CAAM_BLOB)
|
||||||
|
@ -767,6 +767,12 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
|||||||
WOLFSSL_LOCAL void wolfSSL_CleanupHandle();
|
WOLFSSL_LOCAL void wolfSSL_CleanupHandle();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SCE
|
||||||
|
#ifndef WOLFSSL_SCE_GSCE_HANDLE
|
||||||
|
#define WOLFSSL_SCE_GSCE_HANDLE g_sce
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user