diff --git a/proto b/proto index 92f3d9aaf..f9885d5e9 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 92f3d9aaf458722ae2384108f6ccad574f7ac3e0 +Subproject commit f9885d5e92dea1bb2f668705968add0e32667c8a diff --git a/src/esp32/ESP32CryptoEngine.cpp b/src/esp32/ESP32CryptoEngine.cpp index 154491ccb..d7eaa46bf 100644 --- a/src/esp32/ESP32CryptoEngine.cpp +++ b/src/esp32/ESP32CryptoEngine.cpp @@ -47,15 +47,15 @@ class ESP32CryptoEngine : public CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { uint8_t stream_block[16]; static uint8_t scratch[MAX_BLOCKSIZE]; size_t nc_off = 0; - // DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetNum, numBytes); - initNonce(fromNode, packetNum); + // DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes); + initNonce(fromNode, packetId); assert(numBytes <= MAX_BLOCKSIZE); memcpy(scratch, bytes, numBytes); memset(scratch + numBytes, 0, @@ -66,12 +66,12 @@ class ESP32CryptoEngine : public CryptoEngine } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // DEBUG_MSG("ESP32 decrypt!\n"); // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: diff --git a/src/mesh/CryptoEngine.cpp b/src/mesh/CryptoEngine.cpp index bce9bb02f..971080b23 100644 --- a/src/mesh/CryptoEngine.cpp +++ b/src/mesh/CryptoEngine.cpp @@ -16,12 +16,12 @@ void CryptoEngine::setKey(const CryptoKey &k) * * @param bytes is updated in place */ -void CryptoEngine::encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) +void CryptoEngine::encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) { DEBUG_MSG("WARNING: noop encryption!\n"); } -void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) +void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) { DEBUG_MSG("WARNING: noop decryption!\n"); } @@ -29,13 +29,13 @@ void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetNum, size_t numByte /** * Init our 128 bit nonce for a new packet */ -void CryptoEngine::initNonce(uint32_t fromNode, uint64_t packetNum) +void CryptoEngine::initNonce(uint32_t fromNode, uint64_t packetId) { memset(nonce, 0, sizeof(nonce)); // use memcpy to avoid breaking strict-aliasing - memcpy(nonce, &packetNum, sizeof(uint64_t)); + memcpy(nonce, &packetId, sizeof(uint64_t)); memcpy(nonce + sizeof(uint64_t), &fromNode, sizeof(uint32_t)); - //*((uint64_t *)&nonce[0]) = packetNum; + //*((uint64_t *)&nonce[0]) = packetId; //*((uint32_t *)&nonce[8]) = fromNode; } \ No newline at end of file diff --git a/src/mesh/CryptoEngine.h b/src/mesh/CryptoEngine.h index 179f4d139..1dda7ce31 100644 --- a/src/mesh/CryptoEngine.h +++ b/src/mesh/CryptoEngine.h @@ -43,8 +43,8 @@ class CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes); - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes); + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes); + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes); protected: /** @@ -55,7 +55,7 @@ class CryptoEngine * a 32 bit sending node number (stored in little endian order) * a 32 bit block counter (starts at zero) */ - void initNonce(uint32_t fromNode, uint64_t packetNum); + void initNonce(uint32_t fromNode, uint64_t packetId); }; extern CryptoEngine *crypto; diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 46684a4a9..c124e9619 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -260,7 +260,7 @@ typedef struct _Routing { } Routing; typedef struct _FromRadio { - uint32_t num; + uint32_t id; pb_size_t which_payloadVariant; union { MyNodeInfo my_info; @@ -442,7 +442,7 @@ extern "C" { #define Routing_route_request_tag 1 #define Routing_route_reply_tag 2 #define Routing_error_reason_tag 3 -#define FromRadio_num_tag 1 +#define FromRadio_id_tag 1 #define FromRadio_my_info_tag 3 #define FromRadio_node_info_tag 4 #define FromRadio_log_record_tag 7 @@ -581,7 +581,7 @@ X(a, STATIC, SINGULAR, UENUM, level, 4) #define LogRecord_DEFAULT NULL #define FromRadio_FIELDLIST(X, a) \ -X(a, STATIC, SINGULAR, UINT32, num, 1) \ +X(a, STATIC, SINGULAR, UINT32, id, 1) \ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,my_info,my_info), 3) \ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,node_info,node_info), 4) \ X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,log_record,log_record), 7) \ diff --git a/src/nrf52/NRF52CryptoEngine.cpp b/src/nrf52/NRF52CryptoEngine.cpp index 4bf400fd1..1018b94fd 100644 --- a/src/nrf52/NRF52CryptoEngine.cpp +++ b/src/nrf52/NRF52CryptoEngine.cpp @@ -17,28 +17,28 @@ class NRF52CryptoEngine : public CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + 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, packetNum); + 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 packetNum, size_t numBytes, uint8_t *bytes) override + 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, packetNum); + initNonce(fromNode, packetId); ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce); ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes); diff --git a/src/portduino/CrossPlatformCryptoEngine.cpp b/src/portduino/CrossPlatformCryptoEngine.cpp index b0f6fecdf..b3b3853c3 100644 --- a/src/portduino/CrossPlatformCryptoEngine.cpp +++ b/src/portduino/CrossPlatformCryptoEngine.cpp @@ -47,7 +47,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { //uint8_t stream_block[16]; @@ -55,7 +55,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine //size_t nc_off = 0; // DEBUG_MSG("ESP32 encrypt!\n"); - initNonce(fromNode, packetNum); + initNonce(fromNode, packetId); assert(numBytes <= MAX_BLOCKSIZE); memcpy(scratch, bytes, numBytes); memset(scratch + numBytes, 0, @@ -67,10 +67,10 @@ class CrossPlatformCryptoEngine : public CryptoEngine } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: