2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
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
11 * Legacy EVP_PKEY assign/set/get APIs are deprecated for public use, but
12 * still ok for internal use, particularly in providers.
14 #include "internal/deprecated.h"
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"
25 int EVP_PKEY_set1_RSA(EVP_PKEY
*pkey
, RSA
*key
)
27 int ret
= EVP_PKEY_assign_RSA(pkey
, key
);
34 RSA
*evp_pkey_get0_RSA_int(const EVP_PKEY
*pkey
)
36 if (pkey
->type
!= EVP_PKEY_RSA
&& pkey
->type
!= EVP_PKEY_RSA_PSS
) {
37 ERR_raise(ERR_LIB_EVP
, EVP_R_EXPECTING_AN_RSA_KEY
);
40 return evp_pkey_get_legacy((EVP_PKEY
*)pkey
);
43 const RSA
*EVP_PKEY_get0_RSA(const EVP_PKEY
*pkey
)
45 return evp_pkey_get0_RSA_int(pkey
);
48 RSA
*EVP_PKEY_get1_RSA(EVP_PKEY
*pkey
)
50 RSA
*ret
= evp_pkey_get0_RSA_int(pkey
);
58 int EVP_PKEY_set1_EC_KEY(EVP_PKEY
*pkey
, EC_KEY
*key
)
60 if (!EC_KEY_up_ref(key
))
62 if (!EVP_PKEY_assign_EC_KEY(pkey
, key
)) {
69 EC_KEY
*evp_pkey_get0_EC_KEY_int(const EVP_PKEY
*pkey
)
71 if (EVP_PKEY_base_id(pkey
) != EVP_PKEY_EC
) {
72 ERR_raise(ERR_LIB_EVP
, EVP_R_EXPECTING_A_EC_KEY
);
75 return evp_pkey_get_legacy((EVP_PKEY
*)pkey
);
78 const EC_KEY
*EVP_PKEY_get0_EC_KEY(const EVP_PKEY
*pkey
)
80 return evp_pkey_get0_EC_KEY_int(pkey
);
83 EC_KEY
*EVP_PKEY_get1_EC_KEY(EVP_PKEY
*pkey
)
85 EC_KEY
*ret
= evp_pkey_get0_EC_KEY_int(pkey
);
87 if (ret
!= NULL
&& !EC_KEY_up_ref(ret
))
91 #endif /* OPENSSL_NO_EC */