mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
Crypto works!
This commit is contained in:
@@ -5,27 +5,46 @@
|
||||
/**
|
||||
* see docs/software/crypto.md for details.
|
||||
*
|
||||
* The NONCE is constructed by concatenating:
|
||||
* a 32 bit sending node number + a 64 bit packet number + a 32 bit block counter (starts at zero)
|
||||
*/
|
||||
|
||||
class CryptoEngine
|
||||
{
|
||||
protected:
|
||||
/** Our per packet nonce */
|
||||
uint8_t nonce[16];
|
||||
|
||||
public:
|
||||
virtual ~CryptoEngine() {}
|
||||
|
||||
/**
|
||||
* Set the key used for encrypt, decrypt.
|
||||
*
|
||||
* As a special case: If all bytes are zero, we assume _no encryption_ and send all data in cleartext.
|
||||
*
|
||||
* @param numBytes must be 32 for now (AES256)
|
||||
* @param numBytes must be 16 (AES128), 32 (AES256) or 0 (no crypt)
|
||||
* @param bytes a _static_ buffer that will remain valid for the life of this crypto instance (i.e. this class will cache the
|
||||
* provided pointer)
|
||||
*/
|
||||
void setKey(size_t numBytes, const uint8_t *bytes);
|
||||
virtual void setKey(size_t numBytes, uint8_t *bytes);
|
||||
|
||||
/**
|
||||
* Encrypt a packet
|
||||
*
|
||||
* @param bytes is updated in place
|
||||
*/
|
||||
void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
|
||||
void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
|
||||
};
|
||||
virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
|
||||
virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Init our 128 bit nonce for a new packet
|
||||
*
|
||||
* The NONCE is constructed by concatenating (from MSB to LSB):
|
||||
* a 64 bit packet number (stored in little endian order)
|
||||
* a 32 bit sending node number (stored in little endian order)
|
||||
* a 32 bit block counter (starts at zero)
|
||||
*/
|
||||
void initNonce(uint32_t fromNode, uint64_t packetNum);
|
||||
};
|
||||
|
||||
extern CryptoEngine *crypto;
|
||||
|
||||
Reference in New Issue
Block a user