Skip to content

Commit 07de40e

Browse files
committed
fix warnings
fix encrypted key use case Update README
1 parent 0d86137 commit 07de40e

5 files changed

Lines changed: 65 additions & 29 deletions

File tree

IDE/Renesas/e2studio/RZN2L/README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The example project summary is listed below and is relevant for every project.
2222
|Item|Name/Version|
2323
|:--|:--|
2424
|Board|RZN2L|
25-
|Device|R9A07G084M04GBG|
25+
|Device|R9A07G084M08GBG|
2626
|Toolchain|GCC for Renesas RZ|
2727
|Toolchain Version|10.3.1.20210824|
2828
|FSP Version|1.2.0|
@@ -34,7 +34,7 @@ The example project summary is listed below and is relevant for every project.
3434
|Board Support Package Common Files|v1.20||
3535
|I/O Port|v1.2.0||
3636
|Arm CMSIS Version 5 - Core (M)|v5.7.0+renesas.1||
37-
|Board support package for R9A07G084M04GBG|v1.2.0||
37+
|Board support package for R9A07G084M04GBG|v1.2.0|Note1|
3838
|Board support package for RZN2L|v1.2.0||
3939
|Board support package for RZN2L - FSP Data|v1.2.0||
4040
|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.
5050
|Renesas Secure IP Driver|v1.3.0+fsp.1.2.0|Need to contact Renesas to get RSIP module|
5151
|RSIP Engine for RZ/N2L|v1.3.0+fsp.1.2.0|Need to contact Renesas to get RSIP module|
5252

53+
Note1:\
54+
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.
5355

5456
## Setup Steps and Build wolfSSL Library
5557

@@ -93,16 +95,18 @@ The example project summary is listed below and is relevant for every project.
9395
3.) Prepare UART to logging
9496

