1.\" $OpenBSD: X509_ALGOR_dup.3,v 1.22 2023/10/13 05:49:34 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: October 13 2023 $ 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_set_md , 79.Nm X509_ALGOR_cmp 80.Nd create, change, and inspect algorithm identifiers 81.Sh SYNOPSIS 82.In openssl/x509.h 83.Ft X509_ALGOR * 84.Fn X509_ALGOR_new void 85.Ft void 86.Fn X509_ALGOR_free "X509_ALGOR *alg" 87.Ft X509_ALGOR * 88.Fo X509_ALGOR_dup 89.Fa "X509_ALGOR *alg" 90.Fc 91.Ft int 92.Fo X509_ALGOR_set0 93.Fa "X509_ALGOR *alg" 94.Fa "ASN1_OBJECT *aobj" 95.Fa "int ptype" 96.Fa "void *pval" 97.Fc 98.Ft void 99.Fo X509_ALGOR_get0 100.Fa "const ASN1_OBJECT **paobj" 101.Fa "int *pptype" 102.Fa "const void **ppval" 103.Fa "const X509_ALGOR *alg" 104.Fc 105.Ft void 106.Fo X509_ALGOR_set_md 107.Fa "X509_ALGOR *alg" 108.Fa "const EVP_MD *md" 109.Fc 110.Ft int 111.Fo X509_ALGOR_cmp 112.Fa "const X509_ALGOR *a" 113.Fa "const X509_ALGOR *b" 114.Fc 115.Sh DESCRIPTION 116An 117.Vt X509_ALGOR 118object represents an ASN.1 119.Vt AlgorithmIdentifier 120structure defined in RFC 5280 section 4.1.1.2. 121It specifies a cryptographic 122.Fa algorithm 123by an ASN.1 object identifier (OID) that can be obtained from 124.Xr OBJ_nid2obj 3 , 125together with optional algorithm-specific 126.Fa parameters 127of the type 128.Vt ASN1_TYPE , 129see 130.Xr ASN1_TYPE_set 3 . 131.Vt X509_ALGOR 132objects are used by many other objects, for example certificates, 133certificate revocation lists, and certificate requests. 134.Pp 135.Fn X509_ALGOR_new 136allocates a new 137.Vt X509_ALGOR 138object containing the object that 139.Xr OBJ_nid2obj 3 140returns for 141.Dv NID_undef 142as the 143.Fa algorithm 144and a 145.Dv NULL 146pointer as the 147.Fa parameters . 148.Pp 149.Fn X509_ALGOR_free 150frees 151.Fa alg 152and any data contained in it. 153If 154.Fa alg 155is 156.Dv NULL , 157no action occurs. 158.Pp 159.Fn X509_ALGOR_dup 160creates a deep copy of 161.Fa alg . 162It is implemented by calling 163.Xr ASN1_item_dup 3 164with arguments of 165.Dv X509_ALGOR_it 166and 167.Fa alg , 168which is equivalent to calling 169.Xr i2d_X509_ALGOR 3 170and 171.Xr d2i_X509_ALGOR 3 . 172.Pp 173.Fn X509_ALGOR_set0 174sets the algorithm OID of 175.Fa alg 176to 177.Fa aobj 178and the associated parameter type to 179.Fa ptype 180with value 181.Fa pval . 182If 183.Fa ptype 184is 185.Dv V_ASN1_UNDEF , 186the parameter is omitted and 187.Fa pval 188is ignored. 189If 190.Fa ptype 191is zero, 192.Fa pval 193is ignored and the existing parameter is left unchanged, or if 194.Fa alg 195does not contain a parameter, a new, empty parameter of type 196.Dv V_ASN1_UNDEF 197is added. 198Otherwise 199.Fa ptype 200and 201.Fa pval 202have the same meaning as the 203.Fa type 204and 205.Fa value 206parameters to 207.Xr ASN1_TYPE_set 3 . 208Ownership of 209.Fa aobj 210and, unless it is ignored, of 211.Fa pval 212is transferred to 213.Fa alg 214on success. 215.Pp 216.Fn X509_ALGOR_get0 217returns 218.Fa alg Ns 's 219algorithm OID in 220.Pf * Fa paobj , 221its parameter type in 222.Pf * Fa pptype , 223and its parameter value in 224.Pf * Fa ppval . 225Any of 226.Fa paobj , 227.Fa pptype , 228and 229.Fa ppval 230can be 231.Dv NULL . 232If 233.Fa pptype is 234.Dv NULL 235or if 236.Pf * Fa pptype 237is 238.Dv V_ASN1_UNDEF 239then 240.Pf * Fa ppval Ns 's 241value is undefined. 242.Pp 243.Fn X509_ALGOR_set_md 244sets 245.Fa alg 246to appropriate values for the message digest 247.Fa md . 248If the 249.Dv EVP_MD_FLAG_DIGALGID_ABSENT 250flag is not set on 251.Fa md , 252.Fn X509_ALGOR_set_md 253can leave 254.Fa alg 255in a corrupted state due to memory allocation failure. 256This problem can be avoided by preallocating with an error-checked call to 257.Fn X509_ALGOR_set0 alg NULL 0 NULL . 258.Pp 259.Fn X509_ALGOR_cmp 260compares 261.Fa a 262and 263.Fa b . 264.Sh RETURN VALUES 265.Fn X509_ALGOR_new 266and 267.Fn X509_ALGOR_dup 268return a new 269.Vt X509_ALGOR 270object or 271.Dv NULL 272if an error occurs. 273.Pp 274.Fn X509_ALGOR_set0 275returns 1 for success or 0 if 276.Fa alg 277is 278.Dv NULL 279or memory allocation fails. 280.Pp 281.Fn X509_ALGOR_cmp 282returns 0 if 283.Fa a 284and 285.Fa b 286have identical encodings or non-zero otherwise. 287.Sh SEE ALSO 288.Xr ASN1_TYPE_set 3 , 289.Xr d2i_X509_ALGOR 3 , 290.Xr EVP_DigestInit 3 , 291.Xr OBJ_nid2obj 3 , 292.Xr X509_get0_signature 3 , 293.Xr X509_new 3 , 294.Xr X509_PUBKEY_get0_param 3 , 295.Xr X509_signature_dump 3 296.Sh STANDARDS 297RFC 5280: Internet X.509 Public Key Infrastructure Certificate and 298Certificate Revocation List (CRL) Profile 299.Sh HISTORY 300.Fn X509_ALGOR_new 301and 302.Fn X509_ALGOR_free 303appeared in SSLeay 0.4 or earlier and have been available since 304.Ox 2.4 . 305.Pp 306.Fn X509_ALGOR_dup 307first appeared in SSLeay 0.9.1 and has been available since 308.Ox 2.6 . 309.Pp 310.Fn X509_ALGOR_set0 311and 312.Fn X509_ALGOR_get0 313first appeared in OpenSSL 0.9.8h and have been available since 314.Ox 4.5 . 315.Pp 316.Fn X509_ALGOR_cmp 317first appeared in OpenSSL 0.9.8zd, 1.0.0p, and 1.0.1k 318and has been available since 319.Ox 4.9 . 320.Pp 321.Fn X509_ALGOR_set_md 322first appeared in OpenSSL 1.0.1 and has been available since 323.Ox 5.3 . 324.Sh BUGS 325.Fn X509_ALGOR_set_md 326can fail but cannot communicate failure to the caller. 327