You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Make it possible to transfer Strings containing null values via ESP-NOW and FloodingMesh.
- Add uint8ArrayToMultiString and bufferedUint8ArrayToMultiString TypeConversionFunctions to facilitate transfer of Strings containing null values.
- Add HKDF to CryptoInterface.
- Add ChaCha20 + Poly1305 AEAD to CryptoInterface.
- Add customizable nonce generator to CryptoInterface.
- Add ability to automatically encrypt/decrypt ESP-NOW messages via AEAD (ChaCha20 + Poly1305), independent from encrypted ESP-NOW connections.
- Greatly improve performance of incrementSessionKey, espnowGetMessageID, espnowSetMessageID and all non-template TypeConversionFunctions. The average performance increase is roughly a factor 5. Fun fact: Printing a MAC to a HEX String is now over twice as fast when using TypeConversionFunctions compared to using standard functionality like sprintf.
- Add uint64ToUint8Array and uint8ArrayToUint64 TypeConversionFunctions.
- Make it possible to use String values as ESP-NOW and FloodingMesh key seeds, instead of just requiring plain key arrays.
- Add customizable responseTransmittedHook to sendEspnowResponses.
- Add _responsesToSendMutex to make the new responseTransmittedHook safe to use.
- Remove verboseModePrinting from sendPeerRequestConfirmations method to reduce performance variations.
- Fix faulty messageID generation in FloodingMesh.
- Make assert checks more complete and easier to understand in the setMetadataDelimiter method of FloodingMesh.
- Rename EspnowEncryptionKey to EspnowEncryptedConnectionKey since there are now multiple encryption keys.
- Rename acceptsUnencryptedRequests to acceptsUnverifiedRequests, unencryptedMessageID to unsynchronizedMessageID, receivedEncryptedMessage to receivedEncryptedTransmission, since there are now multiple modes of encryption.
- Rename resultArrayLength to outputLength in CryptoInterface and remove its value restrictions in order to match the BearSSL functionality.
- Improve performance of FloodingMesh::encryptedBroadcast.
- Rename FloodingMesh methods maxUnencryptedMessageSize/maxEncryptedMessageSize to maxUnencryptedMessageLength/maxEncryptedMessageLength, so that String length naming is consistent within the library.
- Update examples to illustrate the new features.
- Improve comments.
// A custom encryption key is required when using encrypted ESP-NOW transmissions. There is always a default Kok set, but it can be replaced if desired.
21
21
// All ESP-NOW keys below must match in an encrypted connection pair for encrypted communication to be possible.
22
-
uint8_t espnowEncryptionKey[16] = {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting transmissions.
23
-
0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x32, 0x11
24
-
};
25
-
uint8_t espnowEncryptionKok[16] = {0x22, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting the encryption key.
22
+
// Note that it is also possible to use Strings as key seeds instead of arrays.
23
+
uint8_t espnowEncryptedConnectionKey[16] = {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting transmissions of encrypted connections.
24
+
0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x32, 0x11
25
+
};
26
+
uint8_t espnowEncryptionKok[16] = {0x22, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting the encrypted connection key.
26
27
0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x32, 0x33
27
28
};
28
29
uint8_t espnowHashKey[16] = {0xEF, 0x44, 0x33, 0x0C, 0x33, 0x44, 0xFE, 0x44, // This is the secret key used for HMAC during encrypted connection requests.
// Note that when you modify firstTransmission it is best to avoid using substring or other String methods that rely on null values for String length determination.
176
+
// Otherwise your broadcasts cannot include null values in the message bytes.
// Currently this is exactly the same as the default hook, but you can modify it to alter the behaviour of sendEspnowResponses.
217
+
218
+
(void)response; // This is useful to remove a "unused parameter" compiler warning. Does nothing else.
219
+
(void)recipientMac;
220
+
(void)responseIndex;
221
+
(void)meshInstance;
222
+
223
+
returntrue;
224
+
}
225
+
196
226
voidsetup() {
197
227
// Prevents the flash memory from being worn out, see: https://github.com/esp8266/Arduino/issues/1054 .
198
228
// This will however delay node WiFi start-up by about 700 ms. The delay is 900 ms if we otherwise would have stored the WiFi network we want to connect to.
@@ -222,10 +252,10 @@ void setup() {
222
252
223
253
// Note: This changes the Kok for all EspnowMeshBackend instances on this ESP8266.
224
254
// Encrypted connections added before the Kok change will retain their old Kok.
225
-
// Both Kok and encryption key must match in an encrypted connection pair for encrypted communication to be possible.
255
+
// Both Kok and encrypted connection key must match in an encrypted connection pair for encrypted communication to be possible.
226
256
// Otherwise the transmissions will never reach the recipient, even though acks are received by the sender.
// Makes it possible to find the node through scans, and also makes it possible to recover from an encrypted connection where only the other node is encrypted.
231
261
// Note that only one AP can be active at a time in total, and this will always be the one which was last activated.
@@ -238,6 +268,21 @@ void setup() {
238
268
espnowNode.setMessage(String(F("Hello world request #")) + String(requestNumber) + String(F(" from ")) + espnowNode.getMeshName() + espnowNode.getNodeID() + String(F(".")));
// In addition to using encrypted ESP-NOW connections the framework can also send automatically encrypted messages (AEAD) over both encrypted and unencrypted connections.
274
+
// Using AEAD will only encrypt the message content, not the transmission metadata.
275
+
// The AEAD encryption does not require any pairing, and is thus faster for single messages than establishing a new encrypted connection before transfer.
276
+
// AEAD encryption also works with ESP-NOW broadcasts and supports an unlimited number of nodes, which is not true for encrypted connections.
277
+
// Encrypted ESP-NOW connections do however come with built in replay attack protection, which is not provided by the framework when using AEAD encryption,
278
+
// and allow EspnowProtocolInterpreter::aeadMetadataSize extra message bytes per transmission.
279
+
// Transmissions via encrypted connections are also slightly faster than via AEAD once a connection has been established.
280
+
//
281
+
// Uncomment the lines below to use automatic AEAD encryption/decryption of messages sent/received.
282
+
// All nodes this node wishes to communicate with must then also use encrypted messages with the same getEspnowMessageEncryptionKey(), or messages will not be accepted.
283
+
// Note that using AEAD encrypted messages will reduce the number of message bytes that can be transmitted.
284
+
//espnowNode.setEspnowMessageEncryptionKey("ChangeThisKeySeed_TODO"); // The message encryption key should always be set manually. Otherwise a default key (all zeroes) is used.
// A custom encryption key is required when using encrypted ESP-NOW transmissions. There is always a default Kok set, but it can be replaced if desired.
28
28
// All ESP-NOW keys below must match in an encrypted connection pair for encrypted communication to be possible.
29
-
uint8_t espnowEncryptionKey[16] = {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting transmissions.
30
-
0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x32, 0x11
31
-
};
29
+
// Note that it is also possible to use Strings as key seeds instead of arrays.
30
+
uint8_t espnowEncryptedConnectionKey[16] = {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, // This is the key for encrypting transmissions of encrypted connections.
31
+
0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x32, 0x11
32
+
};
32
33
uint8_t espnowHashKey[16] = {0xEF, 0x44, 0x33, 0x0C, 0x33, 0x44, 0xFE, 0x44, // This is the secret key used for HMAC during encrypted connection requests.
digitalWrite(LED_BUILTIN, LOW); // Turn LED on (LED_BUILTIN is active low)
146
147
}
147
148
149
+
// Uncomment the lines below to use automatic AEAD encryption/decryption of messages sent/received via broadcast() and encryptedBroadcast().
150
+
// The main benefit of AEAD encryption is that it can be used with normal broadcasts (which are substantially faster than encryptedBroadcasts).
151
+
// The main drawbacks are that AEAD only encrypts the message data (not transmission metadata), transfers less data per message and lacks replay attack protection.
152
+
// When using AEAD, potential replay attacks must thus be handled manually.
153
+
//floodingMesh.getEspnowMeshBackend().setEspnowMessageEncryptionKey("ChangeThisKeySeed_TODO"); // The message encryption key should always be set manually. Otherwise a default key (all zeroes) is used.
floodingMeshDelay(5000); // Give some time for user to start the nodes
149
157
}
150
158
@@ -171,7 +179,7 @@ void loop() {
171
179
uint32_t startTime = millis();
172
180
ledState = ledState ^ bool(benchmarkCount); // Make other nodes' LEDs alternate between on and off once benchmarking begins.
173
181
174
-
// Note: The maximum length of an unencrypted broadcast message is given by floodingMesh.maxUnencryptedMessageSize(). It is around 670 bytes by default.
182
+
// Note: The maximum length of an unencrypted broadcast message is given by floodingMesh.maxUnencryptedMessageLength(). It is around 670 bytes by default.
175
183
floodingMesh.broadcast(String(floodingMesh.metadataDelimiter()) + String(ledState) + theOneMac + " is The One.");
0 commit comments