element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Renesas RX65 Envision Kit - part 6: Software SHA
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 1 Dec 2019 4:20 PM Date Created
  • Views 586 views
  • Likes 5 likes
  • Comments 0 comments
  • rx65n
  • rt
  • sha
  • renesas
  • e2studio
  • road_test
Related
Recommended

Renesas RX65 Envision Kit - part 6: Software SHA

Jan Cumps
Jan Cumps
1 Dec 2019

I'm evaluating the Renesas RX65N MCU EV Kit.

In this post,  I'm reviewing the SHA options.

image

source: Renesas SHA package documentation

 

SHA Hardware Accelerated vs Software

 

The RX family has models that come with a hardware accelerator for encryption. These devices will offload many of the manipulations of the data encryption and decryption

image

source: e14 road test home page

 

In particular when you're using the device in secure communication (e.g. with AWS) this module is one you should consider.

The Envision board has R5F565NEDDFB model. That one does not have the silicon accelerator.

.image

source: Renesas datasheet, annotated

 

Oddly, the dedicated evaluation kit for secure communication with AWS uses the R5F565NEDDFP that also doesn't sport the encryption blocks..

 

In the case the hardware module isn't available, the functionality is done fully in software. That's perfect for the functionality the kit is targeting.

A typical use of SHA in these type of application is inside a secure bootloader, where you validate firmware's signature when loading a new version.

That's not time-critical and can be done by the CPU itself (see the out-of box example that only accepts firmware from a USB stick if it's signed with a known key).

 

Example Code

 

The Renesas SHA download for RX contains an example. It's built for another IDE but very easy to use in e2 studio.

The example is straightforward: It has the known SHA1 and SHA256 digest values for a string of 20 zeros.

It will create a digest for such an array in code too, then verfy that the value is as exepted by comparing it with the known good outcome.

Several mechanisms are used. Single data buffer calculation  and incremental calculation for segmented buffers.

Check the example for all details. I'm showing a simple buffer SHA1 and a multi-buffer SHA256 below:

 

Known digests for an array of 64 zeroes:

 

const uint8_t sha1_comp[20] = {
 0xc8, 0xd7, 0xd0, 0xef, 0x0e, 0xed, 0xfa, 0x82, 0xd2, 0xea, 0x1a, 0xa5, 0x92, 0x84, 0x5b, 0x9a, 0x6d, 0x4b, 0x02, 0xb7};

const uint8_t sha256_comp[32] = {
 0xf5, 0xa5, 0xfd, 0x42, 0xd1, 0x6a, 0x20, 0x30, 0x27, 0x98, 0xef, 0x6e, 0xd3, 0x09, 0x97, 0x9b, 0x43, 0x00, 0x3d, 0x23, 0x20, 0xd9, 0xf0, 0xe8, 0xea, 0x98, 0x31, 0xa9, 0x27, 0x59, 0xfb, 0x4b};

 

Snippet of a single-shot and incremental test, all digesting the 64 character array then comparing the resulting digest:

 

flag = R_SHA_INIT | R_SHA_FINISH;
length = 64;
if (R_Sha1_HashDigest(message_sha, hdat_sha1, length, flag, &work_sha1) != R_PROCESS_COMPLETE) {
  fatal_error_sha(1);
}
if( memcmp( &sha1_comp[0], hdat_sha1, 20) != 0)
{
  fatal_error_sha(2);
}

// ...

flag = R_SHA_INIT;
length = 20;
if (R_Sha256_HashDigest( message_sha, hdat_sha256, length, flag, &work_sha256) != R_PROCESS_COMPLETE) {
  fatal_error_sha(15);
}
flag = R_SHA_ADD;
length = 20;
if (R_Sha256_HashDigest( &message_sha[20], hdat_sha256, length, flag, &work_sha256) != R_PROCESS_COMPLETE) {
  fatal_error_sha(16);
}
flag = R_SHA_FINISH;
length = 24;
if (R_Sha256_HashDigest( &message_sha[40], hdat_sha256, length, flag, &work_sha256) != R_PROCESS_COMPLETE) {
  fatal_error_sha(17);
}
if( memcmp( &sha256_comp[0], hdat_sha256, 32) != 0) {
  fatal_error_sha(18);
}
}

 

Creating the Example Project in e2 studio

 

The example in the SHA packet is for a different IDE. Let's create a e2 studio one for it.

To create the project, se the exact same steps as in blog #1. You have to choose the CC-RX toolchain. The Renesas SHA lib is not compatible with GCC's linker.

 

Once it's created, do these modifications in the Properties:

Add an environment variable that points to the place where you installed Renesas' SHA lib:

image

 

Then, add the SHA include files and set RX definition (not critical, but the build will use the RX own includes where appliccable instead of pulling in the dedicated ones for this lib).

Include dir: "${SHA_INSTALL_DIR}/lib"

Macro definition: RX

 

image

 

Include the precompiled lib in the linker settings:

image

library files: "${SHA_INSTALL_DIR}/lib/sha_rx600_little.lib"

 

Then, copy/paste the example source into the project.

You can do that via the File -> Import menu, or just copy/pasting the file ${SHA_INSTALL_DIR}/sample/src/sha_sample.c. with your OS's file explorer.

Take care that you copy the file, when asked by Eclipse. Don't use the advanced link functionality if you plan to play with it and change it for experiments.

 

Then, in the main file generated by you (by following the steps of blog #1, replace the whole content by this:

 

/***********************************************************************
*
*  FILE        : RX65_ssh.c
*  DATE        : 2019-12-01
*  DESCRIPTION : Main Program
*
*  NOTE:THIS IS A TYPICAL EXAMPLE.
*
***********************************************************************/
#include "r_smc_entry.h"

void main(void);
int sha_main(void);

void main(void){
  int i;
  i = sha_main();
}

 

Debug and enjoy. You'll see the library creates the digests, then compares them with the expected value.

If your code ever falls into a fatal_errorxxxx() section, you know something is wrong. This should not happen.

 

For your convenience, I've attached a e2 studio project.

Before you build it, navigate to the project properties, then change the SHA_INSTALL_DIR build variable to point to the location where you installed Renesas' SHA package on your computer.

image

 

Related blog
part 1: Create an Empty Project
part 2a: Blinky with GCC Toolchain
part 2b: Blinky with Timer and Interrupt
part 3: Port an example from Renesas toolchain to GCC
part 4a: Low Power - Sleep
part 4b: Low Power - Software Standby
4c todo: power mode 3
4d todo: power mode 4
part 5: DAC
part 6: Software SHA
part 7: Blinky with FreeRTOS
part 8: DMA
part 9: UART
part 10: Reserve LCD Frame Buffer in Expansion RAM with GCC
part 11: port emWIN to GCC and run an LCD Widget
Renesas RX65N MCU EV Kit - Review
Andrew Johnson's blog series
Renesas Envision Kit RPBRX65N Roadtest
Attachments:
RX65_ssh.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube