| 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 "X509_PUBKEY_NEW 3SSL" |
| 58 |
.TH X509_PUBKEY_NEW 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 |
X509_PUBKEY_new_ex, X509_PUBKEY_new, X509_PUBKEY_free, X509_PUBKEY_dup, |
| 65 |
X509_PUBKEY_set, X509_PUBKEY_get0, X509_PUBKEY_get, |
| 66 |
d2i_PUBKEY_ex, d2i_PUBKEY, i2d_PUBKEY, d2i_PUBKEY_ex_bio, d2i_PUBKEY_bio, |
| 67 |
d2i_PUBKEY_ex_fp, d2i_PUBKEY_fp, i2d_PUBKEY_fp, i2d_PUBKEY_bio, |
| 68 |
X509_PUBKEY_set0_public_key, X509_PUBKEY_set0_param, X509_PUBKEY_get0_param, |
| 69 |
X509_PUBKEY_eq \- SubjectPublicKeyInfo public key functions |
| 70 |
.SH SYNOPSIS |
| 71 |
.IX Header "SYNOPSIS" |
| 72 |
.Vb 1 |
| 73 |
\& #include <openssl/x509.h> |
| 74 |
\& |
| 75 |
\& X509_PUBKEY *X509_PUBKEY_new_ex(OSSL_LIB_CTX *libctx, const char *propq); |
| 76 |
\& X509_PUBKEY *X509_PUBKEY_new(void); |
| 77 |
\& void X509_PUBKEY_free(X509_PUBKEY *a); |
| 78 |
\& X509_PUBKEY *X509_PUBKEY_dup(const X509_PUBKEY *a); |
| 79 |
\& |
| 80 |
\& int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); |
| 81 |
\& EVP_PKEY *X509_PUBKEY_get0(const X509_PUBKEY *key); |
| 82 |
\& EVP_PKEY *X509_PUBKEY_get(const X509_PUBKEY *key); |
| 83 |
\& |
| 84 |
\& EVP_PKEY *d2i_PUBKEY_ex(EVP_PKEY **a, const unsigned char **pp, long length, |
| 85 |
\& OSSL_LIB_CTX *libctx, const char *propq); |
| 86 |
\& EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length); |
| 87 |
\& int i2d_PUBKEY(const EVP_PKEY *a, unsigned char **pp); |
| 88 |
\& |
| 89 |
\& EVP_PKEY *d2i_PUBKEY_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
| 90 |
\& const char *propq); |
| 91 |
\& EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); |
| 92 |
\& |
| 93 |
\& EVP_PKEY *d2i_PUBKEY_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx, |
| 94 |
\& const char *propq); |
| 95 |
\& EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); |
| 96 |
\& |
| 97 |
\& int i2d_PUBKEY_fp(const FILE *fp, EVP_PKEY *pkey); |
| 98 |
\& int i2d_PUBKEY_bio(BIO *bp, const EVP_PKEY *pkey); |
| 99 |
\& |
| 100 |
\& void X509_PUBKEY_set0_public_key(X509_PUBKEY *pub, |
| 101 |
\& unsigned char *penc, int penclen); |
| 102 |
\& int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, |
| 103 |
\& int ptype, void *pval, |
| 104 |
\& unsigned char *penc, int penclen); |
| 105 |
\& int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, |
| 106 |
\& const unsigned char **pk, int *ppklen, |
| 107 |
\& X509_ALGOR **pa, const X509_PUBKEY *pub); |
| 108 |
\& int X509_PUBKEY_eq(X509_PUBKEY *a, X509_PUBKEY *b); |
| 109 |
.Ve |
| 110 |
.SH DESCRIPTION |
| 111 |
.IX Header "DESCRIPTION" |
| 112 |
The \fBX509_PUBKEY\fR structure represents the ASN.1 \fBSubjectPublicKeyInfo\fR |
| 113 |
structure defined in RFC5280 and used in certificates and certificate requests. |
| 114 |
.PP |
| 115 |
\&\fBX509_PUBKEY_new_ex()\fR allocates and initializes an \fBX509_PUBKEY\fR structure |
| 116 |
associated with the given \fBOSSL_LIB_CTX\fR in the \fIlibctx\fR parameter. Any |
| 117 |
algorithm fetches associated with using the \fBX509_PUBKEY\fR object will use |
| 118 |
the property query string \fIpropq\fR. See "ALGORITHM FETCHING" in \fBcrypto\fR\|(7) for |
| 119 |
further information about algorithm fetching. |
| 120 |
.PP |
| 121 |
\&\fBX509_PUBKEY_new()\fR is the same as \fBX509_PUBKEY_new_ex()\fR except that the default |
| 122 |
(NULL) \fBOSSL_LIB_CTX\fR and a NULL property query string are used. |
| 123 |
.PP |
| 124 |
\&\fBX509_PUBKEY_dup()\fR creates a duplicate copy of the \fBX509_PUBKEY\fR object |
| 125 |
specified by \fIa\fR. |
| 126 |
.PP |
| 127 |
\&\fBX509_PUBKEY_free()\fR frees up \fBX509_PUBKEY\fR structure \fIa\fR. If \fIa\fR is NULL |
| 128 |
nothing is done. |
| 129 |
.PP |
| 130 |
\&\fBX509_PUBKEY_set()\fR sets the public key in \fI*x\fR to the public key contained |
| 131 |
in the \fBEVP_PKEY\fR structure \fIpkey\fR. If \fI*x\fR is not NULL any existing |
| 132 |
public key structure will be freed. |
| 133 |
.PP |
| 134 |
\&\fBX509_PUBKEY_get0()\fR returns the public key contained in \fIkey\fR. The returned |
| 135 |
value is an internal pointer which \fBMUST NOT\fR be freed after use. |
| 136 |
.PP |
| 137 |
\&\fBX509_PUBKEY_get()\fR is similar to \fBX509_PUBKEY_get0()\fR except the reference |
| 138 |
count on the returned key is incremented so it \fBMUST\fR be freed using |
| 139 |
\&\fBEVP_PKEY_free()\fR after use. |
| 140 |
.PP |
| 141 |
\&\fBd2i_PUBKEY_ex()\fR decodes an \fBEVP_PKEY\fR structure using \fBSubjectPublicKeyInfo\fR |
| 142 |
format. Some public key decoding implementations may use cryptographic |
| 143 |
algorithms. In this case the supplied library context \fIlibctx\fR and property |
| 144 |
query string \fIpropq\fR are used. |
| 145 |
\&\fBd2i_PUBKEY()\fR does the same as \fBd2i_PUBKEY_ex()\fR except that the default |
| 146 |
library context and property query string are used. |
| 147 |
.PP |
| 148 |
\&\fBi2d_PUBKEY()\fR encodes an \fBEVP_PKEY\fR structure using \fBSubjectPublicKeyInfo\fR |
| 149 |
format. |
| 150 |
.PP |
| 151 |
\&\fBd2i_PUBKEY_bio()\fR, \fBd2i_PUBKEY_fp()\fR, \fBi2d_PUBKEY_bio()\fR and \fBi2d_PUBKEY_fp()\fR are |
| 152 |
similar to \fBd2i_PUBKEY()\fR and \fBi2d_PUBKEY()\fR except they decode or encode using a |
| 153 |
\&\fBBIO\fR or \fBFILE\fR pointer. |
| 154 |
.PP |
| 155 |
\&\fBd2i_PUBKEY_ex_bio()\fR and \fBd2i_PUBKEY_ex_fp()\fR are similar to \fBd2i_PUBKEY_ex()\fR except |
| 156 |
they decode using a \fBBIO\fR or \fBFILE\fR pointer. |
| 157 |
.PP |
| 158 |
\&\fBX509_PUBKEY_set0_public_key()\fR sets the public-key encoding of \fIpub\fR |
| 159 |
to the \fIpenclen\fR bytes contained in buffer \fIpenc\fR. |
| 160 |
Any earlier public-key encoding in \fIpub\fR is freed. |
| 161 |
\&\fIpenc\fR may be NULL to indicate that there is no actual public key data. |
| 162 |
Ownership of the \fIpenc\fR argument is passed to \fIpub\fR. |
| 163 |
.PP |
| 164 |
\&\fBX509_PUBKEY_set0_param()\fR sets the public-key parameters of \fIpub\fR. |
| 165 |
The OID associated with the algorithm is set to \fIaobj\fR. The type of the |
| 166 |
algorithm parameters is set to \fItype\fR using the structure \fIpval\fR. |
| 167 |
If \fIpenc\fR is not NULL the encoding of the public key itself is set |
| 168 |
to the \fIpenclen\fR bytes contained in buffer \fIpenc\fR and |
| 169 |
any earlier public-key encoding in \fIpub\fR is freed. |
| 170 |
On success ownership of all the supplied arguments is passed to \fIpub\fR |
| 171 |
so they must not be freed after the call. |
| 172 |
.PP |
| 173 |
\&\fBX509_PUBKEY_get0_param()\fR retrieves the public key parameters from \fIpub\fR, |
| 174 |
\&\fI*ppkalg\fR is set to the associated OID and the encoding consists of |
| 175 |
\&\fI*ppklen\fR bytes at \fI*pk\fR, \fI*pa\fR is set to the associated |
| 176 |
AlgorithmIdentifier for the public key. If the value of any of these |
| 177 |
parameters is not required it can be set to NULL. All of the |
| 178 |
retrieved pointers are internal and must not be freed after the |
| 179 |
call. |
| 180 |
.PP |
| 181 |
\&\fBX509_PUBKEY_eq()\fR compares two \fBX509_PUBKEY\fR values. |
| 182 |
.SH NOTES |
| 183 |
.IX Header "NOTES" |
| 184 |
The \fBX509_PUBKEY\fR functions can be used to encode and decode public keys |
| 185 |
in a standard format. |
| 186 |
.PP |
| 187 |
In many cases applications will not call the \fBX509_PUBKEY\fR functions |
| 188 |
directly: they will instead call wrapper functions such as \fBX509_get0_pubkey()\fR. |
| 189 |
.SH "RETURN VALUES" |
| 190 |
.IX Header "RETURN VALUES" |
| 191 |
If the allocation fails, \fBX509_PUBKEY_new()\fR and \fBX509_PUBKEY_dup()\fR return |
| 192 |
NULL and set an error code that can be obtained by \fBERR_get_error\fR\|(3). |
| 193 |
Otherwise they return a pointer to the newly allocated structure. |
| 194 |
.PP |
| 195 |
\&\fBX509_PUBKEY_free()\fR does not return a value. |
| 196 |
.PP |
| 197 |
\&\fBX509_PUBKEY_get0()\fR, \fBX509_PUBKEY_get()\fR, \fBd2i_PUBKEY_ex()\fR, \fBd2i_PUBKEY()\fR, |
| 198 |
\&\fBd2i_PUBKEY_ex_bio()\fR, \fBd2i_PUBKEY_bio()\fR, \fBd2i_PUBKEY_ex_fp()\fR and \fBd2i_PUBKEY_fp()\fR |
| 199 |
return a pointer to an \fBEVP_PKEY\fR structure or NULL if an error occurs. |
| 200 |
.PP |
| 201 |
\&\fBi2d_PUBKEY()\fR returns the number of bytes successfully encoded or a |
| 202 |
negative value if an error occurs. |
| 203 |
.PP |
| 204 |
\&\fBi2d_PUBKEY_fp()\fR and \fBi2d_PUBKEY_bio()\fR return 1 if successfully |
| 205 |
encoded or 0 if an error occurs. |
| 206 |
.PP |
| 207 |
\&\fBX509_PUBKEY_set0_public_key()\fR does not return a value. |
| 208 |
.PP |
| 209 |
\&\fBX509_PUBKEY_set()\fR, \fBX509_PUBKEY_set0_param()\fR and \fBX509_PUBKEY_get0_param()\fR |
| 210 |
return 1 for success and 0 if an error occurred. |
| 211 |
.PP |
| 212 |
\&\fBX509_PUBKEY_eq()\fR returns 1 for equal, 0 for different, and < 0 on error. |
| 213 |
.SH "SEE ALSO" |
| 214 |
.IX Header "SEE ALSO" |
| 215 |
\&\fBd2i_X509\fR\|(3), |
| 216 |
\&\fBERR_get_error\fR\|(3), |
| 217 |
\&\fBX509_get_pubkey\fR\|(3), |
| 218 |
.SH HISTORY |
| 219 |
.IX Header "HISTORY" |
| 220 |
The \fBX509_PUBKEY_new_ex()\fR and \fBX509_PUBKEY_eq()\fR functions were added in OpenSSL |
| 221 |
3.0. |
| 222 |
.PP |
| 223 |
The \fBX509_PUBKEY_set0_public_key()\fR, \fBd2i_PUBKEY_ex_bio()\fR and \fBd2i_PUBKEY_ex_fp()\fR |
| 224 |
functions were added in OpenSSL 3.2. |
| 225 |
.SH COPYRIGHT |
| 226 |
.IX Header "COPYRIGHT" |
| 227 |
Copyright 2016\-2022 The OpenSSL Project Authors. All Rights Reserved. |
| 228 |
.PP |
| 229 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 230 |
this file except in compliance with the License. You can obtain a copy |
| 231 |
in the file LICENSE in the source distribution or at |
| 232 |
<https://www.openssl.org/source/license.html>. |