Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
yids
avr-pager
Commits
374054d7
Commit
374054d7
authored
Oct 20, 2016
by
yids
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- building for avr
- fixed keygen - load and save pubkeys - some compiler warnings
parent
cce908bd
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
90 additions
and
64 deletions
+90
-64
avr-src/Makefile
avr-src/Makefile
+11
-7
avr-src/lib-test.c
avr-src/lib-test.c
+3
-4
base-tx/keygen.c
base-tx/keygen.c
+20
-25
base-tx/rx-test.c
base-tx/rx-test.c
+12
-4
libs/pagerlib/packets.h
libs/pagerlib/packets.h
+1
-1
libs/pagerlib/pagerlib.c
libs/pagerlib/pagerlib.c
+31
-3
libs/pagerlib/pagerlib.h
libs/pagerlib/pagerlib.h
+10
-18
libs/pagerlib/things.c
libs/pagerlib/things.c
+1
-2
libs/pagerlib/things.h
libs/pagerlib/things.h
+1
-0
No files found.
avr-src/Makefile
View file @
374054d7
#include /usr/share/arduino/Arduino.mk
CFILES
=
blink.c
LIBCFILE
S
=
../libs/avrnacl/
randombytes/randombytes.c
OBJ
S
=
../libs/avrnacl/
avrnacl_small/obj/randombytes.o ../libs/avrnacl/avrnacl_small/obj/libnacl.a
CFLAGS
=
-Os
-pedantic
-std
=
gnu99
-DARDUINO
-I
../libs/avrnacl/randombytes
-I
../libs/avrnacl/avrnacl_small/include
OPTIMIZE
=
-O3
CC
=
avr-gcc
MCU
=
atmega328p
F_CPU
=
F_CPU
=
16000000UL
...
...
@@ -9,20 +12,21 @@ F_CPU=F_CPU=16000000UL
AVRDUDE_PROGRAMMERID
=
stk200 /
*
Programmer ids are listed
in
/etc/avrdude.conf
*
/
AVRDUDE_PORT
=
/dev/ttyUSB4
all
:
lib-test
blink
:
blink.c
avr-gcc blink.c
$(OPTIMZE)
-g
-I
AVRLIB/
-mmcu
=
$(MCU)
-D
$(F_CPU)
$(CFLAGS)
$(LIBCFILES)
-o
blink.elf
avr-objcopy
-j
.text
-j
.data
-O
ihex blink.elf blink.hex
rm
blink.elf
all
:
lib-test
lib-test
:
lib-test.c
avr-gcc
lib-test.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
$(
LIBCFILE
S)
$(OPTIMZE)
-g
-I
AVRLIB/
-mmcu
=
$(MCU)
-D
$(F_CPU)
$(CFLAGS)
$(LIBCFILES)
-o
lib-test.elf
$(CC)
lib-test.c ../libs/pagerlib/pagerlib.c ../libs/pagerlib/things.c
$(
OBJ
S)
$(OPTIMZE)
-g
-I
AVRLIB/
-mmcu
=
$(MCU)
-D
$(F_CPU)
$(CFLAGS)
-o
lib-test.elf
avr-objcopy
-j
.text
-j
.data
-O
ihex lib-test.elf lib-test.hex
rm
lib-test.elf
upload
:
avrdude
-carduino
-p
atmega328p
-P
/dev/ttyUSB1
-b57600
-U
flash:w:lib-test.hex
debugger
:
lib-test
ddd
--debugger
avr-gdb
-x
gdb.conf
clean
:
rm
-r
*
.elf
*
.hex
include
/home/yids/src/avr/simavr/Makefile.common
avr-src/lib-test.c
View file @
374054d7
...
...
@@ -5,10 +5,9 @@
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
//#include "../libs/RadioHead/RadioHead.h"
#include "../libs/avrnacl/avrnacl.h"
//#include "../libs/pagerlib/pagerlib.h"
//#include "../libs/avrnacl/randombytes/randombytes.h"
#include "../libs/pagerlib/pagerlib.h"
char
tx_priv_key
[
crypto_box_SECRETKEYBYTES
]
=
{
0x23
,
0x4D
,
0x77
,
0xFFFFFFF7
,
0x09
,
0x70
,
0x46
,
0xFFFFFF82
,
0xFFFFFFC7
,
0x0B
,
0x70
,
0x39
,
0xFFFFFFDA
,
0x24
,
0x4A
,
0xFFFFFF9C
,
0x28
,
0x7A
,
0xFFFFFFD8
,
0xFFFFFFCE
,
0x7B
,
0xFFFFFFEF
,
0xFFFFFFFB
,
0x75
,
0x7E
,
0x34
,
0x16
,
0xFFFFFF99
,
0xFFFFFFF6
,
0x60
,
0x08
,
0x0A
};
...
...
base-tx/keygen.c
View file @
374054d7
#include "../libs/micro-ecc/uECC.h"
//
#include "../libs/micro-ecc/uECC.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sodium.h>
#include "../libs/pagerlib/pagerlib.h"
#ifndef uECC_TEST_NUMBER_OF_ITERATIONS
#define uECC_TEST_NUMBER_OF_ITERATIONS 1
#endif
char
shared_secret
[
SHARED_SECRET_SIZE
];
//
char shared_secret[SHARED_SECRET_SIZE];
char
decompressed_point
[
64
];
void
hex_dump
(
struct
pl_keypair
*
keypair
)
{
printf
(
"private key:
\n
"
);
printf
(
"{"
);
for
(
int
i
=
0
;
i
<
ECC_COMPRESSED_SIZE
-
1
;
i
++
){
printf
(
"0x%02X, "
,
keypair
->
private
_key
[
i
]);
for
(
int
i
=
0
;
i
<
crypto_box_SECRETKEYBYTES
;
i
++
){
printf
(
"0x%02X, "
,
keypair
->
secret
_key
[
i
]);
}
printf
(
"}
\n
compressed point
:
\n
{"
);
for
(
int
i
=
0
;
i
<
ECC_COMPRESSED_SIZE
;
i
++
){
printf
(
"0x%02X, "
,
keypair
->
compressed_point
[
i
]);
printf
(
"}
\n
public key
:
\n
{"
);
for
(
int
i
=
0
;
i
<
crypto_box_PUBLICKEYBYTES
;
i
++
){
printf
(
"0x%02X, "
,
keypair
->
public_key
[
i
]);
}
printf
(
"}
\n\n
"
);
}
int
main
()
{
struct
pl_keypair
*
receiver
,
*
sender
;
char
filename
[
64
];
char
pubfilename
[
64
];
struct
pl_keypair
*
keypair
;
struct
pl_ctx
*
context
;
context
=
pl_init
(
context
);
sender
=
(
struct
pl_keypair
*
)
malloc
(
sizeof
(
struct
pl_keypair
));
memset
(
sender
,
9
,
sizeof
(
struct
pl_keypair
));
receiver
=
(
struct
pl_keypair
*
)
malloc
(
sizeof
(
struct
pl_keypair
));
memset
(
receiver
,
2
,
sizeof
(
struct
pl_keypair
));
keypair
=
pl_create_keypair
(
context
);
printf
(
"enter filename for new keypair:
\n
"
);
scanf
(
"%s"
,
filename
);
pl_save_key
(
keypair
,
filename
);
printf
(
"keypair saved in file: %s
\n
"
,
filename
);
strncat
(
filename
,
".pub"
,
4
);
pl_create_keypair
(
context
,
sender
);
pl_save_key
(
sender
,
"sender.keypair"
);
pl_create_keypair
(
context
,
receiver
);
pl_save_key
(
receiver
,
"receiver.keypair"
);
printf
(
"sender key:
\n
"
);
hex_dump
(
sender
);
printf
(
"receiver key:
\n
"
);
hex_dump
(
receiver
);
pl_save_public_key
(
keypair
->
public_key
,
filename
);
printf
(
"public key saved in file: %s
\n
"
,
filename
);
return
0
;
}
base-tx/rx-test.c
View file @
374054d7
...
...
@@ -24,7 +24,13 @@ int main ()
// memcpy(&context->receiver_compressed_point, &receiver->compressed_point, sizeof(context->receiver_compressed_point));
rx_ctx
->
kp
=
rx_kp
;
read
(
STDIN_FILENO
,
rx_ctx
->
msg
,
sizeof
(
struct
pl_pagermessage
));
struct
pl_pagermessage
*
message
=
NULL
;
message
=
(
struct
pl_pagermessage
*
)
malloc
(
sizeof
(
struct
pl_pagermessage
));
read
(
STDIN_FILENO
,
message
,
sizeof
(
struct
pl_pagermessage
));
rx_ctx
->
msg
=
message
;
...
...
@@ -50,10 +56,12 @@ int main ()
break
;
}
while
(
pl_inbox_next
(
rx_ctx
))
{
//
while (pl_inbox_next(rx_ctx))
//
{
pl_inbox_display
(
rx_ctx
);
}
// }
// printf("the decrypted message: %s \n", rx_ctx->msg->msg);
return
0
;
...
...
libs/pagerlib/packets.h
View file @
374054d7
...
...
@@ -10,7 +10,7 @@ extern "C"
#ifndef ARDUINO
#include <sodium.h>
#else
//
include avr
-
nacl
#
include
"../
avrnacl
/avrnacl.h"
#endif
// the text message
...
...
libs/pagerlib/pagerlib.c
View file @
374054d7
...
...
@@ -166,7 +166,7 @@ int pl_receive_message(struct pl_ctx * ctx)
////////////////////////////////////////////////////////////
pl_decrypt
(
struct
pl_ctx
*
ctx
,
struct
pl_pagermessage
*
msg
,
char
plain
[
PLAIN_MSG_SIZE
])
int
pl_decrypt
(
struct
pl_ctx
*
ctx
,
struct
pl_pagermessage
*
msg
,
char
plain
[
PLAIN_MSG_SIZE
])
{
// TODO: figure out why all the hassle with the zerobytes
...
...
@@ -220,7 +220,7 @@ struct pl_keypair * pl_create_keypair(struct pl_ctx *ctx)
#endif
}
int
pl_save_key
(
struct
pl_keypair
*
key
,
char
*
filename
)
int
pl_save_key
(
struct
pl_keypair
*
key
,
char
*
filename
)
{
#ifdef ARDUINO
// not implemented
...
...
@@ -234,7 +234,7 @@ int pl_save_key(struct pl_keypair *key, char * filename)
#endif
}
int
pl_load_key
(
struct
pl_keypair
*
key
,
char
*
filename
)
int
pl_load_key
(
struct
pl_keypair
*
key
,
char
*
filename
)
{
#ifdef ARDUINO
return
1
;
...
...
@@ -247,6 +247,32 @@ int pl_load_key(struct pl_keypair *key, char * filename)
#endif
}
int
pl_save_public_key
(
char
*
pubkey
,
char
*
filename
)
{
#ifdef ARDUINO
return
1
;
#else
FILE
*
sf
;
sf
=
fopen
(
filename
,
"w"
);
fwrite
(
pubkey
,
1
,
crypto_box_PUBLICKEYBYTES
,
sf
);
fclose
(
sf
);
return
0
;
#endif
}
int
pl_load_public_key
(
char
pubkey
[
crypto_box_PUBLICKEYBYTES
],
char
*
filename
)
{
#ifdef ARDUINO
return
1
;
#else
FILE
*
lf
;
lf
=
fopen
(
filename
,
"r"
);
fread
(
pubkey
,
1
,
crypto_box_PUBLICKEYBYTES
,
lf
);
fclose
(
lf
);
return
0
;
#endif
}
int
pl_inbox_append
(
struct
pl_ctx
*
ctx
,
struct
pl_pagermessage
*
msg
)
{
struct
list_inbox
*
list
,
*
ni
,
*
last
,
*
listprev
;
...
...
@@ -433,3 +459,5 @@ int pl_print_keylist(struct pl_ctx *ctx)
#endif
}
}
libs/pagerlib/pagerlib.h
View file @
374054d7
...
...
@@ -3,9 +3,6 @@
extern
"C"
{
#endif
//#define NOCRYPT
#define DEBUG
...
...
@@ -17,16 +14,14 @@ extern "C"
#include "things.h"
#ifdef ARDUINO
// #include <AESLib.h>
#include "../avrnacl/avrnacl.h"
#include "../avrnacl/randombytes/randombytes.h"
#else
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/aes.h"
#include <unistd.h>
#include <ctype.h>
#include <sodium.h>
#include <sodium.h>
#endif
#ifdef DEBUG
...
...
@@ -45,16 +40,12 @@ extern "C"
#define DBM
#endif
#include "packets.h"
/*
* List of all the available keypairs
* Should we use same list for only pubkeys?
* Should we use same list for only pubkeys?
*/
typedef
struct
list_kp
{
uint32_t
id
;
struct
pl_keypair
*
kp
;
...
...
@@ -71,7 +62,7 @@ typedef struct list_kp {
#define MSG_READ 2
typedef
struct
list_inbox
{
int
status
;
// 1 unread 2 read
int
id
;
int
id
;
struct
pl_pagermessage
*
msg
;
struct
list_inbox
*
prev
;
struct
list_inbox
*
next
;
...
...
@@ -93,12 +84,9 @@ struct pl_ctx
// contains the message that will be send or is received
char
clear_message
[
MSG_SIZE
];
char
decryptbuffer
[
PLAIN_MSG_SIZE
];
// my (currently used ) keypair
struct
pl_keypair
*
kp
;
// keypair list (all available keypairs)
struct
list_kp
*
keypairs
;
// place to store messages to be sent or received
struct
pl_pagermessage
*
msg
;
struct
pl_keypair
*
kp
;
// my (currently used ) keypair
struct
list_kp
*
keypairs
;
// keypair list (all available keypairs)
struct
pl_pagermessage
*
msg
;
// place to store messages to be sent or received
int
msgcount
;
struct
list_inbox
*
inbox
;
struct
list_inbox
*
inbox_curr
;
...
...
@@ -133,6 +121,8 @@ int pl_receive_message(struct pl_ctx*);
int
pl_save_key
(
struct
pl_keypair
*
key
,
char
*
filename
);
int
pl_load_key
(
struct
pl_keypair
*
key
,
char
*
filename
);
int
pl_save_public_key
(
char
pubkey
[
crypto_box_PUBLICKEYBYTES
],
char
*
filename
);
int
pl_load_public_key
(
char
pubkey
[
crypto_box_PUBLICKEYBYTES
],
char
*
filename
);
int
pl_print_keylist
(
struct
pl_ctx
*
ctx
);
int
pl_load_key_in_list
(
struct
pl_ctx
*
ctx
,
struct
pl_keypair
*
key
);
int
pl_inbox_append
(
struct
pl_ctx
*
ctx
,
struct
pl_pagermessage
*
msg
);
...
...
@@ -143,6 +133,8 @@ int pl_inbox_next(struct pl_ctx *ctx);
int
pl_inbox_prev
(
struct
pl_ctx
*
ctx
);
int
pl_inbox_delete
(
struct
pl_ctx
*
ctx
);
int
is_zero
(
const
char
*
data
,
int
len
);
#ifdef __cplusplus
}
/* end of extern "C" */
#endif
...
...
libs/pagerlib/things.c
View file @
374054d7
...
...
@@ -81,8 +81,7 @@ dump_buffer(unsigned int n, const unsigned char* buf)
BREAKOUT:
return
;
}
void
dump_buffer_msg
(
char
*
msg
,
unsigned
int
n
,
void
*
buf
)
void
dump_buffer_msg
(
char
*
msg
,
unsigned
int
n
,
void
*
buf
)
{
fprintf
(
stderr
,
"
\n
DBM: %s
\n
"
,
msg
);
dump_buffer
(
n
,
buf
);
...
...
libs/pagerlib/things.h
View file @
374054d7
...
...
@@ -2,6 +2,7 @@
// common.h
void
dump_buffer
(
unsigned
int
,
const
unsigned
char
*
);
void
dump_buffer_msg
(
char
*
msg
,
unsigned
int
n
,
void
*
buf
);
void
vli_print
(
char
*
,
uint8_t
*
,
unsigned
int
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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