Skip to content
Snippets Groups Projects
main.c 2.38 KiB
Newer Older
Yuxiao Mao's avatar
Yuxiao Mao committed
#include <stdint.h>
#include "orca_malloc.h"
#include "myorca_uart.h"
#define __OPTION_ATTACK_ENABLE__ 1
#define __OPTION_VICTIM_ENABLE__ 1

// Attack and Victim code
#if __OPTION_ATTACK_ENABLE__ == 1
#include "attack.h"
#endif
#if __OPTION_VICTIM_ENABLE__ == 1
#include "victim.h"
#endif

// ----------------------------------------------------------------------------
Yuxiao Mao's avatar
Yuxiao Mao committed
// Function declarations
// ----------------------------------------------------------------------------
Yuxiao Mao's avatar
Yuxiao Mao committed
int handle_exception();
void victim_1(int* val_addr);
// ----------------------------------------------------------------------------
// Global variable
// ----------------------------------------------------------------------------
#define HEAP_SIZE_BYTE 1024
char myorca_heap[HEAP_SIZE_BYTE];
int victim_data_address[16];

// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
  // Prepare heap
  orca_init_malloc(myorca_heap, HEAP_SIZE_BYTE, 4);
#if __OPTION_ATTACK_ENABLE__ == 1
Yuxiao Mao's avatar
Yuxiao Mao committed
  uint16_t res[1];
  attack_prepare(victim_data_address);
  uart_printf("\r\nATTACK_ENABLE");
#if __OPTION_VICTIM_ENABLE__ == 1
  test_aes_ctx();
#endif
  unsigned int uart_read_fifo_count = 0;
Yuxiao Mao's avatar
Yuxiao Mao committed
    // UART read -> Interrupt?
    uart_read_fifo_count = uart_get_read_fifo_count();
    if (uart_read_fifo_count > 0) {
      char read_value = uart_read_char();
      uart_printf("\r\nReceived value from Uart: (");
      uart_printc(read_value);
      uart_printf(").");

#if __OPTION_ATTACK_ENABLE__ == 1
      victim_1(victim_data_address);
      uart_printf("--");
    attack_1(res);
    if (res[0] < 3) {
      uart_printc('A');
    }

// ----------------------------------------------------------------------------
// Exception handling
// ----------------------------------------------------------------------------
Yuxiao Mao's avatar
Yuxiao Mao committed
int handle_exception() {
  uart_printf("Exception\r\n");
  while (1) {
  }
Yuxiao Mao's avatar
Yuxiao Mao committed
  return 0;
}

// ----------------------------------------------------------------------------
// Victim code
// victim_1 provide simple memory access
// ----------------------------------------------------------------------------
void victim_1(int* val_addr) {
  uart_printc('V');
  uart_printi(val_addr[0]);
  val_addr[0] = val_addr[0] + 1;