OpenBSD manual page server

Manual Page Search Parameters

EVP_RC2_CBC(3) Library Functions Manual EVP_RC2_CBC(3)

EVP_rc2_cbc, EVP_rc2_ecb, EVP_rc2_cfb64, EVP_rc2_cfb, EVP_rc2_ofb, EVP_rc2_40_cbc, EVP_rc2_64_cbcRivest Cipher 2 in the EVP framework

#include <openssl/evp.h>

const EVP_CIPHER *
EVP_rc2_cbc(void);

const EVP_CIPHER *
EVP_rc2_ecb(void);

const EVP_CIPHER *
EVP_rc2_cfb64(void);

const EVP_CIPHER *
EVP_rc2_cfb(void);

const EVP_CIPHER *
EVP_rc2_ofb(void);

const EVP_CIPHER *
EVP_rc2_40_cbc(void);

const EVP_CIPHER *
EVP_rc2_64_cbc(void);

#include <openssl/rc2.h>

#define RC2_BLOCK 8
#define RC2_KEY_LENGTH 16

RC2 is a block cipher operating on blocks of RC2_BLOCK = 8 bytes, equivalent to 64 bits, using a variable key length with an additional parameter called “effective key bits” or “effective key length”.

(), (), (), and () provide the RC2 encryption algorithm in CBC, ECB, CFB and OFB mode, respectively. () is an alias for EVP_rc2_cfb64(), implemented as a macro.

By default, these functions set both the key length and the effective key length to RC2_KEY_LENGTH = 16 bytes, which is not a very useful value because it is quite short.

Configuring normally requires a multi-step process:

  1. Create a new, empty EVP_CIPHER_CTX object with EVP_CIPHER_CTX_new(3).
  2. Select the operation mode by calling EVP_EncryptInit(3) with the desired type argument, passing NULL pointers for the key and iv arguments.
  3. Select the key length by passing the desired number of bytes to EVP_CIPHER_CTX_set_key_length(3). Doing so overrides the default key length of RC2_KEY_LENGTH = 16. Valid values for keylen are positive and less than or equal to 128.
  4. Select the effective key length by calling EVP_CIPHER_CTX_ctrl(3) with a type argument of EVP_CTRL_SET_RC2_KEY_BITS, passing the desired number of bits in arg. Doing so overrides the default effective key length of 128 bits. Valid values for arg are positive and less than or equal to 1024. The ptr argument is ignored; passing NULL is recommended.
  5. Call EVP_EncryptInit(3) a second time, this time passing NULL for the type argument. The key argument points to an array containing the number of bytes that was passed to EVP_CIPHER_CTX_set_key_length(3), and the iv argument points to an array of eight bytes.
  6. Finally, EVP_EncryptUpdate(3) and EVP_EncryptFinal(3) can be used in the normal way.

Once a ctx object is fully configured, calling EVP_CIPHER_CTX_ctrl(3) with a type argument of EVP_CTRL_GET_RC2_KEY_BITS interprets ptr as a pointer to int and stores the effective key length in bits at that location. In this case, arg is ignored and passing 0 is recommended.

In the CFB and OFB modes, the minimum required total length in bytes of the output buffer is equal to the total number of input bytes to be encoded. In the CBC and ECB modes, the minimum required total length of the output buffer has to be rounded up to the next multiple of the block size of eight bytes.

() and () are obsolete functions that provide the RC2 algorithm in CBC mode with a key length and an effective key length of 40 and 64 bits, respectively.

With the EVP_CIPHER objects documented in the present manual page, EVP_CIPHER_CTX_ctrl() returns 1 for success or 0 if an error occurs.

evp(3), EVP_CIPHER_CTX_set_key_length(3), EVP_EncryptInit(3), RC2_encrypt(3)

EVP_rc2_cbc(), EVP_rc2_ecb(), EVP_rc2_cfb(), and EVP_rc2_ofb() first appeared in SSLeay 0.5.2 and have been available since OpenBSD 2.4.

EVP_rc2_40_cbc() and EVP_rc2_64_cbc() first appeared in SSLeay 0.9.1 and have been available since OpenBSD 2.6.

EVP_rc2_cfb64() first appeared in OpenSSL 0.9.7e and has been available since OpenBSD 3.8.

December 8, 2024 OpenBSD-current