1c7da899bSchristos /* 2*b0d17251Schristos * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved. 3c7da899bSchristos * 4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use 5c7da899bSchristos * this file except in compliance with the License. You can obtain a copy 6c7da899bSchristos * in the file LICENSE in the source distribution or at 7c7da899bSchristos * https://www.openssl.org/source/license.html 8c7da899bSchristos */ 9c7da899bSchristos 10*b0d17251Schristos #ifndef OSSL_INTERNAL_BIO_H 11*b0d17251Schristos # define OSSL_INTERNAL_BIO_H 12*b0d17251Schristos # pragma once 13*b0d17251Schristos 14*b0d17251Schristos # include <openssl/core.h> 15c7da899bSchristos # include <openssl/bio.h> 16c7da899bSchristos 17c7da899bSchristos struct bio_method_st { 18c7da899bSchristos int type; 1953060421Schristos char *name; 2013d40330Schristos int (*bwrite) (BIO *, const char *, size_t, size_t *); 2113d40330Schristos int (*bwrite_old) (BIO *, const char *, int); 2213d40330Schristos int (*bread) (BIO *, char *, size_t, size_t *); 2313d40330Schristos int (*bread_old) (BIO *, char *, int); 24c7da899bSchristos int (*bputs) (BIO *, const char *); 25c7da899bSchristos int (*bgets) (BIO *, char *, int); 26c7da899bSchristos long (*ctrl) (BIO *, int, long, void *); 27c7da899bSchristos int (*create) (BIO *); 28c7da899bSchristos int (*destroy) (BIO *); 2953060421Schristos long (*callback_ctrl) (BIO *, int, BIO_info_cb *); 30c7da899bSchristos }; 31c7da899bSchristos 32c7da899bSchristos void bio_free_ex_data(BIO *bio); 33c7da899bSchristos void bio_cleanup(void); 3413d40330Schristos 3513d40330Schristos 3613d40330Schristos /* Old style to new style BIO_METHOD conversion functions */ 3713d40330Schristos int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written); 3813d40330Schristos int bread_conv(BIO *bio, char *data, size_t datal, size_t *read); 39*b0d17251Schristos 40*b0d17251Schristos /* Changes to these internal BIOs must also update include/openssl/bio.h */ 41*b0d17251Schristos # define BIO_CTRL_SET_KTLS 72 42*b0d17251Schristos # define BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG 74 43*b0d17251Schristos # define BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG 75 44*b0d17251Schristos 45*b0d17251Schristos /* 46*b0d17251Schristos * This is used with socket BIOs: 47*b0d17251Schristos * BIO_FLAGS_KTLS_TX means we are using ktls with this BIO for sending. 48*b0d17251Schristos * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next. 49*b0d17251Schristos * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving. 50*b0d17251Schristos */ 51*b0d17251Schristos # define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000 52*b0d17251Schristos # define BIO_FLAGS_KTLS_RX 0x2000 53*b0d17251Schristos # define BIO_FLAGS_KTLS_TX 0x4000 54*b0d17251Schristos 55*b0d17251Schristos /* KTLS related controls and flags */ 56*b0d17251Schristos # define BIO_set_ktls_flag(b, is_tx) \ 57*b0d17251Schristos BIO_set_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) 58*b0d17251Schristos # define BIO_should_ktls_flag(b, is_tx) \ 59*b0d17251Schristos BIO_test_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) 60*b0d17251Schristos # define BIO_set_ktls_ctrl_msg_flag(b) \ 61*b0d17251Schristos BIO_set_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 62*b0d17251Schristos # define BIO_should_ktls_ctrl_msg_flag(b) \ 63*b0d17251Schristos BIO_test_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 64*b0d17251Schristos # define BIO_clear_ktls_ctrl_msg_flag(b) \ 65*b0d17251Schristos BIO_clear_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 66*b0d17251Schristos 67*b0d17251Schristos # define BIO_set_ktls(b, keyblob, is_tx) \ 68*b0d17251Schristos BIO_ctrl(b, BIO_CTRL_SET_KTLS, is_tx, keyblob) 69*b0d17251Schristos # define BIO_set_ktls_ctrl_msg(b, record_type) \ 70*b0d17251Schristos BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG, record_type, NULL) 71*b0d17251Schristos # define BIO_clear_ktls_ctrl_msg(b) \ 72*b0d17251Schristos BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG, 0, NULL) 73*b0d17251Schristos 74*b0d17251Schristos /* Functions to allow the core to offer the CORE_BIO type to providers */ 75*b0d17251Schristos OSSL_CORE_BIO *ossl_core_bio_new_from_bio(BIO *bio); 76*b0d17251Schristos OSSL_CORE_BIO *ossl_core_bio_new_file(const char *filename, const char *mode); 77*b0d17251Schristos OSSL_CORE_BIO *ossl_core_bio_new_mem_buf(const void *buf, int len); 78*b0d17251Schristos int ossl_core_bio_read_ex(OSSL_CORE_BIO *cb, void *data, size_t dlen, 79*b0d17251Schristos size_t *readbytes); 80*b0d17251Schristos int ossl_core_bio_write_ex(OSSL_CORE_BIO *cb, const void *data, size_t dlen, 81*b0d17251Schristos size_t *written); 82*b0d17251Schristos int ossl_core_bio_gets(OSSL_CORE_BIO *cb, char *buf, int size); 83*b0d17251Schristos int ossl_core_bio_puts(OSSL_CORE_BIO *cb, const char *buf); 84*b0d17251Schristos long ossl_core_bio_ctrl(OSSL_CORE_BIO *cb, int cmd, long larg, void *parg); 85*b0d17251Schristos int ossl_core_bio_up_ref(OSSL_CORE_BIO *cb); 86*b0d17251Schristos int ossl_core_bio_free(OSSL_CORE_BIO *cb); 87*b0d17251Schristos int ossl_core_bio_vprintf(OSSL_CORE_BIO *cb, const char *format, va_list args); 88*b0d17251Schristos 89*b0d17251Schristos int ossl_bio_init_core(OSSL_LIB_CTX *libctx, const OSSL_DISPATCH *fns); 90*b0d17251Schristos 91*b0d17251Schristos #endif 92