upstream sync and gps stuff

This commit is contained in:
liquidraver
2026-10-02 23:10:09 +02:00
parent 5b779478b0
commit f9d01cf33a
21 changed files with 296 additions and 45 deletions
+6 -2
View File
@@ -189,14 +189,18 @@ int Utils::encryptThenMAC(const uint8_t *shared_secret, uint8_t *dest, const uin
int Utils::MACThenDecrypt(const uint8_t *shared_secret, uint8_t *dest, const uint8_t *src, int src_len)
{
if (src_len <= (int)CIPHER_MAC_SIZE) return 0;
int enc_len = src_len - CIPHER_MAC_SIZE;
if (enc_len % CIPHER_BLOCK_SIZE != 0) return 0; /* reject non-block-aligned ciphertext */
uint8_t computed_mac[CIPHER_MAC_SIZE];
if (compute_hmac_truncated(shared_secret, PUB_KEY_SIZE, src + CIPHER_MAC_SIZE, (size_t)src_len - CIPHER_MAC_SIZE, computed_mac, CIPHER_MAC_SIZE) != 0)
if (compute_hmac_truncated(shared_secret, PUB_KEY_SIZE, src + CIPHER_MAC_SIZE, (size_t)enc_len, computed_mac, CIPHER_MAC_SIZE) != 0)
return 0;
/* Constant-time MAC compare. Runs on every encrypted packet — a
* timing oracle here would let attackers forge MACs byte-by-byte
* across the entire mesh, bypassing message authentication. */
if (!Utils::constantTimeEqual(computed_mac, src, CIPHER_MAC_SIZE)) return 0;
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE);
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, enc_len);
}
/* See header for rationale. The `volatile` accumulator forces
+1
View File
@@ -1103,6 +1103,7 @@ int main(void)
* state machine if enabled. */
if (gps_is_available()) {
gps_set_poll_interval_sec(companion_mesh.prefs.gps_interval);
gps_set_standby_max_sec(companion_mesh.prefs.gps_standby_max);
gps_ensure_power_state(companion_mesh.prefs.gps_enabled);
if (companion_mesh.prefs.gps_enabled) {