@@ -74,14 +74,6 @@ extern RF24Mesh mesh;
74
74
75
75
uint8_t current_node_ID ;
76
76
77
- void hash_print (uint8_t * hash ) {
78
- for (int i = 0 ; i < 32 ; i ++ ) {
79
- Serial .print ("0123456789abcdef" [hash [i ] >> 4 ]);
80
- Serial .print ("0123456789abcdef" [hash [i ] & 0xf ]);
81
- }
82
- Serial .println ();
83
- }
84
-
85
77
uint8_t hmacKey2 [] = {
86
78
0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0x10 , 0x11 , 0x12 , 0x13 , 0x14 ,
87
79
0x15 , 0x16 , 0x17 , 0x18 , 0x19
@@ -91,9 +83,6 @@ void signed_network_begin(uint8_t passed_nodeID) {
91
83
Serial .println (F ("Signed network begun" ));
92
84
Serial .println ((uint8_t )& current_node_ID );
93
85
current_node_ID = passed_nodeID ;
94
- Sha256 .initHmac (hmacKey2 , 25 );
95
- for (uint8_t a = 0 ; a < 50 ; a ++ ) Sha256 .write (0xcd );
96
- hash_print (Sha256 .resultHmac ());
97
86
}
98
87
99
88
/*
@@ -113,10 +102,27 @@ void hash_data(void * payload, size_t payload_size) {
113
102
Serial .println ();
114
103
}
115
104
105
+ void hash_print (uint8_t * hash ) {
106
+ for (uint8_t i = 0 ; i < 32 ; i ++ ) {
107
+ Serial .print ("0123456789abcdef" [hash [i ] >> 4 ]);
108
+ Serial .print ("0123456789abcdef" [hash [i ] & 0xf ]);
109
+ }
110
+ Serial .println ();
111
+ }
112
+
116
113
void hash_store (void * hash , void * result_hash ) {
117
114
memmove (result_hash , hash , sizeof (uint8_t [32 ]));
118
115
}
119
116
117
+ bool hash_compare (void * hash1 , void * hash2 ){
118
+ for (uint8_t byte = 0 ; byte < 32 ; byte ++ ){
119
+ if (* (((uint8_t * )hash1 )+ byte ) != * (((uint8_t * )hash2 )+ byte )){
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+
120
126
void requested_noncelist_print () {
121
127
RequestedNonce * current = requested_noncelist_first ;
122
128
Serial .println (F ("___ REQUESTED NONCE LIST DUMP ___" ));
@@ -415,7 +421,11 @@ void sent_noncelist_remove(SentNonce * previous, SentNonce * current) {
415
421
Serial .println ((uint8_t ) previous );
416
422
Serial .print (F ("Next: " ));
417
423
Serial .println ((uint8_t ) current -> next );
418
- previous -> next = current -> next ;
424
+ if (previous != 0 ){
425
+ previous -> next = current -> next ;
426
+ } else {
427
+ sent_noncelist_first = 0 ;
428
+ }
419
429
free (current );
420
430
Serial .println (F ("Removed nonce" ));
421
431
}
@@ -809,7 +819,7 @@ bool UnsignedNetworkAvailable(void) {
809
819
hash_print (payload .hash );
810
820
811
821
free (buf );
812
- if (calculated_hash == payload .hash ) {
822
+ if (hash_compare ( calculated_hash , payload .hash ) ) {
813
823
Serial .println (F ("EQUAL HASH?!" ));
814
824
} else {
815
825
Serial .println (F ("Inequal hash!" ));
0 commit comments