| 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 OSSL_INTERNAL_BIO_H |
| 11 | # define OSSL_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 | /* Changes to these internal BIOs must also update include/openssl/bio.h */ |
| 39 | # define BIO_CTRL_SET_KTLS 72 |
| 40 | # define BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG 74 |
| 41 | # define BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG 75 |
| 42 | |
| 43 | /* |
| 44 | * This is used with socket BIOs: |
| 45 | * BIO_FLAGS_KTLS_TX means we are using ktls with this BIO for sending. |
| 46 | * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next. |
| 47 | * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving. |
| 48 | */ |
| 49 | # define BIO_FLAGS_KTLS_TX 0x800 |
| 50 | # define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000 |
| 51 | # define BIO_FLAGS_KTLS_RX 0x2000 |
| 52 | |
| 53 | /* KTLS related controls and flags */ |
| 54 | # define BIO_set_ktls_flag(b, is_tx) \ |
| 55 | BIO_set_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) |
| 56 | # define BIO_should_ktls_flag(b, is_tx) \ |
| 57 | BIO_test_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) |
| 58 | # define BIO_set_ktls_ctrl_msg_flag(b) \ |
| 59 | BIO_set_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) |
| 60 | # define BIO_should_ktls_ctrl_msg_flag(b) \ |
| 61 | BIO_test_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) |
| 62 | # define BIO_clear_ktls_ctrl_msg_flag(b) \ |
| 63 | BIO_clear_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) |
| 64 | |
| 65 | # define BIO_set_ktls(b, keyblob, is_tx) \ |
| 66 | BIO_ctrl(b, BIO_CTRL_SET_KTLS, is_tx, keyblob) |
| 67 | # define BIO_set_ktls_ctrl_msg(b, record_type) \ |
| 68 | BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG, record_type, NULL) |
| 69 | # define BIO_clear_ktls_ctrl_msg(b) \ |
| 70 | BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG, 0, NULL) |
| 71 | |
| 72 | #endif |
| 73 | |