fix warnings

fix encrypted key use case

Update README
This commit is contained in:
Hideki Miyazaki
2024-04-26 06:50:09 +09:00
parent 0d86137317
commit 07de40e4bd
5 changed files with 65 additions and 29 deletions

View File

@@ -22,7 +22,7 @@ The example project summary is listed below and is relevant for every project.
|Item|Name/Version|
|:--|:--|
|Board|RZN2L|
|Device|R9A07G084M04GBG|
|Device|R9A07G084M08GBG|
|Toolchain|GCC for Renesas RZ|
|Toolchain Version|10.3.1.20210824|
|FSP Version|1.2.0|
@@ -34,7 +34,7 @@ The example project summary is listed below and is relevant for every project.
|Board Support Package Common Files|v1.20||
|I/O Port|v1.2.0||
|Arm CMSIS Version 5 - Core (M)|v5.7.0+renesas.1||
|Board support package for R9A07G084M04GBG|v1.2.0||
|Board support package for R9A07G084M04GBG|v1.2.0|Note1|
|Board support package for RZN2L|v1.2.0||
|Board support package for RZN2L - FSP Data|v1.2.0||
|RSK+RZN2L Board Support Files (RAM execution without flash memory)|v1.2.0||
@@ -50,6 +50,8 @@ The example project summary is listed below and is relevant for every project.
|Renesas Secure IP Driver|v1.3.0+fsp.1.2.0|Need to contact Renesas to get RSIP module|
|RSIP Engine for RZ/N2L|v1.3.0+fsp.1.2.0|Need to contact Renesas to get RSIP module|
Note1:\
To use RSIP drive, a devvice type should be `R9A07G084M04GBG`. However, choosing `R9A07G084M04GBG` won't allow to select `RSK+RZN2L` board. This example uses LED and external flash memory on `RSK + RZN2L` board. Therefore, the example temporary `R9A07G084M04GBG` for the device type. Updating e2studio or fsp could resolve the issue.
## Setup Steps and Build wolfSSL Library
@@ -93,16 +95,18 @@ The example project summary is listed below and is relevant for every project.
3.) Prepare UART to logging
+ Download Sample package from [BACnet Start-Up](https://www.renesas.com/us/en/products/microcontrollers-microprocessors/rz-mpus/bacnet-start-rzn2l-rsk)
+ Copy the following C source files from the project to src/serial_io folder of `test_RZN2L`
+ um_serial_io_uart.c
+ um_serial_io_task_writer.c
+ um_serial_io_cfg.h
+ um_common_api.h
+ um_common_cfg.h
+ um_serial_io.c
+ um_serial_io.h
+ um_serial_io_api.h
+ um_serial_io_internal.h
+ Copy the following C source files from the project to src/serial_io folder of `test_RZN2L`\
um_serial_io_uart.c\
um_serial_io_task_writer.c\
um_serial_io_cfg.h\
um_common_api.h\
um_common_cfg.h\
um_serial_io.c\
um_serial_io.h\
um_serial_io_api.h\
um_serial_io_internal.h
+ Open um_serial_io_task_writer.c and re-name printf to uart_printf
3.) Build `test_RZN2L` project

View File

@@ -361,8 +361,14 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
* in advance. SCE supports 1024 or 2048 bits key size.
* otherwise, falls-through happens.
*/
if (info->pk.rsa.key->ctx.keySz == 1024 ||
info->pk.rsa.key->ctx.keySz == 2048) {
if (cbInfo->keyflgs_crypt.bits.rsapri2048_installedkey_set ||
cbInfo->keyflgs_crypt.bits.rsapub2048_installedkey_set ||
cbInfo->keyflgs_crypt.bits.rsapri1024_installedkey_set ||
cbInfo->keyflgs_crypt.bits.rsapub1024_installedkey_set ) {
ret = wc_fspsm_MakeRsaKey(info->pk.rsa.key, 0, cbInfo);
if (ret == CRYPTOCB_UNAVAILABLE)
return ret;
if (info->pk.rsa.type == RSA_PRIVATE_DECRYPT ||
info->pk.rsa.type == RSA_PUBLIC_ENCRYPT )
@@ -370,7 +376,7 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
ret = wc_fspsm_RsaFunction(info->pk.rsa.in,
info->pk.rsa.inLen,
info->pk.rsa.out,
&info->pk.rsa.outLen,
(word32*)&info->pk.rsa.outLen,
info->pk.rsa.type,
info->pk.rsa.key,
info->pk.rsa.rng);
@@ -379,7 +385,7 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
ret = wc_fspsm_RsaSign(info->pk.rsa.in,
info->pk.rsa.inLen,
info->pk.rsa.out,
info->pk.rsa.outLen,
(word32*)&info->pk.rsa.outLen,
info->pk.rsa.key,
(void*)ctx);
}
@@ -387,7 +393,7 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
ret = wc_fspsm_RsaVerify(info->pk.rsa.in,
info->pk.rsa.inLen,
info->pk.rsa.out,
info->pk.rsa.outLen,
(word32*)&info->pk.rsa.outLen,
info->pk.rsa.key,
(void*)ctx);
}

