bio: Linux TLS Offload
[openssl.git] / include / internal / bio.h
1 /*
2  * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef HEADER_INTERNAL_BIO_H
11 # define HEADER_INTERNAL_BIO_H
12
13 #include <openssl/bio.h>
14
15 struct bio_method_st {
16     int type;
17     char *name;
18     int (*bwrite) (BIO *, const char *, size_t, size_t *);
19     int (*bwrite_old) (BIO *, const char *, int);
20     int (*bread) (BIO *, char *, size_t, size_t *);
21     int (*bread_old) (BIO *, char *, int);
22     int (*bputs) (BIO *, const char *);
23     int (*bgets) (BIO *, char *, int);
24     long (*ctrl) (BIO *, int, long, void *);
25     int (*create) (BIO *);
26     int (*destroy) (BIO *);
27     long (*callback_ctrl) (BIO *, int, BIO_info_cb *);
28 };
29
30 void bio_free_ex_data(BIO *bio);
31 void bio_cleanup(void);
32
33
34 /* Old style to new style BIO_METHOD conversion functions */
35 int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written);
36 int bread_conv(BIO *bio, char *data, size_t datal, size_t *read);
37
38 # define BIO_CTRL_SET_KTLS_SEND                 72
39 # define BIO_CTRL_SET_KTLS_SEND_CTRL_MSG        74
40 # define BIO_CTRL_CLEAR_KTLS_CTRL_MSG      75
41
42 /*
43  * This is used with socket BIOs:
44  * BIO_FLAGS_KTLS means we are using ktls with this BIO.
45  * BIO_FLAGS_KTLS_CTRL_MSG means we are about to send a ctrl message next.
46  */
47 # define BIO_FLAGS_KTLS          0x800
48 # define BIO_FLAGS_KTLS_CTRL_MSG 0x1000
49
50 /* KTLS related controls and flags */
51 # define BIO_set_ktls_flag(b) \
52     BIO_set_flags(b, BIO_FLAGS_KTLS)
53 # define BIO_should_ktls_flag(b) \
54     BIO_test_flags(b, BIO_FLAGS_KTLS)
55 # define BIO_set_ktls_ctrl_msg_flag(b) \
56     BIO_set_flags(b, BIO_FLAGS_KTLS_CTRL_MSG)
57 # define BIO_should_ktls_ctrl_msg_flag(b) \
58     BIO_test_flags(b, (BIO_FLAGS_KTLS_CTRL_MSG))
59 # define BIO_clear_ktls_ctrl_msg_flag(b) \
60     BIO_clear_flags(b, (BIO_FLAGS_KTLS_CTRL_MSG))
61
62 #  define BIO_set_ktls(b, keyblob, is_tx)   \
63      BIO_ctrl(b, BIO_CTRL_SET_KTLS_SEND, is_tx, keyblob)
64 #  define BIO_set_ktls_ctrl_msg(b, record_type)   \
65      BIO_ctrl(b, BIO_CTRL_SET_KTLS_SEND_CTRL_MSG, record_type, NULL)
66 #  define BIO_clear_ktls_ctrl_msg(b) \
67      BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_CTRL_MSG, 0, NULL)
68
69 #endif