Skip to content

Commit 3ee1a7b

Browse files
committed
refactor: remove unused g_vp_enc_key_data and simplify key selection logic
1 parent 9a7788e commit 3ee1a7b

1 file changed

Lines changed: 5 additions & 25 deletions

File tree

core/protocol.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ static uint32_t vp_read_u32_be(const uint8_t *p)
3737
// --------------------------------------
3838
// Simple keyed MAC (SipHash-2-4) + keys
3939
// --------------------------------------
40-
// g_vp_psk : 128-bit key used as root key for derivations
41-
// g_vp_enc_key : 256-bit key used for control-plane AEAD (HELLO/ACK/KEEPALIVE/ERROR)
42-
// g_vp_enc_key_data : 256-bit key used for DATA traffic (per-session, derived from PSK + session id)
40+
// g_vp_psk : 128-bit key used as root key for derivations
41+
// g_vp_enc_key : 256-bit key used for ChaCha20-Poly1305 AEAD
4342
static uint8_t g_vp_psk[16];
4443
static uint8_t g_vp_enc_key[32];
45-
static uint8_t g_vp_enc_key_data[32];
4644
static int g_vp_psk_loaded = 0;
4745

4846
// Forward declaration for KDF
@@ -291,21 +289,8 @@ static void vp_auth_load_key(void);
291289
// control-plane handshake.
292290
void vp_crypto_set_session(const uint8_t session_id[32])
293291
{
292+
(void)session_id;
294293
vp_auth_load_key();
295-
296-
uint8_t label[4] = { 'D', 'A', 'T', 0 };
297-
for (int i = 0; i < 4; i++) {
298-
label[3] = (uint8_t)i;
299-
300-
uint8_t input[4 + 32];
301-
memcpy(input, label, 4);
302-
memcpy(input + 4, session_id, 32);
303-
304-
uint64_t v = vp_siphash24(g_vp_psk, input, sizeof(input));
305-
for (int b = 0; b < 8; b++) {
306-
g_vp_enc_key_data[i * 8 + b] = (uint8_t)(v >> (8 * b));
307-
}
308-
}
309294
}
310295

311296
static void vp_auth_load_key(void)
@@ -318,7 +303,6 @@ static void vp_auth_load_key(void)
318303
const char *env = getenv("VP_PSK");
319304
memset(g_vp_psk, 0, sizeof(g_vp_psk));
320305
memset(g_vp_enc_key, 0, sizeof(g_vp_enc_key));
321-
memset(g_vp_enc_key_data, 0, sizeof(g_vp_enc_key_data));
322306

323307
if (!env || !env[0]) {
324308
fprintf(stderr,
@@ -607,9 +591,7 @@ int vp_encode_packet(vp_crypto_dir_t dir,
607591
if (payload && payload_len > 0)
608592
memcpy(buf + header_len, payload, payload_len);
609593

610-
const uint8_t *key = (hdr->type == VP_PKT_DATA)
611-
? g_vp_enc_key_data
612-
: g_vp_enc_key;
594+
const uint8_t *key = g_vp_enc_key;
613595

614596
uint8_t nonce[12];
615597
vp_build_nonce(dir, &tmp, nonce);
@@ -671,9 +653,7 @@ int vp_decode_packet(vp_crypto_dir_t dir,
671653
if (payload_len > VP_MAX_FRAME_LEN)
672654
return -5;
673655

674-
const uint8_t *key = (hdr->type == VP_PKT_DATA)
675-
? g_vp_enc_key_data
676-
: g_vp_enc_key;
656+
const uint8_t *key = g_vp_enc_key;
677657

678658
uint8_t nonce[12];
679659
vp_build_nonce(dir, hdr, nonce);

0 commit comments

Comments
 (0)