BIO is an encapsulation of IO operations. The BIO abstract interface of OpenSSL can be used not only for the I/O of SSL connections, but also for non-encrypted network connections and file I/O. The source code of BIO is in the crypto/bio folder.
The related data structures of BIO are listed as follows.
BIO structure:
Struct bio_st
{
BIO_METHOD * method;
/* Bio, mode, argp, argi, argl, ret */
Long (* callback) (struct bio_st *, int, const char *, int, long, long );
Char * cb_arg;/* first argument for the callback */
Int init;
Int shutdown;
Int flags;/* extra storage */
Int retry_reason;
Int num;
Void * ptr;
Struct bio_st * next_bio;/* used by filter BIOs */
Struct bio_st * prev_bio;/* used by filter BIOs */
Int references;
Unsigned long num_read;
Unsigned long num_write;
CRYPTO_EX_DATA ex_data;
};
BIO operation structure:
Typedef struct bio_method_st
{
Int type;
Const char * name;
Int (* bwrite) (BIO *, const char *, int );
Int (* bread) (BIO *, char *, int );
Int (* bputs) (BIO *, const char *);
Int (* bgets) (BIO *, char *, int );
Long (* ctrl) (BIO *, int, long, void *);
Int (* create) (BIO *);
Int (* destroy) (BIO *);
Long (* callback_ctrl) (BIO *, int, bio_info_cb *);
} BIO_METHOD;
BIO interface types include source/receive and filter.
# Define BIO_TYPE_DESCRIPTOR0x0100/* socket, fd, connect or accept */
# Define BIO_TYPE_FILTER 0x0200
# Define BIO_TYPE_SOURCE_SINK 0x0400
1. Source/receipt type
# Define BIO_TYPE_MEM (1 | 0x0400)
# Define BIO_TYPE_FILE (2 | 0x0400)
# Define BIO_TYPE_FD (4 | 0x0400 | 0x0100)
# Define BIO_TYPE_SOCKET (5 | 0x0400 | 0x0100)
# Define BIO_TYPE_NULL (6 | 0x0400)
# Define BIO_TYPE_CONNECT (12 | 0x0400 | 0x0100)/* socket-connect */
# Define BIO_TYPE_ACCEPT (13 | 0x0400 | 0x0100)/* socket for accept */
# Define BIO_TYPE_BIO (19 | 0x0400)/* (half a) BIO pair */
# Define BIO_TYPE_DGRAM (21 | 0x0400 | 0x0100)
2. Filter Type
# Define BIO_TYPE_SSL (7 | 0x0200)
# Define BIO_TYPE_MD (8 | 0x0200)/* passive filter */
# Define BIO_TYPE_BUFFER (9 | 0x0200)/* filter */
# Define BIO_TYPE_CIPHER (10 | 0x0200)/* filter */
# Define BIO_TYPE_BASE64 (11 | 0x0200)/* filter */
# Define BIO_TYPE_PROXY_CLIENT (14 | 0x0200)/* client proxy BIO */
# Define BIO_TYPE_PROXY_SERVER (15 | 0x0200)/* server proxy BIO */
# Define BIO_TYPE_NBIO_TEST (16 | 0x0200)/* server proxy BIO */
# Define BIO_TYPE_NULL_FILTER (17 | 0x0200)
# Define BIO_TYPE_BER (18 | 0x0200)/* BER-> bin filter */
# Define BIO_TYPE_LINEBUFFER (20 | 0x0200)/* filter */
# Define BIO_TYPE_ASN1 (22 | 0x0200)/* filter */
# Define BIO_TYPE_COMP (23 | 0x0200)/* filter */
BIO Filter Buffer structure:
Typedef struct bio_f_buffer_ctx_struct
{
/* BIO * bio; * // * this is now in the BIO struct */
Int ibuf_size;/* how big is the input buffer */
Int obuf_size;/* how big is the output buffer */
Char * ibuf;/* the char array */
Int ibuf_len;/* how many bytes are in it */
Int ibuf_off;/* write/read offset */
Char * obuf;/* the char array */
Int obuf_len;/* how many bytes are in it */
Int obuf_off;/* write/read offset */
} BIO_F_BUFFER_CTX;
From Aegeaner's column