1*4724848cSchristos=pod 2*4724848cSchristos 3*4724848cSchristos=head1 NAME 4*4724848cSchristos 5*4724848cSchristosX509_PUBKEY_new, X509_PUBKEY_free, X509_PUBKEY_set, X509_PUBKEY_get0, 6*4724848cSchristosX509_PUBKEY_get, d2i_PUBKEY, i2d_PUBKEY, d2i_PUBKEY_bio, d2i_PUBKEY_fp, 7*4724848cSchristosi2d_PUBKEY_fp, i2d_PUBKEY_bio, X509_PUBKEY_set0_param, 8*4724848cSchristosX509_PUBKEY_get0_param - SubjectPublicKeyInfo public key functions 9*4724848cSchristos 10*4724848cSchristos=head1 SYNOPSIS 11*4724848cSchristos 12*4724848cSchristos #include <openssl/x509.h> 13*4724848cSchristos 14*4724848cSchristos X509_PUBKEY *X509_PUBKEY_new(void); 15*4724848cSchristos void X509_PUBKEY_free(X509_PUBKEY *a); 16*4724848cSchristos 17*4724848cSchristos int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); 18*4724848cSchristos EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key); 19*4724848cSchristos EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key); 20*4724848cSchristos 21*4724848cSchristos EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length); 22*4724848cSchristos int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp); 23*4724848cSchristos 24*4724848cSchristos EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); 25*4724848cSchristos EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); 26*4724848cSchristos 27*4724848cSchristos int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); 28*4724848cSchristos int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); 29*4724848cSchristos 30*4724848cSchristos int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, 31*4724848cSchristos int ptype, void *pval, 32*4724848cSchristos unsigned char *penc, int penclen); 33*4724848cSchristos int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, 34*4724848cSchristos const unsigned char **pk, int *ppklen, 35*4724848cSchristos X509_ALGOR **pa, X509_PUBKEY *pub); 36*4724848cSchristos 37*4724848cSchristos=head1 DESCRIPTION 38*4724848cSchristos 39*4724848cSchristosThe B<X509_PUBKEY> structure represents the ASN.1 B<SubjectPublicKeyInfo> 40*4724848cSchristosstructure defined in RFC5280 and used in certificates and certificate requests. 41*4724848cSchristos 42*4724848cSchristosX509_PUBKEY_new() allocates and initializes an B<X509_PUBKEY> structure. 43*4724848cSchristos 44*4724848cSchristosX509_PUBKEY_free() frees up B<X509_PUBKEY> structure B<a>. If B<a> is NULL 45*4724848cSchristosnothing is done. 46*4724848cSchristos 47*4724848cSchristosX509_PUBKEY_set() sets the public key in B<*x> to the public key contained 48*4724848cSchristosin the B<EVP_PKEY> structure B<pkey>. If B<*x> is not NULL any existing 49*4724848cSchristospublic key structure will be freed. 50*4724848cSchristos 51*4724848cSchristosX509_PUBKEY_get0() returns the public key contained in B<key>. The returned 52*4724848cSchristosvalue is an internal pointer which B<MUST NOT> be freed after use. 53*4724848cSchristos 54*4724848cSchristosX509_PUBKEY_get() is similar to X509_PUBKEY_get0() except the reference 55*4724848cSchristoscount on the returned key is incremented so it B<MUST> be freed using 56*4724848cSchristosEVP_PKEY_free() after use. 57*4724848cSchristos 58*4724848cSchristosd2i_PUBKEY() and i2d_PUBKEY() decode and encode an B<EVP_PKEY> structure 59*4724848cSchristosusing B<SubjectPublicKeyInfo> format. They otherwise follow the conventions of 60*4724848cSchristosother ASN.1 functions such as d2i_X509(). 61*4724848cSchristos 62*4724848cSchristosd2i_PUBKEY_bio(), d2i_PUBKEY_fp(), i2d_PUBKEY_bio() and i2d_PUBKEY_fp() are 63*4724848cSchristossimilar to d2i_PUBKEY() and i2d_PUBKEY() except they decode or encode using a 64*4724848cSchristosB<BIO> or B<FILE> pointer. 65*4724848cSchristos 66*4724848cSchristosX509_PUBKEY_set0_param() sets the public key parameters of B<pub>. The 67*4724848cSchristosOID associated with the algorithm is set to B<aobj>. The type of the 68*4724848cSchristosalgorithm parameters is set to B<type> using the structure B<pval>. 69*4724848cSchristosThe encoding of the public key itself is set to the B<penclen> 70*4724848cSchristosbytes contained in buffer B<penc>. On success ownership of all the supplied 71*4724848cSchristosparameters is passed to B<pub> so they must not be freed after the 72*4724848cSchristoscall. 73*4724848cSchristos 74*4724848cSchristosX509_PUBKEY_get0_param() retrieves the public key parameters from B<pub>, 75*4724848cSchristosB<*ppkalg> is set to the associated OID and the encoding consists of 76*4724848cSchristosB<*ppklen> bytes at B<*pk>, B<*pa> is set to the associated 77*4724848cSchristosAlgorithmIdentifier for the public key. If the value of any of these 78*4724848cSchristosparameters is not required it can be set to B<NULL>. All of the 79*4724848cSchristosretrieved pointers are internal and must not be freed after the 80*4724848cSchristoscall. 81*4724848cSchristos 82*4724848cSchristos=head1 NOTES 83*4724848cSchristos 84*4724848cSchristosThe B<X509_PUBKEY> functions can be used to encode and decode public keys 85*4724848cSchristosin a standard format. 86*4724848cSchristos 87*4724848cSchristosIn many cases applications will not call the B<X509_PUBKEY> functions 88*4724848cSchristosdirectly: they will instead call wrapper functions such as X509_get0_pubkey(). 89*4724848cSchristos 90*4724848cSchristos=head1 RETURN VALUES 91*4724848cSchristos 92*4724848cSchristosIf the allocation fails, X509_PUBKEY_new() returns B<NULL> and sets an error 93*4724848cSchristoscode that can be obtained by L<ERR_get_error(3)>. 94*4724848cSchristos 95*4724848cSchristosOtherwise it returns a pointer to the newly allocated structure. 96*4724848cSchristos 97*4724848cSchristosX509_PUBKEY_free() does not return a value. 98*4724848cSchristos 99*4724848cSchristosX509_PUBKEY_get0() and X509_PUBKEY_get() return a pointer to an B<EVP_PKEY> 100*4724848cSchristosstructure or B<NULL> if an error occurs. 101*4724848cSchristos 102*4724848cSchristosX509_PUBKEY_set(), X509_PUBKEY_set0_param() and X509_PUBKEY_get0_param() 103*4724848cSchristosreturn 1 for success and 0 if an error occurred. 104*4724848cSchristos 105*4724848cSchristos=head1 SEE ALSO 106*4724848cSchristos 107*4724848cSchristosL<d2i_X509(3)>, 108*4724848cSchristosL<ERR_get_error(3)>, 109*4724848cSchristosL<X509_get_pubkey(3)>, 110*4724848cSchristos 111*4724848cSchristos=head1 COPYRIGHT 112*4724848cSchristos 113*4724848cSchristosCopyright 2016 The OpenSSL Project Authors. All Rights Reserved. 114*4724848cSchristos 115*4724848cSchristosLicensed under the OpenSSL license (the "License"). You may not use 116*4724848cSchristosthis file except in compliance with the License. You can obtain a copy 117*4724848cSchristosin the file LICENSE in the source distribution or at 118*4724848cSchristosL<https://www.openssl.org/source/license.html>. 119*4724848cSchristos 120*4724848cSchristos=cut 121