2020-05-09 23:15:01 +00:00
|
|
|
#include "configuration.h"
|
2021-06-27 17:56:28 +00:00
|
|
|
#include "CryptoEngine.h"
|
2020-05-09 23:15:01 +00:00
|
|
|
|
2021-02-23 02:10:35 +00:00
|
|
|
void CryptoEngine::setKey(const CryptoKey &k)
|
2020-05-09 23:15:01 +00:00
|
|
|
{
|
2022-06-04 08:37:24 +00:00
|
|
|
DEBUG_MSG("Using AES%d key!\n", k.length * 8);
|
2021-02-23 02:10:35 +00:00
|
|
|
key = k;
|
2020-05-09 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encrypt a packet
|
|
|
|
*
|
|
|
|
* @param bytes is updated in place
|
|
|
|
*/
|
2022-03-20 00:40:13 +00:00
|
|
|
void CryptoEngine::encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes)
|
2020-05-10 00:51:20 +00:00
|
|
|
{
|
|
|
|
DEBUG_MSG("WARNING: noop encryption!\n");
|
|
|
|
}
|
2020-05-09 23:15:01 +00:00
|
|
|
|
2022-03-20 00:40:13 +00:00
|
|
|
void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes)
|
2020-05-10 00:51:20 +00:00
|
|
|
{
|
|
|
|
DEBUG_MSG("WARNING: noop decryption!\n");
|
2020-05-10 02:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init our 128 bit nonce for a new packet
|
|
|
|
*/
|
2022-03-20 00:40:13 +00:00
|
|
|
void CryptoEngine::initNonce(uint32_t fromNode, uint64_t packetId)
|
2020-05-10 02:08:04 +00:00
|
|
|
{
|
|
|
|
memset(nonce, 0, sizeof(nonce));
|
2021-08-02 17:50:28 +00:00
|
|
|
|
|
|
|
// use memcpy to avoid breaking strict-aliasing
|
2022-03-20 00:40:13 +00:00
|
|
|
memcpy(nonce, &packetId, sizeof(uint64_t));
|
2021-08-02 17:50:28 +00:00
|
|
|
memcpy(nonce + sizeof(uint64_t), &fromNode, sizeof(uint32_t));
|
2020-05-10 00:51:20 +00:00
|
|
|
}
|