1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
.\" $OpenBSD: EVP_PKEY_CTX_ctrl.3,v 1.4 2016/11/21 22:19:15 jmc Exp $
.\"
.Dd $Mdocdate: November 21 2016 $
.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_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_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_SSLV23_PADDING
for SSLv23 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 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_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.
|