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
d11c8deb
Commit
d11c8deb
authored
Dec 06, 2015
by
yids
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- some stuff on key generator
- some cleaning up and defining
parent
6c691b4e
Pipeline
#16
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
39 deletions
+53
-39
arduino-rx/arduino-rx.ino
arduino-rx/arduino-rx.ino
+32
-27
arduino-tx/arduino-tx.ino
arduino-tx/arduino-tx.ino
+21
-12
No files found.
arduino-rx/arduino-rx.ino
View file @
d11c8deb
...
...
@@ -19,7 +19,7 @@
#define BLOCK_SIZE 16
#define NUM_BLOCKS 4
#define NUM_ECC_DIGITS 24 //size of privkey, curvesize in bytes
#define CURVE uECC_secp192r1()
LCDI2C
lcd
=
LCDI2C
(
2
,
16
,
0x50
,
0
);
aes_context
ctx
;
// context for the cbc crypto stuff
...
...
@@ -28,9 +28,16 @@ aes_context ctx; // context for the cbc crypto stuff
RH_ASK
driver
(
5000
);
RHDatagram
manager
(
driver
,
ADDRESS
);
// uECC keys
uint8_t
privkey
[
25
]
=
{
0x50
,
0xEA
,
0x8F
,
0x57
,
0xFD
,
0xBE
,
0x75
,
0xAE
,
0x17
,
0x70
,
0xC6
,
0xF0
,
0x51
,
0x11
,
0x5C
,
0xA
,
0xF6
,
0xFE
,
0xCF
,
0x4
,
0xC9
,
0xBD
,
0xFC
,
0x7D
,
0xD6
};
uint8_t
pubkey
[
48
]
=
{
0x27
,
0x8C
,
0x41
,
0x2C
,
0x1F
,
0xF2
,
0xA9
,
0xCB
,
0x78
,
0xC4
,
0x1E
,
0xBB
,
0x2B
,
0x32
,
0x32
,
0x34
,
0xC3
,
0x5B
,
0xD1
,
0x87
,
0x52
,
0x6C
,
0xBD
,
0x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0x8E
,
0xCD
,
0x31
,
0x88
,
0x50
,
0x2D
,
0xE6
,
0x53
,
0x49
,
0xE8
,
0xC0
,
0xB4
,
0xB5
,
0xC6
,
0x4F
,
0x97
,
0x7F
,
0x6B
};
uint8_t
privkey
[
NUM_ECC_DIGITS
+
1
]
=
{
0xAD
,
0x98
,
0x8E
,
0xC4
,
0x79
,
0x1D
,
0xE0
,
0x2C
,
0xEE
,
0xF8
,
0xB0
,
0xAA
,
0xC9
,
0x3E
,
0x6F
,
0x9D
,
0x1E
,
0x5E
,
0xF7
,
0x96
,
0xD7
,
0x3F
,
0x7F
,
0x2E
,
0xF4
};
uint8_t
*
generateIV
()
{
...
...
@@ -112,30 +119,31 @@ static int RNG(uint8_t *dest, unsigned size) {
void
generateKeys
()
{
const
struct
uECC_Curve_t
*
curve
=
uECC_secp192r1
();
uint8_t
private1
[
25
];
uint8_t
public1
[
48
];
uint8_t
secret1
[
24
];
Serial
.
println
(
"generating keys"
);
const
struct
uECC_Curve_t
*
curve
=
CURVE
;
uint8_t
private1
[
NUM_ECC_DIGITS
+
1
];
uint8_t
public1
[
NUM_ECC_DIGITS
*
2
];
uint8_t
secret1
[
NUM_ECC_DIGITS
];
unsigned
long
a
=
millis
();
uECC_make_key
(
public1
,
private1
,
curve
);
unsigned
long
b
=
millis
();
Serial
.
print
(
"Generated keypair in "
);
Serial
.
print
(
b
-
a
);
Serial
.
println
(
"Milliseconds"
);
Serial
.
print
ln
(
"Public key:
"
);
Serial
.
print
(
"uint8_t pubkey[NUM_ECC_DIGITS*2] = {
"
);
for
(
int
i
=
0
;
i
<
sizeof
(
public1
);
i
++
){
Serial
.
print
(
"0x"
);
Serial
.
print
(
public1
[
i
],
HEX
);
Serial
.
print
(
", "
);
}
Serial
.
println
(
""
);
Serial
.
print
ln
(
"Private key:
"
);
Serial
.
println
(
"
}
"
);
Serial
.
print
(
"uint8_t privkey[NUM_ECC_DIGITS+1] = {
"
);
for
(
int
i
=
0
;
i
<
sizeof
(
private1
);
i
++
){
Serial
.
print
(
"0x"
);
Serial
.
print
(
private1
[
i
],
HEX
);
Serial
.
print
(
", "
);
}
Serial
.
println
(
""
);
Serial
.
println
(
"
}
"
);
}
void
setup
()
...
...
@@ -164,12 +172,12 @@ void hashSecret(uint8_t *p_secret)
void
loop
()
{
// generateKeys(); function to generate keys, have to make a program for this to run on a computer
// generateKeys();
//
function to generate keys, have to make a program for this to run on a computer
// crypto vars //
uint8_t
remotePubkey
[
48
];
uint8_t
sharedSecret
[
NUM_ECC_DIGITS
];
const
struct
uECC_Curve_t
*
curve
=
uECC_secp192r1
()
;
const
struct
uECC_Curve_t
*
curve
=
CURVE
;
// Radio vars //
uint8_t
*
receivedData
;
...
...
@@ -186,20 +194,17 @@ void loop()
Serial
.
print
(
" : "
);
Serial
.
print
(
id
);
Serial
.
println
(
" : "
);
if
(
id
==
50
){
// receiving a public key...
for
(
int
i
=
0
;
i
<
NUM_ECC_DIGITS
*
2
;
i
++
){
remotePubkey
[
i
]
=
buf
[
i
];
//Serial.println(remotePubkey.x[i]);
}
}
if
(
id
==
50
){
// receiving a public key...
for
(
int
i
=
0
;
i
<
NUM_ECC_DIGITS
*
2
;
i
++
){
remotePubkey
[
i
]
=
buf
[
i
];
}
}
if
(
id
==
51
){
// receiving an encrypted message...
Serial
.
println
(
"Storing received message"
);
receivedData
=
buf
;
Serial
.
println
((
char
*
)
receivedData
);
}
if
(
id
==
51
){
// receiving an encrypted message...
Serial
.
println
(
"Storing received message"
);
receivedData
=
buf
;
Serial
.
println
((
char
*
)
receivedData
);
}
}
if
(
uECC_valid_public_key
(
remotePubkey
,
curve
)
==
1
){
...
...
arduino-tx/arduino-tx.ino
View file @
d11c8deb
...
...
@@ -17,15 +17,24 @@
#define ADDRESS 5
#define NUM_ECC_DIGITS 24 //size of privkey, curvesize in bytes
#define CURVE uECC_secp192r1()
aes_context
ctx
;
RH_ASK
driver
(
5000
);
RHDatagram
manager
(
driver
,
ADDRESS
);
// uECC keys
uint8_t
privkey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x26
,
0x85
,
0x78
,
0xFD
,
0xCA
,
0xF4
};
uint8_t
remotePubkey
[
48
]
=
{
0x27
,
0x8C
,
0x
41
,
0x
2C
,
0x
1F
,
0xF
2
,
0x
A
9
,
0x
CB
,
0x7
8
,
0x
C4
,
0x1
E
,
0x
BB
,
0x
2
B
,
0x
32
,
0x32
,
0x
34
,
0x
C3
,
0x
5
B
,
0x
D1
,
0x8
7
,
0x
52
,
0x
6
C
,
0x
BD
,
0x7
F
,
0x
44
,
0x
7
3
,
0x
D
C
,
0x
F0
,
0x
FC
,
0x
93
,
0x
97
,
0x
99
,
0x
46
,
0x
16
,
0x
E0
,
0x
8F
,
0x
6
5
,
0x
A
4
,
0x
CB
,
0x
65
,
0x59
,
0x
A8
,
0xB
F
,
0x
FD
,
0x
B
4
,
0x
61
,
0x
23
,
0x
A8
};
uint8_t
remotePubkey
[
NUM_ECC_DIGITS
*
2
]
=
{
0x99
,
0x61
,
0xB5
,
0x38
,
0x
B3
,
0x
83
,
0x
7E
,
0xF
B
,
0x
D
9
,
0x
3F
,
0x7
1
,
0x
A3
,
0x
8
1
,
0x
77
,
0xB
0
,
0x
48
,
0x32
,
0x
29
,
0x
24
,
0x
6
B
,
0x7
6
,
0x
48
,
0x
9
C
,
0x
7A
,
0x7
0
,
0x
FD
,
0x3
F
,
0xC
4
,
0x
B8
,
0x
AB
,
0x
8E
,
0x
CD
,
0x
31
,
0x
88
,
0x
50
,
0x
2D
,
0x
E6
,
0x5
3
,
0x4
9
,
0x
E8
,
0x
C0
,
0x
B4
,
0xB
5
,
0x
C6
,
0x4
F
,
0x
97
,
0x
7F
,
0x
6B
};
uint8_t
*
generateIV
()
{
...
...
@@ -41,7 +50,7 @@ uint8_t* generateIV()
return
buffer
;
}
char
*
encryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
,
const
aes_context
ctx
)
char
*
encryptAES
(
char
*
p_data
,
const
aes_context
ctx
)
{
Serial
.
print
(
"data:"
);
Serial
.
println
(
p_data
);
...
...
@@ -52,7 +61,7 @@ char* encryptAES(uint8_t* p_secret, char* p_data, const aes_context ctx)
return
p_data
;
}
char
*
decryptAES
(
uint8_t
*
p_secret
,
char
*
p_data
,
const
aes_context
ctx
)
char
*
decryptAES
(
char
*
p_data
,
const
aes_context
ctx
)
{
Serial
.
print
(
"decrypting data..."
);
aes128_cbc_dec_continue
(
ctx
,
p_data
,
BLOCK_SIZE
*
NUM_BLOCKS
);
...
...
@@ -119,11 +128,11 @@ void hashSecret(uint8_t *p_secret)
void
loop
()
{
// crypto vars //
uint8_t
sharedSecret
[
24
];
const
struct
uECC_Curve_t
*
curve
=
uECC_secp192r1
()
;
//
char* data = "Hallo";
//
char* encryptedData;
//
uint8_t iv[16] = {4,9,4,9,4,9,4,9,4,9,4,9,4,9,4,9};
uint8_t
sharedSecret
[
NUM_ECC_DIGITS
];
const
struct
uECC_Curve_t
*
curve
=
CURVE
;
char
*
data
=
"Hallo"
;
char
*
encryptedData
;
uint8_t
iv
[
16
]
=
{
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
,
4
,
9
};
sendPubkey
();
if
(
uECC_valid_public_key
(
remotePubkey
,
curve
)
==
1
){
...
...
@@ -136,7 +145,7 @@ void loop()
// ctx = aes128_cbc_enc_start(&sharedSecret, iv);
// encryptedData = encryptAES(
&sharedSecret,
data, ctx);
// encryptedData = encryptAES(data, ctx);
//
...
...
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