1216615Slstewart/* 2252536Slstewart * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved. 3216615Slstewart * 4216615Slstewart * Licensed under the Apache License 2.0 (the "License"). You may not use 5216615Slstewart * this file except in compliance with the License. You can obtain a copy 6216615Slstewart * in the file LICENSE in the source distribution or at 7220560Slstewart * https://www.openssl.org/source/license.html 8220560Slstewart */ 9220560Slstewart 10216615Slstewart#ifndef OSSL_INTERNAL_BIO_H 11216615Slstewart# define OSSL_INTERNAL_BIO_H 12216615Slstewart# pragma once 13216615Slstewart 14216615Slstewart# include <openssl/core.h> 15216615Slstewart# include <openssl/bio.h> 16216615Slstewart 17216615Slstewartstruct bio_method_st { 18216615Slstewart int type; 19216615Slstewart char *name; 20216615Slstewart int (*bwrite) (BIO *, const char *, size_t, size_t *); 21216615Slstewart int (*bwrite_old) (BIO *, const char *, int); 22216615Slstewart int (*bread) (BIO *, char *, size_t, size_t *); 23216615Slstewart int (*bread_old) (BIO *, char *, int); 24216615Slstewart int (*bputs) (BIO *, const char *); 25216615Slstewart int (*bgets) (BIO *, char *, int); 26216615Slstewart long (*ctrl) (BIO *, int, long, void *); 27216615Slstewart int (*create) (BIO *); 28216615Slstewart int (*destroy) (BIO *); 29216615Slstewart long (*callback_ctrl) (BIO *, int, BIO_info_cb *); 30216615Slstewart}; 31216615Slstewart 32216615Slstewartvoid bio_free_ex_data(BIO *bio); 33216615Slstewartvoid bio_cleanup(void); 34216615Slstewart 35216615Slstewart 36216615Slstewart/* Old style to new style BIO_METHOD conversion functions */ 37216615Slstewartint bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written); 38216615Slstewartint bread_conv(BIO *bio, char *data, size_t datal, size_t *read); 39216615Slstewart 40216615Slstewart/* Changes to these internal BIOs must also update include/openssl/bio.h */ 41216615Slstewart# define BIO_CTRL_SET_KTLS 72 42216615Slstewart# define BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG 74 43216615Slstewart# define BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG 75 44216615Slstewart 45216615Slstewart/* 46216615Slstewart * This is used with socket BIOs: 47216615Slstewart * BIO_FLAGS_KTLS_TX means we are using ktls with this BIO for sending. 48216615Slstewart * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next. 49216615Slstewart * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving. 50216615Slstewart */ 51216615Slstewart# define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000 52216615Slstewart# define BIO_FLAGS_KTLS_RX 0x2000 53216615Slstewart# define BIO_FLAGS_KTLS_TX 0x4000 54216615Slstewart 55216615Slstewart/* KTLS related controls and flags */ 56216615Slstewart# define BIO_set_ktls_flag(b, is_tx) \ 57216615Slstewart BIO_set_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) 58216615Slstewart# define BIO_should_ktls_flag(b, is_tx) \ 59216615Slstewart BIO_test_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX) 60216615Slstewart# define BIO_set_ktls_ctrl_msg_flag(b) \ 61252539Slstewart BIO_set_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 62216615Slstewart# define BIO_should_ktls_ctrl_msg_flag(b) \ 63216615Slstewart BIO_test_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 64216615Slstewart# define BIO_clear_ktls_ctrl_msg_flag(b) \ 65216615Slstewart BIO_clear_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG) 66216615Slstewart 67216615Slstewart# define BIO_set_ktls(b, keyblob, is_tx) \ 68216615Slstewart BIO_ctrl(b, BIO_CTRL_SET_KTLS, is_tx, keyblob) 69216615Slstewart# define BIO_set_ktls_ctrl_msg(b, record_type) \ 70216615Slstewart BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG, record_type, NULL) 71216615Slstewart# define BIO_clear_ktls_ctrl_msg(b) \ 72216615Slstewart BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG, 0, NULL) 73216615Slstewart 74216615Slstewart/* Functions to allow the core to offer the CORE_BIO type to providers */ 75252541SlstewartOSSL_CORE_BIO *ossl_core_bio_new_from_bio(BIO *bio); 76216615SlstewartOSSL_CORE_BIO *ossl_core_bio_new_file(const char *filename, const char *mode); 77216615SlstewartOSSL_CORE_BIO *ossl_core_bio_new_mem_buf(const void *buf, int len); 78216615Slstewartint ossl_core_bio_read_ex(OSSL_CORE_BIO *cb, void *data, size_t dlen, 79216615Slstewart size_t *readbytes); 80252541Slstewartint ossl_core_bio_write_ex(OSSL_CORE_BIO *cb, const void *data, size_t dlen, 81252541Slstewart size_t *written); 82252541Slstewartint ossl_core_bio_gets(OSSL_CORE_BIO *cb, char *buf, int size); 83252541Slstewartint ossl_core_bio_puts(OSSL_CORE_BIO *cb, const char *buf); 84252541Slstewartlong ossl_core_bio_ctrl(OSSL_CORE_BIO *cb, int cmd, long larg, void *parg); 85252541Slstewartint ossl_core_bio_up_ref(OSSL_CORE_BIO *cb); 86252541Slstewartint ossl_core_bio_free(OSSL_CORE_BIO *cb); 87252541Slstewartint ossl_core_bio_vprintf(OSSL_CORE_BIO *cb, const char *format, va_list args); 88252541Slstewart 89216615Slstewartint ossl_bio_init_core(OSSL_LIB_CTX *libctx, const OSSL_DISPATCH *fns); 90216615Slstewart 91252541Slstewart#endif 92252541Slstewart