]>
Commit | Line | Data |
---|---|---|
d30e4c5b DSH |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
d45a97f4 MC |
5 | EVP_PKEY_new, |
6 | EVP_PKEY_up_ref, | |
7 | EVP_PKEY_free, | |
f929439f MC |
8 | EVP_PKEY_new_raw_private_key, |
9 | EVP_PKEY_new_raw_public_key, | |
d45a97f4 | 10 | EVP_PKEY_new_CMAC_key, |
edb77a4d MC |
11 | EVP_PKEY_new_mac_key, |
12 | EVP_PKEY_get_raw_private_key, | |
13 | EVP_PKEY_get_raw_public_key | |
14 | - public/private key allocation and raw key handling functions | |
d30e4c5b DSH |
15 | |
16 | =head1 SYNOPSIS | |
17 | ||
18 | #include <openssl/evp.h> | |
19 | ||
20 | EVP_PKEY *EVP_PKEY_new(void); | |
c5ebfcab | 21 | int EVP_PKEY_up_ref(EVP_PKEY *key); |
d30e4c5b DSH |
22 | void EVP_PKEY_free(EVP_PKEY *key); |
23 | ||
f929439f MC |
24 | EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, |
25 | const unsigned char *key, size_t keylen); | |
26 | EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, | |
27 | const unsigned char *key, size_t keylen); | |
d45a97f4 MC |
28 | EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, |
29 | size_t len, const EVP_CIPHER *cipher); | |
30 | EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, | |
31 | int keylen); | |
d30e4c5b | 32 | |
edb77a4d MC |
33 | int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, |
34 | size_t *len); | |
35 | int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, | |
36 | size_t *len); | |
37 | ||
d30e4c5b DSH |
38 | =head1 DESCRIPTION |
39 | ||
0c497e96 | 40 | The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> structure which is |
edb77a4d MC |
41 | used by OpenSSL to store public and private keys. The reference count is set to |
42 | B<1>. | |
d30e4c5b | 43 | |
0c497e96 DSH |
44 | EVP_PKEY_up_ref() increments the reference count of B<key>. |
45 | ||
46 | EVP_PKEY_free() decrements the reference count of B<key> and, if the reference | |
47 | count is zero, frees it up. If B<key> is NULL, nothing is done. | |
d30e4c5b | 48 | |
f929439f MC |
49 | EVP_PKEY_new_raw_private_key() allocates a new B<EVP_PKEY>. If B<e> is non-NULL |
50 | then the new B<EVP_PKEY> structure is associated with the engine B<e>. The | |
51 | B<type> argument indicates what kind of key this is. The value should be a NID | |
52 | for a public key algorithm that supports raw private keys, i.e. one of | |
d45a97f4 MC |
53 | B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>, |
54 | B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. B<key> points to the | |
55 | raw private key data for this B<EVP_PKEY> which should be of length B<keylen>. | |
56 | The length should be appropriate for the type of the key. The public key data | |
57 | will be automatically derived from the given private key data (if appropriate | |
58 | for the algorithm type). | |
59 | ||
f929439f MC |
60 | EVP_PKEY_new_raw_public_key() works in the same way as |
61 | EVP_PKEY_new_raw_private_key() except that B<key> points to the raw public key | |
62 | data. The B<EVP_PKEY> structure will be initialised without any private key | |
63 | information. Algorithm types that support raw public keys are | |
64 | B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. | |
d45a97f4 | 65 | |
f929439f | 66 | EVP_PKEY_new_CMAC_key() works in the same way as EVP_PKEY_new_raw_private_key() |
d45a97f4 MC |
67 | except it is only for the B<EVP_PKEY_CMAC> algorithm type. In addition to the |
68 | raw private key data, it also takes a cipher algorithm to be used during | |
69 | creation of a CMAC in the B<cipher> argument. | |
70 | ||
f929439f MC |
71 | EVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key(). |
72 | New applications should use EVP_PKEY_new_raw_private_key() instead. | |
d45a97f4 | 73 | |
edb77a4d MC |
74 | EVP_PKEY_get_raw_private_key() fills the buffer provided by B<priv> with raw |
75 | private key data. The number of bytes written is populated in B<*len>. If the | |
76 | buffer B<priv> is NULL then B<*len> is populated with the number of bytes | |
77 | required to hold the key. The calling application is responsible for ensuring | |
78 | that the buffer is large enough to receive the private key data. This function | |
79 | only works for algorithms that support raw private keys. Currently this is: | |
80 | B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>, B<EVP_PKEY_X25519>, | |
81 | B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. | |
82 | ||
83 | EVP_PKEY_get_raw_public_key() fills the buffer provided by B<pub> with raw | |
84 | public key data. The number of bytes written is populated in B<*len>. If the | |
85 | buffer B<pub> is NULL then B<*len> is populated with the number of bytes | |
86 | required to hold the key. The calling application is responsible for ensuring | |
87 | that the buffer is large enough to receive the public key data. This function | |
88 | only works for algorithms that support raw public keys. Currently this is: | |
89 | B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>. | |
90 | ||
d30e4c5b DSH |
91 | =head1 NOTES |
92 | ||
0c497e96 DSH |
93 | The B<EVP_PKEY> structure is used by various OpenSSL functions which require a |
94 | general private key without reference to any particular algorithm. | |
d30e4c5b | 95 | |
edb77a4d MC |
96 | The structure returned by EVP_PKEY_new() is empty. To add a private or public |
97 | key to this empty structure use the appropriate functions described in | |
98 | L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or | |
99 | L<EVP_PKEY_set1_EC_KEY>. | |
d30e4c5b DSH |
100 | |
101 | =head1 RETURN VALUES | |
102 | ||
f929439f | 103 | EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), |
d45a97f4 MC |
104 | EVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly |
105 | allocated B<EVP_PKEY> structure or B<NULL> if an error occurred. | |
d30e4c5b | 106 | |
edb77a4d MC |
107 | EVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and |
108 | EVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure. | |
d30e4c5b DSH |
109 | |
110 | =head1 SEE ALSO | |
111 | ||
edb77a4d MC |
112 | L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA>, L<EVP_PKEY_set1_DH> or |
113 | L<EVP_PKEY_set1_EC_KEY> | |
d30e4c5b DSH |
114 | |
115 | =head1 HISTORY | |
116 | ||
fc5ecadd DMSP |
117 | The |
118 | EVP_PKEY_new() and EVP_PKEY_free() functions exist in all versions of OpenSSL. | |
0c497e96 | 119 | |
fc5ecadd DMSP |
120 | The EVP_PKEY_up_ref() function was added in OpenSSL 1.1.0. |
121 | ||
122 | The | |
edb77a4d MC |
123 | EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), |
124 | EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and | |
fc5ecadd | 125 | EVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1. |
d30e4c5b | 126 | |
e2f92610 RS |
127 | =head1 COPYRIGHT |
128 | ||
b0edda11 | 129 | Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. |
e2f92610 | 130 | |
4746f25a | 131 | Licensed under the Apache License 2.0 (the "License"). You may not use |
e2f92610 RS |
132 | this file except in compliance with the License. You can obtain a copy |
133 | in the file LICENSE in the source distribution or at | |
134 | L<https://www.openssl.org/source/license.html>. | |
135 | ||
136 | =cut |