Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-2017, Mellanox Technologies. All rights reserved. |
| 3 | * Copyright (c) 2016-2017, Dave Watson <davejwatson@fb.com>. All rights reserved. |
| 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
| 34 | #ifndef _TLS_OFFLOAD_H |
| 35 | #define _TLS_OFFLOAD_H |
| 36 | |
| 37 | #include <linux/types.h> |
Dmitry V. Levin | b9f3eb4 | 2017-11-14 06:30:11 +0300 | [diff] [blame] | 38 | #include <asm/byteorder.h> |
Vakul Garg | a54667f | 2018-01-31 21:34:37 +0530 | [diff] [blame] | 39 | #include <linux/crypto.h> |
Dmitry V. Levin | b9f3eb4 | 2017-11-14 06:30:11 +0300 | [diff] [blame] | 40 | #include <linux/socket.h> |
| 41 | #include <linux/tcp.h> |
Daniel Borkmann | d829e9c | 2018-10-13 02:45:59 +0200 | [diff] [blame] | 42 | #include <linux/skmsg.h> |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 43 | #include <linux/netdevice.h> |
Daniel Borkmann | d829e9c | 2018-10-13 02:45:59 +0200 | [diff] [blame] | 44 | |
Dmitry V. Levin | b9f3eb4 | 2017-11-14 06:30:11 +0300 | [diff] [blame] | 45 | #include <net/tcp.h> |
Dave Watson | c46234e | 2018-03-22 10:10:35 -0700 | [diff] [blame] | 46 | #include <net/strparser.h> |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 47 | #include <crypto/aead.h> |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 48 | #include <uapi/linux/tls.h> |
| 49 | |
| 50 | |
| 51 | /* Maximum data size carried in a TLS record */ |
| 52 | #define TLS_MAX_PAYLOAD_SIZE ((size_t)1 << 14) |
| 53 | |
| 54 | #define TLS_HEADER_SIZE 5 |
| 55 | #define TLS_NONCE_OFFSET TLS_HEADER_SIZE |
| 56 | |
| 57 | #define TLS_CRYPTO_INFO_READY(info) ((info)->cipher_type) |
| 58 | |
| 59 | #define TLS_RECORD_TYPE_DATA 0x17 |
| 60 | |
| 61 | #define TLS_AAD_SPACE_SIZE 13 |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 62 | #define TLS_DEVICE_NAME_MAX 32 |
| 63 | |
Vakul Garg | f295b3a | 2019-03-20 02:03:36 +0000 | [diff] [blame] | 64 | #define MAX_IV_SIZE 16 |
Jakub Kicinski | 89fec47 | 2019-06-10 21:40:00 -0700 | [diff] [blame] | 65 | #define TLS_MAX_REC_SEQ_SIZE 8 |
Vakul Garg | f295b3a | 2019-03-20 02:03:36 +0000 | [diff] [blame] | 66 | |
| 67 | /* For AES-CCM, the full 16-bytes of IV is made of '4' fields of given sizes. |
| 68 | * |
| 69 | * IV[16] = b0[1] || implicit nonce[4] || explicit nonce[8] || length[3] |
| 70 | * |
| 71 | * The field 'length' is encoded in field 'b0' as '(length width - 1)'. |
| 72 | * Hence b0 contains (3 - 1) = 2. |
| 73 | */ |
| 74 | #define TLS_AES_CCM_IV_B0_BYTE 2 |
| 75 | |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 76 | /* |
| 77 | * This structure defines the routines for Inline TLS driver. |
| 78 | * The following routines are optional and filled with a |
| 79 | * null pointer if not defined. |
| 80 | * |
| 81 | * @name: Its the name of registered Inline tls device |
| 82 | * @dev_list: Inline tls device list |
| 83 | * int (*feature)(struct tls_device *device); |
| 84 | * Called to return Inline TLS driver capability |
| 85 | * |
| 86 | * int (*hash)(struct tls_device *device, struct sock *sk); |
| 87 | * This function sets Inline driver for listen and program |
| 88 | * device specific functioanlity as required |
| 89 | * |
| 90 | * void (*unhash)(struct tls_device *device, struct sock *sk); |
| 91 | * This function cleans listen state set by Inline TLS driver |
Atul Gupta | df9d4a1 | 2018-12-11 02:20:09 -0800 | [diff] [blame] | 92 | * |
| 93 | * void (*release)(struct kref *kref); |
| 94 | * Release the registered device and allocated resources |
| 95 | * @kref: Number of reference to tls_device |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 96 | */ |
| 97 | struct tls_device { |
| 98 | char name[TLS_DEVICE_NAME_MAX]; |
| 99 | struct list_head dev_list; |
| 100 | int (*feature)(struct tls_device *device); |
| 101 | int (*hash)(struct tls_device *device, struct sock *sk); |
| 102 | void (*unhash)(struct tls_device *device, struct sock *sk); |
Atul Gupta | df9d4a1 | 2018-12-11 02:20:09 -0800 | [diff] [blame] | 103 | void (*release)(struct kref *kref); |
| 104 | struct kref kref; |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 105 | }; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 106 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 107 | enum { |
| 108 | TLS_BASE, |
| 109 | TLS_SW, |
| 110 | #ifdef CONFIG_TLS_DEVICE |
| 111 | TLS_HW, |
| 112 | #endif |
| 113 | TLS_HW_RECORD, |
| 114 | TLS_NUM_CONFIG, |
| 115 | }; |
| 116 | |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 117 | /* TLS records are maintained in 'struct tls_rec'. It stores the memory pages |
| 118 | * allocated or mapped for each TLS record. After encryption, the records are |
| 119 | * stores in a linked list. |
| 120 | */ |
| 121 | struct tls_rec { |
| 122 | struct list_head list; |
Vakul Garg | 9932a29 | 2018-09-24 15:35:56 +0530 | [diff] [blame] | 123 | int tx_ready; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 124 | int tx_flags; |
Vakul Garg | 4e6d472 | 2018-09-30 08:04:35 +0530 | [diff] [blame] | 125 | int inplace_crypto; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 126 | |
Daniel Borkmann | d829e9c | 2018-10-13 02:45:59 +0200 | [diff] [blame] | 127 | struct sk_msg msg_plaintext; |
| 128 | struct sk_msg msg_encrypted; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 129 | |
Daniel Borkmann | d829e9c | 2018-10-13 02:45:59 +0200 | [diff] [blame] | 130 | /* AAD | msg_plaintext.sg.data | sg_tag */ |
| 131 | struct scatterlist sg_aead_in[2]; |
| 132 | /* AAD | msg_encrypted.sg.data (data contains overhead for hdr & iv & tag) */ |
| 133 | struct scatterlist sg_aead_out[2]; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 134 | |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 135 | char content_type; |
| 136 | struct scatterlist sg_content_type; |
| 137 | |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 138 | char aad_space[TLS_AAD_SPACE_SIZE]; |
Vakul Garg | f295b3a | 2019-03-20 02:03:36 +0000 | [diff] [blame] | 139 | u8 iv_data[MAX_IV_SIZE]; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 140 | struct aead_request aead_req; |
| 141 | u8 aead_req_ctx[]; |
| 142 | }; |
| 143 | |
Vakul Garg | 2b794c4 | 2019-02-23 08:42:37 +0000 | [diff] [blame] | 144 | struct tls_msg { |
| 145 | struct strp_msg rxm; |
| 146 | u8 control; |
| 147 | }; |
| 148 | |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 149 | struct tx_work { |
| 150 | struct delayed_work work; |
| 151 | struct sock *sk; |
| 152 | }; |
| 153 | |
| 154 | struct tls_sw_context_tx { |
| 155 | struct crypto_aead *aead_send; |
| 156 | struct crypto_wait async_wait; |
| 157 | struct tx_work tx_work; |
| 158 | struct tls_rec *open_rec; |
Vakul Garg | 9932a29 | 2018-09-24 15:35:56 +0530 | [diff] [blame] | 159 | struct list_head tx_list; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 160 | atomic_t encrypt_pending; |
| 161 | int async_notify; |
Dave Watson | 5b053e1 | 2019-01-30 22:08:21 +0000 | [diff] [blame] | 162 | int async_capable; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 163 | |
| 164 | #define BIT_TX_SCHEDULED 0 |
| 165 | unsigned long tx_bitmask; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 168 | struct tls_sw_context_rx { |
| 169 | struct crypto_aead *aead_recv; |
| 170 | struct crypto_wait async_wait; |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 171 | struct strparser strp; |
Vakul Garg | 692d7b5 | 2019-01-16 10:40:16 +0000 | [diff] [blame] | 172 | struct sk_buff_head rx_list; /* list of decrypted 'data' records */ |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 173 | void (*saved_data_ready)(struct sock *sk); |
John Fastabend | 924ad65 | 2018-10-13 02:46:00 +0200 | [diff] [blame] | 174 | |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 175 | struct sk_buff *recv_pkt; |
| 176 | u8 control; |
Vakul Garg | 692d7b5 | 2019-01-16 10:40:16 +0000 | [diff] [blame] | 177 | int async_capable; |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 178 | bool decrypted; |
Vakul Garg | 94524d8 | 2018-08-29 15:26:55 +0530 | [diff] [blame] | 179 | atomic_t decrypt_pending; |
| 180 | bool async_notify; |
| 181 | }; |
| 182 | |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 183 | struct tls_record_info { |
| 184 | struct list_head list; |
| 185 | u32 end_seq; |
| 186 | int len; |
| 187 | int num_frags; |
| 188 | skb_frag_t frags[MAX_SKB_FRAGS]; |
| 189 | }; |
| 190 | |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 191 | struct tls_offload_context_tx { |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 192 | struct crypto_aead *aead_send; |
| 193 | spinlock_t lock; /* protects records list */ |
| 194 | struct list_head records_list; |
| 195 | struct tls_record_info *open_record; |
| 196 | struct tls_record_info *retransmit_hint; |
| 197 | u64 hint_record_sn; |
| 198 | u64 unacked_record_sn; |
| 199 | |
| 200 | struct scatterlist sg_tx_data[MAX_SKB_FRAGS]; |
| 201 | void (*sk_destruct)(struct sock *sk); |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 202 | u8 driver_state[] __aligned(8); |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 203 | /* The TLS layer reserves room for driver specific state |
| 204 | * Currently the belief is that there is not enough |
| 205 | * driver specific state to justify another layer of indirection |
| 206 | */ |
Jakub Kicinski | 2d6b51c | 2019-06-05 14:11:38 -0700 | [diff] [blame] | 207 | #define TLS_DRIVER_STATE_SIZE_TX 16 |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 208 | }; |
| 209 | |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 210 | #define TLS_OFFLOAD_CONTEXT_SIZE_TX \ |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 211 | (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX) |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 212 | |
Jakub Kicinski | e52972c | 2019-06-04 12:00:12 -0700 | [diff] [blame] | 213 | enum tls_context_flags { |
| 214 | TLS_RX_SYNC_RUNNING = 0, |
| 215 | }; |
| 216 | |
Dave Watson | dbe4255 | 2018-03-22 10:10:06 -0700 | [diff] [blame] | 217 | struct cipher_context { |
Dave Watson | dbe4255 | 2018-03-22 10:10:06 -0700 | [diff] [blame] | 218 | char *iv; |
Dave Watson | dbe4255 | 2018-03-22 10:10:06 -0700 | [diff] [blame] | 219 | char *rec_seq; |
| 220 | }; |
| 221 | |
Sabrina Dubroca | 86029d1 | 2018-09-12 17:44:42 +0200 | [diff] [blame] | 222 | union tls_crypto_context { |
| 223 | struct tls_crypto_info info; |
Dave Watson | fb99bce | 2019-01-30 21:58:05 +0000 | [diff] [blame] | 224 | union { |
| 225 | struct tls12_crypto_info_aes_gcm_128 aes_gcm_128; |
| 226 | struct tls12_crypto_info_aes_gcm_256 aes_gcm_256; |
| 227 | }; |
Sabrina Dubroca | 86029d1 | 2018-09-12 17:44:42 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 230 | struct tls_prot_info { |
| 231 | u16 version; |
| 232 | u16 cipher_type; |
| 233 | u16 prepend_size; |
| 234 | u16 tag_size; |
| 235 | u16 overhead_size; |
| 236 | u16 iv_size; |
Vakul Garg | f295b3a | 2019-03-20 02:03:36 +0000 | [diff] [blame] | 237 | u16 salt_size; |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 238 | u16 rec_seq_size; |
| 239 | u16 aad_size; |
| 240 | u16 tail_size; |
| 241 | }; |
| 242 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 243 | struct tls_context { |
Jakub Kicinski | f0aaa2c | 2019-06-03 15:17:04 -0700 | [diff] [blame] | 244 | /* read-only cache line */ |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 245 | struct tls_prot_info prot_info; |
| 246 | |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 247 | u8 tx_conf:3; |
| 248 | u8 rx_conf:3; |
Ilya Lesokhin | 6d88207 | 2017-11-13 10:22:45 +0200 | [diff] [blame] | 249 | |
Jakub Kicinski | f0aaa2c | 2019-06-03 15:17:04 -0700 | [diff] [blame] | 250 | int (*push_pending_record)(struct sock *sk, int flags); |
| 251 | void (*sk_write_space)(struct sock *sk); |
| 252 | |
| 253 | void *priv_ctx_tx; |
| 254 | void *priv_ctx_rx; |
| 255 | |
| 256 | struct net_device *netdev; |
| 257 | |
| 258 | /* rw cache line */ |
Dave Watson | dbe4255 | 2018-03-22 10:10:06 -0700 | [diff] [blame] | 259 | struct cipher_context tx; |
Dave Watson | c46234e | 2018-03-22 10:10:35 -0700 | [diff] [blame] | 260 | struct cipher_context rx; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 261 | |
| 262 | struct scatterlist *partially_sent_record; |
| 263 | u16 partially_sent_offset; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 264 | |
Dave Watson | c212d2c | 2018-05-01 13:05:39 -0700 | [diff] [blame] | 265 | bool in_tcp_sendpages; |
Daniel Borkmann | d829e9c | 2018-10-13 02:45:59 +0200 | [diff] [blame] | 266 | bool pending_open_record_frags; |
Jakub Kicinski | f0aaa2c | 2019-06-03 15:17:04 -0700 | [diff] [blame] | 267 | unsigned long flags; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 268 | |
Jakub Kicinski | f0aaa2c | 2019-06-03 15:17:04 -0700 | [diff] [blame] | 269 | /* cache cold stuff */ |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 270 | void (*sk_destruct)(struct sock *sk); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 271 | void (*sk_proto_close)(struct sock *sk, long timeout); |
| 272 | |
| 273 | int (*setsockopt)(struct sock *sk, int level, |
| 274 | int optname, char __user *optval, |
| 275 | unsigned int optlen); |
| 276 | int (*getsockopt)(struct sock *sk, int level, |
| 277 | int optname, char __user *optval, |
| 278 | int __user *optlen); |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 279 | int (*hash)(struct sock *sk); |
| 280 | void (*unhash)(struct sock *sk); |
Jakub Kicinski | f0aaa2c | 2019-06-03 15:17:04 -0700 | [diff] [blame] | 281 | |
| 282 | union tls_crypto_context crypto_send; |
| 283 | union tls_crypto_context crypto_recv; |
| 284 | |
| 285 | struct list_head list; |
| 286 | refcount_t refcount; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
Jakub Kicinski | da68b4a | 2019-04-25 12:32:03 -0700 | [diff] [blame] | 289 | enum tls_offload_ctx_dir { |
| 290 | TLS_OFFLOAD_CTX_DIR_RX, |
| 291 | TLS_OFFLOAD_CTX_DIR_TX, |
| 292 | }; |
| 293 | |
| 294 | struct tlsdev_ops { |
| 295 | int (*tls_dev_add)(struct net_device *netdev, struct sock *sk, |
| 296 | enum tls_offload_ctx_dir direction, |
| 297 | struct tls_crypto_info *crypto_info, |
| 298 | u32 start_offload_tcp_sn); |
| 299 | void (*tls_dev_del)(struct net_device *netdev, |
| 300 | struct tls_context *ctx, |
| 301 | enum tls_offload_ctx_dir direction); |
| 302 | void (*tls_dev_resync_rx)(struct net_device *netdev, |
Jakub Kicinski | 89fec47 | 2019-06-10 21:40:00 -0700 | [diff] [blame] | 303 | struct sock *sk, u32 seq, u8 *rcd_sn); |
Jakub Kicinski | da68b4a | 2019-04-25 12:32:03 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
Jakub Kicinski | f953d33b | 2019-06-10 21:40:02 -0700 | [diff] [blame^] | 306 | enum tls_offload_sync_type { |
| 307 | TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ = 0, |
| 308 | TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT = 1, |
| 309 | }; |
| 310 | |
| 311 | #define TLS_DEVICE_RESYNC_NH_START_IVAL 2 |
| 312 | #define TLS_DEVICE_RESYNC_NH_MAX_IVAL 128 |
| 313 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 314 | struct tls_offload_context_rx { |
| 315 | /* sw must be the first member of tls_offload_context_rx */ |
| 316 | struct tls_sw_context_rx sw; |
Jakub Kicinski | f953d33b | 2019-06-10 21:40:02 -0700 | [diff] [blame^] | 317 | enum tls_offload_sync_type resync_type; |
| 318 | /* this member is set regardless of resync_type, to avoid branches */ |
| 319 | u8 resync_nh_reset:1; |
| 320 | /* CORE_NEXT_HINT-only member, but use the hole here */ |
| 321 | u8 resync_nh_do_now:1; |
| 322 | union { |
| 323 | /* TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ */ |
| 324 | struct { |
| 325 | atomic64_t resync_req; |
| 326 | }; |
| 327 | /* TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT */ |
| 328 | struct { |
| 329 | u32 decrypted_failed; |
| 330 | u32 decrypted_tgt; |
| 331 | } resync_nh; |
| 332 | }; |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 333 | u8 driver_state[] __aligned(8); |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 334 | /* The TLS layer reserves room for driver specific state |
| 335 | * Currently the belief is that there is not enough |
| 336 | * driver specific state to justify another layer of indirection |
| 337 | */ |
Jakub Kicinski | 2d6b51c | 2019-06-05 14:11:38 -0700 | [diff] [blame] | 338 | #define TLS_DRIVER_STATE_SIZE_RX 8 |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | #define TLS_OFFLOAD_CONTEXT_SIZE_RX \ |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 342 | (sizeof(struct tls_offload_context_rx) + TLS_DRIVER_STATE_SIZE_RX) |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 343 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 344 | int wait_on_pending_writer(struct sock *sk, long *timeo); |
| 345 | int tls_sk_query(struct sock *sk, int optname, char __user *optval, |
| 346 | int __user *optlen); |
| 347 | int tls_sk_attach(struct sock *sk, int optname, char __user *optval, |
| 348 | unsigned int optlen); |
| 349 | |
Dave Watson | c46234e | 2018-03-22 10:10:35 -0700 | [diff] [blame] | 350 | int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 351 | int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); |
| 352 | int tls_sw_sendpage(struct sock *sk, struct page *page, |
| 353 | int offset, size_t size, int flags); |
| 354 | void tls_sw_close(struct sock *sk, long timeout); |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 355 | void tls_sw_free_resources_tx(struct sock *sk); |
| 356 | void tls_sw_free_resources_rx(struct sock *sk); |
Boris Pismenny | 39f56e1 | 2018-07-13 14:33:41 +0300 | [diff] [blame] | 357 | void tls_sw_release_resources_rx(struct sock *sk); |
Dave Watson | c46234e | 2018-03-22 10:10:35 -0700 | [diff] [blame] | 358 | int tls_sw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, |
| 359 | int nonblock, int flags, int *addr_len); |
John Fastabend | 924ad65 | 2018-10-13 02:46:00 +0200 | [diff] [blame] | 360 | bool tls_sw_stream_read(const struct sock *sk); |
Dave Watson | c46234e | 2018-03-22 10:10:35 -0700 | [diff] [blame] | 361 | ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, |
| 362 | struct pipe_inode_info *pipe, |
| 363 | size_t len, unsigned int flags); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 364 | |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 365 | int tls_set_device_offload(struct sock *sk, struct tls_context *ctx); |
| 366 | int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); |
| 367 | int tls_device_sendpage(struct sock *sk, struct page *page, |
| 368 | int offset, size_t size, int flags); |
Jakub Kicinski | 35b71a34 | 2019-04-10 11:04:31 -0700 | [diff] [blame] | 369 | void tls_device_free_resources_tx(struct sock *sk); |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 370 | void tls_device_init(void); |
| 371 | void tls_device_cleanup(void); |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 372 | int tls_tx_records(struct sock *sk, int flags); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 373 | |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 374 | struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 375 | u32 seq, u64 *p_record_sn); |
| 376 | |
| 377 | static inline bool tls_record_is_start_marker(struct tls_record_info *rec) |
| 378 | { |
| 379 | return rec->len == 0; |
| 380 | } |
| 381 | |
| 382 | static inline u32 tls_record_start_seq(struct tls_record_info *rec) |
| 383 | { |
| 384 | return rec->end_seq - rec->len; |
| 385 | } |
| 386 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 387 | int tls_push_sg(struct sock *sk, struct tls_context *ctx, |
| 388 | struct scatterlist *sg, u16 first_offset, |
| 389 | int flags); |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 390 | int tls_push_partial_record(struct sock *sk, struct tls_context *ctx, |
| 391 | int flags); |
Jakub Kicinski | 35b71a34 | 2019-04-10 11:04:31 -0700 | [diff] [blame] | 392 | bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx); |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 393 | |
Vakul Garg | 2b794c4 | 2019-02-23 08:42:37 +0000 | [diff] [blame] | 394 | static inline struct tls_msg *tls_msg(struct sk_buff *skb) |
| 395 | { |
| 396 | return (struct tls_msg *)strp_msg(skb); |
| 397 | } |
| 398 | |
Boris Pismenny | 9485025 | 2019-02-27 17:38:03 +0200 | [diff] [blame] | 399 | static inline bool tls_is_partially_sent_record(struct tls_context *ctx) |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 400 | { |
Boris Pismenny | 9485025 | 2019-02-27 17:38:03 +0200 | [diff] [blame] | 401 | return !!ctx->partially_sent_record; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static inline int tls_complete_pending_work(struct sock *sk, |
| 405 | struct tls_context *ctx, |
| 406 | int flags, long *timeo) |
| 407 | { |
| 408 | int rc = 0; |
| 409 | |
| 410 | if (unlikely(sk->sk_write_pending)) |
| 411 | rc = wait_on_pending_writer(sk, timeo); |
| 412 | |
Boris Pismenny | 9485025 | 2019-02-27 17:38:03 +0200 | [diff] [blame] | 413 | if (!rc && tls_is_partially_sent_record(ctx)) |
| 414 | rc = tls_push_partial_record(sk, ctx, flags); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 415 | |
| 416 | return rc; |
| 417 | } |
| 418 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 419 | static inline bool tls_is_pending_open_record(struct tls_context *tls_ctx) |
| 420 | { |
| 421 | return tls_ctx->pending_open_record_frags; |
| 422 | } |
| 423 | |
Vakul Garg | 9932a29 | 2018-09-24 15:35:56 +0530 | [diff] [blame] | 424 | static inline bool is_tx_ready(struct tls_sw_context_tx *ctx) |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 425 | { |
| 426 | struct tls_rec *rec; |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 427 | |
Vakul Garg | 9932a29 | 2018-09-24 15:35:56 +0530 | [diff] [blame] | 428 | rec = list_first_entry(&ctx->tx_list, struct tls_rec, list); |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 429 | if (!rec) |
| 430 | return false; |
| 431 | |
Vakul Garg | 9932a29 | 2018-09-24 15:35:56 +0530 | [diff] [blame] | 432 | return READ_ONCE(rec->tx_ready); |
Vakul Garg | a42055e | 2018-09-21 09:46:13 +0530 | [diff] [blame] | 433 | } |
| 434 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 435 | struct sk_buff * |
| 436 | tls_validate_xmit_skb(struct sock *sk, struct net_device *dev, |
| 437 | struct sk_buff *skb); |
| 438 | |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 439 | static inline bool tls_is_sk_tx_device_offloaded(struct sock *sk) |
| 440 | { |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 441 | #ifdef CONFIG_SOCK_VALIDATE_XMIT |
Jakub Kicinski | b4f47f3 | 2019-04-08 17:59:50 -0700 | [diff] [blame] | 442 | return sk_fullsock(sk) && |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 443 | (smp_load_acquire(&sk->sk_validate_xmit_skb) == |
| 444 | &tls_validate_xmit_skb); |
| 445 | #else |
| 446 | return false; |
| 447 | #endif |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 448 | } |
| 449 | |
Dave Watson | f4a8e43 | 2018-03-22 10:10:15 -0700 | [diff] [blame] | 450 | static inline void tls_err_abort(struct sock *sk, int err) |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 451 | { |
Dave Watson | f4a8e43 | 2018-03-22 10:10:15 -0700 | [diff] [blame] | 452 | sk->sk_err = err; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 453 | sk->sk_error_report(sk); |
| 454 | } |
| 455 | |
| 456 | static inline bool tls_bigint_increment(unsigned char *seq, int len) |
| 457 | { |
| 458 | int i; |
| 459 | |
| 460 | for (i = len - 1; i >= 0; i--) { |
| 461 | ++seq[i]; |
| 462 | if (seq[i] != 0) |
| 463 | break; |
| 464 | } |
| 465 | |
| 466 | return (i == -1); |
| 467 | } |
| 468 | |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 469 | static inline struct tls_context *tls_get_ctx(const struct sock *sk) |
| 470 | { |
| 471 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 472 | |
| 473 | return icsk->icsk_ulp_data; |
| 474 | } |
| 475 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 476 | static inline void tls_advance_record_sn(struct sock *sk, |
Jakub Kicinski | fb0f886 | 2019-06-03 15:17:05 -0700 | [diff] [blame] | 477 | struct tls_prot_info *prot, |
| 478 | struct cipher_context *ctx) |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 479 | { |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 480 | if (tls_bigint_increment(ctx->rec_seq, prot->rec_seq_size)) |
Dave Watson | f4a8e43 | 2018-03-22 10:10:15 -0700 | [diff] [blame] | 481 | tls_err_abort(sk, EBADMSG); |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 482 | |
Jakub Kicinski | fb0f886 | 2019-06-03 15:17:05 -0700 | [diff] [blame] | 483 | if (prot->version != TLS_1_3_VERSION) |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 484 | tls_bigint_increment(ctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 485 | prot->iv_size); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static inline void tls_fill_prepend(struct tls_context *ctx, |
| 489 | char *buf, |
| 490 | size_t plaintext_len, |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 491 | unsigned char record_type, |
| 492 | int version) |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 493 | { |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 494 | struct tls_prot_info *prot = &ctx->prot_info; |
| 495 | size_t pkt_len, iv_size = prot->iv_size; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 496 | |
Vakul Garg | 4509de1 | 2019-02-14 07:11:35 +0000 | [diff] [blame] | 497 | pkt_len = plaintext_len + prot->tag_size; |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 498 | if (version != TLS_1_3_VERSION) { |
| 499 | pkt_len += iv_size; |
| 500 | |
| 501 | memcpy(buf + TLS_NONCE_OFFSET, |
| 502 | ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv_size); |
| 503 | } |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 504 | |
| 505 | /* we cover nonce explicit here as well, so buf should be of |
| 506 | * size KTLS_DTLS_HEADER_SIZE + KTLS_DTLS_NONCE_EXPLICIT_SIZE |
| 507 | */ |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 508 | buf[0] = version == TLS_1_3_VERSION ? |
| 509 | TLS_RECORD_TYPE_DATA : record_type; |
| 510 | /* Note that VERSION must be TLS_1_2 for both TLS1.2 and TLS1.3 */ |
| 511 | buf[1] = TLS_1_2_VERSION_MINOR; |
| 512 | buf[2] = TLS_1_2_VERSION_MAJOR; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 513 | /* we can use IV for nonce explicit according to spec */ |
| 514 | buf[3] = pkt_len >> 8; |
| 515 | buf[4] = pkt_len & 0xFF; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Ilya Lesokhin | 213ef6e | 2017-11-13 10:22:47 +0200 | [diff] [blame] | 518 | static inline void tls_make_aad(char *buf, |
| 519 | size_t size, |
| 520 | char *record_sequence, |
| 521 | int record_sequence_size, |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 522 | unsigned char record_type, |
| 523 | int version) |
Ilya Lesokhin | 213ef6e | 2017-11-13 10:22:47 +0200 | [diff] [blame] | 524 | { |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 525 | if (version != TLS_1_3_VERSION) { |
| 526 | memcpy(buf, record_sequence, record_sequence_size); |
| 527 | buf += 8; |
| 528 | } else { |
| 529 | size += TLS_CIPHER_AES_GCM_128_TAG_SIZE; |
| 530 | } |
Ilya Lesokhin | 213ef6e | 2017-11-13 10:22:47 +0200 | [diff] [blame] | 531 | |
Dave Watson | 130b392 | 2019-01-30 21:58:31 +0000 | [diff] [blame] | 532 | buf[0] = version == TLS_1_3_VERSION ? |
| 533 | TLS_RECORD_TYPE_DATA : record_type; |
| 534 | buf[1] = TLS_1_2_VERSION_MAJOR; |
| 535 | buf[2] = TLS_1_2_VERSION_MINOR; |
| 536 | buf[3] = size >> 8; |
| 537 | buf[4] = size & 0xFF; |
| 538 | } |
| 539 | |
| 540 | static inline void xor_iv_with_seq(int version, char *iv, char *seq) |
| 541 | { |
| 542 | int i; |
| 543 | |
| 544 | if (version == TLS_1_3_VERSION) { |
| 545 | for (i = 0; i < 8; i++) |
| 546 | iv[i + 4] ^= seq[i]; |
| 547 | } |
Ilya Lesokhin | 213ef6e | 2017-11-13 10:22:47 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 550 | |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 551 | static inline struct tls_sw_context_rx *tls_sw_ctx_rx( |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 552 | const struct tls_context *tls_ctx) |
| 553 | { |
Boris Pismenny | f66de3e | 2018-04-30 10:16:15 +0300 | [diff] [blame] | 554 | return (struct tls_sw_context_rx *)tls_ctx->priv_ctx_rx; |
| 555 | } |
| 556 | |
| 557 | static inline struct tls_sw_context_tx *tls_sw_ctx_tx( |
| 558 | const struct tls_context *tls_ctx) |
| 559 | { |
| 560 | return (struct tls_sw_context_tx *)tls_ctx->priv_ctx_tx; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 563 | static inline struct tls_offload_context_tx * |
| 564 | tls_offload_ctx_tx(const struct tls_context *tls_ctx) |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 565 | { |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 566 | return (struct tls_offload_context_tx *)tls_ctx->priv_ctx_tx; |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 567 | } |
| 568 | |
John Fastabend | 0608c69 | 2018-12-20 11:35:35 -0800 | [diff] [blame] | 569 | static inline bool tls_sw_has_ctx_tx(const struct sock *sk) |
| 570 | { |
| 571 | struct tls_context *ctx = tls_get_ctx(sk); |
| 572 | |
| 573 | if (!ctx) |
| 574 | return false; |
| 575 | return !!tls_sw_ctx_tx(ctx); |
| 576 | } |
| 577 | |
Boris Pismenny | 7463d3a | 2019-02-27 17:38:04 +0200 | [diff] [blame] | 578 | void tls_sw_write_space(struct sock *sk, struct tls_context *ctx); |
| 579 | void tls_device_write_space(struct sock *sk, struct tls_context *ctx); |
| 580 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 581 | static inline struct tls_offload_context_rx * |
| 582 | tls_offload_ctx_rx(const struct tls_context *tls_ctx) |
| 583 | { |
| 584 | return (struct tls_offload_context_rx *)tls_ctx->priv_ctx_rx; |
| 585 | } |
| 586 | |
Jakub Kicinski | 2e36117 | 2019-06-05 14:11:39 -0700 | [diff] [blame] | 587 | #if IS_ENABLED(CONFIG_TLS_DEVICE) |
| 588 | static inline void *__tls_driver_ctx(struct tls_context *tls_ctx, |
| 589 | enum tls_offload_ctx_dir direction) |
| 590 | { |
| 591 | if (direction == TLS_OFFLOAD_CTX_DIR_TX) |
| 592 | return tls_offload_ctx_tx(tls_ctx)->driver_state; |
| 593 | else |
| 594 | return tls_offload_ctx_rx(tls_ctx)->driver_state; |
| 595 | } |
| 596 | |
| 597 | static inline void * |
| 598 | tls_driver_ctx(const struct sock *sk, enum tls_offload_ctx_dir direction) |
| 599 | { |
| 600 | return __tls_driver_ctx(tls_get_ctx(sk), direction); |
| 601 | } |
| 602 | #endif |
| 603 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 604 | /* The TLS context is valid until sk_destruct is called */ |
| 605 | static inline void tls_offload_rx_resync_request(struct sock *sk, __be32 seq) |
| 606 | { |
| 607 | struct tls_context *tls_ctx = tls_get_ctx(sk); |
| 608 | struct tls_offload_context_rx *rx_ctx = tls_offload_ctx_rx(tls_ctx); |
| 609 | |
Jakub Kicinski | 63a1c95 | 2019-04-25 12:32:04 -0700 | [diff] [blame] | 610 | atomic64_set(&rx_ctx->resync_req, ((u64)ntohl(seq) << 32) | 1); |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 611 | } |
| 612 | |
Jakub Kicinski | f953d33b | 2019-06-10 21:40:02 -0700 | [diff] [blame^] | 613 | static inline void |
| 614 | tls_offload_rx_resync_set_type(struct sock *sk, enum tls_offload_sync_type type) |
| 615 | { |
| 616 | struct tls_context *tls_ctx = tls_get_ctx(sk); |
| 617 | |
| 618 | tls_offload_ctx_rx(tls_ctx)->resync_type = type; |
| 619 | } |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 620 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 621 | int tls_proccess_cmsg(struct sock *sk, struct msghdr *msg, |
| 622 | unsigned char *record_type); |
Atul Gupta | dd0bed1 | 2018-03-31 21:41:52 +0530 | [diff] [blame] | 623 | void tls_register_device(struct tls_device *device); |
| 624 | void tls_unregister_device(struct tls_device *device); |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 625 | int tls_device_decrypted(struct sock *sk, struct sk_buff *skb); |
Boris Pismenny | dafb67f | 2018-07-13 14:33:40 +0300 | [diff] [blame] | 626 | int decrypt_skb(struct sock *sk, struct sk_buff *skb, |
| 627 | struct scatterlist *sgout); |
Dirk van der Merwe | b9727d7 | 2019-06-05 14:11:40 -0700 | [diff] [blame] | 628 | struct sk_buff *tls_encrypt_skb(struct sk_buff *skb); |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 629 | |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 630 | struct sk_buff *tls_validate_xmit_skb(struct sock *sk, |
| 631 | struct net_device *dev, |
| 632 | struct sk_buff *skb); |
| 633 | |
| 634 | int tls_sw_fallback_init(struct sock *sk, |
Boris Pismenny | d80a1b9d | 2018-07-13 14:33:39 +0300 | [diff] [blame] | 635 | struct tls_offload_context_tx *offload_ctx, |
Ilya Lesokhin | e8f6979 | 2018-04-30 10:16:16 +0300 | [diff] [blame] | 636 | struct tls_crypto_info *crypto_info); |
| 637 | |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 638 | int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx); |
| 639 | |
| 640 | void tls_device_offload_cleanup_rx(struct sock *sk); |
Jakub Kicinski | f953d33b | 2019-06-10 21:40:02 -0700 | [diff] [blame^] | 641 | void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq); |
Boris Pismenny | 4799ac8 | 2018-07-13 14:33:43 +0300 | [diff] [blame] | 642 | |
Dave Watson | 3c4d755 | 2017-06-14 11:37:39 -0700 | [diff] [blame] | 643 | #endif /* _TLS_OFFLOAD_H */ |