-
Notifications
You must be signed in to change notification settings - Fork 1
/
RF24Signing.h
178 lines (113 loc) · 4.61 KB
/
RF24Signing.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
A transparent signing library for RF24Mesh
Copyright (C) 2017 Avamander <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sha256.h"
#include <Arduino.h>
#include <avr/pgmspace.h>
#include "RF24.h"
#include "RF24Mesh.h"
#include "RF24Network.h"
#include "sha256.h"
extern class RF24Network network;
extern class RF24Mesh mesh;
#ifndef __RF24Signing_H__
#define __RF24Signing_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SentNonce {
uint8_t toNodeID = 255;
uint32_t nonce = 0;
SentNonce * next = 0;
};
typedef struct ReceivedNonce {
uint8_t fromNodeId = 255;
uint32_t nonce = 0;
uint32_t receivedTimestamp = 0;
ReceivedNonce * next = 0;
};
typedef struct PayloadMetadata { //To calculate the size more easily
uint8_t hash[32] = {0};
uint8_t payload_size = 0;
};
typedef struct BufferListItem { //Buffer list item
uint8_t hash[32] = {0};
uint8_t payload_size = 0;
uint8_t BufferListItemForNode = 0;
BufferListItem * next = 0;
BufferListItem * payload = 0;
};
typedef struct payload_nonce {
uint32_t nonce = 0;
};
typedef struct RequestedNonce {
uint8_t fromNodeId = 255;
uint32_t time = 0;
uint32_t lastrequest = 0;
RequestedNonce * next = 0;
};
typedef struct {
Sha256Class Sha256;
//#import "hmacs.c"
SentNonce * sent_noncelist_first = 0;
ReceivedNonce * received_noncelist_first = 0;
RequestedNonce * requested_noncelist_first = 0;
BufferListItem * bufferlist_first = 0;
uint32_t bufferListMaintenanceTimer = 0;
uint32_t noncelistretrytimer = 0;
uint8_t current_node_ID;
} RF24Signing_;
void RF24Signing_signed_network_begin(uint8_t passed_nodeID);
void RF24Signing_hash_data(void * payload, size_t payload_size);
void RF24Signing_hash_print(uint8_t * hash);
void RF24Signing_hash_store(void * hash, void * result_hash);
bool RF24Signing_hash_compare(void * hash1, void * hash2);
void RF24Signing_requested_noncelist_print(void);
void RF24Signing_sent_noncelist_print(void);
void RF24Signing_bufferlist_print(void);
void RF24Signing_received_noncelist_print(void);
void RF24Signing_random_data_print(void * data, size_t size);
bool RF24Signing_sent_noncelist_initialize(void);
bool RF24Signing_received_noncelist_initialize(void);
bool RF24Signing_bufferlist_initialize(void);
bool RF24Signing_requested_noncelist_initialize(void);
void RF24Signing_request_nonce_from_node_id(uint8_t nodeID);
bool RF24Signing_requested_noncelist_add(uint8_t passed_nodeID);
bool RF24Signing_requested_noncelist_delete(RequestedNonce * previous, RequestedNonce * current);
bool RF24Signing_requested_noncelist_received(uint8_t passed_nodeID);
RequestedNonce * RF24Signing_requested_noncelist_find_for_nodeID(uint8_t passed_nodeID);
bool RF24Signing_requested_noncelist_retry_all(void);
bool RF24Signing_requested_noncelist_remove_timeout(void);
SentNonce * RF24Signing_sent_noncelist_find_from_ID(uint8_t nodeID);
bool RF24Signing_sent_noncelist_add(uint8_t toNodeID, uint32_t nonce);
void RF24Signing_sent_noncelist_remove(SentNonce * previous, SentNonce * current);
void RF24Signing_sent_noncelist_remove_timeout(void);
ReceivedNonce * RF24Signing_received_noncelist_find_from_ID(uint8_t nodeID);
bool RF24Signing_received_noncelist_add(uint8_t passed_fromNodeId, uint32_t passed_nonce);
void RF24Signing_received_noncelist_remove(ReceivedNonce * previous, ReceivedNonce * current);
void RF24Signing_received_noncelist_remove_timeout(void);
void RF24Signing_bufferlist_remove(BufferListItem * previous, BufferListItem * current);
BufferListItem * RF24Signing_bufferlist_find_for_id(uint8_t nodeID);
void RF24Signing_read_hmac_from_progmem(uint8_t nodeID, BufferListItem * hmac_pointer);
bool RF24Signing_bufferlist_send(BufferListItem * item, ReceivedNonce * nonce, BufferListItem * previousitem);
bool RF24Signing_bufferlist_add(uint8_t for_node, void * payload, uint8_t size);
void RF24Signing_bufferlist_send_all(void);
bool RF24Signing_unsigned_network_available(void);
void RF24Signing_signed_network_update(void);
#ifdef __cplusplus
}
#endif
//#ifdef __cplusplus
//#include "cpp_wrapper.h"
//#endif
#endif // __RF24_H__