Skip to content

Commit f18633a

Browse files
authored
Merge pull request #7474 from miyazakh/renesas_rz_rsip_update
Improve Renesas RZ support
2 parents 0d86137 + d4b265e commit f18633a

6 files changed

Lines changed: 71 additions & 34 deletions

File tree

IDE/Renesas/e2studio/RZN2L/README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ They also include benchmark and cryptography tests for the wolfCrypt library.
1010
The example project contains both the wolfSSL and wolfCrypt libraries.
1111
It is built as a `Renesas RZ/N C/C++ FSP Project` and contains the Renesas RZ
1212
configuration. The wolfssl project uses `Renesas Secure IP on RZ`
13-
as hardware acceleration for cyptography.
13+
as hardware acceleration for cryptography.
1414

1515
**Limitation**
1616

@@ -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 driver, a device 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

@@ -75,7 +77,7 @@ The example project summary is listed below and is relevant for every project.
7577
|Thread Symbol|rzn2l_tst_thread|
7678
|Thread Name|rzn2l_tst_thread|
7779
|Thread Stack size|increase depending on your environment<br> e.g. 0xA000|
78-
|Thread MemoryAllocation|Dyamic|
80+
|Thread MemoryAllocation|Dynamic|
7981
|Common General Use Mutexes|Enabled|
8082
|Common General Enable Backward Compatibility|Enabled|
8183
|Common Memory Allocation Support Dynamic Allocation|Enabled|
@@ -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
@@ -113,7 +117,7 @@ The example project summary is listed below and is relevant for every project.
113117

114118
2). Select J-Link ARM and R9A07G084M04
115119

116-
3). Break at Entory point. Change `cpsr` register value from 0xXXXXX1yy to 0xXXXXX1da
120+
3). Break at Entry point. Change `cpsr` register value from 0xXXXXX1yy to 0xXXXXX1da
117121

118122
## Run TLS 1.3 Client
119123
1.) Enable `WOLFSSL_TLS13` macro in `user_settings.h`
@@ -472,7 +476,7 @@ Test complete
472476
```
473477

474478
**Note**
475-
`SHA1/224/256/384/512` and `Random generation` of RSIP driver are enabled at the sampele output above while running wolfCrypt test.
479+
`SHA1/224/256/384/512` and `Random generation` of RSIP driver are enabled at the sample output above while running wolfCrypt test.
476480

477481
## Run Benchmark
478482

@@ -532,7 +536,8 @@ Benchmark complete
532536
End wolfCrypt Benchmark
533537
```
534538
**Note**
535-
`SHA1/224/256/384/512` and `Random generation` of RSIP driver are enabled at the sampele output above.
539+
`SHA1/224/256/384/512` and `Random generation` of RSIP driver are enabled at the sample output above.
540+
536541
## Support
537542

538543
For support inquiries and questions, please email support@wolfssl.com. Feel free to reach out to info@wolfssl.jp as well.

wolfcrypt/src/port/Renesas/renesas_common.c

Lines changed: 9 additions & 3 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+
info->pk.rsa.outLen,
374380
info->pk.rsa.type,
375381
info->pk.rsa.key,
376382
info->pk.rsa.rng);

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 {

wolfcrypt/src/rsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,7 @@ static int RsaPublicEncryptEx(const byte* in, word32 inLen, byte* out,
33183318
if (key->devId != INVALID_DEVID) {
33193319
/* SCE supports 1024 and 2048 bits */
33203320
ret = wc_CryptoCb_Rsa(in, inLen, out,
3321-
outLen, rsa_type, key, rng);
3321+
&outLen, rsa_type, key, rng);
33223322
if (ret != CRYPTOCB_UNAVAILABLE)
33233323
return ret;
33243324
/* fall-through when unavailable */
@@ -3475,7 +3475,7 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
34753475
#ifdef WOLF_CRYPTO_CB
34763476
if (key->devId != INVALID_DEVID) {
34773477
ret = wc_CryptoCb_Rsa(in, inLen, out,
3478-
outLen, rsa_type, key, rng);
3478+
&outLen, rsa_type, key, rng);
34793479
if (ret != CRYPTOCB_UNAVAILABLE)
34803480
return ret;
34813481
/* fall-through when unavailable */

0 commit comments

Comments
 (0)