View File

@@ -1,6 +1,6 @@
/* renesas_fspsm_rsa.c
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
@@ -99,6 +99,33 @@ WOLFSSL_LOCAL int wc_fspsm_MakeRsaKey(RsaKey *key, int size, void* ctx)
key->ctx.wrapped_pri2048_key = info->wrapped_key_rsapri2048;
key->ctx.wrapped_pub2048_key = info->wrapped_key_rsapub2048;
key->ctx.keySz = 2048;
} else if (size == 0) {
if((info->keyflgs_crypt.bits.rsapri2048_installedkey_set != 1) &&
(info->keyflgs_crypt.bits.rsapub2048_installedkey_set != 1) &&
(info->keyflgs_crypt.bits.rsapri1024_installedkey_set != 1) &&
(info->keyflgs_crypt.bits.rsapub1024_installedkey_set != 1)) {
WOLFSSL_MSG("Caller should create user key in advance.");
WOLFSSL_MSG("Caller also need to installedkey to 1.");
return BAD_FUNC_ARG;
}
if (info->keyflgs_crypt.bits.rsapri1024_installedkey_set == 1) {
key->ctx.wrapped_pri1024_key = info->wrapped_key_rsapri1024;
key->ctx.keySz = 1024;
}
if (info->keyflgs_crypt.bits.rsapub1024_installedkey_set == 1) {
key->ctx.wrapped_pub1024_key = info->wrapped_key_rsapub1024;
key->ctx.keySz = 1024;
}
if (info->keyflgs_crypt.bits.rsapri2048_installedkey_set == 1) {
key->ctx.wrapped_pri2048_key = info->wrapped_key_rsapri2048;
key->ctx.keySz = 2048;
}
if (info->keyflgs_crypt.bits.rsapub2048_installedkey_set == 1) {
key->ctx.wrapped_pub2048_key = info->wrapped_key_rsapub2048;
key->ctx.keySz = 2048;
}
} else
return CRYPTOCB_UNAVAILABLE;
@@ -132,8 +159,7 @@ WOLFSSL_LOCAL int wc_fspsm_RsaFunction(const byte* in, word32 inLen, byte* out,
(void) rng;
/* sanity check */
if (in == NULL || out == NULL ||
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
if (in == NULL || out == NULL || key == NULL){
return BAD_FUNC_ARG;
}
@@ -210,8 +236,8 @@ WOLFSSL_LOCAL int wc_fspsm_RsaSign(const byte* in, word32 inLen, byte* out,
int keySize;
/* sanity check */
if (in == NULL || out == NULL || (word32*)outLen <= 0 || info == NULL ||
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
if (in == NULL || out == NULL || *outLen <= 0 || info == NULL ||
key == NULL){
return BAD_FUNC_ARG;
}
@@ -278,8 +304,8 @@ WOLFSSL_LOCAL int wc_fspsm_RsaVerify(const byte* in, word32 inLen, byte* out,
(void) key;
/* sanity check */
if (in == NULL || out == NULL || (word32*)outLen <= 0 || info == NULL ||
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
if (in == NULL || out == NULL || *outLen <= 0 || info == NULL ||
key == NULL){
return BAD_FUNC_ARG;
}
@@ -292,7 +318,7 @@ WOLFSSL_LOCAL int wc_fspsm_RsaVerify(const byte* in, word32 inLen, byte* out,
info->keyflgs_crypt.bits.message_type;/* message 0, hash 1 */
signature.pdata = out;
signature.data_length = (word32*)outLen;
signature.data_length = (word32)*outLen;
#if defined(WOLFSSL_RENESAS_RSIP)
message_hash.hash_type = signature.hash_type =
info->hash_type; /* hash type */

View File

@@ -271,7 +271,7 @@ static int FSPSM_HashUpdate(wolfssl_FSPSM_Hash* hash,
return BAD_FUNC_ARG;
}
wc_fspsm_hw_lock();
ret = Update(&hash->handle, data, sz);
ret = Update(&hash->handle, (byte*)data, sz);
wc_fspsm_hw_unlock();
return ret;
#endif

View File

@@ -188,7 +188,7 @@ WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
{
/* Generate PRNG based on NIST SP800-90A AES CTR-DRBG */
int ret = 0;
word32 buffer[RANDGEN_WORDS];
word32 fspbuf[RANDGEN_WORDS];
while (sz > 0) {
word32 len = sizeof(buffer);
@@ -197,9 +197,9 @@ WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
len = sz;
}
/* return 4 words random number*/
ret = R_RANDOM_GEN(buffer);
ret = R_RANDOM_GEN((uint8_t* const)fspbuf);
if(ret == FSP_SUCCESS) {
XMEMCPY(output, &buffer, len);
XMEMCPY(output, &fspbuf, len);
output += len;
sz -= len;
} else {