BIO structure and BIO related documentation
(Author: DragonKing Mail: wzhah@263.net Posted: http: //gdwzh.126.com openssl professional forum)
The structural definition and related items of BIO are as follows:
(Included in the Bio.h file, its primary file is BIO_LIB.C)
Typedef struct bio_st bio;
Struct Bio_ST
{
BIO_METHOD * METHOD; / / BIO method structure is an important parameter that determines the type and behavior of the BIO type and behavior, and the differences between various BIOs are mainly in this item.
/ * Bio, Mode, Argp, Argi, Argl, Ret * /
Long (* Callback) (Struct Bio_st *, int, const char *, int, long, long); // BIO callback function
Char * cb_arg; / * first argument for the first parameter of the callback * // callback function
INT init; // Initialization flag, initialized to 1, otherwise 0
INT Shutdown; // BIO switch logo, if 1, is in a closed state, if 0, the open state.
INT flag; / * Extra Storage * /
Int retry_reason;
Int Num;
Void * PTR;
Struct Bio_st * next_bio; / * use by filter bios * / bio
Struct Bio_st * prev_bio; / * buy by filter bios * / bio
INT References;
Unsigned long num_read; // read the data length
Unsigned long num_write; // Write data length
Crypto_ex_data ex_data;
}
Among the members of the BIO, Method can be said to be the most critical member, which determines the type of BIO, you can see that when a new BIO structure is declared, you always use the following statement:
BIO * BIO_NEW (BIO_METHOD * TYPE);
As can be seen from the source code, the BIO_NEW function is assigned to some initial variables, mainly to assign each variable in TYPE to the Method member in the BIO structure.
In general, the above TYPE parameter is provided in the form of a type generating function, such as generating a MEM type BIO structure, using the following statement:
BIO * MEM = BIO_NEW (BIO_S_MEM ());
Such functions have some:
[Source / Sink type]
BIO_S_ACCEPT (): Yes a interface that encapsulates a TCP / IP Socket Accept rule and makes TCP / IP operations transparent to the BIO interface.
BIO_S_BIO (): Encapsulates a BIO pair, the data is written from one of the BIO, read from another BIO
BIO_S_CONNECT (): is an interface that encapsulates similar to TCP / IP Socket Connect rules and makes TCP / IP operations transparent for BIO interfaces.
BIO_S_FD (): is a BIO interface that encapsulates the file descriptor, providing a function of similar file reading and writing operations.
BIO_S_FILE (): The BIO of the standard file interface, including the input and output devices such as STDIN, etc.
BIO_S_MEM (): Encapsulates the Bio interface of memory operation, including reading and writing of memory
BIO_S_NULL (): Return to the empty SINK type BIO interface, write all the data reads that this interface is discarded, always returning EOFBIO_S_SOCKET (): Encapsulate the BIO type of the socket interface
[Filter type]
BIO_F_BASE64 (): Encaps the Bio of the Base64 encoding method, when writing, decoding when reading
BIO_F_BUFFER (): Package the BIO operation of the buffer operation, the data writes to the interface is generally preparing to pass the next BIO interface, and the data read from the interface is generally transmitted from another BIO.
BIO_F_CIPHER (): encapsulates the Bio of the plus method, encrypts when writing, and decrypt when reading
BIO_F_MD (): The BIO of the information summary method is encapsulated, and the data read and written through the interface is abstract.
BIO_F_NULL (): A Bio that does not make anything, it is simply transmitted to the next Bio, which is equivalent to not existed.
BIO_F_SSL (): The BIO type of OpenSSL's SSL protocol is encapsulated, that is, add some BIO operation methods for the SSL protocol.
The above various types of functions are the basic unit constituting the powerful function of the BIO, so the various structural and functions of the BIO should be understood, and they should be found in these function types related operational functions.
All of these source files are basically included in the / crypto / bio / directory. C file (most of the same name).
In Bio_Method, a set of behavior functions are defined. The definition of the above-mentioned type BIO_METHOD behavior function is different, and the structure is as follows (as an example of non-16-bit system):
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;
In the Bio member, Callback is also more important, it can be used for program trial or custom change BIO behavior. Details will be introduced in later related parties.
Many of the BIOs are done by the BIO_CTRL series function to be done according to the macro definition of the unless parameter. So understand the behavior of BIO, understand the meaning of the Bio_Ctrl series function and its various parameters.
[Brief Description of the Bio Directory file]
BIO.H: The main defined header file includes a lot of universal macros.
Bio_lib.c The main BIO operation definition file is a compared function.
BSS_ * Series: is a specific operation of Soruce / SINK type BIO
BF_ * Series: is a Filter type BIO specific operation implementation file
BIO_ERR.C: Yes Yes Information Processing File
BIO_CB.C: is the relevant file of the Callback function
B_Print.c: is the processing function file for information output
b_socket.c: is some relevant information processing files connected to the socket connection
b_dump.c: is a storage operation processing of memory content