1EVP_PKEY_CTX_CTRL(3) OpenSSL EVP_PKEY_CTX_CTRL(3)
2
3
4
6 EVP_PKEY_CTX_ctrl, EVP_PKEY_CTX_ctrl_str,
7 EVP_PKEY_CTX_set_signature_md, EVP_PKEY_CTX_get_signature_md,
8 EVP_PKEY_CTX_set_mac_key, EVP_PKEY_CTX_set_rsa_padding,
9 EVP_PKEY_CTX_set_rsa_pss_saltlen, EVP_PKEY_CTX_set_rsa_keygen_bits,
10 EVP_PKEY_CTX_set_rsa_keygen_pubexp, EVP_PKEY_CTX_set_dsa_paramgen_bits,
11 EVP_PKEY_CTX_set_dh_paramgen_prime_len,
12 EVP_PKEY_CTX_set_dh_paramgen_generator, EVP_PKEY_CTX_set_dh_pad,
13 EVP_PKEY_CTX_set_dh_nid, EVP_PKEY_CTX_set_ec_paramgen_curve_nid,
14 EVP_PKEY_CTX_set_ec_param_enc, EVP_PKEY_CTX_set1_id,
15 EVP_PKEY_CTX_get1_id, EVP_PKEY_CTX_get1_id_len - algorithm specific
16 control operations
17
19 #include <openssl/evp.h>
20
21 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
22 int cmd, int p1, void *p2);
23 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
24 const char *value);
25
26 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
27 int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **pmd);
28
29 int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, unsigned char *key, int len);
30
31 #include <openssl/rsa.h>
32
33 int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad);
34 int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int len);
35 int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int mbits);
36 int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
37
38 #include <openssl/dsa.h>
39 int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits);
40
41 #include <openssl/dh.h>
42 int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int len);
43 int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen);
44 int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad);
45 int EVP_PKEY_CTX_set_dh_nid(EVP_PKEY_CTX *ctx, int nid);
46
47 #include <openssl/ec.h>
48 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
49 int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);
50
51 int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, void *id, size_t id_len);
52 int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id);
53 int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
54
56 The function EVP_PKEY_CTX_ctrl() sends a control operation to the
57 context ctx. The key type used must match keytype if it is not -1. The
58 parameter optype is a mask indicating which operations the control can
59 be applied to. The control command is indicated in cmd and any
60 additional arguments in p1 and p2.
61
62 For cmd = EVP_PKEY_CTRL_SET_MAC_KEY, p1 is the length of the MAC key,
63 and p2 is MAC key. This is used by Poly1305, SipHash, HMAC and CMAC.
64
65 Applications will not normally call EVP_PKEY_CTX_ctrl() directly but
66 will instead call one of the algorithm specific macros below.
67
68 The function EVP_PKEY_CTX_ctrl_str() allows an application to send an
69 algorithm specific control operation to a context ctx in string form.
70 This is intended to be used for options specified on the command line
71 or in text files. The commands supported are documented in the openssl
72 utility command line pages for the option -pkeyopt which is supported
73 by the pkeyutl, genpkey and req commands.
74
75 All the remaining "functions" are implemented as macros.
76
77 The EVP_PKEY_CTX_set_signature_md() macro sets the message digest type
78 used in a signature. It can be used in the RSA, DSA and ECDSA
79 algorithms.
80
81 The EVP_PKEY_CTX_get_signature_md() macro gets the message digest type
82 used in a signature. It can be used in the RSA, DSA and ECDSA
83 algorithms.
84
85 Key generation typically involves setting up parameters to be used and
86 generating the private and public key data. Some algorithm
87 implementations allow private key data to be set explicitly using the
88 EVP_PKEY_CTX_set_mac_key() macro. In this case key generation is simply
89 the process of setting up the parameters for the key and then setting
90 the raw key data to the value explicitly provided by that macro.
91 Normally applications would call EVP_PKEY_new_raw_private_key(3) or
92 similar functions instead of this macro.
93
94 The EVP_PKEY_CTX_set_mac_key() macro can be used with any of the
95 algorithms supported by the EVP_PKEY_new_raw_private_key(3) function.
96
97 The macro EVP_PKEY_CTX_set_rsa_padding() sets the RSA padding mode for
98 ctx. The pad parameter can take the value RSA_PKCS1_PADDING for PKCS#1
99 padding, RSA_SSLV23_PADDING for SSLv23 padding, RSA_NO_PADDING for no
100 padding, RSA_PKCS1_OAEP_PADDING for OAEP padding (encrypt and decrypt
101 only), RSA_X931_PADDING for X9.31 padding (signature operations only)
102 and RSA_PKCS1_PSS_PADDING (sign and verify only).
103
104 Two RSA padding modes behave differently if
105 EVP_PKEY_CTX_set_signature_md() is used. If this macro is called for
106 PKCS#1 padding the plaintext buffer is an actual digest value and is
107 encapsulated in a DigestInfo structure according to PKCS#1 when signing
108 and this structure is expected (and stripped off) when verifying. If
109 this control is not used with RSA and PKCS#1 padding then the supplied
110 data is used directly and not encapsulated. In the case of X9.31
111 padding for RSA the algorithm identifier byte is added or checked and
112 removed if this control is called. If it is not called then the first
113 byte of the plaintext buffer is expected to be the algorithm identifier
114 byte.
115
116 The EVP_PKEY_CTX_set_rsa_pss_saltlen() macro sets the RSA PSS salt
117 length to len as its name implies it is only supported for PSS padding.
118 Three special values are supported: RSA_PSS_SALTLEN_DIGEST sets the
119 salt length to the digest length, RSA_PSS_SALTLEN_MAX sets the salt
120 length to the maximum permissible value. When verifying
121 RSA_PSS_SALTLEN_AUTO causes the salt length to be automatically
122 determined based on the PSS block structure. If this macro is not
123 called maximum salt length is used when signing and auto detection when
124 verifying is used by default.
125
126 The EVP_PKEY_CTX_set_rsa_keygen_bits() macro sets the RSA key length
127 for RSA key generation to bits. If not specified 1024 bits is used.
128
129 The EVP_PKEY_CTX_set_rsa_keygen_pubexp() macro sets the public exponent
130 value for RSA key generation to pubexp currently it should be an odd
131 integer. The pubexp pointer is used internally by this function so it
132 should not be modified or free after the call. If this macro is not
133 called then 65537 is used.
134
135 The macro EVP_PKEY_CTX_set_dsa_paramgen_bits() sets the number of bits
136 used for DSA parameter generation to bits. If not specified 1024 is
137 used.
138
139 The macro EVP_PKEY_CTX_set_dh_paramgen_prime_len() sets the length of
140 the DH prime parameter p for DH parameter generation. If this macro is
141 not called then 1024 is used.
142
143 The EVP_PKEY_CTX_set_dh_paramgen_generator() macro sets DH generator to
144 gen for DH parameter generation. If not specified 2 is used.
145
146 The EVP_PKEY_CTX_set_dh_pad() macro sets the DH padding mode. If pad is
147 1 the shared secret is padded with zeroes up to the size of the DH
148 prime p. If pad is zero (the default) then no padding is performed.
149
150 EVP_PKEY_CTX_set_dh_nid() sets the DH parameters to values
151 corresponding to nid. The nid parameter must be NID_ffdhe2048,
152 NID_ffdhe3072, NID_ffdhe4096, NID_ffdhe6144 or NID_ffdhe8192. This
153 macro can be called during parameter or key generation.
154
155 The EVP_PKEY_CTX_set_ec_paramgen_curve_nid() sets the EC curve for EC
156 parameter generation to nid. For EC parameter generation this macro
157 must be called or an error occurs because there is no default curve.
158 This function can also be called to set the curve explicitly when
159 generating an EC key.
160
161 The EVP_PKEY_CTX_set_ec_param_enc() sets the EC parameter encoding to
162 param_enc when generating EC parameters or an EC key. The encoding can
163 be OPENSSL_EC_EXPLICIT_CURVE for explicit parameters (the default in
164 versions of OpenSSL before 1.1.0) or OPENSSL_EC_NAMED_CURVE to use
165 named curve form. For maximum compatibility the named curve form
166 should be used. Note: the OPENSSL_EC_NAMED_CURVE value was only added
167 to OpenSSL 1.1.0; previous versions should use 0 instead.
168
169 The EVP_PKEY_CTX_set1_id(), EVP_PKEY_CTX_get1_id() and
170 EVP_PKEY_CTX_get1_id_len() macros are used to manipulate the special
171 identifier field for specific signature algorithms such as SM2. The
172 EVP_PKEY_CTX_set1_id() sets an ID pointed by id with the length id_len
173 to the library. The library takes a copy of the id so that the caller
174 can safely free the original memory pointed to by id. The
175 EVP_PKEY_CTX_get1_id_len() macro returns the length of the ID set via a
176 previous call to EVP_PKEY_CTX_set1_id(). The length is usually used to
177 allocate adequate memory for further calls to EVP_PKEY_CTX_get1_id().
178 The EVP_PKEY_CTX_get1_id() macro returns the previously set ID value to
179 caller in id. The caller should allocate adequate memory space for the
180 id before calling EVP_PKEY_CTX_get1_id().
181
183 EVP_PKEY_CTX_ctrl() and its macros return a positive value for success
184 and 0 or a negative value for failure. In particular a return value of
185 -2 indicates the operation is not supported by the public key
186 algorithm.
187
189 EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3),
190 EVP_PKEY_sign(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3),
191 EVP_PKEY_derive(3) EVP_PKEY_keygen(3)
192
194 EVP_PKEY_CTX_set1_id(), EVP_PKEY_CTX_get1_id() and
195 EVP_PKEY_CTX_get1_id_len() macros were added in 1.1.1, other functions
196 were first added to OpenSSL 1.0.0.
197
199 Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
200
201 Licensed under the OpenSSL license (the "License"). You may not use
202 this file except in compliance with the License. You can obtain a copy
203 in the file LICENSE in the source distribution or at
204 <https://www.openssl.org/source/license.html>.
205
206
207
2081.1.1 2018-09-11 EVP_PKEY_CTX_CTRL(3)