Browse Source

Minor ifdef rename as it now covers more than just Ed25519

for hardware encryption. Now `USE_CC310_HW_CRYPTO`
pull/2824/head
Nick Dunklee 2 weeks ago
parent
commit
874f0c9ff8
  1. 4
      src/Identity.cpp
  2. 14
      src/Utils.cpp
  3. 4
      src/helpers/radiolib/RadioLibWrappers.h
  4. 2
      variants/heltec_t096/platformio.ini
  5. 2
      variants/rak3401/platformio.ini
  6. 2
      variants/rak4631/platformio.ini
  7. 2
      variants/t1000-e/platformio.ini

4
src/Identity.cpp

@ -4,7 +4,7 @@
#include <ed_25519.h> #include <ed_25519.h>
#include <Ed25519.h> #include <Ed25519.h>
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
#include <Adafruit_nRFCrypto.h> #include <Adafruit_nRFCrypto.h>
#include "nrf_cc310/include/crys_ec_edw_api.h" #include "nrf_cc310/include/crys_ec_edw_api.h"
#endif #endif
@ -20,7 +20,7 @@ Identity::Identity(const char* pub_hex) {
} }
bool Identity::verify(const uint8_t* sig, const uint8_t* message, int msg_len) const { bool Identity::verify(const uint8_t* sig, const uint8_t* message, int msg_len) const {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
// nRF52840 CryptoCell CC310 hardware Ed25519 verification. The software // nRF52840 CryptoCell CC310 hardware Ed25519 verification. The software
// implementations need ~3KB of stack (which can overflow the Adafruit core's // implementations need ~3KB of stack (which can overflow the Adafruit core's
// 4KB loop task stack from the advert receive path); the hardware path // 4KB loop task stack from the advert receive path); the hardware path

14
src/Utils.cpp

@ -2,7 +2,7 @@
#include <AES.h> #include <AES.h>
#include <SHA256.h> #include <SHA256.h>
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
#include <Adafruit_nRFCrypto.h> #include <Adafruit_nRFCrypto.h>
#include "nrf_cc310/include/crys_hash.h" #include "nrf_cc310/include/crys_hash.h"
#include "nrf_cc310/include/crys_hmac.h" #include "nrf_cc310/include/crys_hmac.h"
@ -22,7 +22,7 @@ uint32_t RNG::nextInt(uint32_t _min, uint32_t _max) {
} }
void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* msg, int msg_len) { void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* msg, int msg_len) {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
static CRYS_HASH_Result_t result; static CRYS_HASH_Result_t result;
nRFCrypto.begin(); nRFCrypto.begin();
CRYS_HASH(CRYS_HASH_SHA256_mode, (uint8_t*)msg, (size_t)msg_len, result); CRYS_HASH(CRYS_HASH_SHA256_mode, (uint8_t*)msg, (size_t)msg_len, result);
@ -36,7 +36,7 @@ void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* msg, int msg_l
} }
void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* frag1, int frag1_len, const uint8_t* frag2, int frag2_len) { void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* frag1, int frag1_len, const uint8_t* frag2, int frag2_len) {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
static CRYS_HASHUserContext_t ctx; static CRYS_HASHUserContext_t ctx;
static CRYS_HASH_Result_t result; static CRYS_HASH_Result_t result;
nRFCrypto.begin(); nRFCrypto.begin();
@ -55,7 +55,7 @@ void Utils::sha256(uint8_t *hash, size_t hash_len, const uint8_t* frag1, int fra
} }
int Utils::decrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) { int Utils::decrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
static SaSiAesUserContext_t ctx; static SaSiAesUserContext_t ctx;
SaSiAesUserKeyData_t keyData = { (uint8_t*)shared_secret, CIPHER_KEY_SIZE }; SaSiAesUserKeyData_t keyData = { (uint8_t*)shared_secret, CIPHER_KEY_SIZE };
uint8_t* dp = dest; uint8_t* dp = dest;
@ -89,7 +89,7 @@ int Utils::decrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* s
} }
int Utils::encrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) { int Utils::encrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
static SaSiAesUserContext_t ctx; static SaSiAesUserContext_t ctx;
SaSiAesUserKeyData_t keyData = { (uint8_t*)shared_secret, CIPHER_KEY_SIZE }; SaSiAesUserKeyData_t keyData = { (uint8_t*)shared_secret, CIPHER_KEY_SIZE };
uint8_t* dp = dest; uint8_t* dp = dest;
@ -135,7 +135,7 @@ int Utils::encrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* s
int Utils::encryptThenMAC(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) { int Utils::encryptThenMAC(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) {
int enc_len = encrypt(shared_secret, dest + CIPHER_MAC_SIZE, src, src_len); int enc_len = encrypt(shared_secret, dest + CIPHER_MAC_SIZE, src, src_len);
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
static CRYS_HMACUserContext_t hmac_ctx; static CRYS_HMACUserContext_t hmac_ctx;
static CRYS_HASH_Result_t hmac_result; static CRYS_HASH_Result_t hmac_result;
nRFCrypto.begin(); nRFCrypto.begin();
@ -158,7 +158,7 @@ int Utils::MACThenDecrypt(const uint8_t* shared_secret, uint8_t* dest, const uin
if (src_len <= CIPHER_MAC_SIZE) return 0; // invalid src bytes if (src_len <= CIPHER_MAC_SIZE) return 0; // invalid src bytes
uint8_t hmac[CIPHER_MAC_SIZE]; uint8_t hmac[CIPHER_MAC_SIZE];
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
{ {
static CRYS_HMACUserContext_t hmac_ctx; static CRYS_HMACUserContext_t hmac_ctx;
static CRYS_HASH_Result_t hmac_result; static CRYS_HASH_Result_t hmac_result;

4
src/helpers/radiolib/RadioLibWrappers.h

@ -3,7 +3,7 @@
#include <Mesh.h> #include <Mesh.h>
#include <RadioLib.h> #include <RadioLib.h>
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
#include <Adafruit_nRFCrypto.h> #include <Adafruit_nRFCrypto.h>
#endif #endif
@ -84,7 +84,7 @@ public:
RadioNoiseListener(PhysicalLayer& radio): _radio(&radio) { } RadioNoiseListener(PhysicalLayer& radio): _radio(&radio) { }
void random(uint8_t* dest, size_t sz) override { void random(uint8_t* dest, size_t sz) override {
#ifdef USE_CC310_ED25519 #ifdef USE_CC310_HW_CRYPTO
// CC310 TRNG is higher quality and environment-independent vs radio RSSI noise. // CC310 TRNG is higher quality and environment-independent vs radio RSSI noise.
nRFCrypto.begin(); nRFCrypto.begin();
nRFCrypto.Random.generate(dest, (uint16_t)sz); nRFCrypto.Random.generate(dest, (uint16_t)sz);

2
variants/heltec_t096/platformio.ini

@ -29,7 +29,7 @@ build_flags = ${nrf52_base.build_flags}
-D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_DIO3_TCXO_VOLTAGE=1.8
-D SX126X_CURRENT_LIMIT=140 -D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1 -D SX126X_RX_BOOSTED_GAIN=1
-D USE_CC310_ED25519=1 -D USE_CC310_HW_CRYPTO=1
-D PIN_VEXT_EN=26 ; Vext is connected to VDD which is also connected to TFT & GPS -D PIN_VEXT_EN=26 ; Vext is connected to VDD which is also connected to TFT & GPS
-D PIN_VEXT_EN_ACTIVE=HIGH -D PIN_VEXT_EN_ACTIVE=HIGH
-D PIN_GPS_RX=25 -D PIN_GPS_RX=25

2
variants/rak3401/platformio.ini

@ -13,7 +13,7 @@ build_flags = ${nrf52_base.build_flags}
-D SX126X_CURRENT_LIMIT=140 -D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1 -D SX126X_RX_BOOSTED_GAIN=1
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX with SKY66122 FEM -D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX with SKY66122 FEM
-D USE_CC310_ED25519=1 -D USE_CC310_HW_CRYPTO=1
build_src_filter = ${nrf52_base.build_src_filter} build_src_filter = ${nrf52_base.build_src_filter}
+<../variants/rak3401> +<../variants/rak3401>
+<helpers/sensors> +<helpers/sensors>

2
variants/rak4631/platformio.ini

@ -22,7 +22,7 @@ build_flags = ${nrf52_base.build_flags}
-D LORA_TX_POWER=22 -D LORA_TX_POWER=22
-D SX126X_CURRENT_LIMIT=140 -D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1 -D SX126X_RX_BOOSTED_GAIN=1
-D USE_CC310_ED25519=1 -D USE_CC310_HW_CRYPTO=1
-D ENV_INCLUDE_RAK12035=1 -D ENV_INCLUDE_RAK12035=1
-UENV_INCLUDE_BME680 -UENV_INCLUDE_BME680
-D ENV_INCLUDE_BME680_BSEC=1 -D ENV_INCLUDE_BME680_BSEC=1

2
variants/t1000-e/platformio.ini

@ -18,7 +18,7 @@ build_flags = ${nrf52_base.build_flags}
-D LORA_TX_POWER=22 -D LORA_TX_POWER=22
-D RF_SWITCH_TABLE -D RF_SWITCH_TABLE
-D RX_BOOSTED_GAIN=true -D RX_BOOSTED_GAIN=true
-D USE_CC310_ED25519=1 -D USE_CC310_HW_CRYPTO=1
-D P_LORA_BUSY=7 ; P0.7 -D P_LORA_BUSY=7 ; P0.7
-D P_LORA_SCLK=11 ; P0.11 -D P_LORA_SCLK=11 ; P0.11
-D P_LORA_NSS=12 ; P0.12 -D P_LORA_NSS=12 ; P0.12

Loading…
Cancel
Save