1.\" $OpenBSD: X509_ALGOR_dup.3,v 1.23 2024/03/19 17:34:05 tb Exp $ 2.\" OpenSSL 4692340e Jun 7 15:49:08 2016 -0400 3.\" 4.\" This file is a derived work. 5.\" The changes are covered by the following Copyright and license: 6.\" 7.\" Copyright (c) 2023 Theo Buehler <tb@openbsd.org> 8.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> 9.\" 10.\" Permission to use, copy, modify, and distribute this software for any 11.\" purpose with or without fee is hereby granted, provided that the above 12.\" copyright notice and this permission notice appear in all copies. 13.\" 14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21.\" 22.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>. 23.\" Copyright (c) 2002, 2015 The OpenSSL Project. All rights reserved. 24.\" 25.\" Redistribution and use in source and binary forms, with or without 26.\" modification, are permitted provided that the following conditions 27.\" are met: 28.\" 29.\" 1. Redistributions of source code must retain the above copyright 30.\" notice, this list of conditions and the following disclaimer. 31.\" 32.\" 2. Redistributions in binary form must reproduce the above copyright 33.\" notice, this list of conditions and the following disclaimer in 34.\" the documentation and/or other materials provided with the 35.\" distribution. 36.\" 37.\" 3. All advertising materials mentioning features or use of this 38.\" software must display the following acknowledgment: 39.\" "This product includes software developed by the OpenSSL Project 40.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 41.\" 42.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 43.\" endorse or promote products derived from this software without 44.\" prior written permission. For written permission, please contact 45.\" openssl-core@openssl.org. 46.\" 47.\" 5. Products derived from this software may not be called "OpenSSL" 48.\" nor may "OpenSSL" appear in their names without prior written 49.\" permission of the OpenSSL Project. 50.\" 51.\" 6. Redistributions of any form whatsoever must retain the following 52.\" acknowledgment: 53.\" "This product includes software developed by the OpenSSL Project 54.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 55.\" 56.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 57.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 59.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 60.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 61.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 62.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 63.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 67.\" OF THE POSSIBILITY OF SUCH DAMAGE. 68.\" 69.Dd $Mdocdate: March 19 2024 $ 70.Dt X509_ALGOR_DUP 3 71.Os 72.Sh NAME 73.Nm X509_ALGOR_new , 74.Nm X509_ALGOR_free , 75.Nm X509_ALGOR_dup , 76.Nm X509_ALGOR_set0 , 77.Nm X509_ALGOR_get0 , 78.Nm X509_ALGOR_cmp 79.Nd create, change, and inspect algorithm identifiers 80.Sh SYNOPSIS 81.In openssl/x509.h 82.Ft X509_ALGOR * 83.Fn X509_ALGOR_new void 84.Ft void 85.Fn X509_ALGOR_free "X509_ALGOR *alg" 86.Ft X509_ALGOR * 87.Fo X509_ALGOR_dup 88.Fa "X509_ALGOR *alg" 89.Fc 90.Ft int 91.Fo X509_ALGOR_set0 92.Fa "X509_ALGOR *alg" 93.Fa "ASN1_OBJECT *aobj" 94.Fa "int ptype" 95.Fa "void *pval" 96.Fc 97.Ft void 98.Fo X509_ALGOR_get0 99.Fa "const ASN1_OBJECT **paobj" 100.Fa "int *pptype" 101.Fa "const void **ppval" 102.Fa "const X509_ALGOR *alg" 103.Fc 104.Ft int 105.Fo X509_ALGOR_cmp 106.Fa "const X509_ALGOR *a" 107.Fa "const X509_ALGOR *b" 108.Fc 109.Sh DESCRIPTION 110An 111.Vt X509_ALGOR 112object represents an ASN.1 113.Vt AlgorithmIdentifier 114structure defined in RFC 5280 section 4.1.1.2. 115It specifies a cryptographic 116.Fa algorithm 117by an ASN.1 object identifier (OID) that can be obtained from 118.Xr OBJ_nid2obj 3 , 119together with optional algorithm-specific 120.Fa parameters 121of the type 122.Vt ASN1_TYPE , 123see 124.Xr ASN1_TYPE_set 3 . 125.Vt X509_ALGOR 126objects are used by many other objects, for example certificates, 127certificate revocation lists, and certificate requests. 128.Pp 129.Fn X509_ALGOR_new 130allocates a new 131.Vt X509_ALGOR 132object containing the object that 133.Xr OBJ_nid2obj 3 134returns for 135.Dv NID_undef 136as the 137.Fa algorithm 138and a 139.Dv NULL 140pointer as the 141.Fa parameters . 142.Pp 143.Fn X509_ALGOR_free 144frees 145.Fa alg 146and any data contained in it. 147If 148.Fa alg 149is 150.Dv NULL , 151no action occurs. 152.Pp 153.Fn X509_ALGOR_dup 154creates a deep copy of 155.Fa alg . 156It is implemented by calling 157.Xr ASN1_item_dup 3 158with arguments of 159.Dv X509_ALGOR_it 160and 161.Fa alg , 162which is equivalent to calling 163.Xr i2d_X509_ALGOR 3 164and 165.Xr d2i_X509_ALGOR 3 . 166.Pp 167.Fn X509_ALGOR_set0 168sets the algorithm OID of 169.Fa alg 170to 171.Fa aobj 172and the associated parameter type to 173.Fa ptype 174with value 175.Fa pval . 176If 177.Fa ptype 178is 179.Dv V_ASN1_UNDEF , 180the parameter is omitted and 181.Fa pval 182is ignored. 183If 184.Fa ptype 185is zero, 186.Fa pval 187is ignored and the existing parameter is left unchanged, or if 188.Fa alg 189does not contain a parameter, a new, empty parameter of type 190.Dv V_ASN1_UNDEF 191is added. 192Otherwise 193.Fa ptype 194and 195.Fa pval 196have the same meaning as the 197.Fa type 198and 199.Fa value 200parameters to 201.Xr ASN1_TYPE_set 3 . 202Ownership of 203.Fa aobj 204and, unless it is ignored, of 205.Fa pval 206is transferred to 207.Fa alg 208on success. 209.Pp 210.Fn X509_ALGOR_get0 211returns 212.Fa alg Ns 's 213algorithm OID in 214.Pf * Fa paobj , 215its parameter type in 216.Pf * Fa pptype , 217and its parameter value in 218.Pf * Fa ppval . 219Any of 220.Fa paobj , 221.Fa pptype , 222and 223.Fa ppval 224can be 225.Dv NULL . 226If 227.Fa pptype is 228.Dv NULL 229or if 230.Pf * Fa pptype 231is 232.Dv V_ASN1_UNDEF 233then 234.Pf * Fa ppval Ns 's 235value is undefined. 236.Pp 237.Fn X509_ALGOR_cmp 238compares 239.Fa a 240and 241.Fa b . 242.Sh RETURN VALUES 243.Fn X509_ALGOR_new 244and 245.Fn X509_ALGOR_dup 246return a new 247.Vt X509_ALGOR 248object or 249.Dv NULL 250if an error occurs. 251.Pp 252.Fn X509_ALGOR_set0 253returns 1 for success or 0 if 254.Fa alg 255is 256.Dv NULL 257or memory allocation fails. 258.Pp 259.Fn X509_ALGOR_cmp 260returns 0 if 261.Fa a 262and 263.Fa b 264have identical encodings or non-zero otherwise. 265.Sh SEE ALSO 266.Xr ASN1_TYPE_set 3 , 267.Xr d2i_X509_ALGOR 3 , 268.Xr EVP_DigestInit 3 , 269.Xr OBJ_nid2obj 3 , 270.Xr X509_get0_signature 3 , 271.Xr X509_new 3 , 272.Xr X509_PUBKEY_get0_param 3 , 273.Xr X509_signature_dump 3 274.Sh STANDARDS 275RFC 5280: Internet X.509 Public Key Infrastructure Certificate and 276Certificate Revocation List (CRL) Profile 277.Sh HISTORY 278.Fn X509_ALGOR_new 279and 280.Fn X509_ALGOR_free 281appeared in SSLeay 0.4 or earlier and have been available since 282.Ox 2.4 . 283.Pp 284.Fn X509_ALGOR_dup 285first appeared in SSLeay 0.9.1 and has been available since 286.Ox 2.6 . 287.Pp 288.Fn X509_ALGOR_set0 289and 290.Fn X509_ALGOR_get0 291first appeared in OpenSSL 0.9.8h and have been available since 292.Ox 4.5 . 293.Pp 294.Fn X509_ALGOR_cmp 295first appeared in OpenSSL 0.9.8zd, 1.0.0p, and 1.0.1k 296and has been available since 297.Ox 4.9 . 298