diff options
author | jsing <> | 2014-05-07 17:42:51 +0000 |
---|---|---|
committer | jsing <> | 2014-05-07 17:42:51 +0000 |
commit | dd9b16d5489a1196ae0fcbe4315fe0122b042d7d (patch) | |
tree | b341b2cdc0818410f55d0a4662a40677e4899326 /src/lib/libcrypto/evp/pmeth_fn.c | |
parent | 1b7393e13080fa69e951cc4f482e3d5d85639c70 (diff) | |
download | openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.gz openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.tar.bz2 openbsd-dd9b16d5489a1196ae0fcbe4315fe0122b042d7d.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/evp/pmeth_fn.c')
-rw-r--r-- | src/lib/libcrypto/evp/pmeth_fn.c | 279 |
1 files changed, 136 insertions, 143 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_fn.c b/src/lib/libcrypto/evp/pmeth_fn.c index c4676f2f8d..12dd9e26a1 100644 --- a/src/lib/libcrypto/evp/pmeth_fn.c +++ b/src/lib/libcrypto/evp/pmeth_fn.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -79,15 +79,16 @@ | |||
79 | } \ | 79 | } \ |
80 | } | 80 | } |
81 | 81 | ||
82 | int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) | 82 | int |
83 | { | 83 | EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) |
84 | { | ||
84 | int ret; | 85 | int ret; |
85 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) | 86 | |
86 | { | 87 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { |
87 | EVPerr(EVP_F_EVP_PKEY_SIGN_INIT, | 88 | EVPerr(EVP_F_EVP_PKEY_SIGN_INIT, |
88 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 89 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
89 | return -2; | 90 | return -2; |
90 | } | 91 | } |
91 | ctx->operation = EVP_PKEY_OP_SIGN; | 92 | ctx->operation = EVP_PKEY_OP_SIGN; |
92 | if (!ctx->pmeth->sign_init) | 93 | if (!ctx->pmeth->sign_init) |
93 | return 1; | 94 | return 1; |
@@ -95,36 +96,35 @@ int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) | |||
95 | if (ret <= 0) | 96 | if (ret <= 0) |
96 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 97 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
97 | return ret; | 98 | return ret; |
98 | } | 99 | } |
99 | 100 | ||
100 | int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, | 101 | int |
101 | unsigned char *sig, size_t *siglen, | 102 | EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, |
102 | const unsigned char *tbs, size_t tbslen) | 103 | const unsigned char *tbs, size_t tbslen) |
103 | { | 104 | { |
104 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) | 105 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { |
105 | { | ||
106 | EVPerr(EVP_F_EVP_PKEY_SIGN, | 106 | EVPerr(EVP_F_EVP_PKEY_SIGN, |
107 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 107 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
108 | return -2; | 108 | return -2; |
109 | } | 109 | } |
110 | if (ctx->operation != EVP_PKEY_OP_SIGN) | 110 | if (ctx->operation != EVP_PKEY_OP_SIGN) { |
111 | { | ||
112 | EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED); | 111 | EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED); |
113 | return -1; | 112 | return -1; |
114 | } | 113 | } |
115 | M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN) | 114 | M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN) |
116 | return ctx->pmeth->sign(ctx, sig, siglen, tbs, tbslen); | 115 | return ctx->pmeth->sign(ctx, sig, siglen, tbs, tbslen); |
117 | } | 116 | } |
118 | 117 | ||
119 | int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) | 118 | int |
120 | { | 119 | EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) |
120 | { | ||
121 | int ret; | 121 | int ret; |
122 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) | 122 | |
123 | { | 123 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { |
124 | EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT, | 124 | EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT, |
125 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 125 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
126 | return -2; | 126 | return -2; |
127 | } | 127 | } |
128 | ctx->operation = EVP_PKEY_OP_VERIFY; | 128 | ctx->operation = EVP_PKEY_OP_VERIFY; |
129 | if (!ctx->pmeth->verify_init) | 129 | if (!ctx->pmeth->verify_init) |
130 | return 1; | 130 | return 1; |
@@ -132,35 +132,34 @@ int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) | |||
132 | if (ret <= 0) | 132 | if (ret <= 0) |
133 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 133 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
134 | return ret; | 134 | return ret; |
135 | } | 135 | } |
136 | 136 | ||
137 | int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, | 137 | int |
138 | const unsigned char *sig, size_t siglen, | 138 | EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, |
139 | const unsigned char *tbs, size_t tbslen) | 139 | const unsigned char *tbs, size_t tbslen) |
140 | { | 140 | { |
141 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) | 141 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { |
142 | { | ||
143 | EVPerr(EVP_F_EVP_PKEY_VERIFY, | 142 | EVPerr(EVP_F_EVP_PKEY_VERIFY, |
144 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 143 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
145 | return -2; | 144 | return -2; |
146 | } | 145 | } |
147 | if (ctx->operation != EVP_PKEY_OP_VERIFY) | 146 | if (ctx->operation != EVP_PKEY_OP_VERIFY) { |
148 | { | ||
149 | EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED); | 147 | EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED); |
150 | return -1; | 148 | return -1; |
151 | } | ||
152 | return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); | ||
153 | } | 149 | } |
150 | return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); | ||
151 | } | ||
154 | 152 | ||
155 | int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) | 153 | int |
156 | { | 154 | EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) |
155 | { | ||
157 | int ret; | 156 | int ret; |
158 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) | 157 | |
159 | { | 158 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { |
160 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, | 159 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, |
161 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 160 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
162 | return -2; | 161 | return -2; |
163 | } | 162 | } |
164 | ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; | 163 | ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; |
165 | if (!ctx->pmeth->verify_recover_init) | 164 | if (!ctx->pmeth->verify_recover_init) |
166 | return 1; | 165 | return 1; |
@@ -168,36 +167,36 @@ int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) | |||
168 | if (ret <= 0) | 167 | if (ret <= 0) |
169 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 168 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
170 | return ret; | 169 | return ret; |
171 | } | 170 | } |
172 | 171 | ||
173 | int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, | 172 | int |
174 | unsigned char *rout, size_t *routlen, | 173 | EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, |
175 | const unsigned char *sig, size_t siglen) | 174 | const unsigned char *sig, size_t siglen) |
176 | { | 175 | { |
177 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) | 176 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { |
178 | { | ||
179 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, | 177 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, |
180 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 178 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
181 | return -2; | 179 | return -2; |
182 | } | 180 | } |
183 | if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) | 181 | if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) { |
184 | { | 182 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, |
185 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, EVP_R_OPERATON_NOT_INITIALIZED); | 183 | EVP_R_OPERATON_NOT_INITIALIZED); |
186 | return -1; | 184 | return -1; |
187 | } | 185 | } |
188 | M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER) | 186 | M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER) |
189 | return ctx->pmeth->verify_recover(ctx, rout, routlen, sig, siglen); | 187 | return ctx->pmeth->verify_recover(ctx, rout, routlen, sig, siglen); |
190 | } | 188 | } |
191 | 189 | ||
192 | int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) | 190 | int |
193 | { | 191 | EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) |
192 | { | ||
194 | int ret; | 193 | int ret; |
195 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) | 194 | |
196 | { | 195 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { |
197 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT, | 196 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT, |
198 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 197 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
199 | return -2; | 198 | return -2; |
200 | } | 199 | } |
201 | ctx->operation = EVP_PKEY_OP_ENCRYPT; | 200 | ctx->operation = EVP_PKEY_OP_ENCRYPT; |
202 | if (!ctx->pmeth->encrypt_init) | 201 | if (!ctx->pmeth->encrypt_init) |
203 | return 1; | 202 | return 1; |
@@ -205,36 +204,35 @@ int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) | |||
205 | if (ret <= 0) | 204 | if (ret <= 0) |
206 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 205 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
207 | return ret; | 206 | return ret; |
208 | } | 207 | } |
209 | 208 | ||
210 | int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, | 209 | int |
211 | unsigned char *out, size_t *outlen, | 210 | EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, |
212 | const unsigned char *in, size_t inlen) | 211 | const unsigned char *in, size_t inlen) |
213 | { | 212 | { |
214 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) | 213 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { |
215 | { | ||
216 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, | 214 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, |
217 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 215 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
218 | return -2; | 216 | return -2; |
219 | } | 217 | } |
220 | if (ctx->operation != EVP_PKEY_OP_ENCRYPT) | 218 | if (ctx->operation != EVP_PKEY_OP_ENCRYPT) { |
221 | { | ||
222 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED); | 219 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED); |
223 | return -1; | 220 | return -1; |
224 | } | 221 | } |
225 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) | 222 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) |
226 | return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen); | 223 | return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen); |
227 | } | 224 | } |
228 | 225 | ||
229 | int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) | 226 | int |
230 | { | 227 | EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) |
228 | { | ||
231 | int ret; | 229 | int ret; |
232 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) | 230 | |
233 | { | 231 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { |
234 | EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT, | 232 | EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT, |
235 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 233 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
236 | return -2; | 234 | return -2; |
237 | } | 235 | } |
238 | ctx->operation = EVP_PKEY_OP_DECRYPT; | 236 | ctx->operation = EVP_PKEY_OP_DECRYPT; |
239 | if (!ctx->pmeth->decrypt_init) | 237 | if (!ctx->pmeth->decrypt_init) |
240 | return 1; | 238 | return 1; |
@@ -242,37 +240,35 @@ int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) | |||
242 | if (ret <= 0) | 240 | if (ret <= 0) |
243 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 241 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
244 | return ret; | 242 | return ret; |
245 | } | 243 | } |
246 | 244 | ||
247 | int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, | 245 | int |
248 | unsigned char *out, size_t *outlen, | 246 | EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, |
249 | const unsigned char *in, size_t inlen) | 247 | const unsigned char *in, size_t inlen) |
250 | { | 248 | { |
251 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) | 249 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { |
252 | { | ||
253 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, | 250 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, |
254 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 251 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
255 | return -2; | 252 | return -2; |
256 | } | 253 | } |
257 | if (ctx->operation != EVP_PKEY_OP_DECRYPT) | 254 | if (ctx->operation != EVP_PKEY_OP_DECRYPT) { |
258 | { | ||
259 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED); | 255 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED); |
260 | return -1; | 256 | return -1; |
261 | } | 257 | } |
262 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) | 258 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) |
263 | return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen); | 259 | return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen); |
264 | } | 260 | } |
265 | 261 | ||
266 | 262 | int | |
267 | int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) | 263 | EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) |
268 | { | 264 | { |
269 | int ret; | 265 | int ret; |
270 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) | 266 | |
271 | { | 267 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { |
272 | EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT, | 268 | EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT, |
273 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 269 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
274 | return -2; | 270 | return -2; |
275 | } | 271 | } |
276 | ctx->operation = EVP_PKEY_OP_DERIVE; | 272 | ctx->operation = EVP_PKEY_OP_DERIVE; |
277 | if (!ctx->pmeth->derive_init) | 273 | if (!ctx->pmeth->derive_init) |
278 | return 1; | 274 | return 1; |
@@ -280,23 +276,27 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) | |||
280 | if (ret <= 0) | 276 | if (ret <= 0) |
281 | ctx->operation = EVP_PKEY_OP_UNDEFINED; | 277 | ctx->operation = EVP_PKEY_OP_UNDEFINED; |
282 | return ret; | 278 | return ret; |
283 | } | 279 | } |
284 | 280 | ||
285 | int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | 281 | int |
286 | { | 282 | EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) |
283 | { | ||
287 | int ret; | 284 | int ret; |
288 | if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive||ctx->pmeth->encrypt||ctx->pmeth->decrypt) || !ctx->pmeth->ctrl) | 285 | |
289 | { | 286 | if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive || |
287 | ctx->pmeth->encrypt || ctx->pmeth->decrypt) || | ||
288 | !ctx->pmeth->ctrl) { | ||
290 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 289 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, |
291 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 290 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
292 | return -2; | 291 | return -2; |
293 | } | 292 | } |
294 | if (ctx->operation != EVP_PKEY_OP_DERIVE && ctx->operation != EVP_PKEY_OP_ENCRYPT && ctx->operation != EVP_PKEY_OP_DECRYPT) | 293 | if (ctx->operation != EVP_PKEY_OP_DERIVE && |
295 | { | 294 | ctx->operation != EVP_PKEY_OP_ENCRYPT && |
295 | ctx->operation != EVP_PKEY_OP_DECRYPT) { | ||
296 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 296 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, |
297 | EVP_R_OPERATON_NOT_INITIALIZED); | 297 | EVP_R_OPERATON_NOT_INITIALIZED); |
298 | return -1; | 298 | return -1; |
299 | } | 299 | } |
300 | 300 | ||
301 | ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 0, peer); | 301 | ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 0, peer); |
302 | 302 | ||
@@ -306,18 +306,16 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
306 | if (ret == 2) | 306 | if (ret == 2) |
307 | return 1; | 307 | return 1; |
308 | 308 | ||
309 | if (!ctx->pkey) | 309 | if (!ctx->pkey) { |
310 | { | ||
311 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_NO_KEY_SET); | 310 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_NO_KEY_SET); |
312 | return -1; | 311 | return -1; |
313 | } | 312 | } |
314 | 313 | ||
315 | if (ctx->pkey->type != peer->type) | 314 | if (ctx->pkey->type != peer->type) { |
316 | { | ||
317 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 315 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, |
318 | EVP_R_DIFFERENT_KEY_TYPES); | 316 | EVP_R_DIFFERENT_KEY_TYPES); |
319 | return -1; | 317 | return -1; |
320 | } | 318 | } |
321 | 319 | ||
322 | /* ran@cryptocom.ru: For clarity. The error is if parameters in peer are | 320 | /* ran@cryptocom.ru: For clarity. The error is if parameters in peer are |
323 | * present (!missing) but don't match. EVP_PKEY_cmp_parameters may return | 321 | * present (!missing) but don't match. EVP_PKEY_cmp_parameters may return |
@@ -325,12 +323,11 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
325 | * (different key types) is impossible here because it is checked earlier. | 323 | * (different key types) is impossible here because it is checked earlier. |
326 | * -2 is OK for us here, as well as 1, so we can check for 0 only. */ | 324 | * -2 is OK for us here, as well as 1, so we can check for 0 only. */ |
327 | if (!EVP_PKEY_missing_parameters(peer) && | 325 | if (!EVP_PKEY_missing_parameters(peer) && |
328 | !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) | 326 | !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) { |
329 | { | ||
330 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 327 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, |
331 | EVP_R_DIFFERENT_PARAMETERS); | 328 | EVP_R_DIFFERENT_PARAMETERS); |
332 | return -1; | 329 | return -1; |
333 | } | 330 | } |
334 | 331 | ||
335 | if (ctx->peerkey) | 332 | if (ctx->peerkey) |
336 | EVP_PKEY_free(ctx->peerkey); | 333 | EVP_PKEY_free(ctx->peerkey); |
@@ -338,31 +335,27 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
338 | 335 | ||
339 | ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer); | 336 | ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer); |
340 | 337 | ||
341 | if (ret <= 0) | 338 | if (ret <= 0) { |
342 | { | ||
343 | ctx->peerkey = NULL; | 339 | ctx->peerkey = NULL; |
344 | return ret; | 340 | return ret; |
345 | } | ||
346 | |||
347 | CRYPTO_add(&peer->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
348 | return 1; | ||
349 | } | 341 | } |
350 | 342 | ||
343 | CRYPTO_add(&peer->references, 1, CRYPTO_LOCK_EVP_PKEY); | ||
344 | return 1; | ||
345 | } | ||
351 | 346 | ||
352 | int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) | 347 | int |
353 | { | 348 | EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) |
354 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) | 349 | { |
355 | { | 350 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { |
356 | EVPerr(EVP_F_EVP_PKEY_DERIVE, | 351 | EVPerr(EVP_F_EVP_PKEY_DERIVE, |
357 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | 352 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
358 | return -2; | 353 | return -2; |
359 | } | 354 | } |
360 | if (ctx->operation != EVP_PKEY_OP_DERIVE) | 355 | if (ctx->operation != EVP_PKEY_OP_DERIVE) { |
361 | { | ||
362 | EVPerr(EVP_F_EVP_PKEY_DERIVE, EVP_R_OPERATON_NOT_INITIALIZED); | 356 | EVPerr(EVP_F_EVP_PKEY_DERIVE, EVP_R_OPERATON_NOT_INITIALIZED); |
363 | return -1; | 357 | return -1; |
364 | } | 358 | } |
365 | M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) | 359 | M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) |
366 | return ctx->pmeth->derive(ctx, key, pkeylen); | 360 | return ctx->pmeth->derive(ctx, key, pkeylen); |
367 | } | 361 | } |
368 | |||