Skip to content
21 changes: 21 additions & 0 deletions projects/briey/ascon_test/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PROJ_NAME=ascon_test
DEBUG=no
NO_OPT=yes
BENCH=no
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=no

SRCS = $(wildcard src/*.c) \
$(wildcard src/*.cpp) \
$(wildcard src/*.S) \
../libs/ascon.c \
../libs/stdlib.c

LDSCRIPT = ../libs/linker.ld
INC += -I../../../libs/
INC += -I../libs/

include ../../../resources/gcc.mk
include ../../../resources/subproject.mk
1 change: 1 addition & 0 deletions projects/briey/ascon_test/src/crt.S
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../../resources/crt.S"
90 changes: 90 additions & 0 deletions projects/briey/ascon_test/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <briey.h>

#include <ascon.h>

#define UART_DATA_LEN (8U)
#define UART_BAUD (115200U)

void main() {
struct ascon_param param;
ascon_data_block_t original;
ascon_data_block_t encrypted;
ascon_data_block_t decrypted;
ascon_tag_t tag;
Uart_Config uartConfig;
uartConfig.dataLength = UART_DATA_LEN;
uartConfig.parity = NONE;
uartConfig.stop = ONE;
uartConfig.clockDivider = (CORE_HZ / UART_DATA_LEN / UART_BAUD) - 1;
uart_applyConfig(UART,&uartConfig);

printf("Starting Ascon test\n");
printf("Ascon connectivity check returned %d\n", ascon_is_sane());

original[0] = 0x1234;
original[1] = 0x5678;
original[2] = 0x9ABC;
original[3] = 0xDEF0;

param.key_in[0] = 0x117;
param.key_in[1] = 0x42;
param.key_in[2] = 0x4529;
param.key_in[3] = 0xCAFE;

param.nonce_in[0] = 0x1;
param.nonce_in[1] = 0x0;
param.nonce_in[2] = 0x0;
param.nonce_in[3] = 0x0;
param.associated_size = 0;

param.data_in = &original;
param.data_out = &encrypted;
param.data_size = 1;

printf("Starting encryption\n");

ascon_encrypt(&param);

for (size_t i = 0; i < WIDE_LEN; i++) {
tag[i] = param.tag_out[i];
}
param.data_in = &encrypted;
param.data_out = &decrypted;

printf("Starting decryption\n");
ascon_decrypt(&param);

int passed = 1;
for (size_t i = 0; i < WIDE_LEN; i++) {
printf("Expected: %lx; Actual: %lx\n", original[i], decrypted[i]);

if (original[i] != decrypted[i]) {
passed = 0;
}
}

for (size_t i = 0; i < WIDE_LEN; i++) {
printf("Expected tag: %lx; Actual tag: %lx\n", tag[i], param.tag_out[i]);

if (tag[i] != param.tag_out[i]) {
passed = 0;
}
}



if (passed) {
printf("Ascon test PASSED\n");
} else {
printf("Ascon test FAILED\n");
}

while(1);
}

void irqCallback(){
// Do nothing
}
6 changes: 4 additions & 2 deletions projects/briey/bubblesort/makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
PROJ_NAME=bubblesort
DEBUG=no
NO_OPT=yes
BENCH=no
BENCH=yes
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=yes
TREE=no

CFLAGS += -g

SRCS = $(wildcard src/*.c) \
$(wildcard src/*.cpp) \
Expand Down
12 changes: 6 additions & 6 deletions projects/briey/bubblesort/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void bubbleSort(uint32_t array[], uint32_t size) {
temp = array[j - 1];
array[j - 1] = array[j];
// Flush the cache after every write to throughly test the SDRAM
flushDataCache();
// flushDataCache();
array[j] = temp;
flushDataCache();
// flushDataCache();
}
iter++;
}
Expand Down Expand Up @@ -80,10 +80,10 @@ void main() {
for (;;) {
halt = 1;
// lb/sb are currently broken, let's copy by word for now
//memcpy(sortArray, inputArray, sizeof(uint32_t) * SORT_SIZE);
for (size_t i = 0; i < SORT_SIZE; i++) {
sortArray[i] = inputArray[i];
}
memcpy(sortArray, inputArray, sizeof(uint32_t) * SORT_SIZE);
// for (size_t i = 0; i < SORT_SIZE; i++) {
// sortArray[i] = inputArray[i];
// }

printf("Bubblesort BEGIN\r\n\r\n");

Expand Down
4 changes: 2 additions & 2 deletions projects/briey/dhrystone/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ PROJ_NAME=dhrystone
DEBUG=no
BENCH=no
MULDIV=yes
TREE=no



CFLAGS += -fno-inline -fno-common
CFLAGS += -fno-inline -fno-common -g
LDFLAGS += -lc

CFLAGS += -DPREALLOCATE=1 -DHOST_DEBUG=0 -DMSC_CLOCK
Expand Down
7 changes: 7 additions & 0 deletions projects/briey/lb/lb.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See LICENSE for license details.

#include "riscv_test.h"
#undef RVTEST_RV64U
#define RVTEST_RV64U RVTEST_RV32U

#include "../rv64ui/lb.S"
16 changes: 16 additions & 0 deletions projects/briey/lb/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROJ_NAME=riscv_tests_lb
DEBUG=no
NO_OPT=yes
BENCH=no
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=no

SRCS = $(wildcard ./*.S)

LDSCRIPT = ../libs/linker.ld
INC += -I../libs/riscv_tests/

include ../../../resources/gcc.mk
include ../../../resources/subproject.mk
7 changes: 7 additions & 0 deletions projects/briey/lbu/lbu.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See LICENSE for license details.

#include "riscv_test.h"
#undef RVTEST_RV64U
#define RVTEST_RV64U RVTEST_RV32U

#include "../rv64ui/lbu.S"
16 changes: 16 additions & 0 deletions projects/briey/lbu/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROJ_NAME=riscv_tests_lbu
DEBUG=no
NO_OPT=yes
BENCH=no
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=no

SRCS = $(wildcard ./*.S)

LDSCRIPT = ../libs/linker.ld
INC += -I../libs/riscv_tests/

include ../../../resources/gcc.mk
include ../../../resources/subproject.mk
7 changes: 7 additions & 0 deletions projects/briey/lh/lh.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See LICENSE for license details.

#include "riscv_test.h"
#undef RVTEST_RV64U
#define RVTEST_RV64U RVTEST_RV32U

#include "../rv64ui/lh.S"
16 changes: 16 additions & 0 deletions projects/briey/lh/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROJ_NAME=riscv_tests_lh
DEBUG=no
NO_OPT=yes
BENCH=no
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=no

SRCS = $(wildcard ./*.S)

LDSCRIPT = ../libs/linker.ld
INC += -I../libs/riscv_tests/

include ../../../resources/gcc.mk
include ../../../resources/subproject.mk
7 changes: 7 additions & 0 deletions projects/briey/lhu/lhu.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See LICENSE for license details.

#include "riscv_test.h"
#undef RVTEST_RV64U
#define RVTEST_RV64U RVTEST_RV32U

#include "../rv64ui/lhu.S"
16 changes: 16 additions & 0 deletions projects/briey/lhu/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROJ_NAME=riscv_tests_lhu
DEBUG=no
NO_OPT=yes
BENCH=no
MULDIV=no
# "yes" enables tree mem test and tree zeroing
# run "make tree=no" to disable this
TREE=no

SRCS = $(wildcard ./*.S)

LDSCRIPT = ../libs/linker.ld
INC += -I../libs/riscv_tests/

include ../../../resources/gcc.mk
include ../../../resources/subproject.mk
8 changes: 5 additions & 3 deletions projects/briey/libs/ascon.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static volatile struct {
uint32_t nonce[WIDE_LEN];
uint32_t data[WIDE_LEN];
uint32_t tag[WIDE_LEN];
} *const ASCON128_INTERFACE = (volatile void *) 0x40000000;
} *const ASCON128_INTERFACE = (volatile void *) 0xE0000000;

#define ASCON_CTRL_INIT (1U << 0)
#define ASCON_CTRL_ASSOCIATE (1U << 1)
Expand Down Expand Up @@ -42,7 +42,9 @@ static void ascon_operation(struct ascon_param *param, uint32_t op, uint32_t op_
{
size_t i;

ascon_memcpy(ASCON128_INTERFACE->key, param->key, sizeof(ASCON128_INTERFACE->key));
ascon_memcpy(ASCON128_INTERFACE->key, param->key_in, sizeof(ASCON128_INTERFACE->key));
ascon_memcpy(ASCON128_INTERFACE->nonce, param->nonce_in, sizeof(ASCON128_INTERFACE->nonce));

ASCON128_INTERFACE->control = ASCON_CTRL_INIT;

for (i = 0; i < param->associated_size; ++i) {
Expand All @@ -58,7 +60,7 @@ static void ascon_operation(struct ascon_param *param, uint32_t op, uint32_t op_
ASCON128_INTERFACE->control = (i == param->data_size - 1) ? op_final : op;
}
ascon_memcpy(param->data_out[i-1], ASCON128_INTERFACE->data, sizeof(param->data_in[i-1]));
ascon_memcpy(param->nonce, ASCON128_INTERFACE->nonce, sizeof(param->nonce));
ascon_memcpy(param->tag_out, ASCON128_INTERFACE->tag, sizeof(ASCON128_INTERFACE->tag));
}

void ascon_encrypt(struct ascon_param *param)
Expand Down
13 changes: 8 additions & 5 deletions projects/briey/libs/ascon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

typedef uint32_t ascon_key_t[WIDE_LEN];
typedef uint32_t ascon_nonce_t[WIDE_LEN];
typedef uint32_t ascon_tag_t[WIDE_LEN];
typedef uint32_t ascon_data_block_t[WIDE_LEN];

struct ascon_param {
ascon_key_t key;
const uint32_t *(associated[WIDE_LEN]);
ascon_key_t key_in;
ascon_nonce_t nonce_in;
ascon_data_block_t *associated;
size_t associated_size;
const uint32_t *(data_in[WIDE_LEN]);
ascon_data_block_t *data_in;
size_t data_size;
uint32_t *(data_out[WIDE_LEN]);
ascon_nonce_t nonce;
ascon_data_block_t *data_out;
ascon_tag_t tag_out;
};

int ascon_is_sane(void);
Expand Down
4 changes: 2 additions & 2 deletions projects/briey/libs/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ENTRY(crtStart)

MEMORY {
onChipRam : ORIGIN = 0x80000000, LENGTH = 32K
sdram : ORIGIN = 0x40000000, LENGTH = 128M
sdram : ORIGIN = 0x40000000, LENGTH = 64M
}
_stack_size = DEFINED(_stack_size) ? _stack_size : 2K;
/*
Expand All @@ -34,7 +34,6 @@ _heap_size = 32M - _stack_size - SIZEOF(.noinit);
*/

_memTree_size = 3 * LENGTH(sdram) / 4 ; /* Size of mem. auth. tree */
_heap_size = LENGTH(sdram) - _stack_size - _memTree_size - SIZEOF(.noinit); /* Fill rest of SDRAM with heap */


SECTIONS /*TODO don't initialize useless things, restore literal loading that use 2 instruction in place of onChipRam word */
Expand Down Expand Up @@ -104,6 +103,7 @@ SECTIONS /*TODO don't initialize useless things, restore literal loading that u
. = ALIGN(4);
} > sdram

_heap_size = LENGTH(sdram) - _stack_size - _memTree_size - SIZEOF(.noinit); /* Fill rest of SDRAM with heap */
._user_heap (NOLOAD):
{
. = ALIGN(8);
Expand Down
Loading