WIP auth with ECDSA

auth
Wojciech Kaczmarski 2024-06-19 17:00:40 +02:00
rodzic f177399bb6
commit a94bf85863
3 zmienionych plików z 92 dodań i 34 usunięć

Wyświetl plik

@ -28,11 +28,35 @@ options:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [520, 12.0]
coordinate: [8, 4.0]
rotation: 0
state: enabled
blocks:
- name: can
id: variable
parameters:
comment: ''
value: '0'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 4.0]
rotation: 0
state: true
- name: sign
id: variable
parameters:
comment: ''
value: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [256, 4.0]
rotation: 0
state: true
- name: blocks_file_sink_0
id: blocks_file_sink
parameters:
@ -48,7 +72,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [696, 172.0]
coordinate: [696, 292.0]
rotation: 0
state: true
- name: blocks_stream_mux_0
@ -67,7 +91,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [360, 128.0]
coordinate: [360, 248.0]
rotation: 0
state: enabled
- name: blocks_throttle2_0
@ -88,7 +112,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [536, 180.0]
coordinate: [536, 300.0]
rotation: 0
state: true
- name: blocks_vector_source_x_0
@ -108,7 +132,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [112, 12.0]
coordinate: [112, 132.0]
rotation: 0
state: true
- name: blocks_vector_source_x_0_0
@ -128,7 +152,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [112, 92.0]
coordinate: [112, 212.0]
rotation: 0
state: true
- name: blocks_vector_source_x_0_1
@ -142,13 +166,13 @@ blocks:
repeat: 'True'
tags: '[]'
type: byte
vector: (0x00, 0x05)
vector: ((sign<<3)|(can>>1), ((can&1)<<7)|0x05)
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [112, 172.0]
coordinate: [112, 292.0]
rotation: 0
state: true
- name: blocks_vector_source_x_0_2
@ -169,7 +193,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [112, 332.0]
coordinate: [112, 452.0]
rotation: 0
state: true
- name: blocks_vector_source_x_0_2_0
@ -190,7 +214,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [112, 252.0]
coordinate: [112, 372.0]
rotation: 0
state: true
- name: note_0
@ -203,7 +227,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 28.0]
coordinate: [16, 148.0]
rotation: 0
state: true
- name: note_0_0
@ -216,7 +240,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 108.0]
coordinate: [16, 228.0]
rotation: 0
state: true
- name: note_0_1
@ -229,7 +253,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 188.0]
coordinate: [16, 308.0]
rotation: 0
state: true
- name: note_0_2
@ -242,7 +266,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 348.0]
coordinate: [16, 468.0]
rotation: 0
state: true
- name: note_0_2_0
@ -255,7 +279,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [16, 268.0]
coordinate: [16, 388.0]
rotation: 0
state: true

Wyświetl plik

@ -1,5 +1,5 @@
m17-coder-sym: m17-coder-sym.c
gcc -I ../../libm17 -L ../../libm17 -O2 -Wall -Wextra m17-coder-sym.c -o m17-coder-sym -lm -lm17
gcc -I ../../libm17 -O2 -Wall -Wextra m17-coder-sym.c -o m17-coder-sym -lm -lm17
clean:
rm -f m17-coder-sym

Wyświetl plik

