OpenSSL EVP Series 8 --- EVP

zhaozj2021-02-16  37

OpenSSL EVP Series 8 --- Evp_Digest Series Function Detailed

--- Translation according to OpenSSL DOC / CRYPTO / EVP_DIGESTINIT.POD and its understanding

(Author: DragonKing, Mail: wzhah@263.net, released in:

Http://openssl.126.com OpenSSL Professional Forum, Version: OpenSSL-0.9.7)

The EVP_Digest series provides a function similar to the EVP_ENCRYPT family, defined as follows (openssl / evp.h):

Void EVP_MD_CTX_INIT (EVP_MD_CTX * CTX);

EVP_MD_CTX * EVP_MD_CTX_CREATE (VOID);

INT EVP_DIGESTINIT_EX (EVP_MD_CTX * CTX, Const EVP_MD * TYPE, Engine * IMPL);

INT EVP_DIGESTUPDATE (EVP_MD_CTX * CTX, Const Void * D, Unsigned INT CNT);

INT EVP_DIGESTFINAL_EX (EVP_MD_CTX * CTX, Unsigned Char * MD,

Unsigned int * s);

INT EVP_MD_CTX_CLEANUP (EVP_MD_CTX * CTX);

Void EVP_MD_CTX_DESTROY (EVP_MD_CTX * CTX);

INT EVP_MD_CTX_COPY_EX (EVP_MD_CTX * OUT, Const EVP_MD_CTX * IN);

INT EVP_DIGESTINIT (EVP_MD_CTX * CTX, Const EVP_MD * TYPE);

INT EVP_DIGESTFINAL (EVP_MD_CTX * CTX, unsigned char * md,

Unsigned int * s);

INT EVP_MD_CTX_COPY (EVP_MD_CTX * OUT, EVP_MD_CTX * IN);

#DEFINE EVP_MAX_MD_SIZE (16 20) / * The SSLV3 MD5 Sha1 Type * /

#define evp_md_type (e) ((e) -> TYPE)

#define evp_md_pkey_type (e) ((e) -> pkey_type)

#DEFINE EVP_MD_SIZE (E) -> MD_SIZE)

#define evp_md_block_size (e) -> block_size)

#define evp_md_ctx_md (e) (e) -> Digest)

#define evp_md_ctx_size (e) EVP_MD_SIZE ((E) -> Digest)

#define evp_md_ctx_block_size (e) EVP_MD_BLOCK_SIZE ((e) -> Digest)

#define evp_md_ctx_type (e) EVP_MD_TYPE ((e) -> Digest)

[EVP_MD_CTX_INIT]

This function initializes an EVP_MD_CTX structure.

[EVP_MD_CTX_CREATE]

This function creates an EVP_MD_CTX structure, allocates the memory and initializes, and returns the structure.

[Evp_digestinit_ex]

This function uses the ENGINE pointed to by the parameter IMPL to set the information summary structure, and the parameter CTX must be initialized before calling this function. The parameter TYPE is typically a return value using a function like EVP_SHA1. If IMPL is NULL, the information summary function of the default implementation will be used. Most applications are set to null. Operation successfully returns 1, otherwise it returns 0.

[EVP_DIGESTUPDATE] This function performs information summary to the CNT byte data in parameter d to the CTX structure, which can be called multiple times to perform information over information for more data. Operation successfully returns 1, otherwise it returns 0.

[Evp_digestfinal_ex]

This function returns the summary information data in the CTX structure into the parameter MD. If the parameter S is not null, then the length (byte) of the summary data will be written into the parameter S, most of the case, the value writes Is EVP_MAX_MD_SIZE. After calling this function, you cannot use the same CTX structure to call EVP_DIGESTUPDATE to perform the information summary operation of the data, but if the EVP_DIGESTINIT_EX function is called, the new information summary can be performed after reinitialization. Operation successfully returns 1, otherwise it returns 0.

[EVP_MD_CTX_CLEANUP]

Clear an information summary structure, which should be called when it is used after a message summary structure.

[EVP_MD_CTX_DESTROY]

Clear the information summary structure and release all assigned memory spaces, only the information created by the EVP_MD_CTX_CREATE function can be released using this function.

[Evp_md_ctx_copy_ex]

This function can be used to copy the information summary data from the IN structure to the OUT structure. If there is a large amount of data that needs to be summarized, and these data is only different from the last few bytes, it is especially useful, saving time. Where the OUT structure must be initialized before calling this function. Operation successfully returns 1, otherwise it returns 0.

[Evp_digestinit]

The function function is the same as the EVP_DigestInit_ex function, but the CTX parameter can be used without initialization, and the function only uses the algorithm of default implementation.

[Evp_digestfinal]

This function function is the same as the EVP_DIGESTFINAL_EX function, but the CTX structure will be automatically cleared. In general, now new programs should use the evp_digestinit_ex and evp_digestfinal_ex functions, because these functions can use it after using an EVP_MD_CTX structure, you can use it to make new data processing without re-declaring this structure, and new band_ex The function can also use the non-default implementation algorithm.

[EVP_MD_CTX_COPY]

This function is the same as the EVP_MD_CTX_COPY_EX function function, but the OUT parameter can not initialize.

[EVP_MD_SIZE and EVP_MD_CTX_SIZE]

These two functions returned to the length of the summary information in the structure.

[EVP_MD_BLOCK_SIZE and EVP_MD_CTX_BLOCK_SIZE]

These two functions returns the length of the summary information block processing.

[EVP_MD_TYPE and EVP_MD_CTX_TYPE]

These two functions returned to NID of the information summary structure algorithm. For example, EVP_MD_TYPE (EVP_SHA1 ()) returns NID_SHA1. This function is usually used when setting the ASN1 OID. If the algorithm does not exist, return NID_UNDEF.

[EVP_MD_CTX_MD]

This function returns the EVP_md structure in the given EVP_MD_CTX structure.

[EVP_MD_PKEY_TYPE]

This function returns the NID of the public key signature algorithm in the information summary structure. For example, if EVP_SHA1 is using the RSA signature algorithm, then return NID_SHA1WITHRSAENCRYPTION.

[EVP_MD2, EVP_MD5, EVP_SHA, EVP_SHA1, EVP_MDC2 and EVP_RIPEMD160]

These functions returns the EVP_md structure of the corresponding name, which uses the RSA algorithm as a signature algorithm. In a new program, it is generally recommended to use the SHA1 algorithm.

[EVP_DSS and EVP_DSS1]

The EVP_MD structure returned by these two functions uses the SHA and SHA1 information summary algorithms, but the signature algorithm uses DSS (DSA). [EVP_MD_NULL]

The summary structure returned by this function does not make anything, and the returned summary information is 0.

[EVP_GET_DIGESTBYNAME, EVP_GET_DIGESTBYNID and EVP_GET_DIGESTBYOBJ]

These three functions returned a corresponding EVP_MD algorithm structure according to the given algorithm name, algorithm NID, and ASN1_Object structure. The summary algorithm must be initialized before use, such as initialization using OpenSSL_ADD_ALL_DIGESTS. Returns NULL if the call is unsuccessful.

转载请注明原文地址:https://www.9cbs.com/read-23990.html

New Post(0)