Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
yids
avr-pager
Commits
004b974e
Commit
004b974e
authored
Sep 15, 2016
by
hark
Browse files
bla
parent
ce7fea23
Changes
8
Hide whitespace changes
Inline
Side-by-side
README
View file @
004b974e
...
...
@@ -29,6 +29,8 @@ http://www.johannes-bauer.com/compsci/ecc/
TODO:
- actually make it work
- use NaCL as crypto lib
- find something to hash the secret before using it for the symetric encryption (this is recommended in the uECC lib not sure why)
- generate random IV
- find something to hash pubkeys and make an address out of them
...
...
base-tx/Makefile
View file @
004b974e
ABIN
=
avr-hello
AOBJS
=
avr-hello.o
ACC
=
avr-gcc
AOBJCOPY
=
avr-objcopy
AGDB
=
avr-gdb
ACFLAGS
=
-Os
-DF_CPU
=
16000000UL
-mmcu
=
atmega328p
APORT
=
/dev/ttyACM0
${ABIN}.hex
:
${ABIN}.elf
${AOBJCOPY}
-O
ihex
-R
.eeprom
$<
$@
${ABIN}.elf
:
${AOBJS}
${ACC}
-o
$@
$^
flash
:
${ABIN}.hex
avrdude
-F
-V
-c
arduino
-p
ATMEGA328P
-P
${APORT}
-b
115200
-U
flash:w:
$<
clean
:
rm
-f
${ABIN}
.elf
${ABIN}
.hex
${AOBJS}
CC
=
colorgcc
CFLAGS
=
"-I ../libs -DDEBUG"
...
...
@@ -39,11 +16,14 @@ rx-test: rx-test.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
tx-test
:
tx-test.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
$(CC)
-std
=
c99
-g
-o
tx-test tx-test.c ../libs/micro-ecc/uECC.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
-lmbedtls
-lmbedx509
-lmbedcrypto
$(LIBS)
$(CFLAGS)
keygen
:
keygen.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
$(CC)
-std
=
c99
-g
-o
keygen keygen.c ../libs/micro-ecc/uECC.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
-lmbedtls
-lmbedx509
-lmbedcrypto
$(LIBS)
$(CFLAGS)
#
keygen: keygen.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
#
$(CC) -std=c99 -g -o keygen keygen.c ../libs/micro-ecc/uECC.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c -lmbedtls -lmbedx509 -lmbedcrypto $(LIBS) $(CFLAGS)
test2
:
test2.c
$(CC)
-std
=
c99
-o
test2 test2.c ../libs/micro-ecc/uECC.c
-lmbedtls
-lmbedx509
-lmbedcrypto
$(LIBS)
$(CFLAGS)
clean
:
rm
-r
test
tx-test rx-test keygen
debugger
:
test
ddd
-x
gdb.conf ./test
base-tx/test.c
View file @
004b974e
...
...
@@ -23,57 +23,78 @@
#endif
int
main
()
{
struct
pl_keypair
*
kp
;
kp
=
NULL
;
struct
pl_keypair
*
receiver
,
*
sender
;
receiver
=
NULL
;
sender
=
NULL
;
char
clear_message
[]
=
"Blaat blaat, dit is een test berichtje :), en nog meer en meer en meer 123456744555 blablablablablablabal jajajajaj hee blaat "
;
// initialise the pager
struct
pl_ctx
*
context
;
struct
pl_ctx
*
sender_ctx
,
*
rcv_ctx
;
context
=
pl_init
();
rcv_ctx
=
pl_init
();
sender_ctx
=
pl_init
();
int
f
=
0
;
while
(
f
<
2
)
{
f
++
;
/* create keypairs */
kp
=
pl_create_keypair
(
context
);
receiver
=
pl_create_keypair
(
rcv_ctx
);
pl_load_key_in_list
(
rcv_ctx
,
receiver
);
rcv_ctx
->
kp
=
receiver
;
sender
=
pl_create_keypair
(
sender_ctx
);
pl_load_key_in_list
(
sender_ctx
,
sender
);
sender_ctx
->
kp
=
sender
;
/*
char *kp_b64, *decoded;
// 4*(n/3)
kp_b64 = malloc(4*(sizeof(struct pl_keypair) / 3));
decoded = malloc(sizeof(struct pl_keypair));
base64_encode(kp_b64, kp, sizeof(struct pl_keypair));
printf("base64 keypair: %s \n", kp_b64);
base64_decode(decoded , kp_b64, (4*sizeof(struct pl_keypair) / 3)) ;
*/
pl_load_key_in_list
(
context
,
kp
);
// set key to use for sending the message (FIXME)
context
->
kp
=
kp
;
int
f
=
0
;
while
(
1
)
{
f
++
;
// load the message to send
memcpy
(
context
->
msg
->
msg
,
clear_message
,
MSG_SIZE
);
memcpy
(
sender_ctx
->
msg
->
msg
,
clear_message
,
MSG_SIZE
);
//to who to send the message to (get from kp)
memcpy
(
&
context
->
receiver_compressed_point
,
&
kp
->
compressed_point
,
sizeof
(
context
->
receiver_compressed_point
));
memcpy
(
&
sender_ctx
->
receiver_compressed_point
,
&
receiver
->
compressed_point
,
sizeof
(
sender_ctx
->
receiver_compressed_point
));
pl_send_message
(
sender_ctx
);
printf
(
"crypted msg: %s"
,
sender_ctx
->
msg
->
msg
);
/* copy the message to receiver */
struct
pl_pagermessage
*
message
=
NULL
;
message
=
(
struct
pl_pagermessage
*
)
malloc
(
sizeof
(
struct
pl_pagermessage
));
memcpy
(
message
,
sender_ctx
->
msg
,
sizeof
(
struct
pl_pagermessage
));
rcv_ctx
->
msg
=
message
;
message
=
NULL
;
pl_send_message
(
context
);
printf
(
"crypted msg: %s"
,
context
->
msg
->
msg
);
/* receive the msg */
if
(
pl_receive_message
(
context
)
==
1
)
{
if
(
pl_receive_message
(
rcv_ctx
)
==
1
)
{
printf
(
"failed to receive this message ! (exit 1)
\n
"
);
}
else
{
printf
(
"recv success!
\n
"
);
//
printf(" Message! \n to: %u from: %u \n the decrypted message: %s \n",
context
->msg->address, compressed_point_to_addr(
context
->msg->sender_compressed_point),
context
->msg->msg);
printf
(
" Message!
\n
to: %u from: %u
\n
the decrypted message: %s
\n
"
,
rcv_ctx
->
msg
->
address
,
compressed_point_to_addr
(
rcv_ctx
->
msg
->
sender_compressed_point
),
rcv_ctx
->
msg
->
msg
);
}
}
}
// main
/*
DBG("\n sender.keypair");
DBM("sender", sizeof(struct pl_keypair), sender);
...
...
@@ -87,6 +108,7 @@ int main() {
*/
/*
context->kp = kp;
if (pl_receive_message(context) == 1) {
...
...
@@ -118,4 +140,8 @@ int main() {
pl_inbox_display(context);
}
return 0;
}
*/
//}
libs/pagerlib/packets.h
View file @
004b974e
...
...
@@ -25,7 +25,7 @@ extern "C"
#define CURVE uECC_secp256r1()
#define ECC_COMPRESSED_SIZE 33
#define SHARED_SECRET_SIZE 3
9
#define SHARED_SECRET_SIZE 3
2
/* AES stuff
AES_KEYSIZE: keysize of aes key
IV_SIZE: always 16? FIXME
...
...
simul/atmega48_charlcd.c
View file @
004b974e
...
...
@@ -37,8 +37,8 @@
#include
</usr/local/include/simavr/avr/avr_mcu_section.h>
//
AVR_MCU(F_CPU, "atmega328");
AVR_MCU
(
F_CPU
,
"atmega48"
);
AVR_MCU
(
F_CPU
,
"atmega328"
);
//
AVR_MCU(F_CPU, "atmega48");
static
uint8_t
subsecct
=
0
;
static
uint8_t
hour
=
0
;
...
...
@@ -48,10 +48,12 @@ static volatile uint8_t update_needed = 0;
#include
"avr_hd44780.c"
ISR
(
INT0_vect
)
{
//
ISR( INT0_vect )
//
{
/* External interrupt on pin D2 */
subsecct
++
;
/*
subsecct++;
if (subsecct == 50) {
second++;
subsecct = 0;
...
...
@@ -67,7 +69,9 @@ ISR( INT0_vect )
}
}
}
printf("int \n");
}
*/
int
main
()
{
...
...
@@ -92,20 +96,41 @@ int main()
hd44780_wait_ready
(
0
);
// set up intterupt
//
DDRD &= ~(1 << DDD2); // Clear the PD2 pin
// DDRD &= ~(1 << DDD2); // Clear the PD2 pin
// PD2 (PCINT0 pin) is now an input
//
PORTD |= (1 << PORTD2); // turn On the Pull-up
// PORTD |= (1 << PORTD2); // turn On the Pull-up
// PD2 is now an input with pull-up enabled
EICRA
=
(
1
<<
ISC00
);
/// set INT0 to trigger on ANY logic change
EIMSK
=
(
1
<<
INT0
);
//// Turns on INT0
// EICRA = (1 << ISC00); /// set INT0 to trigger on ANY logic change
// EIMSK = (1 << INT0); //// Turns on INT0
// sei();
while
(
!
update_needed
)
{
_delay_ms
(
50
);
subsecct
++
;
if
(
subsecct
==
50
)
{
second
++
;
subsecct
=
0
;
update_needed
=
1
;
if
(
second
==
60
)
{
minute
++
;
second
=
0
;
if
(
minute
==
60
)
{
minute
=
0
;
hour
++
;
if
(
hour
==
24
)
hour
=
0
;
}
}
}
sei
();
while
(
1
)
{
while
(
!
update_needed
)
sleep_mode
();
// while (!update_needed)
// sleep_mode();
update_needed
=
0
;
char
buffer
[
16
];
...
...
simul/avr_hd44780_conf.h
View file @
004b974e
...
...
@@ -37,7 +37,7 @@
#define HD44780_RS B, 4
/* The data bits have to be not only in ascending order but also consecutive. */
//#define HD44780_D4 D, 4
#define HD44780_D4
C
, 0
#define HD44780_D4
D
, 0
/* Whether to read the busy flag, or fall back to
worst-time delays. */
#define USE_BUSY_BIT 0
...
...
simul/charlcd.c
View file @
004b974e
...
...
@@ -170,7 +170,7 @@ main(
/* Connect Data Lines to Port B, 0-3 D, 4 -7*/
/* These are bidirectional too */
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
avr_irq_t
*
iavr
=
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'
C
'
),
i
);
avr_irq_t
*
iavr
=
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'
D
'
),
i
);
avr_irq_t
*
ilcd
=
hd44780
.
irq
+
IRQ_HD44780_D4
+
i
;
// AVR -> LCD
avr_connect_irq
(
iavr
,
ilcd
);
...
...
@@ -197,6 +197,39 @@ main(
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
IOPORT_IRQ_PIN_ALL
),
8
/* bits */
,
"C0-C7"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
0
),
1
/* bits */
,
"C0"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
1
),
1
/* bits */
,
"C1"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
2
),
1
/* bits */
,
"C2"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
3
),
1
/* bits */
,
"C3"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
4
),
1
/* bits */
,
"C4"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
5
),
1
/* bits */
,
"C5"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
6
),
1
/* bits */
,
"C6"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'C'
),
7
),
1
/* bits */
,
"C7"
);
avr_vcd_add_signal
(
&
vcd_file
,
avr_io_getirq
(
avr
,
AVR_IOCTL_IOPORT_GETIRQ
(
'B'
),
4
),
1
/* bits */
,
"RS"
);
...
...
@@ -229,6 +262,7 @@ main(
" Press 'r' to start recording a 'wave' file - with a LOT of data
\n
"
" Press 's' to stop recording
\n
"
);
//#define GDB
#ifdef GDB
avr
->
gdb_port
=
1234
;
avr
->
state
=
cpu_Stopped
;
...
...
simul/gdb.conf
deleted
100644 → 0
View file @
ce7fea23
file
atmega48_charlcd
.
axf
target
remote
localhost
:
1234
#dir build-atmega328/libs/
#dir build-atmega328/core/
dir
.
#dir ../libs/pagerlib/
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment