]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/p_legacy.c
cad4d67d73dfa9c95ed98ac9d9713690f02f8a4f
[thirdparty/openssl.git] / crypto / evp / p_legacy.c
1 /*
2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 /*
11 * Legacy EVP_PKEY assign/set/get APIs are deprecated for public use, but
12 * still ok for internal use, particularly in providers.
13 */
14 #include "internal/deprecated.h"
15
16 #include <openssl/types.h>
17 #include <openssl/evp.h>
18 #include <openssl/err.h>
19 #include <openssl/rsa.h>
20 #include "crypto/types.h"
21 #include "crypto/evp.h"
22 #include "evp_local.h"
23
24 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
25 {
26 int ret = EVP_PKEY_assign_RSA(pkey, key);
27 if (ret)
28 RSA_up_ref(key);
29 return ret;
30 }
31
32 RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
33 {
34 if (!evp_pkey_downgrade((EVP_PKEY *)pkey)) {
35 ERR_raise(ERR_LIB_EVP, EVP_R_INACCESSIBLE_KEY);
36 return NULL;
37 }
38 if (pkey->type != EVP_PKEY_RSA && pkey->type != EVP_PKEY_RSA_PSS) {
39 ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_AN_RSA_KEY);
40 return NULL;
41 }
42 return pkey->pkey.rsa;
43 }
44
45 RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
46 {
47 RSA *ret = EVP_PKEY_get0_RSA(pkey);
48 if (ret != NULL)
49 RSA_up_ref(ret);
50 return ret;
51 }