1EVP_PKEY_SET1_ENCODED_PUBLIC_KEY(3ossOlp)enESVSPL_PKEY_SET1_ENCODED_PUBLIC_KEY(3ossl)
2
3
4
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
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
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
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() return 1
66
68 See EVP_PKEY_derive_init(3) and EVP_PKEY_derive(3) for information
69 about performing a key exchange operation.
70
71 Set up a peer's EVP_PKEY ready for a key exchange operation
72 #include <openssl/evp.h>
73
74 int exchange(EVP_PKEY *ourkey, unsigned char *peer_pub, size_t peer_pub_len)
75 {
76 EVP_PKEY *peerkey = EVP_PKEY_new();
77
78 if (peerkey == NULL || EVP_PKEY_copy_parameters(peerkey, ourkey) <= 0)
79 return 0;
80
81 if (EVP_PKEY_set1_encoded_public_key(peerkey, peer_pub,
82 peer_pub_len) <= 0)
83 return 0;
84
85 /* Do the key exchange here */
86
87 EVP_PKEY_free(peerkey);
88
89 return 1;
90 }
91
92 Get an encoded public key to send to a peer
93 #include <openssl/evp.h>
94
95 int get_encoded_pub_key(EVP_PKEY *ourkey)
96 {
97 unsigned char *pubkey;
98 size_t pubkey_len;
99
100 pubkey_len = EVP_PKEY_get1_encoded_public_key(ourkey, &pubkey);
101 if (pubkey_len == 0)
102 return 0;
103
104 /*
105 * Send the encoded public key stored in the buffer at "pubkey" and of
106 * length pubkey_len, to the peer.
107 */
108
109 OPENSSL_free(pubkey);
110 return 1;
111 }
112
114 EVP_PKEY_new(3), EVP_PKEY_copy_parameters(3), EVP_PKEY_derive_init(3),
115 EVP_PKEY_derive(3), EVP_PKEY-DH(7), EVP_PKEY-EC(7), EVP_PKEY-X25519(7),
116 EVP_PKEY-X448(7)
117
119 EVP_PKEY_set1_encoded_public_key() and
120 EVP_PKEY_get1_encoded_public_key() were added in OpenSSL 3.0.
121
122 EVP_PKEY_set1_tls_encodedpoint() and EVP_PKEY_get1_tls_encodedpoint()
123 were deprecated in OpenSSL 3.0.
124
126 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
127
128 Licensed under the Apache License 2.0 (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
1353.0.5 2022-0E7V-P0_5PKEY_SET1_ENCODED_PUBLIC_KEY(3ossl)