diff options
author | Vakul Garg <vakul.garg@nxp.com> | 2018-01-31 11:04:37 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-01-31 10:26:30 -0500 |
commit | a54667f6728c2714a400f3c884727da74b6d1717 (patch) | |
tree | 5c722a9de6ef67c3ba7304516838b7e5ae1631d7 | |
parent | 4adfa79fc254efb7b0eb3cd58f62c2c3f805f1ba (diff) |
tls: Add support for encryption using async offload accelerator
Async crypto accelerators (e.g. drivers/crypto/caam) support offloading
GCM operation. If they are enabled, crypto_aead_encrypt() return error
code -EINPROGRESS. In this case tls_do_encryption() needs to wait on a
completion till the time the response for crypto offload request is
received.
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/tls.h | 2 | ||||
-rw-r--r-- | net/tls/tls_sw.c | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/include/net/tls.h b/include/net/tls.h index 9185e53a743c..4913430ab807 100644 --- a/include/net/tls.h +++ b/include/net/tls.h | |||
@@ -36,6 +36,7 @@ | |||
36 | 36 | ||
37 | #include <linux/types.h> | 37 | #include <linux/types.h> |
38 | #include <asm/byteorder.h> | 38 | #include <asm/byteorder.h> |
39 | #include <linux/crypto.h> | ||
39 | #include <linux/socket.h> | 40 | #include <linux/socket.h> |
40 | #include <linux/tcp.h> | 41 | #include <linux/tcp.h> |
41 | #include <net/tcp.h> | 42 | #include <net/tcp.h> |
@@ -57,6 +58,7 @@ | |||
57 | 58 | ||
58 | struct tls_sw_context { | 59 | struct tls_sw_context { |
59 | struct crypto_aead *aead_send; | 60 | struct crypto_aead *aead_send; |
61 | struct crypto_wait async_wait; | ||
60 | 62 | ||
61 | /* Sending context */ | 63 | /* Sending context */ |
62 | char aad_space[TLS_AAD_SPACE_SIZE]; | 64 | char aad_space[TLS_AAD_SPACE_SIZE]; |
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 0a9b72fbd761..f26376e954ae 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c | |||
@@ -214,7 +214,11 @@ static int tls_do_encryption(struct tls_context *tls_ctx, | |||
214 | aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE); | 214 | aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE); |
215 | aead_request_set_crypt(aead_req, ctx->sg_aead_in, ctx->sg_aead_out, | 215 | aead_request_set_crypt(aead_req, ctx->sg_aead_in, ctx->sg_aead_out, |
216 | data_len, tls_ctx->iv); | 216 | data_len, tls_ctx->iv); |
217 | rc = crypto_aead_encrypt(aead_req); | 217 | |
218 | aead_request_set_callback(aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG, | ||
219 | crypto_req_done, &ctx->async_wait); | ||
220 | |||
221 | rc = crypto_wait_req(crypto_aead_encrypt(aead_req), &ctx->async_wait); | ||
218 | 222 | ||
219 | ctx->sg_encrypted_data[0].offset -= tls_ctx->prepend_size; | 223 | ctx->sg_encrypted_data[0].offset -= tls_ctx->prepend_size; |
220 | ctx->sg_encrypted_data[0].length += tls_ctx->prepend_size; | 224 | ctx->sg_encrypted_data[0].length += tls_ctx->prepend_size; |
@@ -665,6 +669,8 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx) | |||
665 | goto out; | 669 | goto out; |
666 | } | 670 | } |
667 | 671 | ||
672 | crypto_init_wait(&sw_ctx->async_wait); | ||
673 | |||
668 | ctx->priv_ctx = (struct tls_offload_context *)sw_ctx; | 674 | ctx->priv_ctx = (struct tls_offload_context *)sw_ctx; |
669 | 675 | ||
670 | crypto_info = &ctx->crypto_send; | 676 | crypto_info = &ctx->crypto_send; |