Commit 6d431eef by Enrico Pozzobon

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

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