mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-13 08:32:08 +00:00
Rename packetNum to packetId
This commit is contained in:
parent
4cd1570543
commit
285413c68c
2
proto
2
proto
@ -1 +1 @@
|
|||||||
Subproject commit 92f3d9aaf458722ae2384108f6ccad574f7ac3e0
|
Subproject commit f9885d5e92dea1bb2f668705968add0e32667c8a
|
@ -47,15 +47,15 @@ class ESP32CryptoEngine : public CryptoEngine
|
|||||||
*
|
*
|
||||||
* @param bytes is updated in place
|
* @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) {
|
if (key.length > 0) {
|
||||||
uint8_t stream_block[16];
|
uint8_t stream_block[16];
|
||||||
static uint8_t scratch[MAX_BLOCKSIZE];
|
static uint8_t scratch[MAX_BLOCKSIZE];
|
||||||
size_t nc_off = 0;
|
size_t nc_off = 0;
|
||||||
|
|
||||||
// DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetNum, numBytes);
|
// DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||||
initNonce(fromNode, packetNum);
|
initNonce(fromNode, packetId);
|
||||||
assert(numBytes <= MAX_BLOCKSIZE);
|
assert(numBytes <= MAX_BLOCKSIZE);
|
||||||
memcpy(scratch, bytes, numBytes);
|
memcpy(scratch, bytes, numBytes);
|
||||||
memset(scratch + numBytes, 0,
|
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");
|
// DEBUG_MSG("ESP32 decrypt!\n");
|
||||||
|
|
||||||
// For CTR, the implementation is the same
|
// For CTR, the implementation is the same
|
||||||
encrypt(fromNode, packetNum, numBytes, bytes);
|
encrypt(fromNode, packetId, numBytes, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -16,12 +16,12 @@ void CryptoEngine::setKey(const CryptoKey &k)
|
|||||||
*
|
*
|
||||||
* @param bytes is updated in place
|
* @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");
|
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");
|
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
|
* 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));
|
memset(nonce, 0, sizeof(nonce));
|
||||||
|
|
||||||
// use memcpy to avoid breaking strict-aliasing
|
// 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));
|
memcpy(nonce + sizeof(uint64_t), &fromNode, sizeof(uint32_t));
|
||||||
//*((uint64_t *)&nonce[0]) = packetNum;
|
//*((uint64_t *)&nonce[0]) = packetId;
|
||||||
//*((uint32_t *)&nonce[8]) = fromNode;
|
//*((uint32_t *)&nonce[8]) = fromNode;
|
||||||
}
|
}
|
@ -43,8 +43,8 @@ class CryptoEngine
|
|||||||
*
|
*
|
||||||
* @param bytes is updated in place
|
* @param bytes is updated in place
|
||||||
*/
|
*/
|
||||||
virtual void encrypt(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 packetNum, size_t numBytes, uint8_t *bytes);
|
virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -55,7 +55,7 @@ class CryptoEngine
|
|||||||
* a 32 bit sending node number (stored in little endian order)
|
* a 32 bit sending node number (stored in little endian order)
|
||||||
* a 32 bit block counter (starts at zero)
|
* 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;
|
extern CryptoEngine *crypto;
|
||||||
|
@ -260,7 +260,7 @@ typedef struct _Routing {
|
|||||||
} Routing;
|
} Routing;
|
||||||
|
|
||||||
typedef struct _FromRadio {
|
typedef struct _FromRadio {
|
||||||
uint32_t num;
|
uint32_t id;
|
||||||
pb_size_t which_payloadVariant;
|
pb_size_t which_payloadVariant;
|
||||||
union {
|
union {
|
||||||
MyNodeInfo my_info;
|
MyNodeInfo my_info;
|
||||||
@ -442,7 +442,7 @@ extern "C" {
|
|||||||
#define Routing_route_request_tag 1
|
#define Routing_route_request_tag 1
|
||||||
#define Routing_route_reply_tag 2
|
#define Routing_route_reply_tag 2
|
||||||
#define Routing_error_reason_tag 3
|
#define Routing_error_reason_tag 3
|
||||||
#define FromRadio_num_tag 1
|
#define FromRadio_id_tag 1
|
||||||
#define FromRadio_my_info_tag 3
|
#define FromRadio_my_info_tag 3
|
||||||
#define FromRadio_node_info_tag 4
|
#define FromRadio_node_info_tag 4
|
||||||
#define FromRadio_log_record_tag 7
|
#define FromRadio_log_record_tag 7
|
||||||
@ -581,7 +581,7 @@ X(a, STATIC, SINGULAR, UENUM, level, 4)
|
|||||||
#define LogRecord_DEFAULT NULL
|
#define LogRecord_DEFAULT NULL
|
||||||
|
|
||||||
#define FromRadio_FIELDLIST(X, a) \
|
#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,my_info,my_info), 3) \
|
||||||
X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,node_info,node_info), 4) \
|
X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,node_info,node_info), 4) \
|
||||||
X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,log_record,log_record), 7) \
|
X(a, STATIC, ONEOF, MESSAGE, (payloadVariant,log_record,log_record), 7) \
|
||||||
|
@ -17,28 +17,28 @@ class NRF52CryptoEngine : public CryptoEngine
|
|||||||
*
|
*
|
||||||
* @param bytes is updated in place
|
* @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");
|
// DEBUG_MSG("NRF52 encrypt!\n");
|
||||||
|
|
||||||
if (key.length > 0) {
|
if (key.length > 0) {
|
||||||
ocrypto_aes_ctr_ctx ctx;
|
ocrypto_aes_ctr_ctx ctx;
|
||||||
|
|
||||||
initNonce(fromNode, packetNum);
|
initNonce(fromNode, packetId);
|
||||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
||||||
|
|
||||||
ocrypto_aes_ctr_encrypt(&ctx, bytes, bytes, numBytes);
|
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");
|
// DEBUG_MSG("NRF52 decrypt!\n");
|
||||||
|
|
||||||
if (key.length > 0) {
|
if (key.length > 0) {
|
||||||
ocrypto_aes_ctr_ctx ctx;
|
ocrypto_aes_ctr_ctx ctx;
|
||||||
|
|
||||||
initNonce(fromNode, packetNum);
|
initNonce(fromNode, packetId);
|
||||||
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
ocrypto_aes_ctr_init(&ctx, key.bytes, key.length, nonce);
|
||||||
|
|
||||||
ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes);
|
ocrypto_aes_ctr_decrypt(&ctx, bytes, bytes, numBytes);
|
||||||
|
@ -47,7 +47,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine
|
|||||||
*
|
*
|
||||||
* @param bytes is updated in place
|
* @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) {
|
if (key.length > 0) {
|
||||||
//uint8_t stream_block[16];
|
//uint8_t stream_block[16];
|
||||||
@ -55,7 +55,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine
|
|||||||
//size_t nc_off = 0;
|
//size_t nc_off = 0;
|
||||||
|
|
||||||
// DEBUG_MSG("ESP32 encrypt!\n");
|
// DEBUG_MSG("ESP32 encrypt!\n");
|
||||||
initNonce(fromNode, packetNum);
|
initNonce(fromNode, packetId);
|
||||||
assert(numBytes <= MAX_BLOCKSIZE);
|
assert(numBytes <= MAX_BLOCKSIZE);
|
||||||
memcpy(scratch, bytes, numBytes);
|
memcpy(scratch, bytes, numBytes);
|
||||||
memset(scratch + numBytes, 0,
|
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
|
// For CTR, the implementation is the same
|
||||||
encrypt(fromNode, packetNum, numBytes, bytes);
|
encrypt(fromNode, packetId, numBytes, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user