/src/openssl/crypto/evp/p_legacy.c
Line  | Count  | Source  | 
1  |  | /*  | 
2  |  |  * Copyright 1995-2025 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 <openssl/ec.h>  | 
21  |  | #include "crypto/types.h"  | 
22  |  | #include "crypto/evp.h"  | 
23  |  | #include "evp_local.h"  | 
24  |  |  | 
25  |  | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)  | 
26  | 0  | { | 
27  | 0  |     int ret;  | 
28  |  | 
  | 
29  | 0  |     if (!RSA_up_ref(key))  | 
30  | 0  |         return 0;  | 
31  |  |  | 
32  | 0  |     ret = EVP_PKEY_assign_RSA(pkey, key);  | 
33  |  | 
  | 
34  | 0  |     if (!ret)  | 
35  | 0  |         RSA_free(key);  | 
36  |  | 
  | 
37  | 0  |     return ret;  | 
38  | 0  | }  | 
39  |  |  | 
40  |  | RSA *evp_pkey_get0_RSA_int(const EVP_PKEY *pkey)  | 
41  | 0  | { | 
42  | 0  |     if (pkey->type != EVP_PKEY_RSA && pkey->type != EVP_PKEY_RSA_PSS) { | 
43  | 0  |         ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_AN_RSA_KEY);  | 
44  | 0  |         return NULL;  | 
45  | 0  |     }  | 
46  | 0  |     return evp_pkey_get_legacy((EVP_PKEY *)pkey);  | 
47  | 0  | }  | 
48  |  |  | 
49  |  | const RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)  | 
50  | 0  | { | 
51  | 0  |     return evp_pkey_get0_RSA_int(pkey);  | 
52  | 0  | }  | 
53  |  |  | 
54  |  | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)  | 
55  | 0  | { | 
56  | 0  |     RSA *ret = evp_pkey_get0_RSA_int(pkey);  | 
57  |  | 
  | 
58  | 0  |     if (ret != NULL && !RSA_up_ref(ret))  | 
59  | 0  |         ret = NULL;  | 
60  |  | 
  | 
61  | 0  |     return ret;  | 
62  | 0  | }  | 
63  |  |  | 
64  |  | #ifndef OPENSSL_NO_EC  | 
65  |  | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)  | 
66  | 0  | { | 
67  | 0  |     if (!EC_KEY_up_ref(key))  | 
68  | 0  |         return 0;  | 
69  | 0  |     if (!EVP_PKEY_assign_EC_KEY(pkey, key)) { | 
70  | 0  |         EC_KEY_free(key);  | 
71  | 0  |         return 0;  | 
72  | 0  |     }  | 
73  | 0  |     return 1;  | 
74  | 0  | }  | 
75  |  |  | 
76  |  | EC_KEY *evp_pkey_get0_EC_KEY_int(const EVP_PKEY *pkey)  | 
77  | 0  | { | 
78  | 0  |     if (EVP_PKEY_get_base_id(pkey) != EVP_PKEY_EC) { | 
79  | 0  |         ERR_raise(ERR_LIB_EVP, EVP_R_EXPECTING_A_EC_KEY);  | 
80  | 0  |         return NULL;  | 
81  | 0  |     }  | 
82  | 0  |     return evp_pkey_get_legacy((EVP_PKEY *)pkey);  | 
83  | 0  | }  | 
84  |  |  | 
85  |  | const EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)  | 
86  | 0  | { | 
87  | 0  |     return evp_pkey_get0_EC_KEY_int(pkey);  | 
88  | 0  | }  | 
89  |  |  | 
90  |  | EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)  | 
91  | 0  | { | 
92  | 0  |     EC_KEY *ret = evp_pkey_get0_EC_KEY_int(pkey);  | 
93  |  | 
  | 
94  | 0  |     if (ret != NULL && !EC_KEY_up_ref(ret))  | 
95  | 0  |         ret = NULL;  | 
96  | 0  |     return ret;  | 
97  | 0  | }  | 
98  |  | #endif /* OPENSSL_NO_EC */  |