mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-13 02:22:55 +03:00
- 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.
This commit is contained in:
@ -25,30 +25,27 @@
|
||||
#include "EspnowProtocolInterpreter.h"
|
||||
#include "TypeConversionFunctions.h"
|
||||
#include <algorithm>
|
||||
#include "EspnowMeshBackend.h"
|
||||
|
||||
namespace EspnowProtocolInterpreter
|
||||
{
|
||||
const uint64_t uint64LeftmostBits = 0xFFFFFFFF00000000;
|
||||
|
||||
uint8_t espnowProtocolBytesSize()
|
||||
{
|
||||
uint8_t espnowMetadataSize()
|
||||
{
|
||||
return 16;
|
||||
return espnowProtocolBytesSize + (EspnowMeshBackend::useEncryptedMessages() ? aeadMetadataSize : 0);
|
||||
}
|
||||
|
||||
String espnowGetMessageContent(uint8_t *transmission, uint8_t transmissionLength)
|
||||
String espnowGetMessageContent(uint8_t *transmissionDataArray, uint8_t transmissionLength)
|
||||
{
|
||||
if(transmissionLength < espnowProtocolBytesSize())
|
||||
String messageContent = emptyString;
|
||||
|
||||
if(transmissionLength >= espnowMetadataSize())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure we have a NULL terminated character array so the String() constructor knows where to stop.
|
||||
uint8_t bufferedTransmission[transmissionLength + 1];
|
||||
std::copy_n(transmission, transmissionLength, bufferedTransmission);
|
||||
bufferedTransmission[transmissionLength] = 0;
|
||||
return String((char *)(bufferedTransmission + espnowProtocolBytesSize()));
|
||||
uint8_t messageSize = transmissionLength - espnowMetadataSize();
|
||||
|
||||
messageContent = uint8ArrayToMultiString(transmissionDataArray + espnowMetadataSize(), messageSize);
|
||||
}
|
||||
|
||||
return messageContent;
|
||||
}
|
||||
|
||||
char espnowGetMessageType(const uint8_t *transmissionDataArray)
|
||||
@ -79,22 +76,12 @@ namespace EspnowProtocolInterpreter
|
||||
|
||||
uint64_t espnowGetMessageID(const uint8_t *transmissionDataArray)
|
||||
{
|
||||
uint64_t outcome = 0;
|
||||
for(int shiftingFortune = 56; shiftingFortune >= 0; shiftingFortune -= 8)
|
||||
{
|
||||
outcome |= ((uint64_t)transmissionDataArray[espnowMessageIDIndex + 7 - shiftingFortune/8] << shiftingFortune);
|
||||
}
|
||||
|
||||
return outcome;
|
||||
return uint8ArrayToUint64(transmissionDataArray + espnowMessageIDIndex);
|
||||
}
|
||||
|
||||
uint8_t *espnowSetMessageID(uint8_t *transmissionDataArray, uint64_t messageID)
|
||||
{
|
||||
for(int shiftingFortune = 56; shiftingFortune >= 0; shiftingFortune -= 8)
|
||||
{
|
||||
transmissionDataArray[espnowMessageIDIndex + 7 - shiftingFortune/8] = messageID >> shiftingFortune & 0xFF;
|
||||
}
|
||||
return transmissionDataArray;
|
||||
return uint64ToUint8Array(messageID, transmissionDataArray + espnowMessageIDIndex);
|
||||
}
|
||||
|
||||
bool usesEncryption(uint64_t messageID)
|
||||
|
Reference in New Issue
Block a user