NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
main.c File Reference

Example program showing how to use the CFU's custom instructions (XTEA example). More...

#include <neorv32.h>

Macros

User configuration
#define BAUD_RATE   19200
 
#define XTEA_ROUNDS   20
 
#define DATA_NUM   64
 
Define macros for easy CFU instruction wrapping
#define xtea_hw_init(sum)
 
#define xtea_hw_enc_v0_step(v0, v1)
 
#define xtea_hw_enc_v1_step(v0, v1)
 
#define xtea_hw_dec_v0_step(v0, v1)
 
#define xtea_hw_dec_v1_step(v0, v1)
 
#define xtea_hw_illegal_inst()
 

Functions

void xtea_sw_encipher (uint32_t num_cycles, uint32_t *v, const uint32_t k[4])
 
void xtea_sw_decipher (unsigned int num_cycles, uint32_t *v, const uint32_t k[4])
 
int main ()
 

Variables

Global variables
const uint32_t xtea_delta = 0x9e3779b9
 
const uint32_t key [4] = {0x207230ba, 0x1ffba710, 0xc45271ef, 0xdd01768a}
 
uint32_t input_data [DATA_NUM]
 
uint32_t cypher_data_sw [DATA_NUM]
 
uint32_t cypher_data_hw [DATA_NUM]
 
uint32_t plain_data_sw [DATA_NUM]
 
uint32_t plain_data_hw [DATA_NUM]
 
uint32_t time_enc_sw
 
uint32_t time_enc_hw
 
uint32_t time_dec_sw
 
uint32_t time_dec_hw
 

Detailed Description

Example program showing how to use the CFU's custom instructions (XTEA example).

Author
Stephan Nolting
Note
Take a look at the highly-commented "hardware-counterpart" of this CFU example in 'rtl/core/neorv32_cpu_cp_cfu.vhd'.

Macro Definition Documentation

◆ BAUD_RATE

#define BAUD_RATE   19200

UART BAUD rate

◆ DATA_NUM

#define DATA_NUM   64

Input data size (in number of 32-bit words), has to be even

◆ xtea_hw_dec_v0_step

#define xtea_hw_dec_v0_step ( v0,
v1 )
Value:
neorv32_cfu_r3_instr(0b0000000, 0b010, v0, v1)
#define neorv32_cfu_r3_instr(funct7, funct3, rs1, rs2)
Definition neorv32_cpu_cfu.h:34

◆ xtea_hw_dec_v1_step

#define xtea_hw_dec_v1_step ( v0,
v1 )
Value:
neorv32_cfu_r3_instr(0b0000000, 0b011, v0, v1)

◆ xtea_hw_enc_v0_step

#define xtea_hw_enc_v0_step ( v0,
v1 )
Value:
neorv32_cfu_r3_instr(0b0000000, 0b000, v0, v1)

◆ xtea_hw_enc_v1_step

#define xtea_hw_enc_v1_step ( v0,
v1 )
Value:
neorv32_cfu_r3_instr(0b0000000, 0b001, v0, v1)

◆ xtea_hw_illegal_inst

#define xtea_hw_illegal_inst ( )
Value:
neorv32_cfu_r3_instr(0b0000000, 0b111, 0, 0 )

◆ xtea_hw_init

#define xtea_hw_init ( sum)
Value:
neorv32_cfu_r3_instr(0b0000000, 0b100, sum, 0 )

◆ XTEA_ROUNDS

#define XTEA_ROUNDS   20

Number XTEA rounds

Function Documentation

◆ main()

int main ( void )

Main function: run pure-SW XTEA and compare with HW-accelerated XTEA

Note
This program requires UART0 and the Zxcfu and Zicntr ISA extension.
Returns
0 if execution was successful

◆ xtea_sw_decipher()

void xtea_sw_decipher ( unsigned int num_cycles,
uint32_t * v,
const uint32_t k[4] )

XTEA decryption - software reference Source: https://de.wikipedia.org/wiki/Extended_Tiny_Encryption_Algorithm

Parameters
[in]num_cyclesNumber of encryption cycles.
[in,out]vDecryption data/result array (2x32-bit).
[in]kDecryption key array (4x32-bit).

◆ xtea_sw_encipher()

void xtea_sw_encipher ( uint32_t num_cycles,
uint32_t * v,
const uint32_t k[4] )

XTEA encryption - software reference Source: https://de.wikipedia.org/wiki/Extended_Tiny_Encryption_Algorithm

Parameters
[in]num_cyclesNumber of encryption cycles.
[in,out]vEncryption data/result array (2x32-bit).
[in]kEncryption key array (4x32-bit).

Variable Documentation

◆ cypher_data_hw

uint32_t cypher_data_hw[DATA_NUM]

XTEA delta (round-key update); do not change

◆ cypher_data_sw

uint32_t cypher_data_sw[DATA_NUM]

Encryption result buffer

◆ input_data

uint32_t input_data[DATA_NUM]

Encryption input data

◆ key

const uint32_t key[4] = {0x207230ba, 0x1ffba710, 0xc45271ef, 0xdd01768a}

Secret encryption/decryption key (128-bit)

◆ plain_data_hw

uint32_t plain_data_hw[DATA_NUM]

XTEA delta (round-key update); do not change

◆ plain_data_sw

uint32_t plain_data_sw[DATA_NUM]

Decryption result buffer

◆ time_dec_hw

uint32_t time_dec_hw

XTEA delta (round-key update); do not change

◆ time_dec_sw

uint32_t time_dec_sw

XTEA delta (round-key update); do not change

◆ time_enc_hw

uint32_t time_enc_hw

XTEA delta (round-key update); do not change

◆ time_enc_sw

uint32_t time_enc_sw

Timing data

◆ xtea_delta

const uint32_t xtea_delta = 0x9e3779b9

XTEA delta (round-key update); do not change