---
name: "libressl-EVP_CIPHER_meth_new"
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_CIPHER_meth_new"
---

# libressl-EVP\_CIPHER\_meth\_new(3)

Routines to build up EVP\_CIPHER methods

## NAME

**EVP\_CIPHER\_meth\_new**, **EVP\_CIPHER\_meth\_dup**, **EVP\_CIPHER\_meth\_free**, **EVP\_CIPHER\_meth\_set\_iv\_length**, **EVP\_CIPHER\_meth\_set\_flags**, **EVP\_CIPHER\_meth\_set\_impl\_ctx\_size**, **EVP\_CIPHER\_meth\_set\_init**, **EVP\_CIPHER\_meth\_set\_do\_cipher**, **EVP\_CIPHER\_meth\_set\_cleanup**, **EVP\_CIPHER\_meth\_set\_set\_asn1\_params**, **EVP\_CIPHER\_meth\_set\_get\_asn1\_params**, **EVP\_CIPHER\_meth\_set\_ctrl** – Routines to build up EVP\_CIPHER methods

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*EVP\_CIPHER* *\**\

**EVP\_CIPHER\_meth\_new**(*int cipher\_type*, *int block\_size*, *int key\_len*);

*EVP\_CIPHER* *\**\

**EVP\_CIPHER\_meth\_dup**(*const EVP\_CIPHER \*cipher*);

*void*\

**EVP\_CIPHER\_meth\_free**(*EVP\_CIPHER \*cipher*);

*int*\

**EVP\_CIPHER\_meth\_set\_iv\_length**(*EVP\_CIPHER \*cipher*, *int iv\_len*);

*int*\

**EVP\_CIPHER\_meth\_set\_flags**(*EVP\_CIPHER \*cipher*, *unsigned long flags*);

*int*\

**EVP\_CIPHER\_meth\_set\_impl\_ctx\_size**(*EVP\_CIPHER \*cipher*, *int ctx\_size*);

*int*\

**EVP\_CIPHER\_meth\_set\_init**(*EVP\_CIPHER \*cipher*, *int (\*init)(EVP\_CIPHER\_CTX \*ctx, const unsigned char \*key, const unsigned char \*iv, int enc)*);

*int*\

**EVP\_CIPHER\_meth\_set\_do\_cipher**(*EVP\_CIPHER \*cipher*, *int (\*do\_cipher)(EVP\_CIPHER\_CTX \*ctx, unsigned char \*out, const unsigned char \*in, size\_t inl)*);

*int*\

**EVP\_CIPHER\_meth\_set\_cleanup**(*EVP\_CIPHER \*cipher*, *int (\*cleanup)(EVP\_CIPHER\_CTX \*)*);

*int*\

**EVP\_CIPHER\_meth\_set\_set\_asn1\_params**(*EVP\_CIPHER \*cipher*, *int (\*set\_asn1\_parameters)(EVP\_CIPHER\_CTX \*, ASN1\_TYPE \*)*);

*int*\

**EVP\_CIPHER\_meth\_set\_get\_asn1\_params**(*EVP\_CIPHER \*cipher*, *int (\*get\_asn1\_parameters)(EVP\_CIPHER\_CTX \*, ASN1\_TYPE \*)*);

*int*\

**EVP\_CIPHER\_meth\_set\_ctrl**(*EVP\_CIPHER \*cipher*, *int (\*ctrl)(EVP\_CIPHER\_CTX \*, int type, int arg, void \*ptr)*);

## DESCRIPTION

The *EVP\_CIPHER* type is a structure holding function pointers for a symmetric cipher implementation.

**EVP\_CIPHER\_meth\_new**() allocates a new *EVP\_CIPHER* structure. The cipher's NID (see EVP\_CIPHER\_nid(3)) is set to *cipher\_type*, the block size and key length are set to *block\_size* and *key\_len*, respectively.

**EVP\_CIPHER\_meth\_dup**() creates a copy of *cipher*.

**EVP\_CIPHER\_meth\_free**() frees an *EVP\_CIPHER* structure.

**EVP\_CIPHER\_meth\_set\_iv\_length**() sets the length of the initialization vector. This is only needed when the implemented cipher mode requires it.

**EVP\_CIPHER\_meth\_set\_flags**() overwrites the flags to describe optional behaviours in *cipher* with *flags*. At most one of the following cipher modes can be set: EVP\_CIPH\_STREAM\_CIPHER, EVP\_CIPH\_ECB\_MODE, EVP\_CIPH\_CBC\_MODE, EVP\_CIPH\_CFB\_MODE, EVP\_CIPH\_OFB\_MODE, EVP\_CIPH\_CTR\_MODE, EVP\_CIPH\_GCM\_MODE, EVP\_CIPH\_CCM\_MODE, EVP\_CIPH\_XTS\_MODE, and EVP\_CIPH\_WRAP\_MODE.

Zero or more of the following flags can be OR'ed into the *flags* argument:

- EVP\_CIPH\_VARIABLE\_LENGTH

  This cipher has a variable key length, and the function EVP\_CIPHER\_CTX\_set\_key\_length(3) can be used with it.

- EVP\_CIPH\_CUSTOM\_IV

  Instruct EVP\_CipherInit\_ex(3) and similar initialization functions to leave storing and initialising the IV entirely to the implementation. If this flag is set, the implementation is typically expected to do that in its *init* function.

