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 number of bytes written is populated in *len.
72       If the buffer priv is NULL then *len is populated with the number of
73       bytes required to hold the key. The calling application is responsible
74       for ensuring that the buffer is large enough to receive the private key
75       data. This function only works for algorithms that support raw private
76       keys. Currently this is: EVP_PKEY_HMAC, EVP_PKEY_POLY1305,
77       EVP_PKEY_SIPHASH, EVP_PKEY_X25519, EVP_PKEY_ED25519, EVP_PKEY_X448 or
78       EVP_PKEY_ED448.
79
80       EVP_PKEY_get_raw_public_key() fills the buffer provided by pub with raw
81       public key data. The number of bytes written is populated in *len. If
82       the buffer pub is NULL then *len is populated with the number of bytes
83       required to hold the key. The calling application is responsible for
84       ensuring that the buffer is large enough to receive the public key
85       data. This function only works for algorithms that support raw public
86       keys. Currently this is: EVP_PKEY_X25519, EVP_PKEY_ED25519,
87       EVP_PKEY_X448 or EVP_PKEY_ED448.
88

NOTES

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

RETURN VALUES

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

SEE ALSO

109       EVP_PKEY_set1_RSA(3), EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH or
110       EVP_PKEY_set1_EC_KEY
111

HISTORY

113       EVP_PKEY_new() and EVP_PKEY_free() exist in all versions of OpenSSL.
114
115       EVP_PKEY_up_ref() was first added to OpenSSL 1.1.0.
116       EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(),
117       EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and
118       EVP_PKEY_get_raw_public_key() were first added to OpenSSL 1.1.1.
119
121       Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
122
123       Licensed under the OpenSSL license (the "License").  You may not use
124       this file except in compliance with the License.  You can obtain a copy
125       in the file LICENSE in the source distribution or at
126       <https://www.openssl.org/source/license.html>.
127
128
129
1301.1.1                             2018-09-11                   EVP_PKEY_NEW(3)
Impressum