Add OPENSSL_VERSION_AT_LEAST
[openssl.git] / doc / man3 / EVP_PKEY_set1_RSA.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY,
6 EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY,
7 EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA, EVP_PKEY_get0_DH, EVP_PKEY_get0_EC_KEY,
8 EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH,
9 EVP_PKEY_assign_EC_KEY, EVP_PKEY_get0_hmac, EVP_PKEY_type, EVP_PKEY_id,
10 EVP_PKEY_base_id, EVP_PKEY_set1_engine - EVP_PKEY assignment functions
11
12 =head1 SYNOPSIS
13
14  #include <openssl/evp.h>
15
16  int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
17  int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
18  int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
19  int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
20
21  RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
22  DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
23  DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
24  EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
25
26  const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
27  RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
28  DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
29  DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey);
30  EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey);
31
32  int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key);
33  int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key);
34  int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key);
35  int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
36
37  int EVP_PKEY_id(const EVP_PKEY *pkey);
38  int EVP_PKEY_base_id(const EVP_PKEY *pkey);
39  int EVP_PKEY_type(int type);
40
41  int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine);
42
43 =head1 DESCRIPTION
44
45 EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
46 EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>.
47
48 EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
49 EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or
50 B<NULL> if the key is not of the correct type.
51
52 EVP_PKEY_get0_hmac(), EVP_PKEY_get0_RSA(), EVP_PKEY_get0_DSA(),
53 EVP_PKEY_get0_DH() and EVP_PKEY_get0_EC_KEY() also return the
54 referenced key in B<pkey> or B<NULL> if the key is not of the
55 correct type but the reference count of the returned key is
56 B<not> incremented and so must not be freed up after use.
57
58 EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
59 and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key>
60 however these use the supplied B<key> internally and so B<key>
61 will be freed when the parent B<pkey> is freed.
62
63 EVP_PKEY_base_id() returns the type of B<pkey>. For example
64 an RSA key will return B<EVP_PKEY_RSA>.
65
66 EVP_PKEY_id() returns the actual OID associated with B<pkey>. Historically keys
67 using the same algorithm could use different OIDs. For example an RSA key could
68 use the OIDs corresponding to the NIDs B<NID_rsaEncryption> (equivalent to
69 B<EVP_PKEY_RSA>) or B<NID_rsa> (equivalent to B<EVP_PKEY_RSA2>). The use of
70 alternative non-standard OIDs is now rare so B<EVP_PKEY_RSA2> et al are not
71 often seen in practice.
72
73 EVP_PKEY_type() returns the underlying type of the NID B<type>. For example
74 EVP_PKEY_type(EVP_PKEY_RSA2) will return B<EVP_PKEY_RSA>.
75
76 EVP_PKEY_set1_engine() sets the ENGINE handling B<pkey> to B<engine>. It
77 must be called after the key algorithm and components are set up.
78 If B<engine> does not include an B<EVP_PKEY_METHOD> for B<pkey> an
79 error occurs.
80
81 =head1 NOTES
82
83 In accordance with the OpenSSL naming convention the key obtained
84 from or assigned to the B<pkey> using the B<1> functions must be
85 freed as well as B<pkey>.
86
87 EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
88 and EVP_PKEY_assign_EC_KEY() are implemented as macros.
89
90 Most applications wishing to know a key type will simply call
91 EVP_PKEY_base_id() and will not care about the actual type:
92 which will be identical in almost all cases.
93
94 Previous versions of this document suggested using EVP_PKEY_type(pkey->type)
95 to determine the type of a key. Since B<EVP_PKEY> is now opaque this
96 is no longer possible: the equivalent is EVP_PKEY_base_id(pkey).
97
98 EVP_PKEY_set1_engine() is typically used by an ENGINE returning an HSM
99 key as part of its routine to load a private key.
100
101 =head1 RETURN VALUES
102
103 EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and
104 EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure.
105
106 EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and
107 EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if
108 an error occurred.
109
110 EVP_PKEY_assign_RSA(), EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH()
111 and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure.
112
113 EVP_PKEY_base_id(), EVP_PKEY_id() and EVP_PKEY_type() return a key
114 type or B<NID_undef> (equivalently B<EVP_PKEY_NONE>) on error.
115
116 EVP_PKEY_set1_engine() returns 1 for success and 0 for failure.
117
118 =head1 SEE ALSO
119
120 L<EVP_PKEY_new(3)>
121
122 =head1 COPYRIGHT
123
124 Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
125
126 Licensed under the OpenSSL license (the "License").  You may not use
127 this file except in compliance with the License.  You can obtain a copy
128 in the file LICENSE in the source distribution or at
129 L<https://www.openssl.org/source/license.html>.
130
131 =cut