.\" $OpenBSD: EVP_PKEY_CTX_ctrl.3,v 1.8 2017/08/28 17:41:59 jsing Exp $ .\" OpenSSL EVP_PKEY_CTX_ctrl.pod 1722496f Jun 8 15:18:38 2017 -0400 .\" OpenSSL EVP_PKEY_CTX_ctrl.pod e03af178 Dec 11 17:05:57 2014 -0500 .\" .\" This file was written by Dr. Stephen Henson . .\" Copyright (c) 2006, 2009, 2013, 2014, 2015 The OpenSSL Project. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" 3. All advertising materials mentioning features or use of this .\" software must display the following acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" .\" .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to .\" endorse or promote products derived from this software without .\" prior written permission. For written permission, please contact .\" openssl-core@openssl.org. .\" .\" 5. Products derived from this software may not be called "OpenSSL" .\" nor may "OpenSSL" appear in their names without prior written .\" permission of the OpenSSL Project. .\" .\" 6. Redistributions of any form whatsoever must retain the following .\" acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" .\" .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd $Mdocdate: August 28 2017 $ .Dt EVP_PKEY_CTX_CTRL 3 .Os .Sh NAME .Nm EVP_PKEY_CTX_ctrl , .Nm EVP_PKEY_CTX_ctrl_str , .Nm EVP_PKEY_CTX_set_signature_md , .Nm EVP_PKEY_CTX_set_rsa_padding , .Nm EVP_PKEY_CTX_set_rsa_pss_saltlen , .Nm EVP_PKEY_CTX_set_rsa_keygen_bits , .Nm EVP_PKEY_CTX_set_rsa_keygen_pubexp , .Nm EVP_PKEY_CTX_set_dsa_paramgen_bits , .Nm EVP_PKEY_CTX_set_dh_paramgen_prime_len , .Nm EVP_PKEY_CTX_set_dh_paramgen_generator , .Nm EVP_PKEY_CTX_set_ec_paramgen_curve_nid .Nd algorithm specific control operations .Sh SYNOPSIS .In openssl/evp.h .Ft int .Fo EVP_PKEY_CTX_ctrl .Fa "EVP_PKEY_CTX *ctx" .Fa "int keytype" .Fa "int optype" .Fa "int cmd" .Fa "int p1" .Fa "void *p2" .Fc .Ft int .Fo EVP_PKEY_CTX_ctrl_str .Fa "EVP_PKEY_CTX *ctx" .Fa "const char *type" .Fa "const char *value" .Fc .In openssl/rsa.h .Ft int .Fo EVP_PKEY_CTX_set_signature_md .Fa "EVP_PKEY_CTX *ctx" .Fa "const EVP_MD *md" .Fc .Ft int .Fo EVP_PKEY_CTX_set_rsa_padding .Fa "EVP_PKEY_CTX *ctx" .Fa "int pad" .Fc .Ft int .Fo EVP_PKEY_CTX_set_rsa_pss_saltlen .Fa "EVP_PKEY_CTX *ctx" .Fa "int len" .Fc .Ft int .Fo EVP_PKEY_CTX_set_rsa_keygen_bits .Fa "EVP_PKEY_CTX *ctx" .Fa "int mbits" .Fc .Ft int .Fo EVP_PKEY_CTX_set_rsa_keygen_pubexp .Fa "EVP_PKEY_CTX *ctx" .Fa "BIGNUM *pubexp" .Fc .In openssl/dsa.h .Ft int .Fo EVP_PKEY_CTX_set_dsa_paramgen_bits .Fa "EVP_PKEY_CTX *ctx" .Fa "int nbits" .Fc .In openssl/dh.h .Ft int .Fo EVP_PKEY_CTX_set_dh_paramgen_prime_len .Fa "EVP_PKEY_CTX *ctx" .Fa "int len" .Fc .Ft int .Fo EVP_PKEY_CTX_set_dh_paramgen_generator .Fa "EVP_PKEY_CTX *ctx" .Fa "int gen" .Fc .In openssl/ec.h .Ft int .Fo EVP_PKEY_CTX_set_ec_paramgen_curve_nid .Fa "EVP_PKEY_CTX *ctx" .Fa "int nid" .Fc .Sh DESCRIPTION The function .Fn EVP_PKEY_CTX_ctrl sends a control operation to the context .Fa ctx . The key type used must match .Fa keytype if it is not -1. The parameter .Fa optype is a mask indicating which operations the control can be applied to. The control command is indicated in .Fa cmd and any additional arguments in .Fa p1 and .Fa p2 . .Pp Applications will not normally call .Fn EVP_PKEY_CTX_ctrl directly but will instead call one of the algorithm specific macros below. .Pp The function .Fn EVP_PKEY_CTX_ctrl_str allows an application to send an algorithm specific control operation to a context .Fa ctx in string form. This is intended to be used for options specified on the command line or in text files. The commands supported are documented in the .Xr openssl 1 utility command line pages for the option .Fl pkeyopt which is supported by the .Cm pkeyutl , .Cm genpkey , and .Cm req commands. .Pp All the remaining "functions" are implemented as macros. .Pp The .Fn EVP_PKEY_CTX_set_signature_md macro sets the message digest type used in a signature. It can be used with any public key algorithm supporting signature operations. .Pp The macro .Fn EVP_PKEY_CTX_set_rsa_padding sets the RSA padding mode for .Fa ctx . The .Fa pad parameter can take the value .Dv RSA_PKCS1_PADDING for PKCS#1 padding, .Dv RSA_NO_PADDING for no padding, .Dv RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt only), .Dv RSA_X931_PADDING for X9.31 padding (signature operations only) and .Dv RSA_PKCS1_PSS_PADDING (sign and verify only). .Pp Two RSA padding modes behave differently if .Fn EVP_PKEY_CTX_set_signature_md is used. If this macro is called for PKCS#1 padding, the plaintext buffer is an actual digest value and is encapsulated in a .Vt DigestInfo structure according to PKCS#1 when signing and this structure is expected (and stripped off) when verifying. If this control is not used with RSA and PKCS#1 padding then the supplied data is used directly and not encapsulated. In the case of X9.31 padding for RSA the algorithm identifier byte is added or checked and removed if this control is called. If it is not called then the first byte of the plaintext buffer is expected to be the algorithm identifier byte. .Pp The .Fn EVP_PKEY_CTX_set_rsa_pss_saltlen macro sets the RSA PSS salt length to .Fa len . As its name implies, it is only supported for PSS padding. Two special values are supported: -1 sets the salt length to the digest length. When signing -2 sets the salt length to the maximum permissible value. When verifying -2 causes the salt length to be automatically determined based on the PSS block structure. If this macro is not called a salt length value of -2 is used by default. .Pp The .Fn EVP_PKEY_CTX_set_rsa_keygen_bits macro sets the RSA key length for RSA key generation to .Fa mbits . If not specified, 1024 bits is used. .Pp The .Fn EVP_PKEY_CTX_set_rsa_keygen_pubexp macro sets the public exponent value for RSA key generation to .Fa pubexp . Currently, it should be an odd integer. The .Fa pubexp pointer is used internally by this function, so it should not be modified or freed after the call. If this macro is not called, then 65537 is used. .Pp The macro .Fn EVP_PKEY_CTX_set_dsa_paramgen_bits sets the number of bits used for DSA parameter generation to .Fa nbits . If not specified, 1024 is used. .Pp The macro .Fn EVP_PKEY_CTX_set_dh_paramgen_prime_len sets the length of the DH prime parameter .Fa len for DH parameter generation. If this macro is not called, then 1024 is used. .Pp The .Fn EVP_PKEY_CTX_set_dh_paramgen_generator macro sets DH generator to .Fa gen for DH parameter generation. If not specified, 2 is used. .Pp The .Fn EVP_PKEY_CTX_set_ec_paramgen_curve_nid sets the EC curve for EC parameter generation to .Fa nid . For EC parameter generation, this macro must be called or an error occurs because there is no default curve. .Sh RETURN VALUES .Fn EVP_PKEY_CTX_ctrl and its macros return a positive value for success and 0 or a negative value for failure. In particular, a return value of -2 indicates the operation is not supported by the public key algorithm. .Sh SEE ALSO .Xr EVP_PKEY_CTX_new 3 , .Xr EVP_PKEY_decrypt 3 , .Xr EVP_PKEY_derive 3 , .Xr EVP_PKEY_encrypt 3 , .Xr EVP_PKEY_get_default_digest_nid 3 , .Xr EVP_PKEY_keygen 3 , .Xr EVP_PKEY_sign 3 , .Xr EVP_PKEY_verify 3 , .Xr EVP_PKEY_verify_recover 3 .Sh HISTORY These functions were first added to OpenSSL 1.0.0.