Skip to content

Commit a54667f

Browse files
nxa22042davem330
authored andcommitted
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>
1 parent 4adfa79 commit a54667f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/net/tls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <linux/types.h>
3838
#include <asm/byteorder.h>
39+
#include <linux/crypto.h>
3940
#include <linux/socket.h>
4041
#include <linux/tcp.h>
4142
#include <net/tcp.h>
@@ -57,6 +58,7 @@
5758

5859
struct tls_sw_context {
5960
struct crypto_aead *aead_send;
61+
struct crypto_wait async_wait;
6062

6163
/* Sending context */
6264
char aad_space[TLS_AAD_SPACE_SIZE];

net/tls/tls_sw.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ static int tls_do_encryption(struct tls_context *tls_ctx,
214214
aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE);
215215
aead_request_set_crypt(aead_req, ctx->sg_aead_in, ctx->sg_aead_out,
216216
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);
218222

219223
ctx->sg_encrypted_data[0].offset -= tls_ctx->prepend_size;
220224
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)
665669
goto out;
666670
}
667671

672+
crypto_init_wait(&sw_ctx->async_wait);
673+
668674
ctx->priv_ctx = (struct tls_offload_context *)sw_ctx;
669675

670676
crypto_info = &ctx->crypto_send;

0 commit comments

Comments
 (0)