- EVP\_CIPH\_ALWAYS\_CALL\_INIT

  Instruct EVP\_CipherInit\_ex(3) and similar initialization functions to call the implementation's *init* function even if the *key* argument is NULL.

- EVP\_CIPH\_CTRL\_INIT

  Instruct EVP\_CipherInit\_ex(3) and similar initialization functions to call the implementation's *ctrl* function with a command *type* of EVP\_CTRL\_INIT early during the setup.

- EVP\_CIPH\_NO\_PADDING

  Instruct EVP\_CipherFinal\_ex(3) and similar finalization functions to not use standard block padding but instead report an error if the total amount of data to be encrypted or decrypted is not a multiple of the block size.

- EVP\_CIPH\_RAND\_KEY

  Instruct EVP\_CIPHER\_CTX\_rand\_key(3) to not generate a random key using [arc4random\_buf(3)](/arc4random_buf/3.md) but instead leave that to the implementation by calling the *ctrl* function with a command *type* of EVP\_CTRL\_RAND\_KEY and the pointer to the key memory storage in *ptr*.

- EVP\_CIPH\_CUSTOM\_COPY

  Instruct EVP\_CIPHER\_CTX\_copy(3) to call the implementation's *ctrl* function with a command *type* of EVP\_CTRL\_COPY and the destination *EVP\_CIPHER\_CTX \*out* in the *ptr* argument immediately before returning successfully. The intended use is for further things to deal with after the implementation specific data block has been copied. The implementation-specific data block is reached with EVP\_CIPHER\_CTX\_get\_cipher\_data(3).

- EVP\_CIPH\_FLAG\_DEFAULT\_ASN1

  Instruct EVP\_CIPHER\_param\_to\_asn1(3) to use ASN1\_TYPE\_set\_octetstring(3) if no *set\_asn1\_parameters* function is installed, and instruct EVP\_CIPHER\_asn1\_to\_param(3) to use ASN1\_TYPE\_get\_octetstring(3) if no *get\_asn1\_parameters* function is installed.

- EVP\_CIPH\_FLAG\_LENGTH\_BITS

  Signals that the length of the input buffer for encryption / decryption is to be understood as the number of bits instead of bytes for this implementation. This is only useful for CFB1 ciphers.

- EVP\_CIPH\_FLAG\_CUSTOM\_CIPHER

  Instruct EVP\_CipherUpdate(3), EVP\_CipherFinal\_ex(3), and similar encryption, decryption, and finalization functions that the implementation's *do\_cipher* function takes care of everything, including padding, buffering and finalization.

- EVP\_CIPH\_FLAG\_AEAD\_CIPHER

  This indicates that this is an AEAD cipher implementation.

**EVP\_CIPHER\_meth\_set\_impl\_ctx\_size**() sets the size of the EVP\_CIPHER's implementation context so that it can be automatically allocated.

**EVP\_CIPHER\_meth\_set\_init**() sets the *init* function for *cipher*. The cipher init function is called by EVP\_CipherInit(3), EVP\_CipherInit\_ex(3), EVP\_EncryptInit(3), EVP\_EncryptInit\_ex(3), EVP\_DecryptInit(3), and EVP\_DecryptInit\_ex(3).

**EVP\_CIPHER\_meth\_set\_do\_cipher**() sets the cipher function for *cipher*. The cipher function is called by EVP\_CipherUpdate(3), EVP\_EncryptUpdate(3), EVP\_DecryptUpdate(3), EVP\_CipherFinal(3), EVP\_EncryptFinal(3), EVP\_EncryptFinal\_ex(3), EVP\_DecryptFinal(3) and EVP\_DecryptFinal\_ex(3).

**EVP\_CIPHER\_meth\_set\_cleanup**() sets the function for *cipher* to do extra cleanup before the method's private data structure is cleaned out and freed. Note that the cleanup function is passed a **EVP\_CIPHER\_CTX** **\***, the private data structure is then available with EVP\_CIPHER\_CTX\_get\_cipher\_data(3). This cleanup function is called by EVP\_CIPHER\_CTX\_reset(3) and EVP\_CIPHER\_CTX\_free(3).

**EVP\_CIPHER\_meth\_set\_set\_asn1\_params**() sets the function for *cipher* to set the AlgorithmIdentifier "parameter" based on the passed cipher. This function is called by EVP\_CIPHER\_param\_to\_asn1(3). **EVP\_CIPHER\_meth\_set\_get\_asn1\_params**() sets the function for *cipher* that sets the cipher parameters based on an ASN.1 AlgorithmIdentifier "parameter". Both these functions are needed when there is a need for custom data (more or other than the cipher IV). They are called by EVP\_CIPHER\_param\_to\_asn1(3) and EVP\_CIPHER\_asn1\_to\_param(3) respectively if defined.

**EVP\_CIPHER\_meth\_set\_ctrl**() sets the control function for *cipher*.

## RETURN VALUES

**EVP\_CIPHER\_meth\_new**() and **EVP\_CIPHER\_meth\_dup**() return a pointer to a newly created *EVP\_CIPHER*, or NULL on failure.

All **EVP\_CIPHER\_meth\_set\_\***() functions return 1.

## SEE ALSO

evp(3), EVP\_EncryptInit(3)

## HISTORY

These functions first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 7.3.
