diff options
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
-rw-r--r-- | src/lib/libcrypto/evp/p_lib.c | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c index b6cef5a14c..2e0830b96e 100644 --- a/src/lib/libcrypto/evp/p_lib.c +++ b/src/lib/libcrypto/evp/p_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p_lib.c,v 1.29 2022/06/27 12:36:05 tb Exp $ */ | 1 | /* $OpenBSD: p_lib.c,v 1.30 2022/11/10 14:46:44 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -279,6 +279,96 @@ EVP_PKEY_set_type(EVP_PKEY *pkey, int type) | |||
279 | } | 279 | } |
280 | 280 | ||
281 | EVP_PKEY * | 281 | EVP_PKEY * |
282 | EVP_PKEY_new_raw_private_key(int type, ENGINE *engine, | ||
283 | const unsigned char *private_key, size_t len) | ||
284 | { | ||
285 | EVP_PKEY *ret; | ||
286 | |||
287 | if ((ret = EVP_PKEY_new()) == NULL) | ||
288 | goto err; | ||
289 | |||
290 | if (!pkey_set_type(ret, engine, type, NULL, -1)) | ||
291 | goto err; | ||
292 | |||
293 | if (ret->ameth->set_priv_key == NULL) { | ||
294 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
295 | goto err; | ||
296 | } | ||
297 | if (!ret->ameth->set_priv_key(ret, private_key, len)) { | ||
298 | EVPerror(EVP_R_KEY_SETUP_FAILED); | ||
299 | goto err; | ||
300 | } | ||
301 | |||
302 | return ret; | ||
303 | |||
304 | err: | ||
305 | EVP_PKEY_free(ret); | ||
306 | |||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | EVP_PKEY * | ||
311 | EVP_PKEY_new_raw_public_key(int type, ENGINE *engine, | ||
312 | const unsigned char *public_key, size_t len) | ||
313 | { | ||
314 | EVP_PKEY *ret; | ||
315 | |||
316 | if ((ret = EVP_PKEY_new()) == NULL) | ||
317 | goto err; | ||
318 | |||
319 | if (!pkey_set_type(ret, engine, type, NULL, -1)) | ||
320 | goto err; | ||
321 | |||
322 | if (ret->ameth->set_pub_key == NULL) { | ||
323 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
324 | goto err; | ||
325 | } | ||
326 | if (!ret->ameth->set_pub_key(ret, public_key, len)) { | ||
327 | EVPerror(EVP_R_KEY_SETUP_FAILED); | ||
328 | goto err; | ||
329 | } | ||
330 | |||
331 | return ret; | ||
332 | |||
333 | err: | ||
334 | EVP_PKEY_free(ret); | ||
335 | |||
336 | return NULL; | ||
337 | } | ||
338 | |||
339 | int | ||
340 | EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, | ||
341 | unsigned char *out_private_key, size_t *out_len) | ||
342 | { | ||
343 | if (pkey->ameth->get_priv_key == NULL) { | ||
344 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
345 | return 0; | ||
346 | } | ||
347 | if (!pkey->ameth->get_priv_key(pkey, out_private_key, out_len)) { | ||
348 | EVPerror(EVP_R_GET_RAW_KEY_FAILED); | ||
349 | return 0; | ||
350 | } | ||
351 | |||
352 | return 1; | ||
353 | } | ||
354 | |||
355 | int | ||
356 | EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, | ||
357 | unsigned char *out_public_key, size_t *out_len) | ||
358 | { | ||
359 | if (pkey->ameth->get_pub_key == NULL) { | ||
360 | EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); | ||
361 | return 0; | ||
362 | } | ||
363 | if (!pkey->ameth->get_pub_key(pkey, out_public_key, out_len)) { | ||
364 | EVPerror(EVP_R_GET_RAW_KEY_FAILED); | ||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | return 1; | ||
369 | } | ||
370 | |||
371 | EVP_PKEY * | ||
282 | EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len, | 372 | EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len, |
283 | const EVP_CIPHER *cipher) | 373 | const EVP_CIPHER *cipher) |
284 | { | 374 | { |
@@ -581,4 +671,3 @@ EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid) | |||
581 | return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, | 671 | return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, |
582 | 0, pnid); | 672 | 0, pnid); |
583 | } | 673 | } |
584 | |||