Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Encrypted CAN
daredevil-small
Commits
846db403
Commit
846db403
authored
6 years ago
by
Tmplt
Browse files
Options
Download
Patches
Plain Diff
feat: prefix sensor payload with init vector, MAC
parent
fe0e71e1
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+17
-6
src/main.rs
with
17 additions
and
6 deletions
+17
-6
src/main.rs
+
17
−
6
View file @
846db403
...
...
@@ -77,20 +77,31 @@ const APP: () = {
let
can
=
resources
.CAN
;
let
csec
=
resources
.CSEC
;
let
mut
sensor_bytes
:
[
u8
;
adc
::
CHANNEL_COUNT
*
2
]
=
[
0
;
adc
::
CHANNEL_COUNT
*
2
];
u8_array_from_16_array
(
&
adc
.read
(),
&
mut
sensor_bytes
);
let
mut
payload
:
[
u8
;
16
+
// message Authentication code
16
+
// initialization vector
adc
::
CHANNEL_COUNT
*
2
// Two u16
]
=
[
0
;
32
+
adc
::
CHANNEL_COUNT
*
2
];
// let mut sensor_bytes: [u8; adc::CHANNEL_COUNT * 2] = [0; adc::CHANNEL_COUNT * 2];
u8_array_from_16_array
(
&
adc
.read
(),
&
mut
payload
[
32
..
]);
// Randomize our initialization vector.
let
mut
init_vec
:
[
u8
;
16
]
=
[
0
;
16
];
csec
.generate_rnd
(
&
mut
init_vec
)
.unwrap
();
payload
[
16
..
32
]
.clone_from_slice
(
&
init_vec
);
// Encrypt the sensor data.
let
mut
payloa
d
:
[
u8
;
16
+
adc
::
CHANNEL_COUNT
*
2
]
=
[
0
;
16
+
adc
::
CHANNEL_COUNT
*
2
];
csec
.encrypt_cbc
(
&
sensor_bytes
,
&
init_vec
,
&
mut
payload
[
16
..
])
let
mut
encrypte
d
:
[
u8
;
adc
::
CHANNEL_COUNT
*
2
]
=
[
0
;
adc
::
CHANNEL_COUNT
*
2
];
csec
.encrypt_cbc
(
&
payload
[
32
..
]
,
&
init_vec
,
&
mut
encrypted
[
..
])
.unwrap
();
payload
[
32
..
]
.clone_from_slice
(
&
encrypted
);
// Generate a MAC (Message Authentication Code) for our payload
let
mut
cmac
:
[
u8
;
16
]
=
[
0
;
16
];
csec
.generate_mac
(
&
payload
[
16
..
],
&
mut
cmac
)
.unwrap
();
payload
[
..
16
]
.clone_from_slice
(
&
cmac
);
// Transmit the payload, with a prefixed initialization vector.
payload
[
..
16
]
.clone_from_slice
(
&
init_vec
);
can
.transmit
(
&
payload
);
schedule
.poll_sensor
(
scheduled
+
PERIOD
.cycles
())
.unwrap
();
...
...
This diff is collapsed.
Click to expand it.
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!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets