
#use wml::openssl-macros area=docs page=EVP_PKEY_CTX_ctrl

<title>Documents, EVP_PKEY_CTX_ctrl(3)</title>

<h1>EVP_PKEY_CTX_ctrl(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
EVP_PKEY_ctrl, EVP_PKEY_ctrl_str - algorithm specific control operations

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/evp.h&gt;
</PRE>
<PRE> int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
                                int cmd, int p1, void *p2);
 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
                                                const char *value);
</PRE>
<PRE> int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
</PRE>
<PRE> #include &lt;openssl/rsa.h&gt;
</PRE>
<PRE> int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
</PRE>
<PRE> int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad);
 int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int len);
 int EVP_PKEY_CTX_set_rsa_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int mbits);
 int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
</PRE>
<PRE> #include &lt;openssl/dsa.h&gt;
 int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits);
</PRE>
<PRE> #include &lt;openssl/dh.h&gt;
 int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int len);
 int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen);
</PRE>
<PRE> #include &lt;openssl/ec.h&gt;
 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The function <CODE>EVP_PKEY_CTX_ctrl()</CODE> sends a control operation to
the context
<STRONG>ctx</STRONG>. The key type used must match <STRONG>keytype</STRONG> if it is not -1. The parameter
<STRONG>optype</STRONG> is a mask indicating which operations the control can be applied to. The
control command is indicated in <STRONG>cmd</STRONG> and any additional arguments in
<STRONG>p1</STRONG> and <STRONG>p2</STRONG>.

</P>
<P>
Applications will not normally call <CODE>EVP_PKEY_CTX_ctrl()</CODE>
directly but will instead call one of the algorithm specific macros below.

</P>
<P>
The function <CODE>EVP_PKEY_ctrl_str()</CODE> allows an application to send
an algorithm specific control operation to a context <STRONG>ctx</STRONG> 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
openssl utility command line pages for the option <STRONG>-pkeyopt</STRONG> which is supported by the
<STRONG>pkeyutl</STRONG>, <STRONG>genpkey</STRONG> and <STRONG>req</STRONG> commands.

</P>
<P>
All the remaining ``functions'' are implemented as macros.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_signature_md()</CODE> macro sets the message
digest type used in a signature. It can be used with any public key
algorithm supporting signature operations.

</P>
<P>
The macro <CODE>EVP_PKEY_CTX_set_rsa_padding()</CODE> sets the RSA padding
mode for <STRONG>ctx</STRONG>. The <STRONG>pad</STRONG> parameter can take the value RSA_PKCS1_PADDING for PKCS#1 padding,
RSA_SSLV23_PADDING for SSLv23 padding, RSA_NO_PADDING for no padding,
RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt only),
RSA_X931_PADDING for X9.31 padding (signature operations only) and
RSA_PKCS1_PSS_PADDING (sign and verify only).

</P>
<P>
Two RSA padding modes behave differently if
<CODE>EVP_PKEY_CTX_set_signature_md()</CODE> is used. If this macro is
called for PKCS#1 padding the plaintext buffer is an actual digest value
and is encapsulated in a 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.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_rsa_pss_saltlen()</CODE> macro sets the RSA PSS
salt length to
<STRONG>len</STRONG> 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
<STRONG>PSS</STRONG> block structure. If this macro is not called a salt length value of -2 is
used by default.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_rsa_rsa_keygen_bits()</CODE> macro sets the RSA
key length for RSA key genration to <STRONG>bits</STRONG>. If not specified 1024 bits is used.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_rsa_keygen_pubexp()</CODE> macro sets the public
exponent value for RSA key generation to <STRONG>pubexp</STRONG> currently it should be an odd integer. The
<STRONG>pubexp</STRONG> pointer is used internally by this function so it should not be modified or
free after the call. If this macro is not called then 65537 is used.

</P>
<P>
The macro <CODE>EVP_PKEY_CTX_set_dsa_paramgen_bits()</CODE> sets the number
of bits used for DSA parameter generation to <STRONG>bits</STRONG>. If not specified 1024 is used.

</P>
<P>
The macro <CODE>EVP_PKEY_CTX_set_dh_paramgen_prime_len()</CODE> sets the
length of the DH prime parameter <STRONG>p</STRONG> for DH parameter generation. If this macro is not called then 1024 is used.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_dh_paramgen_generator()</CODE> macro sets DH
generator to <STRONG>gen</STRONG>
for DH parameter generation. If not specified 2 is used.

</P>
<P>
The <CODE>EVP_PKEY_CTX_set_ec_paramgen_curve_nid()</CODE> sets the EC curve
for EC parameter generation to <STRONG>nid</STRONG>. For EC parameter generation this macro must be called or an error occurs
because there is no default curve.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>EVP_PKEY_CTX_ctrl()</CODE> 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.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/EVP_PKEY_CTX_new.html#">EVP_PKEY_CTX_new(3)</A>,
<A HREF="../crypto/EVP_PKEY_encrypt.html#">EVP_PKEY_encrypt(3)</A>,
<A HREF="../crypto/EVP_PKEY_decrypt.html#">EVP_PKEY_decrypt(3)</A>,
<A HREF="../crypto/EVP_PKEY_sign.html#">EVP_PKEY_sign(3)</A>,
<A HREF="../crypto/EVP_PKEY_verify.html#">EVP_PKEY_verify(3)</A>,
<A HREF="../crypto/EVP_PKEY_verify_recover.html#">EVP_PKEY_verify_recover(3)</A>,
<A HREF="../crypto/EVP_PKEY_derive.html#">EVP_PKEY_derive(3)</A> 
 
<A HREF="../crypto/EVP_PKEY_keygen.html#">EVP_PKEY_keygen(3)</A> 

 

</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
These functions were first added to OpenSSL 1.0.0.

</P>
:}

