Commit 6d431eef by Enrico Pozzobon

Merge branch 'master' of lab.las3.de:lwc/compare

parents 938ddf74 062ba968
build/
all-lwc-submission-files/
*.log
......@@ -131,8 +131,8 @@ def main(argv):
# For testing, we only do the first 5
files = files[:5]
# For testing, we only do the first 1
files = files[:1]
# Clear the build directory as it is a leftover from the previous execution
if os.path.isdir('build'):
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#define CRYPTO_KEYBYTES 16
#define CRYPTO_NSECBYTES 0
#define CRYPTO_NPUBBYTES 16
#define CRYPTO_ABYTES 16
#define CRYPTO_NOOVERLAP 1
......@@ -46,6 +46,8 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c \
Src/RTT/SEGGER_RTT.c \
Src/RTT/SEGGER_RTT_printf.c \
$(SRC_FILES)
# ASM sources
......@@ -114,7 +116,7 @@ C_INCLUDES = \
-IInc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include
-IDrivers/CMSIS/Include
# compile gcc flags
......
......@@ -43,8 +43,11 @@
#include <stdint.h>
#include "crypto_aead.h"
#include "api.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#define MAX_LEN 1400
#define dbg_printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
unsigned char c[MAX_LEN];
unsigned long long clen = 0;
......@@ -52,6 +55,7 @@ unsigned char m[MAX_LEN];
unsigned long long mlen = 0;
unsigned char ad[MAX_LEN];
unsigned long long adlen = 0;
unsigned char text[2] = "OK";
unsigned char nsec[CRYPTO_NSECBYTES];
const unsigned long long nslen = CRYPTO_NSECBYTES;
......@@ -65,44 +69,45 @@ void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void read_variable_serial(unsigned char action);
static void write_variable_serial(unsigned char target[], unsigned long long len);
static void write_variable_serial(unsigned char target[], uint32_t len);
static void read_serial(void *dst, unsigned int len) {
unsigned char *buf = dst;
dbg_printf("Reading %d serial bytes\n", len);
for (int i = 0; i < len; i++) {
while (LL_USART_IsActiveFlag_RXNE(USART1));
while (!LL_USART_IsActiveFlag_RXNE(USART1));
buf[i] = LL_USART_ReceiveData8(USART1);
}
dbg_printf("done.\n", len);
}
static void write_serial(const void *src, unsigned int len) {
const unsigned char *buf = src;
for (int i = 0; i < len; i++) {
while (!LL_USART_IsActiveFlag_TXE(USART1));
dbg_printf("Write to serial: %02x\n", buf[i]);
while (!(LL_USART_IsActiveFlag_TXE(USART1)));
LL_USART_TransmitData8(USART1, buf[i]);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
dbg_printf("Done writing!\n");
}
}
static void read_variable_serial(unsigned char action) {
uint32_t len;
dbg_printf("Let's read our variable: %c\n", action);
read_serial(&len, sizeof(len));
dbg_printf("with length %lu \n", len);
switch(action) {
case 'k':
while (len != CRYPTO_KEYBYTES);
read_serial(k, len);
break;
case 'p':
while (len != CRYPTO_NPUBBYTES);
read_serial(k, len);
if (len != CRYPTO_NPUBBYTES) { dbg_printf("Assert failed %d != %d\n", len, CRYPTO_NPUBBYTES); for(;;); }
read_serial(npub, len);
break;
case 's':
while (len != CRYPTO_NSECBYTES);
read_serial(k, len);
read_serial(nsec, len);
break;
case 'a':
while (len > MAX_LEN);
......@@ -124,7 +129,7 @@ static void read_variable_serial(unsigned char action) {
}
}
static void write_variable_serial(unsigned char target[], unsigned long long len) {
static void write_variable_serial(unsigned char target[], uint32_t len) {
write_serial(&len, sizeof(len));
write_serial(target, len);
}
......@@ -160,7 +165,7 @@ int main(void)
SystemClock_Config();
/* USER CODE BEGIN SysInit */
SEGGER_RTT_Init();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
......@@ -176,8 +181,9 @@ int main(void)
int res;
while (1) {
read_serial(&rcv, sizeof(rcv));
switch (rcv) {
read_serial(&rcv, 1);
dbg_printf("Received action: %c\n", rcv);
switch (rcv) {
case 'c':
case 'm':
case 'a':
......@@ -199,11 +205,16 @@ int main(void)
break;
case 'e':
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
dbg_printf("m: "); for (int i = 0; i < mlen; i++) dbg_printf("%02x", m[i]); dbg_printf("\n");
dbg_printf("a: "); for (int i = 0; i < adlen; i++) dbg_printf("%02x", ad[i]); dbg_printf("\n");
dbg_printf("p: "); for (int i = 0; i < nplen; i++) dbg_printf("%02x", npub[i]); dbg_printf("\n");
dbg_printf("k: "); for (int i = 0; i < klen; i++) dbg_printf("%02x", k[i]); dbg_printf("\n");
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
break;
default:
return 2;
default:
continue;
}
/* USER CODE END WHILE */
}
......
#!/bin/bash
mv $HDR_FILES Inc/
......@@ -4,4 +4,3 @@ device STM32F103C8
loadbin build/blackpill.bin 0x8000000
r
g
exit
#!/usr/bin/env python3
#!/usr/bin/python3 -u
import os
import sys
import time
import struct
import serial
from subprocess import Popen, PIPE, run
f = open("subprocess.log", "w+")
ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash():
......@@ -15,9 +18,11 @@ def read(channel, l):
if channel == 'ser':
data = ser.read(l)
elif channel == 'std':
data = sys.stdin.read(l)
data = sys.stdin.buffer.read(l)
else:
raise Exception("read() complains: no sai channelino")
# if channel == "std" and len(data) == 0:
# sys.exit(0)
if len(data) != l:
raise Exception("could not read %d bytes of data (got %d)" % (l, len(data)))
return data
......@@ -25,8 +30,9 @@ def read(channel, l):
def write(channel, data):
if channel == 'ser':
l = ser.write(data)
f.write("Data sent to serial: " + str(data) + "\n")
elif channel == 'std':
l = sys.stdout.write(data)
l = sys.stdout.buffer.write(data)
else:
raise Exception("write() complains: no sai channelino")
if len(data) != l:
......@@ -34,33 +40,40 @@ def write(channel, data):
def obtain(channel):
l = read(channel, 4)
l = str.encode(l)
(l, ) = struct.unpack("<I", l)
f.write("Trying to read %d bytes from %s\n" % (l, channel))
return read(channel, l)
def submit(channel, action, data):
h = struct.pack("<BI", ord(action), len(data))
if channel == "std":
h = struct.pack("<I", len(data))
else:
h = struct.pack("<BI", ord(action), len(data))
write(channel, h)
write(channel, str.encode(data))
write(channel, data)
time.sleep(0.1)
def main():
#flash()
print("Hello, World!")
while(1):
action = read('std', 1)
if (action):
if action == 'c' or action == 'm' or action == 'a' or action == 'k' or action == 's' or action == 'p':
data = obtain('std')
submit('ser', action, data)
f.write("Read following action from stdin: %s\n" % action)
if action == b'c' or action == b'm' or action == b'a' or action == b'k' or action == b's' or action == b'p':
data = obtain('std')
submit('ser', action, data)
elif action == 'e' or action == 'd':
write('ser', str.encode(action))
elif action == b'e' or action == b'd':
write('ser', action)
elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P':
write('ser', str.encode(action))
data = obtain('ser')
submit('std', action, data)
else:
raise Exception("no capiche aczione %s" % (action))
elif action == b'C' or action == b'M' or action == b'A' or action == b'K' or action == b'S' or action == b'P':
write('ser', action)
data = obtain('ser')
f.write("Obtained following data from serial: %s\n" % data)
submit('std', action, data)
f.write("Submitted following data to stdout: %s\n" % data)
else:
raise Exception("no capiche aczione %s" % (action))
if __name__ == "__main__":
sys.exit(main())
......@@ -40,8 +40,8 @@ def main(argv):
(l, ) = struct.unpack("<I", l)
return read(l)
#if read(14) != b"Hello, World!\n":
# raise Exception("Unexpected output")
if read(14) != b"Hello, World!\n":
raise Exception("Unexpected output")
m = b""
ad = b""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment