---
name: "libressl-EVP_MD_CTX_ctrl"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-EVP_MD_CTX_ctrl"
---

# libressl-EVP\_MD\_CTX\_ctrl(3)

configure EVP message digest contexts

## NAME

**EVP\_MD\_CTX\_ctrl**, **EVP\_MD\_CTX\_set\_flags**, **EVP\_MD\_CTX\_clear\_flags**, **EVP\_MD\_CTX\_test\_flags**, **EVP\_MD\_CTX\_pkey\_ctx**, **EVP\_MD\_CTX\_set\_pkey\_ctx**, **EVP\_MD\_CTX\_md\_data** – configure EVP message digest contexts

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/evp.h\>**

*int*\

**EVP\_MD\_CTX\_ctrl**(*EVP\_MD\_CTX \*ctx*, *int command*, *int p1*, *void\* p2*);

*void*\

**EVP\_MD\_CTX\_set\_flags**(*EVP\_MD\_CTX \*ctx*, *int flags*);

*void*\

**EVP\_MD\_CTX\_clear\_flags**(*EVP\_MD\_CTX \*ctx*, *int flags*);

*int*\

**EVP\_MD\_CTX\_test\_flags**(*const EVP\_MD\_CTX \*ctx*, *int flags*);

*EVP\_PKEY\_CTX* *\**\

**EVP\_MD\_CTX\_pkey\_ctx**(*const EVP\_MD\_CTX \*ctx*);

*void*\

**EVP\_MD\_CTX\_set\_pkey\_ctx**(*EVP\_MD\_CTX \*ctx*, *EVP\_PKEY\_CTX \*pctx*);

*void* *\**\

**EVP\_MD\_CTX\_md\_data**(*const EVP\_MD\_CTX \*ctx*);

## DESCRIPTION

**EVP\_MD\_CTX\_ctrl**() performs the digest-specific control *command* with the command-specific arguments *p1* and *p2* on *ctx*, which needs to already be set up with EVP\_DigestInit\_ex(3) before calling this function. Other restrictions may apply depending on the control *command* and digest implementation.

If the *command* is EVP\_MD\_CTRL\_MICALG, *p1* is ignored and *p2* is an output argument of the type *char \*\*p2*. A string specifying the digest Message Integrity Check algorithm is allocated and a pointer to this string is returned in \**p2*. It is the responsibility of the caller to [free(3)](/free/3.md) \**p2* when it is no longer needed. This *command* is used by SMIME\_write\_CMS(3) and SMIME\_write\_PKCS7(3) when creating S/MIME multipart/signed messages as specified in RFC 3851.

**EVP\_MD\_CTX\_set\_flags**() sets and **EVP\_MD\_CTX\_clear\_flags**() clears all the flag bits in *ctx* that are set in the *flags* argument. **EVP\_MD\_CTX\_test\_flags**() tests which of the flag bits that are set in the *flags* argument are also set in *ctx*. Possible flag bits are:

- EVP\_MD\_CTX\_FLAG\_NO\_INIT

  Instruct EVP\_DigestInit\_ex(3) and functions calling it not to initialise the internal data that is specific to the digest method and its implementation.

- EVP\_MD\_CTX\_FLAG\_ONESHOT

  Instruct the digest to optimize for one update only, if possible. For digest algorithms built into the library, this flag usually has no effect.

**EVP\_MD\_CTX\_pkey\_ctx**() returns the *EVP\_PKEY\_CTX* assigned to *ctx*. The returned pointer should not be freed by the caller.

**EVP\_MD\_CTX\_set\_pkey\_ctx**() assigns *pctx* to *ctx*. This is normally used to provide a customized *EVP\_PKEY\_CTX* to EVP\_DigestSignInit(3) or EVP\_DigestVerifyInit(3). The caller retains ownership of the *pctx* passed to this function and is responsible for freeing it when it is no longer needed.

If the *ctx* already contains a *EVP\_PKEY\_CTX* when this function is called, that old *EVP\_PKEY\_CTX* is freed if it was created internally, but if it was also installed with **EVP\_MD\_CTX\_set\_pkey\_ctx**(), the pointer to the old *EVP\_PKEY\_CTX* is merely replaced by the new pointer and ownership of the old *EVP\_PKEY\_CTX* remains with the previous caller.

Passing a NULL pointer for the *pctx* argument is also allowed. In that case, any *EVP\_PKEY\_CTX* already assigned to *ctx* is dissociated from it as described above, but no new *EVP\_PKEY\_CTX* is assigned.

**EVP\_MD\_CTX\_md\_data**() returns the digest method private data of *ctx*. The space is allocated with a size determined at compile time. The size is not exposed by an API.

## RETURN VALUES

**EVP\_MD\_CTX\_ctrl**() returns 1 for success or 0 for failure.

**EVP\_MD\_CTX\_test\_flags**() returns the bitwise OR of the *flags* argument and the flags set in *ctx*.

**EVP\_MD\_CTX\_pkey\_ctx**() and **EVP\_MD\_CTX\_md\_data**() return pointers to storage owned by *ctx*.

## SEE ALSO

evp(3), EVP\_DigestInit(3), EVP\_MD\_nid(3)

## HISTORY

**EVP\_MD\_CTX\_set\_flags**(), **EVP\_MD\_CTX\_clear\_flags**(), and **EVP\_MD\_CTX\_test\_flags**(), first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2.

**EVP\_MD\_CTX\_ctrl**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 5.7.

**EVP\_MD\_CTX\_pkey\_ctx**() and **EVP\_MD\_CTX\_md\_data**() first appeared in OpenSSL 1.1.0 and **EVP\_MD\_CTX\_set\_pkey\_ctx**() in OpenSSL 1.1.1. These functions have been available since OpenBSD 7.1.
