Skip to content

Commit 3658b76

Browse files
authored
Merge pull request #509 from miyazakh/rh850_sign_example
Add wolfCrypt sample on RH850 using CS+
2 parents 72a3658 + 932dbf7 commit 3658b76

File tree

9 files changed

+3813
-0
lines changed

9 files changed

+3813
-0
lines changed

Renesas/cs+/RH850/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# wolfCrypt Examples on Renesas RH850
2+
3+
This repository contains the Renesas RH850 examples.
4+
5+
# Building wolfCrypt and sample code
6+
7+
Before you begin, make sure you have the necessary tools and libraries installed.
8+
## Tools and Libraries
9+
| Tool/Library| Version| Description||
10+
|:--|:--|:--|:--|
11+
|Board||Renesas RH850/F1KM-S4||
12+
|Device||DR7F701649||
13+
|Toolchain|V2.06.00 [28 Nov 2023]|CC-RH RH850 Family Compiler||
14+
|IDE|V8.11.00 [30 Nov 2023]|CS+ for CC||
15+
|<a id="sw_package"></a> Software Package||[Y-ASK-RH850F1KM-S4-V3 Software Package](https://www.renesas.com/en/document/sws/y-ask-rh850f1km-s4-v3-software-package?r=1261056)||
16+
17+
### Prepare boot.asm, cstart.asm and iodefine.h
18+
1. Open CS+
19+
2. Menu `File` -> `Create New Project`. Select `R7F01649`. Input `Dummy_Project` as project name. Click `Create` button.
20+
3. Copy `boot.asm`, `cstart.asm` and `iodefine.h` to `wolfssl-examples\Renesas\cs+\RH850\rsapss_sign_verify`
21+
22+
### Prepare modules and peripherals by [Y-ASK-RH850F1KM-S4-V3 Software Package](https://www.renesas.com/en/document/sws/y-ask-rh850f1km-s4-v3-software-package?r=1261056)
23+
1. Download the package from [https://www.renesas.com/en/document/sws/y-ask-rh850f1km-s4-v3-software-package?r=1261056](https://www.renesas.com/en/document/sws/y-ask-rh850f1km-s4-v3-software-package?r=1261056)
24+
2. Unzip the package
25+
3. Copy the folder `Y-ASK-RH850F1KM-S4-V3_sample_V101\source\modules and peripherals` to the folder `<wolfssl-examples>\Renesas\cs+\RH850`
26+
4. Copy the folder `Y-ASK-RH850F1KM-S4-V3_sample_V101\device\r_typedefs.h, r_device.h, intVecNumF1KM.h and dr7f701649.dvf.h` to the folder `<wolfssl-examples>\Renesas\cs+\RH850`
27+
28+
### Build RSA PSS Sign and Verify Sample
29+
1. Open [CS+](#DeviceFile) project file under `<wolfssl-examples>\Renesas\cs+\RH850\rsapss_sign_verify\rh850_rsapss_sign.mtpj`
30+
2. Modify `boot.asm`
31+
2-1. Uncomment `USE_TABLE_REFERENCE_METHOD` so that the sample program is able to use table reference for interrupt
32+
2-2. Change `section "EINTTBL", const` as follows:
33+
```
34+
.section "EIINTTBL", const
35+
.align 512
36+
.offset (0x22*4)
37+
.dw #_INTRLIN30UR0
38+
.offset (0x51*4)
39+
.dw #_INTTAUJ0I1
40+
.offset (0x54*4)
41+
.dw #_INTCOSTM0
42+
;.dw #_Dummy_EI ; INT0
43+
;.dw #_Dummy_EI ; INT1
44+
;.dw #_Dummy_EI ; INT2
45+
;.rept 512 - 0x54
46+
;.dw #_Dummy_EI ; INTn
47+
;.endm
48+
```
49+
2-3. Specify RAM addresses as follows:
50+
```
51+
GLOBAL_RAM_ADDR .set 0xFEEE8000
52+
GLOBAL_RAM_END .set 0xFEEE7FFF
53+
LOCAL_RAM_ADDR .set 0xFEBC0000
54+
LOCAL_RAM_END .set 0xFEBFFFFF
55+
```
56+
3. Modify `cstart.asm`
57+
3-1. Change `STACKSIZE` from `0x200` to `0XA000`
58+
59+
2. Build project, Menu `Build` -> `Build Project`
60+
3. Download the project to target device, `Debug` -> `Download...`
61+
62+
The result can be observed through UART. Please connect to the cable to the board and open terminal with the following properties.
63+
64+
|||
65+
|:-|:-|
66+
|baud rate | 9600|
67+
|data | 8|
68+
|parity | none|
69+
|stop bit | 1|
70+
|flow control | none|
71+
72+
Example output
73+
```
74+
System Initializetion finish.
75+
RSA Sign and Verify Example
76+
Hashing message: This is the string to be signed
77+
Signing hash of message
78+
Hashing message: This is the string to be signed
79+
Verify hash of message
80+
RSA PSS verify success
81+
```
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* example_main.c
2+
*
3+
* Copyright (C) 2006-2025 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
#include <wolfssl/wolfcrypt/types.h>
22+
#include <wolfssl/wolfcrypt/aes.h>
23+
#include <wolfssl/wolfcrypt/cmac.h>
24+
#include "iodefine.h"
25+
#include "rh_string.h"
26+
#include "r_system.h"
27+
#include "r_intc.h"
28+
29+
void R_LIN_Init(void);
30+
void R_UART_Init(void);
31+
void R_UART_SendString(char string[]);
32+
33+
#define INTC2ICOSTM0 INTC2.ICOSTM0.UINT16
34+
35+
#define MSG_LEN 128
36+
37+
char msg_buf[MSG_LEN + 1];
38+
size_t msg_offset = 0;
39+
40+
int rsapss_sign_verify();
41+
42+
/* 1ms tick timer */
43+
static long tick = 0;
44+
#define NUMINTCOSTM0 0x54
45+
#pragma interrupt INTCOSTM0(enable=true, channel=NUMINTCOSTM0)
46+
void INTCOSTM0(void)
47+
{
48+
tick++;
49+
}
50+
51+
#define YEAR ( \
52+
((__DATE__)[7] - '0') * 1000 + \
53+
((__DATE__)[8] - '0') * 100 + \
54+
((__DATE__)[9] - '0') * 10 + \
55+
((__DATE__)[10] - '0') * 1 \
56+
)
57+
58+
#define MONTH ( \
59+
__DATE__[2] == 'n' ? (__DATE__[1] == 'a' ? 1 : 6) \
60+
: __DATE__[2] == 'b' ? 2 \
61+
: __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 3 : 4) \
62+
: __DATE__[2] == 'y' ? 5 \
63+
: __DATE__[2] == 'l' ? 7 \
64+
: __DATE__[2] == 'g' ? 8 \
65+
: __DATE__[2] == 'p' ? 9 \
66+
: __DATE__[2] == 't' ? 10 \
67+
: __DATE__[2] == 'v' ? 11 \
68+
: 12 \
69+
)
70+
71+
time_t time(time_t *t)
72+
{
73+
(void)t;
74+
return ((YEAR-1970)*365+30*MONTH)*24*60*60 + tick++;
75+
}
76+
77+
void PrintTextln(char* TextArray)
78+
{
79+
R_UART_SendString(TextArray);
80+
R_UART_SendString("\r\n");
81+
}
82+
83+
void main(void);
84+
85+
#if !defined(WOLFSSL_STATIC_MEMORY)
86+
#include <stddef.h>
87+
#define SIZEOF_HEAP 0xB000
88+
int _REL_sysheap[SIZEOF_HEAP >> 2];
89+
size_t _REL_sizeof_sysheap = SIZEOF_HEAP;
90+
#endif
91+
92+
void main(void)
93+
{
94+
byte ret;
95+
96+
R_SYSTEM_ClockInit();
97+
R_SYSTEM_TimerInit();
98+
R_SYSTEM_TimerStart();
99+
R_UART_Init();
100+
R_LIN_Init();
101+
/* Enable Table Interrupt */
102+
R_INTC_SetTableBit((uint16_t*)R_ICOSTM0);
103+
R_INTC_UnmaskInterrupt((uint16_t*)R_ICOSTM0);
104+
/* Enable interrupts */
105+
__EI();
106+
107+
rh_string_init(MSG_LEN + 1, &msg_offset, msg_buf);
108+
printf("System Initialization finish.");
109+
printf("RSA Sign and Verify Example");
110+
111+
ret = rsapss_sign_verify();
112+
if (ret != 0) {
113+
printf("rsapss_sign_verify failed ret=%d.", ret);
114+
}
115+
}

0 commit comments

Comments
 (0)