Skip to content
Permalink
Browse files

Remove unused struct members

  • Loading branch information
jedisct1 committed Nov 24, 2019
1 parent cf8b2bc commit 2b402ef45dfa8a3ceff65e298500f0f82fd1c4b6
Showing with 21 additions and 31 deletions.
  1. +2 −12 hydrogen.h
  2. +19 −19 impl/kx.h
@@ -180,19 +180,9 @@ typedef struct hydro_kx_session_keypair {
uint8_t tx[hydro_kx_SESSIONKEYBYTES];
} hydro_kx_session_keypair;

typedef struct hydro_kx_cipher_state {
uint8_t k[hydro_secretbox_KEYBYTES];
uint64_t msg_id;
} hydro_kx_cipher_state;

typedef struct hydro_kx_handshake_state {
hydro_kx_keypair kp;
hydro_kx_keypair eph_kp;
} hydro_kx_handshake_state;

typedef struct hydro_kx_state {
hydro_kx_handshake_state hs;
hydro_hash_state h_st;
hydro_kx_keypair eph_kp;
hydro_hash_state h_st;
} hydro_kx_state;

void hydro_kx_keygen(hydro_kx_keypair *static_kp);
@@ -207,12 +207,12 @@ hydro_kx_n_1(hydro_kx_session_keypair *kp, uint8_t packet1[hydro_kx_N_PACKET1BYT
hydro_hash_update(&state.h_st, peer_static_pk, hydro_x25519_PUBLICKEYBYTES);

hydro_hash_update(&state.h_st, psk, hydro_kx_PSKBYTES);
hydro_kx_eph_keygen(&state, &state.hs.eph_kp);
if (hydro_kx_dh(&state, state.hs.eph_kp.sk, peer_static_pk) != 0) {
hydro_kx_eph_keygen(&state, &state.eph_kp);
if (hydro_kx_dh(&state, state.eph_kp.sk, peer_static_pk) != 0) {
return -1;
}
hydro_kx_aead_encrypt(&state, packet1_mac, NULL, 0);
memcpy(packet1_eph_pk, state.hs.eph_kp.pk, sizeof state.hs.eph_kp.pk);
memcpy(packet1_eph_pk, state.eph_kp.pk, sizeof state.eph_kp.pk);

hydro_kx_final(&state, kp->rx, kp->tx);

@@ -260,15 +260,15 @@ hydro_kx_kk_1(hydro_kx_state *state, uint8_t packet1[hydro_kx_KK_PACKET1BYTES],
hydro_hash_update(&state->h_st, static_kp->pk, hydro_kx_PUBLICKEYBYTES);
hydro_hash_update(&state->h_st, peer_static_pk, hydro_kx_PUBLICKEYBYTES);

hydro_kx_eph_keygen(state, &state->hs.eph_kp);
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_static_pk) != 0) {
hydro_kx_eph_keygen(state, &state->eph_kp);
if (hydro_kx_dh(state, state->eph_kp.sk, peer_static_pk) != 0) {
return -1;
}
if (hydro_kx_dh(state, static_kp->sk, peer_static_pk) != 0) {
return -1;
}
hydro_kx_aead_encrypt(state, packet1_mac, NULL, 0);
memcpy(packet1_eph_pk, state->hs.eph_kp.pk, sizeof state->hs.eph_kp.pk);
memcpy(packet1_eph_pk, state->eph_kp.pk, sizeof state->eph_kp.pk);

return 0;
}
@@ -300,16 +300,16 @@ hydro_kx_kk_2(hydro_kx_session_keypair *kp, uint8_t packet2[hydro_kx_KK_PACKET2B
return -1;
}

hydro_kx_eph_keygen(&state, &state.hs.eph_kp);
if (hydro_kx_dh(&state, state.hs.eph_kp.sk, peer_eph_pk) != 0) {
hydro_kx_eph_keygen(&state, &state.eph_kp);
if (hydro_kx_dh(&state, state.eph_kp.sk, peer_eph_pk) != 0) {
return -1;
}
if (hydro_kx_dh(&state, state.hs.eph_kp.sk, peer_static_pk) != 0) {
if (hydro_kx_dh(&state, state.eph_kp.sk, peer_static_pk) != 0) {
return -1;
}
hydro_kx_aead_encrypt(&state, packet2_mac, NULL, 0);
hydro_kx_final(&state, kp->tx, kp->rx);
memcpy(packet2_eph_pk, state.hs.eph_kp.pk, sizeof state.hs.eph_kp.pk);
memcpy(packet2_eph_pk, state.eph_kp.pk, sizeof state.eph_kp.pk);

return 0;
}
@@ -322,7 +322,7 @@ hydro_kx_kk_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
const uint8_t *packet2_mac = &packet2[hydro_kx_PUBLICKEYBYTES];

hydro_hash_update(&state->h_st, peer_eph_pk, hydro_kx_PUBLICKEYBYTES);
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_eph_pk) != 0) {
if (hydro_kx_dh(state, state->eph_kp.sk, peer_eph_pk) != 0) {
return -1;
}
if (hydro_kx_dh(state, static_kp->sk, peer_eph_pk) != 0) {
@@ -351,9 +351,9 @@ hydro_kx_xx_1(hydro_kx_state *state, uint8_t packet1[hydro_kx_XX_PACKET1BYTES],
}
hydro_kx_init_state(state, "Noise_XXpsk0+psk3_hydro1");

hydro_kx_eph_keygen(state, &state->hs.eph_kp);
hydro_kx_eph_keygen(state, &state->eph_kp);
hydro_hash_update(&state->h_st, psk, hydro_kx_PSKBYTES);
memcpy(packet1_eph_pk, state->hs.eph_kp.pk, sizeof state->hs.eph_kp.pk);
memcpy(packet1_eph_pk, state->eph_kp.pk, sizeof state->eph_kp.pk);
hydro_kx_aead_encrypt(state, packet1_mac, NULL, 0);

return 0;
@@ -382,8 +382,8 @@ hydro_kx_xx_2(hydro_kx_state *state, uint8_t packet2[hydro_kx_XX_PACKET2BYTES],
return -1;
}

hydro_kx_eph_keygen(state, &state->hs.eph_kp);
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_eph_pk) != 0) {
hydro_kx_eph_keygen(state, &state->eph_kp);
if (hydro_kx_dh(state, state->eph_kp.sk, peer_eph_pk) != 0) {
return -1;
}
hydro_kx_aead_encrypt(state, packet2_enc_static_pk, static_kp->pk, sizeof static_kp->pk);
@@ -392,7 +392,7 @@ hydro_kx_xx_2(hydro_kx_state *state, uint8_t packet2[hydro_kx_XX_PACKET2BYTES],
}
hydro_kx_aead_encrypt(state, packet2_mac, NULL, 0);

memcpy(packet2_eph_pk, state->hs.eph_kp.pk, sizeof state->hs.eph_kp.pk);
memcpy(packet2_eph_pk, state->eph_kp.pk, sizeof state->eph_kp.pk);

return 0;
}
@@ -419,14 +419,14 @@ hydro_kx_xx_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
peer_static_pk = peer_static_pk_;
}
hydro_hash_update(&state->h_st, peer_eph_pk, hydro_kx_PUBLICKEYBYTES);
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_eph_pk) != 0) {
if (hydro_kx_dh(state, state->eph_kp.sk, peer_eph_pk) != 0) {
return -1;
}
if (hydro_kx_aead_decrypt(state, peer_static_pk, peer_enc_static_pk,
hydro_kx_PUBLICKEYBYTES + hydro_kx_AEAD_MACBYTES) != 0) {
return -1;
}
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_static_pk) != 0) {
if (hydro_kx_dh(state, state->eph_kp.sk, peer_static_pk) != 0) {
return -1;
}
if (hydro_kx_aead_decrypt(state, NULL, packet2_mac, hydro_kx_AEAD_MACBYTES) != 0) {
@@ -463,7 +463,7 @@ hydro_kx_xx_4(hydro_kx_state *state, hydro_kx_session_keypair *kp,
hydro_kx_PUBLICKEYBYTES + hydro_kx_AEAD_MACBYTES) != 0) {
return -1;
}
if (hydro_kx_dh(state, state->hs.eph_kp.sk, peer_static_pk) != 0) {
if (hydro_kx_dh(state, state->eph_kp.sk, peer_static_pk) != 0) {
return -1;
}
hydro_hash_update(&state->h_st, psk, hydro_kx_PSKBYTES);

0 comments on commit 2b402ef

Please sign in to comment.
You can’t perform that action at this time.