1EVP_PKEY_SET1_ENCODED_PUBLIC_KEY(3ossOlp)enESVSPL_PKEY_SET1_ENCODED_PUBLIC_KEY(3ossl)
2
3
4

NAME

6       EVP_PKEY_set1_encoded_public_key, EVP_PKEY_get1_encoded_public_key,
7       EVP_PKEY_set1_tls_encodedpoint, EVP_PKEY_get1_tls_encodedpoint -
8       functions to set and get public key data within an EVP_PKEY
9

SYNOPSIS

11        #include <openssl/evp.h>
12
13        int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey,
14                                             const unsigned char *pub, size_t publen);
15
16        size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub);
17
18       The following functions have been deprecated since OpenSSL 3.0, and can
19       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
20       version value, see openssl_user_macros(7):
21
22        int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
23                                           const unsigned char *pt, size_t ptlen);
24
25        size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt);
26

DESCRIPTION

28       EVP_PKEY_set1_encoded_public_key() can be used to set the public key
29       value within an existing EVP_PKEY object. For the built-in OpenSSL
30       algorithms this currently only works for those that support key
31       exchange. Parameters are not set as part of this operation, so
32       typically an application will create an EVP_PKEY first, set the
33       parameters on it, and then call this function.  For example setting the
34       parameters might be done using EVP_PKEY_copy_parameters(3).
35
36       The format for the encoded public key will depend on the algorithm in
37       use. For DH it should be encoded as a positive integer in big-endian
38       form. For EC is should be a point conforming to Sec. 2.3.4 of the SECG
39       SEC 1 ("Elliptic Curve Cryptography") standard. For X25519 and X448 it
40       should be encoded in a format as defined by RFC7748.
41
42       The key to be updated is supplied in pkey. The buffer containing the
43       encoded key is pointed to be pub. The length of the buffer is supplied
44       in publen.
45
46       EVP_PKEY_get1_encoded_public_key() does the equivalent operation except
47       that the encoded public key is returned to the application. The key
48       containing the public key data is supplied in pkey. A buffer containing
49       the encoded key will be allocated and stored in *ppub. The length of
50       the encoded public key is returned by the function. The application is
51       responsible for freeing the allocated buffer.
52
53       The macro EVP_PKEY_set1_tls_encodedpoint() is deprecated and simply
54       calls EVP_PKEY_set1_encoded_public_key() with all the same arguments.
55       New applications should use EVP_PKEY_set1_encoded_public_key() instead.
56
57       The macro EVP_PKEY_get1_tls_encodedpoint() is deprecated and simply
58       calls EVP_PKEY_get1_encoded_public_key() with all the same arguments.
59       New applications should use EVP_PKEY_get1_encoded_public_key() instead.
60

RETURN VALUES

62       EVP_PKEY_set1_encoded_public_key() returns 1 for success and 0 or a
63       negative value for failure.
64
65       EVP_PKEY_get1_encoded_public_key() returns the length of the encoded
66       key or 0 for failure.
67

EXAMPLES

69       See EVP_PKEY_derive_init(3) and EVP_PKEY_derive(3) for information
70       about performing a key exchange operation.
71
72   Set up a peer's EVP_PKEY ready for a key exchange operation
73        #include <openssl/evp.h>
74
75        int exchange(EVP_PKEY *ourkey, unsigned char *peer_pub, size_t peer_pub_len)
76        {
77            EVP_PKEY *peerkey = EVP_PKEY_new();
78
79            if (peerkey == NULL || EVP_PKEY_copy_parameters(peerkey, ourkey) <= 0)
80                return 0;
81
82            if (EVP_PKEY_set1_encoded_public_key(peerkey, peer_pub,
83                                                 peer_pub_len) <= 0)
84                return 0;
85
86            /* Do the key exchange here */
87
88            EVP_PKEY_free(peerkey);
89
90            return 1;
91        }
92
93   Get an encoded public key to send to a peer
94        #include <openssl/evp.h>
95
96        int get_encoded_pub_key(EVP_PKEY *ourkey)
97        {
98            unsigned char *pubkey;
99            size_t pubkey_len;
100
101           pubkey_len = EVP_PKEY_get1_encoded_public_key(ourkey, &pubkey);
102           if (pubkey_len == 0)
103               return 0;
104
105           /*
106            * Send the encoded public key stored in the buffer at "pubkey" and of
107            * length pubkey_len, to the peer.
108            */
109
110           OPENSSL_free(pubkey);
111           return 1;
112        }
113

SEE ALSO

115       EVP_PKEY_new(3), EVP_PKEY_copy_parameters(3), EVP_PKEY_derive_init(3),
116       EVP_PKEY_derive(3), EVP_PKEY-DH(7), EVP_PKEY-EC(7), EVP_PKEY-X25519(7),
117       EVP_PKEY-X448(7)
118

HISTORY

120       EVP_PKEY_set1_encoded_public_key() and
121       EVP_PKEY_get1_encoded_public_key() were added in OpenSSL 3.0.
122
123       EVP_PKEY_set1_tls_encodedpoint() and EVP_PKEY_get1_tls_encodedpoint()
124       were deprecated in OpenSSL 3.0.
125
127       Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
128
129       Licensed under the Apache License 2.0 (the "License").  You may not use
130       this file except in compliance with the License.  You can obtain a copy
131       in the file LICENSE in the source distribution or at
132       <https://www.openssl.org/source/license.html>.
133
134
135
1363.0.9                             2023-0E7V-P2_7PKEY_SET1_ENCODED_PUBLIC_KEY(3ossl)
Impressum