diff options
Diffstat (limited to 'src/lib/libcrypto/evp/pmeth_fn.c')
-rw-r--r-- | src/lib/libcrypto/evp/pmeth_fn.c | 67 |
1 files changed, 25 insertions, 42 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_fn.c b/src/lib/libcrypto/evp/pmeth_fn.c index 4cf18a0be1..c9117eedd4 100644 --- a/src/lib/libcrypto/evp/pmeth_fn.c +++ b/src/lib/libcrypto/evp/pmeth_fn.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pmeth_fn.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pmeth_fn.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -76,7 +76,7 @@ | |||
76 | } \ | 76 | } \ |
77 | else if (*arglen < pksize) \ | 77 | else if (*arglen < pksize) \ |
78 | { \ | 78 | { \ |
79 | EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\ | 79 | EVPerror(EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\ |
80 | return 0; \ | 80 | return 0; \ |
81 | } \ | 81 | } \ |
82 | } | 82 | } |
@@ -87,8 +87,7 @@ EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) | |||
87 | int ret; | 87 | int ret; |
88 | 88 | ||
89 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { | 89 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { |
90 | EVPerr(EVP_F_EVP_PKEY_SIGN_INIT, | 90 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
91 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
92 | return -2; | 91 | return -2; |
93 | } | 92 | } |
94 | ctx->operation = EVP_PKEY_OP_SIGN; | 93 | ctx->operation = EVP_PKEY_OP_SIGN; |
@@ -105,12 +104,11 @@ EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, | |||
105 | const unsigned char *tbs, size_t tbslen) | 104 | const unsigned char *tbs, size_t tbslen) |
106 | { | 105 | { |
107 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { | 106 | if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { |
108 | EVPerr(EVP_F_EVP_PKEY_SIGN, | 107 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
109 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
110 | return -2; | 108 | return -2; |
111 | } | 109 | } |
112 | if (ctx->operation != EVP_PKEY_OP_SIGN) { | 110 | if (ctx->operation != EVP_PKEY_OP_SIGN) { |
113 | EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED); | 111 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
114 | return -1; | 112 | return -1; |
115 | } | 113 | } |
116 | M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN) | 114 | M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN) |
@@ -123,8 +121,7 @@ EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx) | |||
123 | int ret; | 121 | int ret; |
124 | 122 | ||
125 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { | 123 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { |
126 | EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT, | 124 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
127 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
128 | return -2; | 125 | return -2; |
129 | } | 126 | } |
130 | ctx->operation = EVP_PKEY_OP_VERIFY; | 127 | ctx->operation = EVP_PKEY_OP_VERIFY; |
@@ -141,12 +138,11 @@ EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, | |||
141 | const unsigned char *tbs, size_t tbslen) | 138 | const unsigned char *tbs, size_t tbslen) |
142 | { | 139 | { |
143 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { | 140 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { |
144 | EVPerr(EVP_F_EVP_PKEY_VERIFY, | 141 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
145 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
146 | return -2; | 142 | return -2; |
147 | } | 143 | } |
148 | if (ctx->operation != EVP_PKEY_OP_VERIFY) { | 144 | if (ctx->operation != EVP_PKEY_OP_VERIFY) { |
149 | EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED); | 145 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
150 | return -1; | 146 | return -1; |
151 | } | 147 | } |
152 | return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); | 148 | return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); |
@@ -158,8 +154,7 @@ EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) | |||
158 | int ret; | 154 | int ret; |
159 | 155 | ||
160 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { | 156 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { |
161 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, | 157 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
162 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
163 | return -2; | 158 | return -2; |
164 | } | 159 | } |
165 | ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; | 160 | ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; |
@@ -176,13 +171,11 @@ EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, | |||
176 | const unsigned char *sig, size_t siglen) | 171 | const unsigned char *sig, size_t siglen) |
177 | { | 172 | { |
178 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { | 173 | if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { |
179 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, | 174 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
180 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
181 | return -2; | 175 | return -2; |
182 | } | 176 | } |
183 | if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) { | 177 | if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) { |
184 | EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, | 178 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
185 | EVP_R_OPERATON_NOT_INITIALIZED); | ||
186 | return -1; | 179 | return -1; |
187 | } | 180 | } |
188 | M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER) | 181 | M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER) |
@@ -195,8 +188,7 @@ EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) | |||
195 | int ret; | 188 | int ret; |
196 | 189 | ||
197 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { | 190 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { |
198 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT, | 191 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
199 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
200 | return -2; | 192 | return -2; |
201 | } | 193 | } |
202 | ctx->operation = EVP_PKEY_OP_ENCRYPT; | 194 | ctx->operation = EVP_PKEY_OP_ENCRYPT; |
@@ -213,12 +205,11 @@ EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, | |||
213 | const unsigned char *in, size_t inlen) | 205 | const unsigned char *in, size_t inlen) |
214 | { | 206 | { |
215 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { | 207 | if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { |
216 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, | 208 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
217 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
218 | return -2; | 209 | return -2; |
219 | } | 210 | } |
220 | if (ctx->operation != EVP_PKEY_OP_ENCRYPT) { | 211 | if (ctx->operation != EVP_PKEY_OP_ENCRYPT) { |
221 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED); | 212 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
222 | return -1; | 213 | return -1; |
223 | } | 214 | } |
224 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) | 215 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) |
@@ -231,8 +222,7 @@ EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) | |||
231 | int ret; | 222 | int ret; |
232 | 223 | ||
233 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { | 224 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { |
234 | EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT, | 225 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
235 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
236 | return -2; | 226 | return -2; |
237 | } | 227 | } |
238 | ctx->operation = EVP_PKEY_OP_DECRYPT; | 228 | ctx->operation = EVP_PKEY_OP_DECRYPT; |
@@ -249,12 +239,11 @@ EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, | |||
249 | const unsigned char *in, size_t inlen) | 239 | const unsigned char *in, size_t inlen) |
250 | { | 240 | { |
251 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { | 241 | if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { |
252 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, | 242 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
253 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
254 | return -2; | 243 | return -2; |
255 | } | 244 | } |
256 | if (ctx->operation != EVP_PKEY_OP_DECRYPT) { | 245 | if (ctx->operation != EVP_PKEY_OP_DECRYPT) { |
257 | EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED); | 246 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
258 | return -1; | 247 | return -1; |
259 | } | 248 | } |
260 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) | 249 | M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) |
@@ -267,8 +256,7 @@ EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) | |||
267 | int ret; | 256 | int ret; |
268 | 257 | ||
269 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { | 258 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { |
270 | EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT, | 259 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
271 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
272 | return -2; | 260 | return -2; |
273 | } | 261 | } |
274 | ctx->operation = EVP_PKEY_OP_DERIVE; | 262 | ctx->operation = EVP_PKEY_OP_DERIVE; |
@@ -288,15 +276,13 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
288 | if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive || | 276 | if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive || |
289 | ctx->pmeth->encrypt || ctx->pmeth->decrypt) || | 277 | ctx->pmeth->encrypt || ctx->pmeth->decrypt) || |
290 | !ctx->pmeth->ctrl) { | 278 | !ctx->pmeth->ctrl) { |
291 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 279 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
292 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
293 | return -2; | 280 | return -2; |
294 | } | 281 | } |
295 | if (ctx->operation != EVP_PKEY_OP_DERIVE && | 282 | if (ctx->operation != EVP_PKEY_OP_DERIVE && |
296 | ctx->operation != EVP_PKEY_OP_ENCRYPT && | 283 | ctx->operation != EVP_PKEY_OP_ENCRYPT && |
297 | ctx->operation != EVP_PKEY_OP_DECRYPT) { | 284 | ctx->operation != EVP_PKEY_OP_DECRYPT) { |
298 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 285 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
299 | EVP_R_OPERATON_NOT_INITIALIZED); | ||
300 | return -1; | 286 | return -1; |
301 | } | 287 | } |
302 | 288 | ||
@@ -309,13 +295,12 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
309 | return 1; | 295 | return 1; |
310 | 296 | ||
311 | if (!ctx->pkey) { | 297 | if (!ctx->pkey) { |
312 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_NO_KEY_SET); | 298 | EVPerror(EVP_R_NO_KEY_SET); |
313 | return -1; | 299 | return -1; |
314 | } | 300 | } |
315 | 301 | ||
316 | if (ctx->pkey->type != peer->type) { | 302 | if (ctx->pkey->type != peer->type) { |
317 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 303 | EVPerror(EVP_R_DIFFERENT_KEY_TYPES); |
318 | EVP_R_DIFFERENT_KEY_TYPES); | ||
319 | return -1; | 304 | return -1; |
320 | } | 305 | } |
321 | 306 | ||
@@ -326,8 +311,7 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) | |||
326 | * -2 is OK for us here, as well as 1, so we can check for 0 only. */ | 311 | * -2 is OK for us here, as well as 1, so we can check for 0 only. */ |
327 | if (!EVP_PKEY_missing_parameters(peer) && | 312 | if (!EVP_PKEY_missing_parameters(peer) && |
328 | !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) { | 313 | !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) { |
329 | EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, | 314 | EVPerror(EVP_R_DIFFERENT_PARAMETERS); |
330 | EVP_R_DIFFERENT_PARAMETERS); | ||
331 | return -1; | 315 | return -1; |
332 | } | 316 | } |
333 | 317 | ||
@@ -349,12 +333,11 @@ int | |||
349 | EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) | 333 | EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) |
350 | { | 334 | { |
351 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { | 335 | if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { |
352 | EVPerr(EVP_F_EVP_PKEY_DERIVE, | 336 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); |
353 | EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
354 | return -2; | 337 | return -2; |
355 | } | 338 | } |
356 | if (ctx->operation != EVP_PKEY_OP_DERIVE) { | 339 | if (ctx->operation != EVP_PKEY_OP_DERIVE) { |
357 | EVPerr(EVP_F_EVP_PKEY_DERIVE, EVP_R_OPERATON_NOT_INITIALIZED); | 340 | EVPerror(EVP_R_OPERATON_NOT_INITIALIZED); |
358 | return -1; | 341 | return -1; |
359 | } | 342 | } |
360 | M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) | 343 | M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) |