Make it clear that you can't use all ciphers for CMAC
[openssl.git] / doc / man3 / EVP_PKEY_new.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_new,
6 EVP_PKEY_up_ref,
7 EVP_PKEY_free,
8 EVP_PKEY_new_raw_private_key_with_libctx,
9 EVP_PKEY_new_raw_private_key,
10 EVP_PKEY_new_raw_public_key_with_libctx,
11 EVP_PKEY_new_raw_public_key,
12 EVP_PKEY_new_CMAC_key,
13 EVP_PKEY_new_mac_key,
14 EVP_PKEY_get_raw_private_key,
15 EVP_PKEY_get_raw_public_key
16 - public/private key allocation and raw key handling functions
17
18 =head1 SYNOPSIS
19
20  #include <openssl/evp.h>
21
22  EVP_PKEY *EVP_PKEY_new(void);
23  int EVP_PKEY_up_ref(EVP_PKEY *key);
24  void EVP_PKEY_free(EVP_PKEY *key);
25
26  EVP_PKEY *EVP_PKEY_new_raw_private_key_with_libctx(OPENSSL_CTX *libctx,
27                                                     const char *keytype,
28                                                     const char *propq,
29                                                     const unsigned char *key,
30                                                     size_t keylen);
31  EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
32                                         const unsigned char *key, size_t keylen);
33  EVP_PKEY *EVP_PKEY_new_raw_public_key_with_libctx(OPENSSL_CTX *libctx,
34                                                    const char *keytype,
35                                                    const char *propq,
36                                                    const unsigned char *key,
37                                                    size_t keylen);
38  EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
39                                        const unsigned char *key, size_t keylen);
40  EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
41                                  size_t len, const EVP_CIPHER *cipher);
42  EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
43                                 int keylen);
44
45  int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv,
46                                   size_t *len);
47  int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub,
48                                  size_t *len);
49
50 =head1 DESCRIPTION
51
52 The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> structure which is
53 used by OpenSSL to store public and private keys. The reference count is set to
54 B<1>.
55
56 EVP_PKEY_up_ref() increments the reference count of B<key>.
57
58 EVP_PKEY_free() decrements the reference count of B<key> and, if the reference
59 count is zero, frees it up. If B<key> is NULL, nothing is done.
60
61 EVP_PKEY_new_raw_private_key_with_libctx() allocates a new B<EVP_PKEY>. Unless
62 an engine should be used for the key type, a provider for the key is found using
63 the library context I<libctx> and the property query string I<propq>. The
64 I<keytype> argument indicates what kind of key this is. The value should be a
65 string for a public key algorithm that supports raw private keys, i.e one of
66 "POLY1305", "SIPHASH", "X25519", "ED25519", "X448" or "ED448". Note that you may
67 also use "HMAC" which is not a public key algorithm but is treated as such by
68 some OpenSSL APIs. You are encouraged to use the EVP_MAC APIs instead for HMAC
69 (see L<EVP_MAC(3)>). I<key> points to the raw private key data for this
70 B<EVP_PKEY> which should be of length I<keylen>. The length should be
71 appropriate for the type of the key. The public key data will be automatically
72 derived from the given private key data (if appropriate for the algorithm type).
73
74 EVP_PKEY_new_raw_private_key() does the same as
75 EVP_PKEY_new_raw_private_key_with_libctx() except that the default library
76 context and default property query are used instead. If B<e> is non-NULL then
77 the new B<EVP_PKEY> structure is associated with the engine B<e>. The B<type>
78 argument indicates what kind of key this is. The value should be a NID for a
79 public key algorithm that supports raw private keys, i.e. one of
80 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>. As for
82 EVP_PKEY_new_raw_private_key_with_libctx() you may also use B<EVP_PKEY_HMAC>.
83
84 EVP_PKEY_new_raw_public_key_with_libctx() works in the same way as
85 EVP_PKEY_new_raw_private_key_with_libctx() except that B<key> points to the raw
86 public key data. The B<EVP_PKEY> structure will be initialised without any
87 private key information. Algorithm types that support raw public keys are
88 "X25519", "ED25519", "X448" or "ED448".
89
90 EVP_PKEY_new_raw_public_key() works in the same way as
91 EVP_PKEY_new_raw_private_key() except that B<key> points to the raw public key
92 data. The B<EVP_PKEY> structure will be initialised without any private key
93 information. Algorithm types that support raw public keys are
94 B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
95
96 EVP_PKEY_new_CMAC_key() works in the same way as EVP_PKEY_new_raw_private_key()
97 except it is only for the B<EVP_PKEY_CMAC> algorithm type. In addition to the
98 raw private key data, it also takes a cipher algorithm to be used during
99 creation of a CMAC in the B<cipher> argument. The cipher should be a standard
100 encryption only cipher. For example AEAD and XTS ciphers should not be used.
101
102 EVP_PKEY_new_mac_key() works in the same way as EVP_PKEY_new_raw_private_key().
103 New applications should use EVP_PKEY_new_raw_private_key() instead.
104
105 EVP_PKEY_get_raw_private_key() fills the buffer provided by B<priv> with raw
106 private key data. The size of the B<priv> buffer should be in B<*len> on entry
107 to the function, and on exit B<*len> is updated with the number of bytes
108 actually written. If the buffer B<priv> is NULL then B<*len> is populated with
109 the number of bytes required to hold the key. The calling application is
110 responsible for ensuring that the buffer is large enough to receive the private
111 key data. This function only works for algorithms that support raw private keys.
112 Currently this is: B<EVP_PKEY_HMAC>, B<EVP_PKEY_POLY1305>, B<EVP_PKEY_SIPHASH>,
113 B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or B<EVP_PKEY_ED448>.
114
115 EVP_PKEY_get_raw_public_key() fills the buffer provided by B<pub> with raw
116 public key data. The size of the B<pub> buffer should be in B<*len> on entry
117 to the function, and on exit B<*len> is updated with the number of bytes
118 actually written. If the buffer B<pub> is NULL then B<*len> is populated with
119 the number of bytes required to hold the key. The calling application is
120 responsible for ensuring that the buffer is large enough to receive the public
121 key data. This function only works for algorithms that support raw public  keys.
122 Currently this is: B<EVP_PKEY_X25519>, B<EVP_PKEY_ED25519>, B<EVP_PKEY_X448> or
123 B<EVP_PKEY_ED448>.
124
125 =head1 NOTES
126
127 The B<EVP_PKEY> structure is used by various OpenSSL functions which require a
128 general private key without reference to any particular algorithm.
129
130 The structure returned by EVP_PKEY_new() is empty. To add a private or public
131 key to this empty structure use the appropriate functions described in
132 L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA(3)>, L<EVP_PKEY_set1_DH(3)> or
133 L<EVP_PKEY_set1_EC_KEY(3)>.
134
135 =head1 RETURN VALUES
136
137 EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
138 EVP_PKEY_new_CMAC_key() and EVP_PKEY_new_mac_key() return either the newly
139 allocated B<EVP_PKEY> structure or B<NULL> if an error occurred.
140
141 EVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and
142 EVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure.
143
144 =head1 SEE ALSO
145
146 L<EVP_PKEY_set1_RSA(3)>, L<EVP_PKEY_set1_DSA(3)>, L<EVP_PKEY_set1_DH(3)> or
147 L<EVP_PKEY_set1_EC_KEY(3)>
148
149 =head1 HISTORY
150
151 The
152 EVP_PKEY_new() and EVP_PKEY_free() functions exist in all versions of OpenSSL.
153
154 The EVP_PKEY_up_ref() function was added in OpenSSL 1.1.0.
155
156 The
157 EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
158 EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and
159 EVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1.
160
161 The EVP_PKEY_new_raw_private_key_with_libctx and
162 EVP_PKEY_new_raw_public_key_with_libctx functions were added in OpenSSL 3.0.
163
164 =head1 COPYRIGHT
165
166 Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
167
168 Licensed under the Apache License 2.0 (the "License").  You may not use
169 this file except in compliance with the License.  You can obtain a copy
170 in the file LICENSE in the source distribution or at
171 L<https://www.openssl.org/source/license.html>.
172
173 =cut