use a tiny software AES lib if user needs AES-256

This commit is contained in:
Thomas Göttgens
2022-04-26 17:50:50 +02:00
parent d640478289
commit 76e48178c8
3 changed files with 275 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
#include "configuration.h"
#include "CryptoEngine.h"
#include <Adafruit_nRFCrypto.h>
#include "aes-256/tiny-aes.h"
class NRF52CryptoEngine : public CryptoEngine
{
public:
@@ -18,7 +18,12 @@ class NRF52CryptoEngine : public CryptoEngine
{
// DEBUG_MSG("NRF52 encrypt!\n");
if (key.length > 0) {
if (key.length > 16) {
AES_ctx ctx;
initNonce(fromNode, packetId);
AES_init_ctx_iv(&ctx, key.bytes, nonce);
AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes);
} else if (key.length > 0) {
nRFCrypto.begin();
nRFCrypto_AES ctx;
uint8_t myLen = ctx.blockLen(numBytes);
@@ -36,7 +41,12 @@ class NRF52CryptoEngine : public CryptoEngine
{
// DEBUG_MSG("NRF52 decrypt!\n");
if (key.length > 0) {
if (key.length > 16) {
AES_ctx ctx;
initNonce(fromNode, packetId);
AES_init_ctx_iv(&ctx, key.bytes, nonce);
AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes);
} else if (key.length > 0) {
nRFCrypto.begin();
nRFCrypto_AES ctx;
uint8_t myLen = ctx.blockLen(numBytes);