summaryrefslogtreecommitdiffstatshomepage
path: root/src/data.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-04 14:38:04 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-04 14:38:04 +0100
commit1be1f3d19318475865b9556e9f0b4535150e0bc6 (patch)
treee8d4d41ebe110d2deea45f70b6998ac9455d3979 /src/data.c
parentsend: queue bundles on same CPU (diff)
downloadwireguard-monolithic-historical-1be1f3d19318475865b9556e9f0b4535150e0bc6.tar.xz
wireguard-monolithic-historical-1be1f3d19318475865b9556e9f0b4535150e0bc6.zip
data: keep FPU on when possible
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/data.c b/src/data.c
index 55cc118..1f6c5b6 100644
--- a/src/data.c
+++ b/src/data.c
@@ -84,13 +84,12 @@ struct packet_data_encryption_ctx {
uint64_t nonce;
};
-static inline void skb_encrypt(struct sk_buff *skb, struct noise_keypair *keypair)
+static inline void skb_encrypt(struct sk_buff *skb, struct noise_keypair *keypair, bool have_simd)
{
struct packet_data_encryption_ctx *ctx = (struct packet_data_encryption_ctx *)skb->cb;
struct scatterlist sg[ctx->num_frags]; /* This should be bound to at most 128 by the caller. */
struct message_data *header;
-
/* We have to remember to add the checksum to the innerpacket, in case the receiver forwards it. */
if (likely(!skb_checksum_setup(skb, true)))
skb_checksum_help(skb);
@@ -105,7 +104,7 @@ static inline void skb_encrypt(struct sk_buff *skb, struct noise_keypair *keypai
/* Now we can encrypt the scattergather segments */
sg_init_table(sg, ctx->num_frags);
skb_to_sgvec(skb, sg, sizeof(struct message_data), noise_encrypted_len(ctx->plaintext_len));
- chacha20poly1305_encrypt_sg(sg, sg, ctx->plaintext_len, NULL, 0, ctx->nonce, keypair->sending.key);
+ chacha20poly1305_encrypt_sg(sg, sg, ctx->plaintext_len, NULL, 0, ctx->nonce, keypair->sending.key, have_simd);
}
static inline bool skb_decrypt(struct sk_buff *skb, uint8_t num_frags, uint64_t nonce, struct noise_symmetric_key *key)
@@ -159,13 +158,12 @@ struct packet_bundle_ctx {
static inline void queue_encrypt_reset(struct sk_buff_head *queue, struct noise_keypair *keypair)
{
struct sk_buff *skb;
- /* TODO: as a later optimization, we can activate the FPU just once
- * for the entire loop, rather than turning it on and off for each
- * packet. */
+ bool have_simd = chacha20poly1305_init_simd();
skb_queue_walk(queue, skb) {
- skb_encrypt(skb, keypair);
+ skb_encrypt(skb, keypair, have_simd);
skb_reset(skb);
}
+ chacha20poly1305_deinit_simd(have_simd);
noise_keypair_put(keypair);
}