A VexRiscv with AES128 on the memory mapped bus. Works in simulation and on the ULX3S.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

97 lines
1.9 KiB

#include <stdbool.h>
#include "hal.h"
#define LENGTH 4
typedef struct {
volatile uint32_t key[LENGTH];
volatile uint32_t state_in[LENGTH];
volatile uint32_t useEncDec;
volatile uint32_t valid_in;
volatile uint32_t valid_out;
volatile uint32_t state_out[LENGTH];
} Aes_Mem;
#define AES_MEM ((Aes_Mem*)(0xF0030000))
void writeKey(uint32_t * key) {
for (unsigned i = 0; i < LENGTH; i++) {
AES_MEM->key[i] = key[i];
}
}
void writeState(uint32_t * state) {
for (unsigned i = 0; i < LENGTH; i++) {
AES_MEM->state_in[i] = state[i];
}
}
void setEncDec(int encDec) {
AES_MEM->useEncDec = encDec;
}
void setValidIn() {
AES_MEM->valid_in = 1;
}
void readState(uint32_t * state) {
for (unsigned i = 0; i < LENGTH; i++) {
state[i] = AES_MEM->state_out[i];
}
}
void printState(uint32_t * state) {
printf("State:\n");
for(unsigned i = 0; i < LENGTH; i++) {
printf("%08x",state[LENGTH-i-1]);
}
printf("\n");
}
void printKey(uint32_t * key) {
printf("Key:\n");
for(unsigned i = 0; i < LENGTH; i++) {
printf("%08x",key[LENGTH-i-1]);
}
printf("\n");
}
int main(void) {
printf("HELLO WORLD\n");
// uint32_t state[LENGTH] = {0x6bc1bee2, 0x2e409f96, 0xe93d7e11, 0x7393172a};
// uint32_t key[LENGTH] = {0x2b7e1516, 0x28aed2a6, 0xabf71588, 0x09cf4f3c};
uint32_t state[LENGTH] = {0x7393172a, 0xe93d7e11, 0x2e409f96, 0x6bc1bee2};
uint32_t key[LENGTH] = {0x09cf4f3c, 0xabf71588, 0x28aed2a6, 0x2b7e1516};
writeKey(key);
while (1) {
printState(state);
printKey(key);
writeState(state);
setEncDec(1);
setValidIn();
while (AES_MEM->valid_out != 1);
readState(state);
printState(state);
writeState(state);
setEncDec(0);
setValidIn();
while (AES_MEM->valid_out != 1);
readState(state);
printState(state);
}
return 0;
}