| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "EVP_PKEY_SET1_ENCODED_PUBLIC_KEY 3SSL" |
| 58 |
.TH EVP_PKEY_SET1_ENCODED_PUBLIC_KEY 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
EVP_PKEY_set1_encoded_public_key, EVP_PKEY_get1_encoded_public_key, |
| 65 |
EVP_PKEY_set1_tls_encodedpoint, EVP_PKEY_get1_tls_encodedpoint |
| 66 |
\&\- functions to set and get public key data within an EVP_PKEY |
| 67 |
.SH SYNOPSIS |
| 68 |
.IX Header "SYNOPSIS" |
| 69 |
.Vb 1 |
| 70 |
\& #include <openssl/evp.h> |
| 71 |
\& |
| 72 |
\& int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey, |
| 73 |
\& const unsigned char *pub, size_t publen); |
| 74 |
\& |
| 75 |
\& size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub); |
| 76 |
.Ve |
| 77 |
.PP |
| 78 |
The following functions have been deprecated since OpenSSL 3.0, and can be |
| 79 |
hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value, |
| 80 |
see \fBopenssl_user_macros\fR\|(7): |
| 81 |
.PP |
| 82 |
.Vb 2 |
| 83 |
\& int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, |
| 84 |
\& const unsigned char *pt, size_t ptlen); |
| 85 |
\& |
| 86 |
\& size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt); |
| 87 |
.Ve |
| 88 |
.SH DESCRIPTION |
| 89 |
.IX Header "DESCRIPTION" |
| 90 |
\&\fBEVP_PKEY_set1_encoded_public_key()\fR can be used to set the public key value |
| 91 |
within an existing EVP_PKEY object, which does not yet have either a public or |
| 92 |
private key assigned. |
| 93 |
For the built-in OpenSSL algorithms this currently only works for those that |
| 94 |
support key exchange or key encapsulation. |
| 95 |
Parameters are not set as part of this operation, so typically an application |
| 96 |
will create an EVP_PKEY first, set the parameters on it, and then call this |
| 97 |
function. |
| 98 |
For example setting the parameters might be done using |
| 99 |
\&\fBEVP_PKEY_copy_parameters\fR\|(3). |
| 100 |
.PP |
| 101 |
The format for the encoded public key will depend on the algorithm in use. For |
| 102 |
DH it should be encoded as a positive integer in big-endian form. For EC is |
| 103 |
should be a point conforming to Sec. 2.3.4 of the SECG SEC 1 ("Elliptic |
| 104 |
Curve Cryptography") standard. For \fBX25519\fR and \fBX448\fR it should be encoded |
| 105 |
in the format defined by RFC7748. |
| 106 |
For \fBML\-KEM\-512\fR, \fBML\-KEM\-768\fR and \fBML\-KEM\-1024\fR, this is the public key |
| 107 |
format defined in \fBFIPS 203\fR (the 12\-bit per-coefficient encoded public \fIt\fR |
| 108 |
vector and 32\-byte matrix seed \fIrho\fR). |
| 109 |
.PP |
| 110 |
The key to be updated is supplied in \fBpkey\fR. The buffer containing the encoded |
| 111 |
key is pointed to be \fBpub\fR. The length of the buffer is supplied in \fBpublen\fR. |
| 112 |
.PP |
| 113 |
\&\fBEVP_PKEY_get1_encoded_public_key()\fR does the equivalent operation except that |
| 114 |
the encoded public key is returned to the application. The key containing the |
| 115 |
public key data is supplied in \fBpkey\fR. A buffer containing the encoded key will |
| 116 |
be allocated and stored in \fB*ppub\fR. The length of the encoded public key is |
| 117 |
returned by the function. The application is responsible for freeing the |
| 118 |
allocated buffer. |
| 119 |
.PP |
| 120 |
The macro \fBEVP_PKEY_set1_tls_encodedpoint()\fR is deprecated and simply calls |
| 121 |
\&\fBEVP_PKEY_set1_encoded_public_key()\fR with all the same arguments. New applications |
| 122 |
should use \fBEVP_PKEY_set1_encoded_public_key()\fR instead. |
| 123 |
.PP |
| 124 |
The macro \fBEVP_PKEY_get1_tls_encodedpoint()\fR is deprecated and simply calls |
| 125 |
\&\fBEVP_PKEY_get1_encoded_public_key()\fR with all the same arguments. New applications |
| 126 |
should use \fBEVP_PKEY_get1_encoded_public_key()\fR instead. |
| 127 |
.SH "RETURN VALUES" |
| 128 |
.IX Header "RETURN VALUES" |
| 129 |
\&\fBEVP_PKEY_set1_encoded_public_key()\fR returns 1 for success and 0 or a negative |
| 130 |
value for failure. |
| 131 |
.PP |
| 132 |
\&\fBEVP_PKEY_get1_encoded_public_key()\fR returns the length of the encoded key or 0 for failure. |
| 133 |
.SH EXAMPLES |
| 134 |
.IX Header "EXAMPLES" |
| 135 |
See \fBEVP_PKEY_derive_init\fR\|(3) and \fBEVP_PKEY_derive\fR\|(3) for information about |
| 136 |
performing a key exchange operation. |
| 137 |
.SS "Set up a peer's EVP_PKEY ready for a key exchange operation" |
| 138 |
.IX Subsection "Set up a peer's EVP_PKEY ready for a key exchange operation" |
| 139 |
.Vb 1 |
| 140 |
\& #include <openssl/evp.h> |
| 141 |
\& |
| 142 |
\& int exchange(EVP_PKEY *ourkey, unsigned char *peer_pub, size_t peer_pub_len) |
| 143 |
\& { |
| 144 |
\& EVP_PKEY *peerkey = EVP_PKEY_new(); |
| 145 |
\& |
| 146 |
\& if (peerkey == NULL || EVP_PKEY_copy_parameters(peerkey, ourkey) <= 0) |
| 147 |
\& return 0; |
| 148 |
\& |
| 149 |
\& if (EVP_PKEY_set1_encoded_public_key(peerkey, peer_pub, |
| 150 |
\& peer_pub_len) <= 0) |
| 151 |
\& return 0; |
| 152 |
\& |
| 153 |
\& /* Do the key exchange here */ |
| 154 |
\& |
| 155 |
\& EVP_PKEY_free(peerkey); |
| 156 |
\& |
| 157 |
\& return 1; |
| 158 |
\& } |
| 159 |
.Ve |
| 160 |
.SS "Get an encoded public key to send to a peer" |
| 161 |
.IX Subsection "Get an encoded public key to send to a peer" |
| 162 |
.Vb 1 |
| 163 |
\& #include <openssl/evp.h> |
| 164 |
\& |
| 165 |
\& int get_encoded_pub_key(EVP_PKEY *ourkey) |
| 166 |
\& { |
| 167 |
\& unsigned char *pubkey; |
| 168 |
\& size_t pubkey_len; |
| 169 |
\& |
| 170 |
\& pubkey_len = EVP_PKEY_get1_encoded_public_key(ourkey, &pubkey); |
| 171 |
\& if (pubkey_len == 0) |
| 172 |
\& return 0; |
| 173 |
\& |
| 174 |
\& /* |
| 175 |
\& * Send the encoded public key stored in the buffer at "pubkey" and of |
| 176 |
\& * length pubkey_len, to the peer. |
| 177 |
\& */ |
| 178 |
\& |
| 179 |
\& OPENSSL_free(pubkey); |
| 180 |
\& return 1; |
| 181 |
\& } |
| 182 |
.Ve |
| 183 |
.SH "SEE ALSO" |
| 184 |
.IX Header "SEE ALSO" |
| 185 |
\&\fBEVP_PKEY_new\fR\|(3), |
| 186 |
\&\fBEVP_PKEY_copy_parameters\fR\|(3), |
| 187 |
\&\fBEVP_PKEY_derive_init\fR\|(3), |
| 188 |
\&\fBEVP_PKEY_derive\fR\|(3), |
| 189 |
\&\fBEVP_PKEY\-DH\fR\|(7), |
| 190 |
\&\fBEVP_PKEY\-EC\fR\|(7), |
| 191 |
\&\fBEVP_PKEY\-X25519\fR\|(7), |
| 192 |
\&\fBEVP_PKEY\-X448\fR\|(7), |
| 193 |
\&\fBEVP_PKEY\-ML\-KEM\-512\fR\|(7), |
| 194 |
\&\fBEVP_PKEY\-ML\-KEM\-768\fR\|(7), |
| 195 |
\&\fBEVP_PKEY\-ML\-KEM\-1024\fR\|(7). |
| 196 |
.SH HISTORY |
| 197 |
.IX Header "HISTORY" |
| 198 |
\&\fBEVP_PKEY_set1_encoded_public_key()\fR and \fBEVP_PKEY_get1_encoded_public_key()\fR were |
| 199 |
added in OpenSSL 3.0. |
| 200 |
.PP |
| 201 |
\&\fBEVP_PKEY_set1_tls_encodedpoint()\fR and \fBEVP_PKEY_get1_tls_encodedpoint()\fR were |
| 202 |
deprecated in OpenSSL 3.0. |
| 203 |
.PP |
| 204 |
Support for \fBML-KEM\fR was added in OpenSSL 3.5. |
| 205 |
.SH COPYRIGHT |
| 206 |
.IX Header "COPYRIGHT" |
| 207 |
Copyright 2020\-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 208 |
.PP |
| 209 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 210 |
this file except in compliance with the License. You can obtain a copy |
| 211 |
in the file LICENSE in the source distribution or at |
| 212 |
<https://www.openssl.org/source/license.html>. |