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