Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/mesh/CryptoEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "CryptoEngine.h"
// #include "NodeDB.h"
#include "architecture.h"
#include <memory>

#if !(MESHTASTIC_EXCLUDE_PKI)
#include "NodeDB.h"
Expand Down Expand Up @@ -169,10 +170,9 @@ void CryptoEngine::hash(uint8_t *bytes, size_t numBytes)

void CryptoEngine::aesSetKey(const uint8_t *key_bytes, size_t key_len)
{
delete aes;
aes = nullptr;
if (key_len != 0) {
aes = new AESSmall256();
aes = std::unique_ptr<AESSmall256>(new AESSmall256());
aes->setKey(key_bytes, key_len);
Comment thread
Jorropo marked this conversation as resolved.
}
}
Expand Down Expand Up @@ -231,12 +231,11 @@ void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes
// Generic implementation of AES-CTR encryption.
void CryptoEngine::encryptAESCtr(CryptoKey _key, uint8_t *_nonce, size_t numBytes, uint8_t *bytes)
{
delete ctr;
ctr = nullptr;
std::unique_ptr<CTRCommon> ctr;
if (_key.length == 16)
ctr = new CTR<AES128>();
ctr = std::unique_ptr<CTRCommon>(new CTR<AES128>());
else
ctr = new CTR<AES256>();
ctr = std::unique_ptr<CTRCommon>(new CTR<AES256>());
Comment thread
Jorropo marked this conversation as resolved.
ctr->setKey(_key.bytes, _key.length);
static uint8_t scratch[MAX_BLOCKSIZE];
memcpy(scratch, bytes, numBytes);
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/CryptoEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "configuration.h"
#include "mesh-pb-constants.h"
#include <Arduino.h>
#include <memory>

extern concurrency::Lock *cryptLock;

Expand Down Expand Up @@ -48,7 +49,7 @@ class CryptoEngine
virtual void aesSetKey(const uint8_t *key, size_t key_len);

virtual void aesEncrypt(uint8_t *in, uint8_t *out);
AESSmall256 *aes = NULL;
std::unique_ptr<AESSmall256> aes = nullptr;

#endif

Expand Down Expand Up @@ -77,7 +78,6 @@ class CryptoEngine
/** Our per packet nonce */
uint8_t nonce[16] = {0};
CryptoKey key = {};
CTRCommon *ctr = NULL;
#if !(MESHTASTIC_EXCLUDE_PKI)
uint8_t shared_key[32] = {0};
uint8_t private_key[32] = {0};
Expand Down