Files
firmware/src/nrf52/NRF52CryptoEngine.cpp
Thomas Göttgens 213d9512f1 WIP: unify the RAK targets into one firmware (#1350)
* First steps to unify GPS Lib for RAK 1910 and RAK 12500

* Technicalities. Out with the old and build the new.

* Adapt Matrix

* We use 0.4.5 now

* While we're at it, yank the RAK815, it's EOL

* Satisfy CI - for now

* - yank UBX library, talk to GPS chip with NMEA only.
- more autodetect going on, this time for the Eink Display.

TODO: actually do something with the scan findings.

* i swear this works on windows! :-)

* these are only there to make CI happy

* don't update eink display if not detected.

* Replace Oberon Crypt Library with modified Adafruit Library. This elimintaes the need for the sdk-nfxlib submodule.

* - Revert auto screen selection (incomplete)
- Revert nrF crypto engine (needs more work)
- add separate defines for not-auto-selecting screen lib.

* Define 2 new variants for RAK - with or without epaper

* Update variants

Co-authored-by: Sacha Weatherstone <sachaw100@hotmail.com>
Co-authored-by: Ben Meadors <thebentern@tuta.io>
2022-04-25 15:13:41 +10:00

94 lines
2.6 KiB
C++

#include "configuration.h"
#include "CryptoEngine.h"
#include "ocrypto_aes_ctr.h"
// #include <Adafruit_nRFCrypto.h>
class NRF52CryptoEngine : public CryptoEngine
{
public:
NRF52CryptoEngine() {}
~NRF52CryptoEngine() {}
/**
* Encrypt a packet
*
* @param bytes is updated in place
*/
virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
{
// DEBUG_MSG("NRF52 encrypt!\n");
if (key.length > 0) {
ocrypto_aes_ctr_ctx ctx;
initNonce(fromNode, packetId);
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
ocrypto_aes_ctr_encrypt(&ctx, bytes, bytes, numBytes);
}
}
virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
{
// DEBUG_MSG("NRF52 decrypt!\n");
if (key.length > 0) {
ocrypto_aes_ctr_ctx ctx;
initNonce(fromNode, packetId);
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes);
}
}
private:
};
// /**
// * Encrypt a packet
// *
// * @param bytes is updated in place
// */
// virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
// {
// DEBUG_MSG("NRF52 encrypt!\n");
// if (key.length > 0) {
// nRFCrypto_AES ctx;
// uint8_t myLen = ctx.blockLen(numBytes);
// char encBuf[myLen] = {0};
// memcpy(encBuf, bytes, numBytes);
// initNonce(fromNode, packetId);
// nRFCrypto.begin();
// ctx.begin();
// ctx.Process(encBuf, numBytes, nonce, key.bytes, key.length, (char*)bytes, ctx.encryptFlag, ctx.ctrMode);
// ctx.end();
// nRFCrypto.end();
// }
// }
// virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
// {
// DEBUG_MSG("NRF52 decrypt!\n");
// if (key.length > 0) {
// nRFCrypto_AES ctx;
// uint8_t myLen = ctx.blockLen(numBytes);
// char decBuf[myLen] = {0};
// memcpy(decBuf, bytes, numBytes);
// initNonce(fromNode, packetId);
// nRFCrypto.begin();
// ctx.begin();
// ctx.Process(decBuf, numBytes, nonce, key.bytes, key.length, (char*)bytes, ctx.decryptFlag, ctx.ctrMode);
// ctx.end();
// nRFCrypto.end();
// }
// }
// private:
// };
CryptoEngine *crypto = new NRF52CryptoEngine();