NEORV32 - Software Framework Documentation
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_CYCLES   20
 
#define DATA_NUM   64
 
Define macros for easy custom instruction wrapping
#define xtea_hw_init(sum)   neorv32_cfu_r3_instr(0b0000000, 0b100, sum, 0)
 
#define xtea_hw_enc_v0_step(v0, v1)   neorv32_cfu_r3_instr(0b0000000, 0b000, v0, v1)
 
#define xtea_hw_enc_v1_step(v0, v1)   neorv32_cfu_r3_instr(0b0000000, 0b001, v0, v1)
 
#define xtea_hw_dec_v0_step(v0, v1)   neorv32_cfu_r3_instr(0b0000000, 0b010, v0, v1)
 
#define xtea_hw_dec_v1_step(v0, v1)   neorv32_cfu_r3_instr(0b0000000, 0b011, v0, v1)
 

Functions

uint32_t xorshift32 (void)
 
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_CYCLES

#define XTEA_CYCLES   20

Number XTEA cycles

Function Documentation

◆ main()

int main ( void )

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

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

◆ xorshift32()

uint32_t xorshift32 ( void )

Pseudo-random number generator (to generate deterministic test data).

Returns
Random data (32-bit).

◆ 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)

◆ cypher_data_sw

uint32_t cypher_data_sw[DATA_NUM]

Encryption results

◆ input_data

uint32_t input_data[DATA_NUM]

Encryption input data

◆ key

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

Encryption/decryption key (128-bit)

◆ plain_data_hw

uint32_t plain_data_hw[DATA_NUM]

XTEA delta (round-key update)

◆ plain_data_sw

uint32_t plain_data_sw[DATA_NUM]

Decryption results

◆ time_dec_hw

uint32_t time_dec_hw

XTEA delta (round-key update)

◆ time_dec_sw

uint32_t time_dec_sw

XTEA delta (round-key update)

◆ time_enc_hw

uint32_t time_enc_hw

XTEA delta (round-key update)

◆ time_enc_sw

uint32_t time_enc_sw

Timing data

◆ xtea_delta

const uint32_t xtea_delta = 0x9e3779b9

XTEA delta (round-key update)