mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-14 04:15:08 +02:00
Zero padding before passing buffers to methods
This commit is contained in:
parent
63a6d4305f
commit
b0e96e71fa
7 changed files with 4 additions and 15 deletions
|
@ -118,8 +118,6 @@ static bool method_encrypt(
|
||||||
UNUSED fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
|
UNUSED fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
|
||||||
*out = fastd_buffer_alloc(in.len, COMMON_HEADROOM, 0);
|
*out = fastd_buffer_alloc(in.len, COMMON_HEADROOM, 0);
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
uint8_t nonce[session->method->cipher_info->iv_length ?: 1] __attribute__((aligned(8)));
|
uint8_t nonce[session->method->cipher_info->iv_length ?: 1] __attribute__((aligned(8)));
|
||||||
fastd_method_expand_nonce(nonce, session->common.send_nonce, sizeof(nonce));
|
fastd_method_expand_nonce(nonce, session->common.send_nonce, sizeof(nonce));
|
||||||
|
|
||||||
|
@ -168,8 +166,6 @@ static bool method_decrypt(
|
||||||
|
|
||||||
*out = fastd_buffer_alloc(in.len, 0, 0);
|
*out = fastd_buffer_alloc(in.len, 0, 0);
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
|
int n_blocks = block_count(in.len, sizeof(fastd_block128_t));
|
||||||
|
|
||||||
fastd_block128_t *inblocks = in.data;
|
fastd_block128_t *inblocks = in.data;
|
||||||
|
|
|
@ -275,7 +275,6 @@ static bool method_decrypt(
|
||||||
nonce))
|
nonce))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
put_size(&inblocks[n_blocks], in.len - sizeof(fastd_block128_t));
|
put_size(&inblocks[n_blocks], in.len - sizeof(fastd_block128_t));
|
||||||
|
|
||||||
if (!session->ghash->digest(session->ghash_state, &tag, inblocks + 1, n_blocks * sizeof(fastd_block128_t)))
|
if (!session->ghash->digest(session->ghash_state, &tag, inblocks + 1, n_blocks * sizeof(fastd_block128_t)))
|
||||||
|
|
|
@ -243,8 +243,6 @@ static bool method_decrypt(
|
||||||
nonce))
|
nonce))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
if (!session->uhash->digest(session->uhash_state, &tag, inblocks + 1, in.len - sizeof(fastd_block128_t)))
|
if (!session->uhash->digest(session->uhash_state, &tag, inblocks + 1, in.len - sizeof(fastd_block128_t)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
|
@ -232,8 +232,6 @@ static bool method_decrypt(
|
||||||
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce))
|
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
put_size(&inblocks[n_blocks], in.len - sizeof(fastd_block128_t));
|
put_size(&inblocks[n_blocks], in.len - sizeof(fastd_block128_t));
|
||||||
|
|
||||||
if (!session->ghash->digest(session->ghash_state, &tag, inblocks + 1, n_blocks * sizeof(fastd_block128_t)))
|
if (!session->ghash->digest(session->ghash_state, &tag, inblocks + 1, n_blocks * sizeof(fastd_block128_t)))
|
||||||
|
|
|
@ -134,8 +134,6 @@ static bool method_encrypt(
|
||||||
|
|
||||||
*out = fastd_buffer_alloc(in.len, COMMON_HEADROOM, 0);
|
*out = fastd_buffer_alloc(in.len, COMMON_HEADROOM, 0);
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
uint8_t nonce[session->method->cipher_info->iv_length] __attribute__((aligned(8)));
|
uint8_t nonce[session->method->cipher_info->iv_length] __attribute__((aligned(8)));
|
||||||
fastd_method_expand_nonce(nonce, session->common.send_nonce, sizeof(nonce));
|
fastd_method_expand_nonce(nonce, session->common.send_nonce, sizeof(nonce));
|
||||||
|
|
||||||
|
@ -200,8 +198,6 @@ static bool method_decrypt(
|
||||||
fastd_block128_t *inblocks = in.data;
|
fastd_block128_t *inblocks = in.data;
|
||||||
fastd_block128_t *outblocks = out->data;
|
fastd_block128_t *outblocks = out->data;
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
bool ok = session->cipher->crypt(
|
bool ok = session->cipher->crypt(
|
||||||
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce);
|
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce);
|
||||||
|
|
||||||
|
|
|
@ -195,8 +195,6 @@ static bool method_decrypt(
|
||||||
fastd_block128_t *outblocks = out->data;
|
fastd_block128_t *outblocks = out->data;
|
||||||
fastd_block128_t tag;
|
fastd_block128_t tag;
|
||||||
|
|
||||||
fastd_buffer_zero_pad(in);
|
|
||||||
|
|
||||||
if (!session->cipher->crypt(
|
if (!session->cipher->crypt(
|
||||||
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce))
|
session->cipher_state, outblocks, inblocks, n_blocks * sizeof(fastd_block128_t), nonce))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
@ -113,6 +113,8 @@ static void protocol_handle_recv(fastd_peer_t *peer, fastd_buffer_t buffer) {
|
||||||
fastd_buffer_t recv_buffer;
|
fastd_buffer_t recv_buffer;
|
||||||
bool ok = false, reordered = false;
|
bool ok = false, reordered = false;
|
||||||
|
|
||||||
|
fastd_buffer_zero_pad(buffer);
|
||||||
|
|
||||||
if (is_session_valid(&peer->protocol_state->old_session))
|
if (is_session_valid(&peer->protocol_state->old_session))
|
||||||
ok = peer->protocol_state->old_session.method->provider->decrypt(
|
ok = peer->protocol_state->old_session.method->provider->decrypt(
|
||||||
peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer, &reordered);
|
peer, peer->protocol_state->old_session.method_state, &recv_buffer, buffer, &reordered);
|
||||||
|
@ -162,6 +164,8 @@ fail:
|
||||||
static void session_send(fastd_peer_t *peer, fastd_buffer_t buffer, protocol_session_t *session) {
|
static void session_send(fastd_peer_t *peer, fastd_buffer_t buffer, protocol_session_t *session) {
|
||||||
size_t stat_size = buffer.len;
|
size_t stat_size = buffer.len;
|
||||||
|
|
||||||
|
fastd_buffer_zero_pad(buffer);
|
||||||
|
|
||||||
fastd_buffer_t send_buffer;
|
fastd_buffer_t send_buffer;
|
||||||
if (!session->method->provider->encrypt(peer, session->method_state, &send_buffer, buffer)) {
|
if (!session->method->provider->encrypt(peer, session->method_state, &send_buffer, buffer)) {
|
||||||
fastd_buffer_free(buffer);
|
fastd_buffer_free(buffer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue