---
name: "libressl-EVP_CIPHER_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_CIPHER_CTX_ctrl"
---

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

configure EVP cipher contexts

## NAME

**EVP\_CIPHER\_CTX\_ctrl**, **EVP\_CIPHER\_CTX\_set\_padding**, **EVP\_CIPHER\_CTX\_set\_key\_length**, **EVP\_CIPHER\_CTX\_key\_length**, **EVP\_CIPHER\_key\_length**, **EVP\_CIPHER\_CTX\_iv\_length**, **EVP\_CIPHER\_iv\_length**, **EVP\_CIPHER\_CTX\_set\_iv**, **EVP\_CIPHER\_CTX\_get\_iv** – configure EVP cipher contexts

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**EVP\_CIPHER\_CTX\_ctrl**(*EVP\_CIPHER\_CTX \*ctx*, *int type*, *int arg*, *void \*ptr*);

*int*\

**EVP\_CIPHER\_CTX\_set\_padding**(*EVP\_CIPHER\_CTX \*x*, *int padding*);

*int*\

**EVP\_CIPHER\_CTX\_set\_key\_length**(*EVP\_CIPHER\_CTX \*x*, *int keylen*);

*int*\

**EVP\_CIPHER\_CTX\_key\_length**(*const EVP\_CIPHER\_CTX \*ctx*);

*int*\

**EVP\_CIPHER\_key\_length**(*const EVP\_CIPHER \*e*);

*int*\

**EVP\_CIPHER\_CTX\_iv\_length**(*const EVP\_CIPHER\_CTX \*ctx*);

*int*\

**EVP\_CIPHER\_iv\_length**(*const EVP\_CIPHER \*e*);

*int*\

**EVP\_CIPHER\_CTX\_set\_iv**(*EVP\_CIPHER\_CTX \*ctx*, *const unsigned char \*iv*, *size\_t len*);

*int*\

**EVP\_CIPHER\_CTX\_get\_iv**(*const EVP\_CIPHER\_CTX \*ctx*, *unsigned char \*iv*, *size\_t len*);

## DESCRIPTION

**EVP\_CIPHER\_CTX\_ctrl**() allows various cipher specific parameters to be determined and set. Currently only the RC2 effective key length can be set; see EVP\_rc2\_cbc(3) for details.

**EVP\_CIPHER\_CTX\_set\_padding**() enables or disables padding. This function should be called after the context is set up for encryption or decryption with EVP\_EncryptInit\_ex(3), EVP\_DecryptInit\_ex(3), or EVP\_CipherInit\_ex(3). By default encryption operations are padded using standard block padding and the padding is checked and removed when decrypting. If the *padding* parameter is zero, then no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of the block size or an error will occur.

**EVP\_CIPHER\_CTX\_set\_key\_length**() sets the key length of the cipher ctx. If the cipher is a fixed length cipher, then attempting to set the key length to any value other than the fixed value is an error.

**EVP\_CIPHER\_CTX\_key\_length**() and **EVP\_CIPHER\_key\_length**() return the key length of a cipher when passed an *EVP\_CIPHER\_CTX* or *EVP\_CIPHER* structure. The constant EVP\_MAX\_KEY\_LENGTH is the maximum key length for all ciphers. Note: although **EVP\_CIPHER\_key\_length**() is fixed for a given cipher, the value of **EVP\_CIPHER\_CTX\_key\_length**() may be different for variable key length ciphers.

**EVP\_CIPHER\_CTX\_iv\_length**() and **EVP\_CIPHER\_iv\_length**() return the IV length of a cipher when passed an *EVP\_CIPHER\_CTX* or *EVP\_CIPHER*. They will return zero if the cipher does not use an IV. **EVP\_CIPHER\_CTX\_iv\_length**() can fail and return -1. The constant EVP\_MAX\_IV\_LENGTH is the maximum IV length for all ciphers.

**EVP\_CIPHER\_CTX\_set\_iv**() and **EVP\_CIPHER\_CTX\_get\_iv**() set and retrieve the IV for an *EVP\_CIPHER\_CTX*, respectively. In both cases, the specified IV length must exactly equal the expected IV length for the context as returned by **EVP\_CIPHER\_CTX\_iv\_length**().

## RETURN VALUES

**EVP\_CIPHER\_CTX\_ctrl**() returns 1 for success or 0 for failure. Some implementations may return negative values for some errors.

**EVP\_CIPHER\_CTX\_set\_padding**() always returns 1.

**EVP\_CIPHER\_CTX\_set\_key\_length**(), **EVP\_CIPHER\_CTX\_set\_iv**(), and **EVP\_CIPHER\_CTX\_get\_iv**() return 1 for success or 0 for failure.

**EVP\_CIPHER\_CTX\_key\_length**() and **EVP\_CIPHER\_key\_length**() return the key length.

**EVP\_CIPHER\_CTX\_iv\_length**() and **EVP\_CIPHER\_iv\_length**() return the IV length or zero if the cipher does not use an IV. **EVP\_CIPHER\_CTX\_iv\_length**() can fail and return -1.

## SEE ALSO

evp(3), EVP\_CIPHER\_nid(3), EVP\_EncryptInit(3)

## HISTORY

**EVP\_CIPHER\_CTX\_key\_length**(), **EVP\_CIPHER\_key\_length**(), **EVP\_CIPHER\_CTX\_iv\_length**(), and **EVP\_CIPHER\_iv\_length**() first appeared in SSLeay 0.6.5 and have been available since OpenBSD 2.4.

**EVP\_CIPHER\_CTX\_ctrl**() and **EVP\_CIPHER\_CTX\_set\_key\_length**() first appeared in OpenSSL 0.9.6 and have been available since OpenBSD 2.9.

**EVP\_CIPHER\_CTX\_set\_padding**() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2.

**EVP\_CIPHER\_CTX\_set\_iv**() and **EVP\_CIPHER\_CTX\_get\_iv**() first appeared in LibreSSL 2.8.1 and have been available since OpenBSD 6.4.

## BUGS

EVP\_MAX\_KEY\_LENGTH and EVP\_MAX\_IV\_LENGTH only refer to the internal ciphers with default key lengths. If custom ciphers exceed these values, the results are unpredictable. This is because it has become standard practice to define a generic key as a fixed unsigned char array containing EVP\_MAX\_KEY\_LENGTH bytes.
