Skip to content

Commit d0fd80e

Browse files
committed
Fixed sent nonce buffering, hashing comparison.
1 parent 890658e commit d0fd80e

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

RF24Signing.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ extern RF24Mesh mesh;
7474

7575
uint8_t current_node_ID;
7676

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-
8577
uint8_t hmacKey2[] = {
8678
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
8779
0x15, 0x16, 0x17, 0x18, 0x19
@@ -91,9 +83,6 @@ void signed_network_begin(uint8_t passed_nodeID) {
9183
Serial.println(F("Signed network begun"));
9284
Serial.println((uint8_t)&current_node_ID);
9385
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());
9786
}
9887

9988
/*
@@ -113,10 +102,27 @@ void hash_data(void * payload, size_t payload_size) {
113102
Serial.println();
114103
}
115104

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+
116113
void hash_store(void * hash, void * result_hash) {
117114
memmove(result_hash, hash, sizeof(uint8_t[32]));
118115
}
119116

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+
120126
void requested_noncelist_print() {
121127
RequestedNonce * current = requested_noncelist_first;
122128
Serial.println(F("___ REQUESTED NONCE LIST DUMP ___"));
@@ -415,7 +421,11 @@ void sent_noncelist_remove(SentNonce * previous, SentNonce * current) {
415421
Serial.println((uint8_t) previous);
416422
Serial.print(F("Next: "));
417423
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+
}
419429
free(current);
420430
Serial.println(F("Removed nonce"));
421431
}
@@ -809,7 +819,7 @@ bool UnsignedNetworkAvailable(void) {
809819
hash_print(payload.hash);
810820

811821
free(buf);
812-
if (calculated_hash == payload.hash) {
822+
if (hash_compare(calculated_hash, payload.hash)) {
813823
Serial.println(F("EQUAL HASH?!"));
814824
} else {
815825
Serial.println(F("Inequal hash!"));

examples/helloworld_rx/helloworld_rx.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
22
Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
33
Copyright (C) 2014 TMRh20
4-
Copyright (C) 2016 Avamander <avamander@gmail.com>
4+
Copyright (C) 2017 Avamander <avamander@gmail.com>
55
This program is free software; you can redistribute it and/or
66
modify it under the terms of the GNU General Public License
77
version 2 as published by the Free Software Foundation.
88
*/
99

10-
/**BFE48206F706666666E736565746C7166203A65
10+
/**
1111
Simplest possible example of using RF24Signing. With neat serial commands.
1212
1313
RECEIVER NODE

examples/helloworld_tx/helloworld_tx.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
/*
33
Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
44
Copyright (C) 2014 TMRh20
5-
Copyright (C) 2016 Avamander <avamander@gmail.com>
5+
Copyright (C) 2017 Avamander <avamander@gmail.com>
66
This program is free software; you can redistribute it and/or
77
modify it under the terms of the GNU General Public License
88
version 2 as published by the Free Software Foundation.
99
*/
1010

1111
/**
12-
Simplest possible example of using RF24Network
12+
Simplest possible example of using RF24Signing
1313
1414
TRANSMITTER NODE
1515
Every 2 seconds, send a payload to the receiver node.

0 commit comments

Comments
 (0)