xref: /openbsd/lib/libcrypto/man/EVP_PKEY_new.3 (revision 5a38ef86)
1.\" $OpenBSD: EVP_PKEY_new.3,v 1.16 2021/10/25 13:48:12 schwarze Exp $
2.\" full merge up to: OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
4.\"
5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>
6.\" and Matt Caswell <matt@openssl.org>.
7.\" Copyright (c) 2002, 2018 The OpenSSL Project.  All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in
18.\"    the documentation and/or other materials provided with the
19.\"    distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\"    software must display the following acknowledgment:
23.\"    "This product includes software developed by the OpenSSL Project
24.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\"    endorse or promote products derived from this software without
28.\"    prior written permission. For written permission, please contact
29.\"    openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\"    nor may "OpenSSL" appear in their names without prior written
33.\"    permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\"    acknowledgment:
37.\"    "This product includes software developed by the OpenSSL Project
38.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: October 25 2021 $
54.Dt EVP_PKEY_NEW 3
55.Os
56.Sh NAME
57.Nm EVP_PKEY_new ,
58.Nm EVP_PKEY_up_ref ,
59.Nm EVP_PKEY_free ,
60.Nm EVP_PKEY_new_CMAC_key ,
61.Nm EVP_PKEY_new_mac_key
62.Nd private key allocation functions
63.Sh SYNOPSIS
64.In openssl/evp.h
65.Ft EVP_PKEY *
66.Fn EVP_PKEY_new void
67.Ft int
68.Fo EVP_PKEY_up_ref
69.Fa "EVP_PKEY *key"
70.Fc
71.Ft void
72.Fo EVP_PKEY_free
73.Fa "EVP_PKEY *key"
74.Fc
75.Ft EVP_PKEY *
76.Fo EVP_PKEY_new_CMAC_key
77.Fa "ENGINE *e"
78.Fa "const unsigned char *priv"
79.Fa "size_t len"
80.Fa "const EVP_CIPHER *cipher"
81.Fc
82.Ft EVP_PKEY *
83.Fo EVP_PKEY_new_mac_key
84.Fa "int type"
85.Fa "ENGINE *e"
86.Fa "const unsigned char *key"
87.Fa "int keylen"
88.Fc
89.Sh DESCRIPTION
90The
91.Vt EVP_PKEY
92structure is used by various OpenSSL functions which require a general
93private key without reference to any particular algorithm.
94.Pp
95The
96.Fn EVP_PKEY_new
97function allocates an empty
98.Vt EVP_PKEY
99structure.
100The reference count is set to 1.
101To add a private or public key to it, use the functions described in
102.Xr EVP_PKEY_set1_RSA 3 .
103.Pp
104.Fn EVP_PKEY_up_ref
105increments the reference count of
106.Fa key
107by 1.
108.Pp
109.Fn EVP_PKEY_free
110decrements the reference count of
111.Fa key
112by 1, and if the reference count reaches zero, frees it up.
113If
114.Fa key
115is a
116.Dv NULL
117pointer, no action occurs.
118.Pp
119.Fn EVP_PKEY_new_CMAC_key
120allocates a new
121.Vt EVP_PKEY
122for the
123.Dv EVP_PKEY_CMAC
124algorithm type.
125If
126.Fa e
127is
128.Pf non- Dv NULL ,
129then the new
130.Vt EVP_PKEY
131is associated with the engine
132.Fa e .
133.Fa priv
134points to the raw private key data
135of length
136.Fa len
137for this
138.Vt EVP_PKEY .
139.Fa cipher
140specifies a cipher algorithm to be used during creation of the CMAC.
141.Fa cipher
142should be a standard encryption only cipher.
143For example, AEAD and XTS ciphers should not be used.
144.Pp
145.Fn EVP_PKEY_new_mac_key
146allocates a new
147.Vt EVP_PKEY .
148If
149.Fa e
150is
151.Pf non- Dv NULL ,
152then the new
153.Vt EVP_PKEY
154structure is associated with the engine
155.Fa e .
156The
157.Fa type
158argument indicates what kind of key this is.
159The value should be a NID for a public key algorithm that supports
160raw private keys, for example
161.Dv EVP_PKEY_HMAC .
162.Fa key
163points to the raw private key data for this
164.Vt EVP_PKEY
165which should be of length
166.Fa keylen .
167The length should be appropriate for the type of the key.
168The public key data will be automatically derived from the given
169private key data (if appropriate for the algorithm type).
170.Sh RETURN VALUES
171.Fn EVP_PKEY_new ,
172.Fn EVP_PKEY_new_CMAC_key ,
173and
174.Fn EVP_PKEY_new_mac_key
175return either the newly allocated
176.Vt EVP_PKEY
177structure or
178.Dv NULL
179if an error occurred.
180.Pp
181.Fn EVP_PKEY_up_ref
182returns 1 for success or 0 for failure.
183.Sh SEE ALSO
184.Xr CMAC_Init 3 ,
185.Xr d2i_PrivateKey 3 ,
186.Xr evp 3 ,
187.Xr EVP_PKCS82PKEY 3 ,
188.Xr EVP_PKEY_add1_attr 3 ,
189.Xr EVP_PKEY_asn1_new 3 ,
190.Xr EVP_PKEY_cmp 3 ,
191.Xr EVP_PKEY_CTX_new 3 ,
192.Xr EVP_PKEY_get_default_digest_nid 3 ,
193.Xr EVP_PKEY_meth_new 3 ,
194.Xr EVP_PKEY_print_private 3 ,
195.Xr EVP_PKEY_set1_RSA 3 ,
196.Xr X509_get_pubkey_parameters 3
197.Sh HISTORY
198.Fn EVP_PKEY_new
199and
200.Fn EVP_PKEY_free
201first appeared in SSLeay 0.6.0 and have been available since
202.Ox 2.4 .
203.Pp
204.Fn EVP_PKEY_new_CMAC_key
205first appeared in OpenSSL 1.1.1 and has been available since
206.Ox 6.9 .
207.Pp
208.Fn EVP_PKEY_new_mac_key
209first appeared in OpenSSL 1.0.0 and has been available since
210.Ox 4.9 .
211.Pp
212.Fn EVP_PKEY_up_ref
213first appeared in OpenSSL 1.1.0 and has been available since
214.Ox 6.3 .
215