Debian Codegraph @

crt/s2n/tls/s2n_ktls.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include "api/unstable/ktls.h"
19 #include "tls/s2n_connection.h"
20 /* Define headers needed to enable and use kTLS.
21 *
22 * The inline header definitions are required to compile kTLS specific code.
23 * kTLS has been tested on linux. For all other platforms, kTLS is marked as
24 * unsupported, and will return an unsupported error.
25 */
26 #include "tls/s2n_ktls_parameters.h"
27
28 /* A set of kTLS configurations representing the combination of sending
29 * and receiving.
30 */
31 typedef enum {
32 /* Enable kTLS for the send socket. */
33 S2N_KTLS_MODE_SEND,
34 /* Enable kTLS for the receive socket. */
35 S2N_KTLS_MODE_RECV,
36 } s2n_ktls_mode;
37
38 bool s2n_ktls_is_supported_on_platform();
39 S2N_RESULT s2n_ktls_get_file_descriptor(struct s2n_connection *conn, s2n_ktls_mode ktls_mode, int *fd);
40
41 int s2n_ktls_send_cb(void *io_context, const uint8_t *buf, uint32_t len);
42 ssize_t s2n_ktls_sendv_with_offset(struct s2n_connection *conn, const struct iovec *bufs,
43 ssize_t count, ssize_t offs, s2n_blocked_status *blocked);
44 int s2n_ktls_record_writev(struct s2n_connection *conn, uint8_t content_type,
45 const struct iovec *in, int in_count, size_t offs, size_t to_write);
46 int s2n_ktls_read_full_record(struct s2n_connection *conn, uint8_t *record_type);
47 S2N_RESULT s2n_ktls_key_update_send(struct s2n_connection *conn, size_t bytes_requested);
48 S2N_RESULT s2n_ktls_key_update_process(struct s2n_connection *conn);
49 S2N_RESULT s2n_ktls_set_estimated_sequence_number(struct s2n_connection *conn, size_t bytes_written);
50 S2N_RESULT s2n_ktls_check_estimated_record_limit(struct s2n_connection *conn, size_t bytes_requested);
51
52 int s2n_connection_ktls_enable_send(struct s2n_connection *conn);
53 int s2n_connection_ktls_enable_recv(struct s2n_connection *conn);
54
55 #ifndef _WIN32
56
57 #include <sys/socket.h>
58
59 /* These use POSIX socket types not available on Windows */
60 S2N_RESULT s2n_ktls_sendmsg(void *io_context, uint8_t record_type, const struct iovec *msg_iov,
61 size_t msg_iovlen, s2n_blocked_status *blocked, size_t *bytes_written);
62 S2N_RESULT s2n_ktls_recvmsg(void *io_context, uint8_t *record_type, uint8_t *buf,
63 size_t buf_len, s2n_blocked_status *blocked, size_t *bytes_read);
64
65 /* Testing */
66 typedef int (*s2n_setsockopt_fn)(int socket, int level, int option_name, const void *option_value,
67 socklen_t option_len);
68 S2N_RESULT s2n_ktls_set_setsockopt_cb(s2n_setsockopt_fn cb);
69 typedef ssize_t (*s2n_ktls_sendmsg_fn)(void *io_context, const struct msghdr *msg);
70 typedef ssize_t (*s2n_ktls_recvmsg_fn)(void *io_context, struct msghdr *msg);
71 S2N_RESULT s2n_ktls_set_sendmsg_cb(struct s2n_connection *conn, s2n_ktls_sendmsg_fn send_cb,
72 void *send_ctx);
73 S2N_RESULT s2n_ktls_set_recvmsg_cb(struct s2n_connection *conn, s2n_ktls_recvmsg_fn recv_cb,
74 void *recv_ctx);
75 void s2n_ktls_configure_connection(struct s2n_connection *conn, s2n_ktls_mode ktls_mode);
76
77 int s2n_sendfile(struct s2n_connection *conn, int in_fd, off_t offset, size_t count,
78 size_t *bytes_written, s2n_blocked_status *blocked);
79 #endif