1EVP_PKEY_NEW(3)                     OpenSSL                    EVP_PKEY_NEW(3)
2
3
4

NAME

6       EVP_PKEY_new, EVP_PKEY_up_ref, EVP_PKEY_free,
7       EVP_PKEY_new_raw_private_key, EVP_PKEY_new_raw_public_key,
8       EVP_PKEY_new_CMAC_key, EVP_PKEY_new_mac_key,
9       EVP_PKEY_get_raw_private_key, EVP_PKEY_get_raw_public_key -
10       public/private key allocation and raw key handling functions
11

SYNOPSIS

13        #include <openssl/evp.h>
14
15        EVP_PKEY *EVP_PKEY_new(void);
16        int EVP_PKEY_up_ref(EVP_PKEY *key);
17        void EVP_PKEY_free(EVP_PKEY *key);
18
19        EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
20                                               const unsigned char *key, size_t keylen);
21        EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
22                                              const unsigned char *key, size_t keylen);
23        EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
24                                        size_t len, const EVP_CIPHER *cipher);
25        EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
26                                       int keylen);
27
28        int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv,
29                                         size_t *len);
30        int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub,
31                                        size_t *len);
32

DESCRIPTION

34       The EVP_PKEY_new() function allocates an empty EVP_PKEY structure which
35       is used by OpenSSL to store public and private keys. The reference
36       count is set to 1.
37
38       EVP_PKEY_up_ref() increments the reference count of key.
39
40       EVP_PKEY_free() decrements the reference count of key and, if the
41       reference count is zero, frees it up. If key is NULL, nothing is done.
42
43       EVP_PKEY_new_raw_private_key() allocates a new EVP_PKEY. If e is non-
44       NULL then the new EVP_PKEY structure is associated with the engine e.
45       The type argument indicates what kind of key this is. The value should
46       be a NID for a public key algorithm that supports raw private keys,
47       i.e. one of EVP_PKEY_HMAC, EVP_PKEY_POLY1305, EVP_PKEY_SIPHASH,
48       EVP_PKEY_X25519, EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448. key
49       points to the raw private key data for this EVP_PKEY which should be of
50       length keylen.  The length should be appropriate for the type of the
51       key. The public key data will be automatically derived from the given
52       private key data (if appropriate for the algorithm type).
53
54       EVP_PKEY_new_raw_public_key() works in the same way as
55       EVP_PKEY_new_raw_private_key() except that key points to the raw public
56       key data. The EVP_PKEY structure will be initialised without any
57       private key information. Algorithm types that support raw public keys
58       are EVP_PKEY_X25519, EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
59
60       EVP_PKEY_new_CMAC_key() works in the same way as
61       EVP_PKEY_new_raw_private_key() except it is only for the EVP_PKEY_CMAC
62       algorithm type. In addition to the raw private key data, it also takes
63       a cipher algorithm to be used during creation of a CMAC in the cipher
64       argument. The cipher should be a standard encryption only cipher. For
65       example AEAD and XTS ciphers should not be used.
66
67       EVP_PKEY_new_mac_key() works in the same way as
68       EVP_PKEY_new_raw_private_key().  New applications should use
69       EVP_PKEY_new_raw_private_key() instead.
70
71       EVP_PKEY_get_raw_private_key() fills the buffer provided by priv with
72       raw private key data. The size of the priv buffer should be in *len on
73       entry to the function, and on exit *len is updated with the number of
74       bytes actually written. If the buffer priv is NULL then *len is
75       populated with the number of bytes required to hold the key. The
76       calling application is responsible for ensuring that the buffer is
77       large enough to receive the private key data. This function only works
78       for algorithms that support raw private keys.  Currently this is:
79       EVP_PKEY_HMAC, EVP_PKEY_POLY1305, EVP_PKEY_SIPHASH, EVP_PKEY_X25519,
80       EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
81
82       EVP_PKEY_get_raw_public_key() fills the buffer provided by pub with raw
83       public key data. The size of the pub buffer should be in *len on entry
84       to the function, and on exit *len is updated with the number of bytes
85       actually written. If the buffer pub is NULL then *len is populated with
86       the number of bytes required to hold the key. The calling application
87       is responsible for ensuring that the buffer is large enough to receive
88       the public key data. This function only works for algorithms that
89       support raw public  keys.  Currently this is: EVP_PKEY_X25519,
90       EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
91

NOTES

93       The EVP_PKEY structure is used by various OpenSSL functions which
94       require a general private key without reference to any particular
95       algorithm.
96
97       The structure returned by EVP_PKEY_new() is empty. To add a private or
98       public key to this empty structure use the appropriate functions
99       described in EVP_PKEY_set1_RSA(3), EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH
100       or EVP_PKEY_set1_EC_KEY.
101

RETURN VALUES

103       EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(),
104       EVP_PKEY_new_raw_public_key(), EVP_PKEY_new_CMAC_key() and
105       EVP_PKEY_new_mac_key() return either the newly allocated EVP_PKEY
106       structure or NULL if an error occurred.
107
108       EVP_PKEY_up_ref(), EVP_PKEY_get_raw_private_key() and
109       EVP_PKEY_get_raw_public_key() return 1 for success and 0 for failure.
110

SEE ALSO

112       EVP_PKEY_set1_RSA(3), EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH or
113       EVP_PKEY_set1_EC_KEY
114

HISTORY

116       The EVP_PKEY_new() and EVP_PKEY_free() functions exist in all versions
117       of OpenSSL.
118
119       The EVP_PKEY_up_ref() function was added in OpenSSL 1.1.0.
120
121       The EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
122       EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and
123       EVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1.
124
126       Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
127
128       Licensed under the OpenSSL license (the "License").  You may not use
129       this file except in compliance with the License.  You can obtain a copy
130       in the file LICENSE in the source distribution or at
131       <https://www.openssl.org/source/license.html>.
132
133
134
1351.1.1i                            2021-01-26                   EVP_PKEY_NEW(3)
Impressum