Skip to content
GitLab
Menu
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
3b56c073
Commit
3b56c073
authored
Nov 30, 2015
by
yids
Browse files
now uses cbc to sent bigger messages
parent
5331afd0
Pipeline
#4
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
arduino-rx/arduino-rx.ino
View file @
3b56c073
...
...
@@ -10,6 +10,12 @@
#include <RadioHead.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include <string.h>
#define BLOCK_SIZE 16
#define NUM_BLOCKS 4
aes_context
ctx
;
// context for the cbc crypto stuff
RH_ASK
driver
;
...
...
@@ -24,6 +30,7 @@ EccPoint remotePubkey = {
{
0x90
,
0x6F
,
0xFC
,
0xC8
,
0x07
,
0xA8
,
0x93
,
0x9C
,
0x3B
,
0xDC
,
0xAF
,
0xF1
,
0x8D
,
0xA9
,
0x96
,
0xF8
,
0xC2
,
0x3B
,
0x85
,
0x3E
,
0x5C
,
0x65
,
0xDE
,
0x32
},
{
0xE1
,
0xB1
,
0x28
,
0x7F
,
0xD3
,
0xB0
,
0x94
,
0x24
,
0x69
,
0x95
,
0xDE
,
0x76
,
0x40
,
0x15
,
0x6E
,
0xAE
,
0x74
,
0xE9
,
0x56
,
0x94
,
0xA7
,
0xE4
,
0x63
,
0xEF
}};
void
p
(
char
*
fmt
,
...
){
char
tmp
[
128
];
// resulting string limited to 128 chars
va_list
args
;
...
...
@@ -41,21 +48,36 @@ void dump(char *text, uint8_t *d) {
Serial
.
print
(
"
\n
"
);
}
char
*
encryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
)
uint8_t
*
generateIV
(
)
{
Serial
.
print
(
"
\n
"
);
Serial
.
println
(
"encoding data..."
);
uint8_t
buffer
[
BLOCK_SIZE
];
Serial
.
println
(
"generating IV..."
);
for
(
int
i
=
0
;
i
<
BLOCK_SIZE
;
i
++
){
buffer
[
i
]
=
random
(
64
);
}
for
(
int
i
=
0
;
i
<
17
;
i
++
){
Serial
.
print
(
buffer
[
i
]);
}
Serial
.
println
(
""
);
return
buffer
;
}
char
*
encryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
,
const
aes_context
ctx
)
{
Serial
.
print
(
"data:"
);
Serial
.
println
(
p_data
);
aes128_enc_single
(
p_secret
,
p_data
);
Serial
.
print
(
"encrypting data..."
);
aes128_cbc_enc_continue
(
ctx
,
p_data
,
BLOCK_SIZE
*
NUM_BLOCKS
);
aes128_cbc_enc_finish
(
ctx
);
Serial
.
println
(
"done"
);
return
p_data
;
}
char
*
decryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
)
char
*
decryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
,
const
aes_context
ctx
)
{
Serial
.
print
(
"
\n
"
);
Serial
.
println
(
"decoding data..."
);
aes128_dec_
s
in
gle
(
p_secret
,
p_data
);
Serial
.
print
(
"
decrypting data...
"
);
aes128_cbc_dec_continue
(
ctx
,
p_data
,
BLOCK_SIZE
*
NUM_BLOCKS
);
aes128_
cbc_
dec_
f
in
ish
(
ctx
);
Serial
.
println
(
"done"
);
return
p_data
;
}
...
...
@@ -77,26 +99,31 @@ void setup()
Serial
.
println
(
"hoi"
);
if
(
!
driver
.
init
())
Serial
.
println
(
"init failed"
);
randomSeed
(
analogRead
(
0
));
}
void
loop
()
{
// Crypto //
uint8_t
sharedSecret
=
calcSharedSecret
(
&
remotePubkey
,
privkey
)
;
char
*
data
=
"Hallo dit is een testbericht jwz"
;
char
data
[]
=
"0123456789012345"
;
char
*
enc
od
edData
;
char
*
dec
od
edData
;
uint8_t
sharedSecret
=
calcSharedSecret
(
&
remotePubkey
,
privkey
)
;
char
*
enc
rypt
edData
;
char
*
dec
rypt
edData
;
encodedData
=
encryptAES
(
&
sharedSecret
,
data
);
Serial
.
print
(
"encoded data:"
);
Serial
.
println
(
encodedData
);
// uint8_t* iv = generateIV();
uint8_t
iv
[
16
]
=
{
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
};
ctx
=
aes128_cbc_enc_start
(
&
sharedSecret
,
iv
);
encryptedData
=
encryptAES
(
&
sharedSecret
,
data
,
ctx
);
decodedData
=
decryptAES
(
&
sharedSecret
,
encodedData
);
Serial
.
print
(
"decoded data:"
);
Serial
.
println
(
decodedData
);
ctx
=
aes128_cbc_enc_start
(
&
sharedSecret
,
iv
);
decryptedData
=
decryptAES
(
&
sharedSecret
,
encryptedData
,
ctx
);
Serial
.
print
(
"decrypted data:"
);
Serial
.
println
(
decryptedData
);
Serial
.
println
(
""
);
// Radio //
/*
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
...
...
@@ -107,4 +134,5 @@ void loop()
// Message with a good checksum received, dump it.
driver.printBuffer("Got encrypted:", buf, buflen);
}
*/
}
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