mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-22 12:24:22 +00:00
Merge branch 'PowerSaving-v17' of https://github.com/IoTThinks/MeshCore into keymindCascade
# Conflicts: # examples/companion_radio/MyMesh.cpp # examples/companion_radio/NodePrefs.h # examples/simple_repeater/MyMesh.cpp # examples/simple_room_server/MyMesh.cpp # examples/simple_sensor/SensorMesh.cpp # platformio.ini # src/MeshCore.h # src/helpers/CommonCLI.cpp # src/helpers/CommonCLI.h # src/helpers/radiolib/CustomSX1262Wrapper.h # src/helpers/radiolib/CustomSX1268Wrapper.h # src/helpers/radiolib/LR11x0Reset.h # src/helpers/radiolib/SX126xReset.h
This commit is contained in:
+21
-11
@@ -5,8 +5,9 @@
|
||||
#include <Ed25519.h>
|
||||
|
||||
#ifdef USE_CC310_HW_CRYPTO
|
||||
#include <Adafruit_nRFCrypto.h>
|
||||
#include "helpers/NRF52Crypto.h"
|
||||
#include "nrf_cc310/include/crys_ec_edw_api.h"
|
||||
#include "nrf_cc310/include/crys_ec_mont_edw_error.h"
|
||||
#endif
|
||||
|
||||
namespace mesh {
|
||||
@@ -21,20 +22,29 @@ Identity::Identity(const char* pub_hex) {
|
||||
}
|
||||
|
||||
bool Identity::verify(const uint8_t* sig, const uint8_t* message, int msg_len) const {
|
||||
if (sig == NULL || message == NULL || msg_len < 0) return false;
|
||||
|
||||
#ifdef USE_CC310_HW_CRYPTO
|
||||
// nRF52840 CryptoCell CC310 hardware Ed25519 verification. The software
|
||||
// implementations need ~3KB of stack (which can overflow the Adafruit core's
|
||||
// 4KB loop task stack from the advert receive path); the hardware path
|
||||
// needs much less, around 600-700bytes. The CC310 workspace is static, faster,
|
||||
// should save power at scale as well.
|
||||
static CRYS_ECEDW_TempBuff_t cc310_tmp;
|
||||
nRFCrypto.begin();
|
||||
CRYSError_t rc = CRYS_ECEDW_Verify((uint8_t*)sig, CRYS_ECEDW_SIGNATURE_BYTES,
|
||||
(uint8_t*)pub_key, CRYS_ECEDW_MOD_SIZE_IN_BYTES,
|
||||
(uint8_t*)message, (size_t)msg_len, &cc310_tmp);
|
||||
nRFCrypto.end();
|
||||
return rc == CRYS_OK;
|
||||
#elif 0
|
||||
// needs much less, around 600-700 bytes. Access is serialized because the
|
||||
// workspace and the CC310 driver are not reentrant.
|
||||
CC310CryptoSession session;
|
||||
if (session) {
|
||||
static CRYS_ECEDW_TempBuff_t cc310_tmp;
|
||||
const CRYSError_t rc = CRYS_ECEDW_Verify(
|
||||
const_cast<uint8_t*>(sig), CRYS_ECEDW_SIGNATURE_BYTES,
|
||||
const_cast<uint8_t*>(pub_key), CRYS_ECEDW_MOD_SIZE_IN_BYTES,
|
||||
const_cast<uint8_t*>(message), static_cast<size_t>(msg_len), &cc310_tmp);
|
||||
if (rc == CRYS_OK) return true;
|
||||
// A normal signature mismatch is a conclusive hardware result. Other
|
||||
// CC310 errors fall through to the correctness-preserving software path.
|
||||
if (rc == CRYS_ECEDW_SIGN_VERIFY_FAILED_ERROR) return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// NOTE: memory corruption bug was found in this function!!
|
||||
return ed25519_verify(sig, message, msg_len, pub_key);
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user