Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Renesas/cs+/RH850/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# wolfCrypt Examples on Renesas RH850

This repository contains the Renesas RH850 examples.

# Building wolfCrypt and sample code

Before you begin, make sure you have the necessary tools and libraries installed.
## Tools and Libraries
| Tool/Library| Version| Description||
|:--|:--|:--|:--|
|Board||Renesas RH850/F1KM-S4||
|Device||DR7F701649||
|Toolchain|V2.06.00 [28 Nov 2023]|CC-RH RH850 Family Compiler||
|IDE|V8.11.00 [30 Nov 2023]|CS+ for CC||
|<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)||

### Prepare boot.asm, cstart.asm and iodefine.h
1. Open CS+
2. Menu `File` -> `Create New Project`. Select `R7F01649`. Input `Dummy_Project` as project name. Click `Create` button.
3. Copy `boot.asm`, `cstart.asm` and `iodefine.h` to `wolfssl-examples\Renesas\cs+\RH850\rsapss_sign_verify`

### 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)
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)
2. Unzip the package
3. Copy the folder `Y-ASK-RH850F1KM-S4-V3_sample_V101\source\modules and peripherals` to the folder `<wolfssl-examples>\Renesas\cs+\RH850`
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`

### Build RSA PSS Sign and Verify Sample
1. Open [CS+](#DeviceFile) project file under `<wolfssl-examples>\Renesas\cs+\RH850\rsapss_sign_verify\rh850_rsapss_sign.mtpj`
2. Modify `boot.asm`
2-1. Uncomment `USE_TABLE_REFERENCE_METHOD` so that the sample program is able to use table reference for interrupt
2-2. Change `section "EINTTBL", const` as follows:
```
.section "EIINTTBL", const
.align 512
.offset (0x22*4)
.dw #_INTRLIN30UR0
.offset (0x51*4)
.dw #_INTTAUJ0I1
.offset (0x54*4)
.dw #_INTCOSTM0
;.dw #_Dummy_EI ; INT0
;.dw #_Dummy_EI ; INT1
;.dw #_Dummy_EI ; INT2
;.rept 512 - 0x54
;.dw #_Dummy_EI ; INTn
;.endm
```
2-3. Specify RAM addresses as follows:
```
GLOBAL_RAM_ADDR .set 0xFEEE8000
GLOBAL_RAM_END .set 0xFEEE7FFF
LOCAL_RAM_ADDR .set 0xFEBC0000
LOCAL_RAM_END .set 0xFEBFFFFF
```
3. Modify `cstart.asm`
3-1. Change `STACKSIZE` from `0x200` to `0XA000`

2. Build project, Menu `Build` -> `Build Project`
3. Download the project to target device, `Debug` -> `Download...`

The result can be observed through UART. Please connect to the cable to the board and open terminal with the following properties.

|||
|:-|:-|
|baud rate | 9600|
|data | 8|
|parity | none|
|stop bit | 1|
|flow control | none|

Example output
```
System Initializetion finish.
RSA Sign and Verify Example
Hashing message: This is the string to be signed
Signing hash of message
Hashing message: This is the string to be signed
Verify hash of message
RSA PSS verify success
```
115 changes: 115 additions & 0 deletions Renesas/cs+/RH850/rsapss_sign_verify/example_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* example_main.c
*
* Copyright (C) 2006-2025 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/wolfcrypt/cmac.h>
#include "iodefine.h"
#include "rh_string.h"
#include "r_system.h"
#include "r_intc.h"

void R_LIN_Init(void);
void R_UART_Init(void);
void R_UART_SendString(char string[]);

#define INTC2ICOSTM0 INTC2.ICOSTM0.UINT16

#define MSG_LEN 128

char msg_buf[MSG_LEN + 1];
size_t msg_offset = 0;

int rsapss_sign_verify();

/* 1ms tick timer */
static long tick = 0;
#define NUMINTCOSTM0 0x54
#pragma interrupt INTCOSTM0(enable=true, channel=NUMINTCOSTM0)
void INTCOSTM0(void)
{
tick++;
}

#define YEAR ( \
((__DATE__)[7] - '0') * 1000 + \
((__DATE__)[8] - '0') * 100 + \
((__DATE__)[9] - '0') * 10 + \
((__DATE__)[10] - '0') * 1 \
)

#define MONTH ( \
__DATE__[2] == 'n' ? (__DATE__[1] == 'a' ? 1 : 6) \
: __DATE__[2] == 'b' ? 2 \
: __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 3 : 4) \
: __DATE__[2] == 'y' ? 5 \
: __DATE__[2] == 'l' ? 7 \
: __DATE__[2] == 'g' ? 8 \
: __DATE__[2] == 'p' ? 9 \
: __DATE__[2] == 't' ? 10 \
: __DATE__[2] == 'v' ? 11 \
: 12 \
)

time_t time(time_t *t)
{
(void)t;
return ((YEAR-1970)*365+30*MONTH)*24*60*60 + tick++;
}

void PrintTextln(char* TextArray)
{
R_UART_SendString(TextArray);
R_UART_SendString("\r\n");
}

void main(void);

#if !defined(WOLFSSL_STATIC_MEMORY)
#include <stddef.h>
#define SIZEOF_HEAP 0xB000
int _REL_sysheap[SIZEOF_HEAP >> 2];
size_t _REL_sizeof_sysheap = SIZEOF_HEAP;
#endif

void main(void)
{
byte ret;

R_SYSTEM_ClockInit();
R_SYSTEM_TimerInit();
R_SYSTEM_TimerStart();
R_UART_Init();
R_LIN_Init();
/* Enable Table Interrupt */
R_INTC_SetTableBit((uint16_t*)R_ICOSTM0);
R_INTC_UnmaskInterrupt((uint16_t*)R_ICOSTM0);
/* Enable interrupts */
__EI();

rh_string_init(MSG_LEN + 1, &msg_offset, msg_buf);
printf("System Initialization finish.");
printf("RSA Sign and Verify Example");

ret = rsapss_sign_verify();
if (ret != 0) {
printf("rsapss_sign_verify failed ret=%d.", ret);
}
}
Loading
Loading