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