mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-05 21:31:47 +00:00
Merge pull request #1405 from meshtastic/rak-hw-crypto
use nRF52 Hardware Cryptography
This commit is contained in:
commit
d640478289
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,9 +1,6 @@
|
|||||||
[submodule "proto"]
|
[submodule "proto"]
|
||||||
path = proto
|
path = proto
|
||||||
url = https://github.com/meshtastic/Meshtastic-protobufs.git
|
url = https://github.com/meshtastic/Meshtastic-protobufs.git
|
||||||
[submodule "sdk-nrfxlib"]
|
|
||||||
path = sdk-nrfxlib
|
|
||||||
url = https://github.com/nrfconnect/sdk-nrfxlib.git
|
|
||||||
[submodule "design"]
|
[submodule "design"]
|
||||||
path = design
|
path = design
|
||||||
url = https://github.com/meshtastic/meshtastic-design.git
|
url = https://github.com/meshtastic/meshtastic-design.git
|
||||||
|
@ -130,7 +130,6 @@ build_type = debug ; I'm debugging with ICE a lot now
|
|||||||
build_flags =
|
build_flags =
|
||||||
${arduino_base.build_flags} -Wno-unused-variable
|
${arduino_base.build_flags} -Wno-unused-variable
|
||||||
-Isrc/nrf52
|
-Isrc/nrf52
|
||||||
-Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.7
|
|
||||||
src_filter =
|
src_filter =
|
||||||
${arduino_base.src_filter} -<esp32/> -<nimble/> -<mesh/wifi/> -<mesh/http/> -<modules/esp32> -<mqtt/>
|
${arduino_base.src_filter} -<esp32/> -<nimble/> -<mesh/wifi/> -<mesh/http/> -<modules/esp32> -<mqtt/>
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
@ -142,8 +141,7 @@ build_flags = ${nrf52_base.build_flags}
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${arduino_base.lib_deps}
|
${arduino_base.lib_deps}
|
||||||
${environmental.lib_deps}
|
${environmental.lib_deps}
|
||||||
Adafruit nRFCrypto
|
https://github.com/Kongduino/Adafruit_nRFCrypto.git
|
||||||
; https://github.com/Kongduino/Adafruit_nRFCrypto.git
|
|
||||||
|
|
||||||
; Note: By default no lora device is created for this build - it uses a simulated interface
|
; Note: By default no lora device is created for this build - it uses a simulated interface
|
||||||
[env:nrf52840dk]
|
[env:nrf52840dk]
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Subproject commit e6e02cb83d238fae2f54f084858bd5e49a31afa1
|
|
@ -1,7 +1,6 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "CryptoEngine.h"
|
#include "CryptoEngine.h"
|
||||||
#include "ocrypto_aes_ctr.h"
|
#include <Adafruit_nRFCrypto.h>
|
||||||
// #include <Adafruit_nRFCrypto.h>
|
|
||||||
|
|
||||||
class NRF52CryptoEngine : public CryptoEngine
|
class NRF52CryptoEngine : public CryptoEngine
|
||||||
{
|
{
|
||||||
@ -20,12 +19,16 @@ class NRF52CryptoEngine : public CryptoEngine
|
|||||||
// DEBUG_MSG("NRF52 encrypt!\n");
|
// DEBUG_MSG("NRF52 encrypt!\n");
|
||||||
|
|
||||||
if (key.length > 0) {
|
if (key.length > 0) {
|
||||||
ocrypto_aes_ctr_ctx ctx;
|
nRFCrypto.begin();
|
||||||
|
nRFCrypto_AES ctx;
|
||||||
|
uint8_t myLen = ctx.blockLen(numBytes);
|
||||||
|
char encBuf[myLen] = {0};
|
||||||
|
memcpy(encBuf, bytes, numBytes);
|
||||||
initNonce(fromNode, packetId);
|
initNonce(fromNode, packetId);
|
||||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
ctx.begin();
|
||||||
|
ctx.Process(encBuf, numBytes, nonce, key.bytes, key.length, (char*)bytes, ctx.encryptFlag, ctx.ctrMode);
|
||||||
ocrypto_aes_ctr_encrypt(&ctx, bytes, bytes, numBytes);
|
ctx.end();
|
||||||
|
nRFCrypto.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,60 +37,20 @@ class NRF52CryptoEngine : public CryptoEngine
|
|||||||
// DEBUG_MSG("NRF52 decrypt!\n");
|
// DEBUG_MSG("NRF52 decrypt!\n");
|
||||||
|
|
||||||
if (key.length > 0) {
|
if (key.length > 0) {
|
||||||
ocrypto_aes_ctr_ctx ctx;
|
nRFCrypto.begin();
|
||||||
|
nRFCrypto_AES ctx;
|
||||||
|
uint8_t myLen = ctx.blockLen(numBytes);
|
||||||
|
char decBuf[myLen] = {0};
|
||||||
|
memcpy(decBuf, bytes, numBytes);
|
||||||
initNonce(fromNode, packetId);
|
initNonce(fromNode, packetId);
|
||||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
ctx.begin();
|
||||||
|
ctx.Process(decBuf, numBytes, nonce, key.bytes, key.length, (char*)bytes, ctx.decryptFlag, ctx.ctrMode);
|
||||||
ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes);
|
ctx.end();
|
||||||
|
nRFCrypto.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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();
|
CryptoEngine *crypto = new NRF52CryptoEngine();
|
||||||
|
Loading…
Reference in New Issue
Block a user