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.
65
66       EVP_PKEY_new_mac_key() works in the same way as
67       EVP_PKEY_new_raw_private_key().  New applications should use
68       EVP_PKEY_new_raw_private_key() instead.
69
70       EVP_PKEY_get_raw_private_key() fills the buffer provided by priv with
71       raw private key data. The size of the priv buffer should be in *len on
72       entry to the function, and on exit *len is updated with the number of
73       bytes actually written. If the buffer priv is NULL then *len is
74       populated with the number of bytes required to hold the key. The
75       calling application is responsible for ensuring that the buffer is
76       large enough to receive the private key data. This function only works
77       for algorithms that support raw private keys.  Currently this is:
78       EVP_PKEY_HMAC, EVP_PKEY_POLY1305, EVP_PKEY_SIPHASH, EVP_PKEY_X25519,
79       EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
80
81       EVP_PKEY_get_raw_public_key() fills the buffer provided by pub with raw
82       public key data. The size of the pub buffer should be in *len on entry
83       to the function, and on exit *len is updated with the number of bytes
84       actually written. If the buffer pub is NULL then *len is populated with
85       the number of bytes required to hold the key. The calling application
86       is responsible for ensuring that the buffer is large enough to receive
87       the public key data. This function only works for algorithms that
88       support raw public  keys.  Currently this is: EVP_PKEY_X25519,
89       EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
90

NOTES

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

RETURN VALUES

102       EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(),
103       EVP_PKEY_new_raw_public_key(), EVP_PKEY_new_CMAC_key() and
104       EVP_PKEY_new_mac_key() return either the newly allocated EVP_PKEY
105       structure or NULL if an error occurred.
106
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.
109

SEE ALSO

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

HISTORY

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