-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgps_1.c
More file actions
53 lines (45 loc) · 1.6 KB
/
gps_1.c
File metadata and controls
53 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <string.h>
#include "gps_1.h"
#include "gps_types.h"
#include "crypto_1.h"
#include "crypto_types.h"
#include "key_management_1.h"
GPS_position current_destination;
enum GPS_return_status init_crypto_module() {
crypto_init();
crypto_key key = {0};
key_management_create_key(&key, sizeof(key));
if (crypto_set_key(key) == valid_key_provided) {
crypto_nonce nonce = {0};
key_management_create_nonce(&nonce, sizeof(nonce));
if (crypto_set_nonce(nonce) == valid_nonce_provided) {
return GPS_success;
}
}
return GPS_failure;
}
enum GPS_return_status set_destination_postition(GPS_position position) {
current_destination = position;
return GPS_success;
}
GPS_position get_destination_position() { return current_destination; }
enum GPS_return_status get_current_position(GPS_position *position) {
uint8_t position_as_bytes[12];
uint8_t hmac_as_bytes[HMAC_LENGTH];
if (GPS_driver_obtain_current_position(position_as_bytes, hmac_as_bytes) ==
0) {
if (crypto_verify_hmac(position_as_bytes, 16, hmac_as_bytes) ==
valid_hmac) {
GPS_position pos = {
(uint8_t)(position_as_bytes[0] << 1) + position_as_bytes[1],
(uint8_t)(position_as_bytes[2] << 1) + position_as_bytes[3],
(uint8_t)(position_as_bytes[4] << 1) + position_as_bytes[5],
(uint8_t)(position_as_bytes[6] << 1) + position_as_bytes[7],
(uint8_t)(position_as_bytes[8] << 1) + position_as_bytes[9],
(uint8_t)(position_as_bytes[10] << 1) + position_as_bytes[11]};
*position = pos;
return GPS_success;
}
}
return GPS_failure;
}