9597
+ Download Sample package from [BACnet Start-Up](https://www.renesas.com/us/en/products/microcontrollers-microprocessors/rz-mpus/bacnet-start-rzn2l-rsk)
96-
+ Copy the following C source files from the project to src/serial_io folder of `test_RZN2L`
97-
+ um_serial_io_uart.c
98-
+ um_serial_io_task_writer.c
99-
+ um_serial_io_cfg.h
100-
+ um_common_api.h
101-
+ um_common_cfg.h
102-
+ um_serial_io.c
103-
+ um_serial_io.h
104-
+ um_serial_io_api.h
105-
+ um_serial_io_internal.h
98+
+ Copy the following C source files from the project to src/serial_io folder of `test_RZN2L`\
99+
um_serial_io_uart.c\
100+
um_serial_io_task_writer.c\
101+
um_serial_io_cfg.h\
102+
um_common_api.h\
103+
um_common_cfg.h\
104+
um_serial_io.c\
105+
um_serial_io.h\
106+
um_serial_io_api.h\
107+
um_serial_io_internal.h
108+
109+
106110
+ Open um_serial_io_task_writer.c and re-name printf to uart_printf
107111

108112
3.) Build `test_RZN2L` project

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,22 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
361361
* in advance. SCE supports 1024 or 2048 bits key size.
362362
* otherwise, falls-through happens.
363363
*/
364-
if (info->pk.rsa.key->ctx.keySz == 1024 ||
365-
info->pk.rsa.key->ctx.keySz == 2048) {
364+
if (cbInfo->keyflgs_crypt.bits.rsapri2048_installedkey_set ||
365+
cbInfo->keyflgs_crypt.bits.rsapub2048_installedkey_set ||
366+
cbInfo->keyflgs_crypt.bits.rsapri1024_installedkey_set ||
367+
cbInfo->keyflgs_crypt.bits.rsapub1024_installedkey_set ) {
368+
369+
ret = wc_fspsm_MakeRsaKey(info->pk.rsa.key, 0, cbInfo);
370+
if (ret == CRYPTOCB_UNAVAILABLE)
371+
return ret;
366372

367373
if (info->pk.rsa.type == RSA_PRIVATE_DECRYPT ||
368374
info->pk.rsa.type == RSA_PUBLIC_ENCRYPT )
369375
{
370376
ret = wc_fspsm_RsaFunction(info->pk.rsa.in,
371377
info->pk.rsa.inLen,
372378
info->pk.rsa.out,
373-
&info->pk.rsa.outLen,
379+
(word32*)&info->pk.rsa.outLen,
374380
info->pk.rsa.type,
375381
info->pk.rsa.key,
376382
info->pk.rsa.rng);
@@ -379,15 +385,15 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
379385
ret = wc_fspsm_RsaSign(info->pk.rsa.in,
380386
info->pk.rsa.inLen,
381387
info->pk.rsa.out,
382-
info->pk.rsa.outLen,
388+
(word32*)&info->pk.rsa.outLen,
383389
info->pk.rsa.key,
384390
(void*)ctx);
385391
}
386392
else if (info->pk.rsa.type == RSA_PUBLIC_DECRYPT /* verify */) {
387393
ret = wc_fspsm_RsaVerify(info->pk.rsa.in,
388394
info->pk.rsa.inLen,
389395
info->pk.rsa.out,
390-
info->pk.rsa.outLen,
396+
(word32*)&info->pk.rsa.outLen,
391397
info->pk.rsa.key,
392398
(void*)ctx);
393399
}

wolfcrypt/src/port/Renesas/renesas_fspsm_rsa.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* renesas_fspsm_rsa.c
22
*
3-
* Copyright (C) 2006-2023 wolfSSL Inc.
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
44
*
55
* This file is part of wolfSSL.
66
*
@@ -99,6 +99,33 @@ WOLFSSL_LOCAL int wc_fspsm_MakeRsaKey(RsaKey *key, int size, void* ctx)
9999
key->ctx.wrapped_pri2048_key = info->wrapped_key_rsapri2048;
100100
key->ctx.wrapped_pub2048_key = info->wrapped_key_rsapub2048;
101101
key->ctx.keySz = 2048;
102+
} else if (size == 0) {
103+
if((info->keyflgs_crypt.bits.rsapri2048_installedkey_set != 1) &&
104+
(info->keyflgs_crypt.bits.rsapub2048_installedkey_set != 1) &&
105+
(info->keyflgs_crypt.bits.rsapri1024_installedkey_set != 1) &&
106+
(info->keyflgs_crypt.bits.rsapub1024_installedkey_set != 1)) {
107+
WOLFSSL_MSG("Caller should create user key in advance.");
108+
WOLFSSL_MSG("Caller also need to installedkey to 1.");
109+
return BAD_FUNC_ARG;
110+
}
111+
112+
if (info->keyflgs_crypt.bits.rsapri1024_installedkey_set == 1) {
113+
key->ctx.wrapped_pri1024_key = info->wrapped_key_rsapri1024;
114+
key->ctx.keySz = 1024;
115+
}
116+
if (info->keyflgs_crypt.bits.rsapub1024_installedkey_set == 1) {
117+
key->ctx.wrapped_pub1024_key = info->wrapped_key_rsapub1024;
118+
key->ctx.keySz = 1024;
119+
}
120+
121+
if (info->keyflgs_crypt.bits.rsapri2048_installedkey_set == 1) {
122+
key->ctx.wrapped_pri2048_key = info->wrapped_key_rsapri2048;
123+
key->ctx.keySz = 2048;
124+
}
125+
if (info->keyflgs_crypt.bits.rsapub2048_installedkey_set == 1) {
126+
key->ctx.wrapped_pub2048_key = info->wrapped_key_rsapub2048;
127+
key->ctx.keySz = 2048;
128+
}
102129
} else
103130
return CRYPTOCB_UNAVAILABLE;
104131

@@ -132,8 +159,7 @@ WOLFSSL_LOCAL int wc_fspsm_RsaFunction(const byte* in, word32 inLen, byte* out,
132159
(void) rng;
133160

134161
/* sanity check */
135-
if (in == NULL || out == NULL ||
136-
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
162+
if (in == NULL || out == NULL || key == NULL){
137163
return BAD_FUNC_ARG;
138164
}
139165

@@ -210,8 +236,8 @@ WOLFSSL_LOCAL int wc_fspsm_RsaSign(const byte* in, word32 inLen, byte* out,
210236
int keySize;
211237

212238
/* sanity check */
213-
if (in == NULL || out == NULL || (word32*)outLen <= 0 || info == NULL ||
214-
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
239+
if (in == NULL || out == NULL || *outLen <= 0 || info == NULL ||
240+
key == NULL){
215241
return BAD_FUNC_ARG;
216242
}
217243

@@ -278,8 +304,8 @@ WOLFSSL_LOCAL int wc_fspsm_RsaVerify(const byte* in, word32 inLen, byte* out,
278304
(void) key;
279305

280306
/* sanity check */
281-
if (in == NULL || out == NULL || (word32*)outLen <= 0 || info == NULL ||
282-
((key == NULL) && (key->ctx.keySz != 1024 && key->ctx.keySz != 2048))){
307+
if (in == NULL || out == NULL || *outLen <= 0 || info == NULL ||
308+
key == NULL){
283309
return BAD_FUNC_ARG;
284310
}
285311

@@ -292,7 +318,7 @@ WOLFSSL_LOCAL int wc_fspsm_RsaVerify(const byte* in, word32 inLen, byte* out,
292318
info->keyflgs_crypt.bits.message_type;/* message 0, hash 1 */
293319

294320
signature.pdata = out;
295-
signature.data_length = (word32*)outLen;
321+
signature.data_length = (word32)*outLen;
296322
#if defined(WOLFSSL_RENESAS_RSIP)
297323
message_hash.hash_type = signature.hash_type =
298324
info->hash_type; /* hash type */

wolfcrypt/src/port/Renesas/renesas_fspsm_sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static int FSPSM_HashUpdate(wolfssl_FSPSM_Hash* hash,
271271
return BAD_FUNC_ARG;
272272
}
273273
wc_fspsm_hw_lock();
274-
ret = Update(&hash->handle, data, sz);
274+
ret = Update(&hash->handle, (byte*)data, sz);
275275
wc_fspsm_hw_unlock();
276276
return ret;
277277
#endif

wolfcrypt/src/port/Renesas/renesas_fspsm_util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
188188
{
189189
/* Generate PRNG based on NIST SP800-90A AES CTR-DRBG */
190190
int ret = 0;
191-
word32 buffer[RANDGEN_WORDS];
191+
word32 fspbuf[RANDGEN_WORDS];
192192

193193
while (sz > 0) {
194194
word32 len = sizeof(buffer);
@@ -197,9 +197,9 @@ WOLFSSL_LOCAL int wc_fspsm_GenerateRandBlock(byte* output, word32 sz)
197197
len = sz;
198198
}
199199
/* return 4 words random number*/
200-
ret = R_RANDOM_GEN(buffer);
200+
ret = R_RANDOM_GEN((uint8_t* const)fspbuf);
201201
if(ret == FSP_SUCCESS) {
202-
XMEMCPY(output, &buffer, len);
202+
XMEMCPY(output, &fspbuf, len);
203203
output += len;
204204
sz -= len;
205205
} else {

0 commit comments

Comments
 (0)