@ -5,6 +5,8 @@
//libm17
#include <m17.h>
//micro-ecc
#include "../../micro-ecc/uECC.h"
//#define FN60_DEBUG
@ -24,6 +26,10 @@ uint8_t lich_cnt=0; //0..5 LICH counter
uint8_t got_lsf=0; //have we filled the LSF struct yet?
uint8_t finished=0;
//used for signatures
uint8_t digest[16]={0}; //16-byte field for the stream digest
uint8_t signed_str=0; //is the stream supposed to be signed?
//main routine
int main(void)
{
@ -52,6 +58,18 @@ int main(void)
memcpy(data, next_data, sizeof(data));
//calculate stream digest
signed_str=(lsf.type[0]>>3)&1;
if(signed_str) //signed stream? check bit 11 of TYPE
{
for(uint8_t i=0; i<sizeof(digest); i++)
digest[i]^=data[i];
uint8_t tmp=digest[0];
for(uint8_t i=0; i<sizeof(digest)-1; i++)
digest[i]=digest[i+1];
digest[sizeof(digest)-1]=tmp;
}
//we could discard the data we already have
if(fread(&(next_lsf.dst), 6, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.src), 6, 1, stdin)<1) finished=1;
@ -75,7 +93,12 @@ int main(void)
unpack_LICH(enc_bits, lich_encoded);
//encode the rest of the frame (starting at bit 96 - 0..95 are filled with LICH)
conv_encode_stream_frame(&enc_bits[96], data, finished ? (fn | 0x8000) : fn);
if(!signed_str)
conv_encode_stream_frame(&enc_bits[96], data, finished ? (fn | 0x8000) : fn);
else //dont set the MSB is the stream is signed
{
conv_encode_stream_frame(&enc_bits[96], data, fn);
}
//reorder bits
reorder_bits(rf_bits, enc_bits);
@ -83,31 +106,47 @@ int main(void)
//randomize
randomize_bits(rf_bits);
//send dummy symbols (debug)
/*float s=0.0;
for(uint8_t i=0; i<SYM_PER_PLD; i++) //40ms * 4800 - 8 (syncword)
fwrite((uint8_t*)&s, sizeof(float), 1, stdout);*/
//send frame data
send_data(frame_buff, &frame_buff_cnt, rf_bits);
fwrite((uint8_t*)frame_buff, SYM_PER_FRA*sizeof(float), 1, stdout);
/*printf("\tDATA: ");
for(uint8_t i=0; i<16; i++)
printf("%02X", data[i]);
printf("\n");*/
//increment the Frame Number
fn = (fn + 1) % 0x8000;
//increment the LICH counter
lich_cnt = (lich_cnt + 1) % 6;
if(finished && signed_str) //if we are done, and the stream is signed, so we need to transmit the signature (4 frames)
{
uint8_t sig[64];
for(uint8_t i=0; i<sizeof(sig); i++) //test fill
sig[i]=i;
//1 of 4
fn = 0x7FFC; //signature has to start at 0x7FFC to end at 0x7FFF (0xFFFF with EoT marker set)
for(uint8_t i=0; i<4; i++)
{
frame_buff_cnt=0;
send_syncword(frame_buff, &frame_buff_cnt, SYNC_STR);
extract_LICH(lich, lich_cnt, &lsf); //continue with next LICH_CNT
encode_LICH(lich_encoded, lich);
unpack_LICH(enc_bits, lich_encoded);
conv_encode_stream_frame(&enc_bits[96], &sig[i*16], fn);
reorder_bits(rf_bits, enc_bits);
randomize_bits(rf_bits);
send_data(frame_buff, &frame_buff_cnt, rf_bits);
fwrite((uint8_t*)frame_buff, SYM_PER_FRA*sizeof(float), 1, stdout);
fn = (fn<0x7FFE) ? fn+1 : (0x7FFF|0x8000);
lich_cnt = (lich_cnt + 1) % 6;
}
}
//debug-only
#ifdef FN60_DEBUG
#ifdef FN60_DEBUG
if(fn==6*10)
return 0;
#endif
#endif
}
else //LSF
{
@ -137,11 +176,6 @@ int main(void)
send_data(frame_buff, &frame_buff_cnt, rf_bits);
fwrite((uint8_t*)frame_buff, SYM_PER_PLD*sizeof(float), 1, stdout);
//send dummy symbols (debug)
/*float s=0.0;
for(uint8_t i=0; i<184; i++) //40ms * 4800 - 8 (syncword)
write((uint8_t*)&s, sizeof(float), 1, stdout);*/
/*printf("DST: ");
for(uint8_t i=0; i<6; i++)
printf("%02X", lsf.dst[i]);