Debian Codegraph @

crt/s2n/tls/s2n_async_offload.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/async_offload.h"
19 #include "crypto/s2n_signature.h"
20 #include "tls/s2n_async_pkey.h"
21 #include "tls/s2n_handshake.h"
22 #include "utils/s2n_blob.h"
23 #include "utils/s2n_result.h"
24
25 /**
26 * Macro to handle async re-entry in a handshake state handler that may invoke the async offloading callback.
27 * Add this guard to the code that should only be executed in the initial entry (i.e. when async_state ==
28 * S2N_ASYNC_NOT_INVOKED). If the async operation is invoked but not completed, we throw an error to indicate
29 * the handshake is still blocked. After the async operation is completed and the user retries s2n_negotiate(),
30 * we reset the async_offload_op object and proceed with the remaining code in the current state.
31 */
32 #define S2N_ASYNC_OFFLOAD_POSIX_GUARD(conn, code) \
33 POSIX_ENSURE_REF(conn); \
34 if (conn->async_offload_op.async_state == S2N_ASYNC_NOT_INVOKED) { \
35 code; \
36 } else if (conn->async_offload_op.async_state == S2N_ASYNC_INVOKED) { \
37 POSIX_BAIL(S2N_ERR_ASYNC_BLOCKED); \
38 } \
39 POSIX_GUARD_RESULT(s2n_async_offload_op_reset(&conn->async_offload_op));
40
41 typedef S2N_RESULT (*s2n_async_offload_perform_fn)(struct s2n_async_offload_op *op);
42
43 typedef S2N_RESULT (*s2n_async_offload_op_data_free)(struct s2n_async_offload_op *op);
44
45 struct s2n_async_offload_op {
46 s2n_async_offload_op_type type;
47 s2n_async_state async_state;
48 struct s2n_connection *conn;
49 s2n_async_offload_perform_fn perform;
50 s2n_async_offload_op_data_free op_data_free;
51 /* Collect arguments required by each operation */
52 union {
53 struct s2n_async_pkey_verify_data async_pkey_verify;
54 /* Add a new struct for each supported op type */
55 } op_data;
56 };
57
58 S2N_RESULT s2n_async_offload_cb_invoke(struct s2n_connection *conn, struct s2n_async_offload_op *op);
59 S2N_RESULT s2n_async_offload_op_wipe(struct s2n_async_offload_op *op);
60 S2N_RESULT s2n_async_offload_op_reset(struct s2n_async_offload_op *op);
61 bool s2n_async_offload_op_is_in_allow_list(struct s2n_config *config, s2n_async_offload_op_type op_type);