summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handshake.h7
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c10
2 files changed, 11 insertions, 6 deletions
diff --git a/src/handshake.h b/src/handshake.h
index e3d4960..4aff83c 100644
--- a/src/handshake.h
+++ b/src/handshake.h
@@ -119,6 +119,13 @@ static inline void fastd_handshake_add(fastd_context_t *ctx, fastd_buffer_t *buf
memcpy(dst, data, len);
}
+static inline uint8_t* fastd_handshake_add_zero(fastd_context_t *ctx, fastd_buffer_t *buffer, fastd_handshake_record_type_t type, size_t len) {
+ uint8_t *dst = fastd_handshake_extend(ctx, buffer, type, len);
+
+ memset(dst, 0, len);
+ return dst;
+}
+
static inline void fastd_handshake_add_uint8(fastd_context_t *ctx, fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint8_t value) {
uint8_t *dst = fastd_handshake_extend(ctx, buffer, type, 1);
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index d1592d6..742e310 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -160,10 +160,9 @@ static void respond_handshake(fastd_context_t *ctx, const fastd_socket_t *sock,
fastd_handshake_add(ctx, &buffer, RECORD_T, HASHBYTES, hmacbuf.b);
}
- memset(&hmacbuf, 0, sizeof(hmacbuf));
- fastd_handshake_add(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES, hmacbuf.b);
+ uint8_t *hmac = fastd_handshake_add_zero(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES);
fastd_hmacsha256(&hmacbuf, peer->protocol_state->shared_handshake_key.w, fastd_handshake_tlv_data(&buffer), fastd_handshake_tlv_len(&buffer));
- memcpy(buffer.data+buffer.len-HASHBYTES, hmacbuf.b, HASHBYTES);
+ memcpy(hmac, hmacbuf.b, HASHBYTES);
fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer);
}
@@ -328,10 +327,9 @@ static void finish_handshake(fastd_context_t *ctx, fastd_socket_t *sock, const f
fastd_handshake_add(ctx, &buffer, RECORD_T, HASHBYTES, hmacbuf.b);
}
- memset(&hmacbuf, 0, sizeof(hmacbuf));
- fastd_handshake_add(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES, hmacbuf.b);
+ uint8_t *hmac = fastd_handshake_add_zero(ctx, &buffer, RECORD_TLV_MAC, HASHBYTES);
fastd_hmacsha256(&hmacbuf, shared_handshake_key.w, fastd_handshake_tlv_data(&buffer), fastd_handshake_tlv_len(&buffer));
- memcpy(buffer.data+buffer.len-HASHBYTES, hmacbuf.b, HASHBYTES);
+ memcpy(hmac, hmacbuf.b, HASHBYTES);
fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer);
}