1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5*b077aed3SPierre ProncheryX509_PUBKEY_new_ex, X509_PUBKEY_new, X509_PUBKEY_free, X509_PUBKEY_dup, 6*b077aed3SPierre ProncheryX509_PUBKEY_set, X509_PUBKEY_get0, X509_PUBKEY_get, 7*b077aed3SPierre Proncheryd2i_PUBKEY_ex, d2i_PUBKEY, i2d_PUBKEY, d2i_PUBKEY_bio, d2i_PUBKEY_fp, 8*b077aed3SPierre Proncheryi2d_PUBKEY_fp, i2d_PUBKEY_bio, X509_PUBKEY_set0_param, X509_PUBKEY_get0_param, 9*b077aed3SPierre ProncheryX509_PUBKEY_eq - SubjectPublicKeyInfo public key functions 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim=head1 SYNOPSIS 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim #include <openssl/x509.h> 14e71b7053SJung-uk Kim 15*b077aed3SPierre Pronchery X509_PUBKEY *X509_PUBKEY_new_ex(OSSL_LIB_CTX *libctx, const char *propq); 16e71b7053SJung-uk Kim X509_PUBKEY *X509_PUBKEY_new(void); 17e71b7053SJung-uk Kim void X509_PUBKEY_free(X509_PUBKEY *a); 18*b077aed3SPierre Pronchery X509_PUBKEY *X509_PUBKEY_dup(const X509_PUBKEY *a); 19e71b7053SJung-uk Kim 20e71b7053SJung-uk Kim int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); 21*b077aed3SPierre Pronchery EVP_PKEY *X509_PUBKEY_get0(const X509_PUBKEY *key); 22*b077aed3SPierre Pronchery EVP_PKEY *X509_PUBKEY_get(const X509_PUBKEY *key); 23e71b7053SJung-uk Kim 24*b077aed3SPierre Pronchery EVP_PKEY *d2i_PUBKEY_ex(EVP_PKEY **a, const unsigned char **pp, long length, 25*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq); 26e71b7053SJung-uk Kim EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length); 27*b077aed3SPierre Pronchery int i2d_PUBKEY(const EVP_PKEY *a, unsigned char **pp); 28e71b7053SJung-uk Kim 29e71b7053SJung-uk Kim EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); 30e71b7053SJung-uk Kim EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); 31e71b7053SJung-uk Kim 32*b077aed3SPierre Pronchery int i2d_PUBKEY_fp(const FILE *fp, EVP_PKEY *pkey); 33*b077aed3SPierre Pronchery int i2d_PUBKEY_bio(BIO *bp, const EVP_PKEY *pkey); 34e71b7053SJung-uk Kim 35e71b7053SJung-uk Kim int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, 36e71b7053SJung-uk Kim int ptype, void *pval, 37e71b7053SJung-uk Kim unsigned char *penc, int penclen); 38e71b7053SJung-uk Kim int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, 39e71b7053SJung-uk Kim const unsigned char **pk, int *ppklen, 40*b077aed3SPierre Pronchery X509_ALGOR **pa, const X509_PUBKEY *pub); 41*b077aed3SPierre Pronchery int X509_PUBKEY_eq(X509_PUBKEY *a, X509_PUBKEY *b); 42e71b7053SJung-uk Kim 43e71b7053SJung-uk Kim=head1 DESCRIPTION 44e71b7053SJung-uk Kim 45e71b7053SJung-uk KimThe B<X509_PUBKEY> structure represents the ASN.1 B<SubjectPublicKeyInfo> 46e71b7053SJung-uk Kimstructure defined in RFC5280 and used in certificates and certificate requests. 47e71b7053SJung-uk Kim 48*b077aed3SPierre ProncheryX509_PUBKEY_new_ex() allocates and initializes an B<X509_PUBKEY> structure 49*b077aed3SPierre Proncheryassociated with the given B<OSSL_LIB_CTX> in the I<libctx> parameter. Any 50*b077aed3SPierre Proncheryalgorithm fetches associated with using the B<X509_PUBKEY> object will use 51*b077aed3SPierre Proncherythe property query string I<propq>. See L<crypto(7)/ALGORITHM FETCHING> for 52*b077aed3SPierre Proncheryfurther information about algorithm fetching. 53e71b7053SJung-uk Kim 54*b077aed3SPierre ProncheryX509_PUBKEY_new() is the same as X509_PUBKEY_new_ex() except that the default 55*b077aed3SPierre Pronchery(NULL) B<OSSL_LIB_CTX> and a NULL property query string are used. 56*b077aed3SPierre Pronchery 57*b077aed3SPierre ProncheryX509_PUBKEY_dup() creates a duplicate copy of the B<X509_PUBKEY> object 58*b077aed3SPierre Proncheryspecified by I<a>. 59*b077aed3SPierre Pronchery 60*b077aed3SPierre ProncheryX509_PUBKEY_free() frees up B<X509_PUBKEY> structure I<a>. If I<a> is NULL 61e71b7053SJung-uk Kimnothing is done. 62e71b7053SJung-uk Kim 63*b077aed3SPierre ProncheryX509_PUBKEY_set() sets the public key in I<*x> to the public key contained 64*b077aed3SPierre Proncheryin the B<EVP_PKEY> structure I<pkey>. If I<*x> is not NULL any existing 65e71b7053SJung-uk Kimpublic key structure will be freed. 66e71b7053SJung-uk Kim 67*b077aed3SPierre ProncheryX509_PUBKEY_get0() returns the public key contained in I<key>. The returned 68e71b7053SJung-uk Kimvalue is an internal pointer which B<MUST NOT> be freed after use. 69e71b7053SJung-uk Kim 70e71b7053SJung-uk KimX509_PUBKEY_get() is similar to X509_PUBKEY_get0() except the reference 71e71b7053SJung-uk Kimcount on the returned key is incremented so it B<MUST> be freed using 72e71b7053SJung-uk KimEVP_PKEY_free() after use. 73e71b7053SJung-uk Kim 74*b077aed3SPierre Proncheryd2i_PUBKEY_ex() decodes an B<EVP_PKEY> structure using B<SubjectPublicKeyInfo> 75*b077aed3SPierre Proncheryformat. Some public key decoding implementations may use cryptographic 76*b077aed3SPierre Proncheryalgorithms. In this case the supplied library context I<libctx> and property 77*b077aed3SPierre Proncheryquery string I<propq> are used. 78*b077aed3SPierre Proncheryd2i_PUBKEY() does the same as d2i_PUBKEY_ex() except that the default 79*b077aed3SPierre Proncherylibrary context and property query string are used. 80*b077aed3SPierre Pronchery 81*b077aed3SPierre Proncheryi2d_PUBKEY() encodes an B<EVP_PKEY> structure using B<SubjectPublicKeyInfo> 82*b077aed3SPierre Proncheryformat. 83e71b7053SJung-uk Kim 84e71b7053SJung-uk Kimd2i_PUBKEY_bio(), d2i_PUBKEY_fp(), i2d_PUBKEY_bio() and i2d_PUBKEY_fp() are 85e71b7053SJung-uk Kimsimilar to d2i_PUBKEY() and i2d_PUBKEY() except they decode or encode using a 86e71b7053SJung-uk KimB<BIO> or B<FILE> pointer. 87e71b7053SJung-uk Kim 88*b077aed3SPierre ProncheryX509_PUBKEY_set0_param() sets the public key parameters of I<pub>. The 89*b077aed3SPierre ProncheryOID associated with the algorithm is set to I<aobj>. The type of the 90*b077aed3SPierre Proncheryalgorithm parameters is set to I<type> using the structure I<pval>. 91*b077aed3SPierre ProncheryThe encoding of the public key itself is set to the I<penclen> 92*b077aed3SPierre Proncherybytes contained in buffer I<penc>. On success ownership of all the supplied 93*b077aed3SPierre Proncheryparameters is passed to I<pub> so they must not be freed after the 94e71b7053SJung-uk Kimcall. 95e71b7053SJung-uk Kim 96*b077aed3SPierre ProncheryX509_PUBKEY_get0_param() retrieves the public key parameters from I<pub>, 97*b077aed3SPierre ProncheryI<*ppkalg> is set to the associated OID and the encoding consists of 98*b077aed3SPierre ProncheryI<*ppklen> bytes at I<*pk>, I<*pa> is set to the associated 99e71b7053SJung-uk KimAlgorithmIdentifier for the public key. If the value of any of these 100*b077aed3SPierre Proncheryparameters is not required it can be set to NULL. All of the 101e71b7053SJung-uk Kimretrieved pointers are internal and must not be freed after the 102e71b7053SJung-uk Kimcall. 103e71b7053SJung-uk Kim 104*b077aed3SPierre ProncheryX509_PUBKEY_eq() compares two B<X509_PUBKEY> values. 105*b077aed3SPierre Pronchery 106e71b7053SJung-uk Kim=head1 NOTES 107e71b7053SJung-uk Kim 108e71b7053SJung-uk KimThe B<X509_PUBKEY> functions can be used to encode and decode public keys 109e71b7053SJung-uk Kimin a standard format. 110e71b7053SJung-uk Kim 111e71b7053SJung-uk KimIn many cases applications will not call the B<X509_PUBKEY> functions 112e71b7053SJung-uk Kimdirectly: they will instead call wrapper functions such as X509_get0_pubkey(). 113e71b7053SJung-uk Kim 114e71b7053SJung-uk Kim=head1 RETURN VALUES 115e71b7053SJung-uk Kim 116*b077aed3SPierre ProncheryIf the allocation fails, X509_PUBKEY_new() and X509_PUBKEY_dup() return 117*b077aed3SPierre ProncheryNULL and set an error code that can be obtained by L<ERR_get_error(3)>. 118*b077aed3SPierre ProncheryOtherwise they return a pointer to the newly allocated structure. 119e71b7053SJung-uk Kim 120e71b7053SJung-uk KimX509_PUBKEY_free() does not return a value. 121e71b7053SJung-uk Kim 122e71b7053SJung-uk KimX509_PUBKEY_get0() and X509_PUBKEY_get() return a pointer to an B<EVP_PKEY> 123*b077aed3SPierre Proncherystructure or NULL if an error occurs. 124e71b7053SJung-uk Kim 125e71b7053SJung-uk KimX509_PUBKEY_set(), X509_PUBKEY_set0_param() and X509_PUBKEY_get0_param() 126e71b7053SJung-uk Kimreturn 1 for success and 0 if an error occurred. 127e71b7053SJung-uk Kim 128*b077aed3SPierre ProncheryX509_PUBKEY_eq() returns 1 for equal, 0 for different, and < 0 on error. 129*b077aed3SPierre Pronchery 130e71b7053SJung-uk Kim=head1 SEE ALSO 131e71b7053SJung-uk Kim 132e71b7053SJung-uk KimL<d2i_X509(3)>, 133e71b7053SJung-uk KimL<ERR_get_error(3)>, 134e71b7053SJung-uk KimL<X509_get_pubkey(3)>, 135e71b7053SJung-uk Kim 136*b077aed3SPierre Pronchery=head1 HISTORY 137*b077aed3SPierre Pronchery 138*b077aed3SPierre ProncheryThe X509_PUBKEY_new_ex() and X509_PUBKEY_eq() functions were added in OpenSSL 139*b077aed3SPierre Pronchery3.0. 140*b077aed3SPierre Pronchery 141e71b7053SJung-uk Kim=head1 COPYRIGHT 142e71b7053SJung-uk Kim 143*b077aed3SPierre ProncheryCopyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. 144e71b7053SJung-uk Kim 145*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 146e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 147e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 148e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 149e71b7053SJung-uk Kim 150e71b7053SJung-uk Kim=cut 151