Skip to content

Commit

Permalink
tls: rx: only copy IV from the packet for TLS 1.2
Browse files Browse the repository at this point in the history
TLS 1.3 and ChaChaPoly don't carry IV in the packet.
The code before this change would copy out iv_size
worth of whatever followed the TLS header in the packet
and then for TLS 1.3 | ChaCha overwrite that with
the sequence number. Waste of cycles especially
with TLS 1.2 being close to dead and TLS 1.3 being
the common case.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Apr 13, 2022
1 parent f7d45f4 commit a4ae58c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,20 +1482,20 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
}

/* Prepare IV */
err = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE,
iv + iv_offset + prot->salt_size,
prot->iv_size);
if (err < 0) {
kfree(mem);
return err;
}
if (prot->version == TLS_1_3_VERSION ||
prot->cipher_type == TLS_CIPHER_CHACHA20_POLY1305)
prot->cipher_type == TLS_CIPHER_CHACHA20_POLY1305) {
memcpy(iv + iv_offset, tls_ctx->rx.iv,
prot->iv_size + prot->salt_size);
else
} else {
err = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE,
iv + iv_offset + prot->salt_size,
prot->iv_size);
if (err < 0) {
kfree(mem);
return err;
}
memcpy(iv + iv_offset, tls_ctx->rx.iv, prot->salt_size);

}
xor_iv_with_seq(prot, iv + iv_offset, tls_ctx->rx.rec_seq);

/* Prepare AAD */
Expand Down

0 comments on commit a4ae58c

Please sign in to comment.