summaryrefslogtreecommitdiffstats
path: root/src/protocols/ec25519_fhmqvc
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-03-20 14:26:32 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-03-20 14:26:32 +0100
commit39a2215fd39d02b260ee77a7a434379a3b4327d1 (patch)
treee14ff63d75b8f6636907cecd31509b7d4e5f93bb /src/protocols/ec25519_fhmqvc
parentcefdc338d800ba057c6de45dc3d64ce83babe014 (diff)
downloadfastd-39a2215fd39d02b260ee77a7a434379a3b4327d1.tar
fastd-39a2215fd39d02b260ee77a7a434379a3b4327d1.zip
ec25519_fhmqvc: simplify protocol_handle_recv control flow
Diffstat (limited to 'src/protocols/ec25519_fhmqvc')
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
index a80021a..f343fc4 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
@@ -130,41 +130,34 @@ static void protocol_handle_recv(fastd_peer_t *peer, fastd_buffer_t buffer) {
goto fail;
fastd_buffer_t recv_buffer;
- bool ok = false, reordered;
+ bool ok = false, reordered = false;
- if (is_session_valid(&peer->protocol_state->old_session)) {
- reordered = false;
- if (peer->protocol_state->old_session.method->provider->decrypt(peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer, &reordered))
- ok = true;
- }
+ if (is_session_valid(&peer->protocol_state->old_session))
+ ok = peer->protocol_state->old_session.method->provider->decrypt(peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer, &reordered);
if (!ok) {
- reordered = false;
- if (peer->protocol_state->session.method->provider->decrypt(peer, peer->protocol_state->session.method_state, &recv_buffer, buffer, &reordered)) {
- ok = true;
-
- if (peer->protocol_state->old_session.method) {
- pr_debug("invalidating old session with %P", peer);
- peer->protocol_state->old_session.method->provider->session_free(peer->protocol_state->old_session.method_state);
- peer->protocol_state->old_session = (protocol_session_t){};
- }
-
- if (!peer->protocol_state->session.handshakes_cleaned) {
- pr_debug("cleaning left handshakes with %P", peer);
- fastd_peer_unschedule_handshake(peer);
- peer->protocol_state->session.handshakes_cleaned = true;
-
- if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state))
- fastd_protocol_ec25519_fhmqvc_send_empty(peer, &peer->protocol_state->session);
- }
-
- check_session_refresh(peer);
+ ok = peer->protocol_state->session.method->provider->decrypt(peer, peer->protocol_state->session.method_state, &recv_buffer, buffer, &reordered);
+ if (!ok) {
+ pr_debug2("verification failed for packet received from %P", peer);
+ goto fail;
}
- }
- if (!ok) {
- pr_debug2("verification failed for packet received from %P", peer);
- goto fail;
+ if (peer->protocol_state->old_session.method) {
+ pr_debug("invalidating old session with %P", peer);
+ peer->protocol_state->old_session.method->provider->session_free(peer->protocol_state->old_session.method_state);
+ peer->protocol_state->old_session = (protocol_session_t){};
+ }
+
+ if (!peer->protocol_state->session.handshakes_cleaned) {
+ pr_debug("cleaning left handshakes with %P", peer);
+ fastd_peer_unschedule_handshake(peer);
+ peer->protocol_state->session.handshakes_cleaned = true;
+
+ if (peer->protocol_state->session.method->provider->session_is_initiator(peer->protocol_state->session.method_state))
+ fastd_protocol_ec25519_fhmqvc_send_empty(peer, &peer->protocol_state->session);
+ }
+
+ check_session_refresh(peer);
}
fastd_peer_seen(peer);