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