1.\" $OpenBSD: EVP_MD_nid.3,v 1.4 2024/03/05 17:21:40 tb Exp $ 2.\" full merge up to: OpenSSL man3/EVP_DigestInit.pod 3.\" 24a535ea Sep 22 13:14:20 2020 +0100 4.\" 5.\" This file is a derived work. 6.\" The changes are covered by the following Copyright and license: 7.\" 8.\" Copyright (c) 2023 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.\" and Antoine Salon <asalon@vmware.com>. 24.\" Copyright (c) 2000, 2012, 2019 The OpenSSL Project. 25.\" All rights reserved. 26.\" 27.\" Redistribution and use in source and binary forms, with or without 28.\" modification, are permitted provided that the following conditions 29.\" are met: 30.\" 31.\" 1. Redistributions of source code must retain the above copyright 32.\" notice, this list of conditions and the following disclaimer. 33.\" 34.\" 2. Redistributions in binary form must reproduce the above copyright 35.\" notice, this list of conditions and the following disclaimer in 36.\" the documentation and/or other materials provided with the 37.\" distribution. 38.\" 39.\" 3. All advertising materials mentioning features or use of this 40.\" software must display the following acknowledgment: 41.\" "This product includes software developed by the OpenSSL Project 42.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 43.\" 44.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 45.\" endorse or promote products derived from this software without 46.\" prior written permission. For written permission, please contact 47.\" openssl-core@openssl.org. 48.\" 49.\" 5. Products derived from this software may not be called "OpenSSL" 50.\" nor may "OpenSSL" appear in their names without prior written 51.\" permission of the OpenSSL Project. 52.\" 53.\" 6. Redistributions of any form whatsoever must retain the following 54.\" acknowledgment: 55.\" "This product includes software developed by the OpenSSL Project 56.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 57.\" 58.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 59.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 61.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 62.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 63.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 64.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 65.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 67.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 68.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 69.\" OF THE POSSIBILITY OF SUCH DAMAGE. 70.\" 71.Dd $Mdocdate: March 5 2024 $ 72.Dt EVP_MD_NID 3 73.Os 74.Sh NAME 75.Nm EVP_MD_nid , 76.Nm EVP_MD_type , 77.Nm EVP_MD_CTX_type , 78.Nm EVP_MD_name , 79.Nm EVP_MD_size , 80.Nm EVP_MD_CTX_size , 81.Nm EVP_MD_block_size , 82.Nm EVP_MD_CTX_block_size , 83.Nm EVP_MD_flags , 84.Nm EVP_MD_pkey_type 85.Nd inspect EVP_MD objects 86.Sh SYNOPSIS 87.In openssl/evp.h 88.Ft int 89.Fo EVP_MD_nid 90.Fa "const EVP_MD *md" 91.Fc 92.Ft int 93.Fo EVP_MD_type 94.Fa "const EVP_MD *md" 95.Fc 96.Ft int 97.Fo EVP_MD_CTX_type 98.Fa "const EVP_MD_CTX *ctx" 99.Fc 100.Ft const char * 101.Fo EVP_MD_name 102.Fa "const EVP_MD *md" 103.Fc 104.Ft int 105.Fo EVP_MD_size 106.Fa "const EVP_MD *md" 107.Fc 108.Ft int 109.Fo EVP_MD_CTX_size 110.Fa "const EVP_MD_CTX *ctx" 111.Fc 112.Ft int 113.Fo EVP_MD_block_size 114.Fa "const EVP_MD *md" 115.Fc 116.Ft int 117.Fo EVP_MD_CTX_block_size 118.Fa "const EVP_MD_CTX *ctx" 119.Fc 120.Ft unsigned long 121.Fo EVP_MD_flags 122.Fa "const EVP_MD *md" 123.Fc 124.Ft int 125.Fo EVP_MD_pkey_type 126.Fa "const EVP_MD *md" 127.Fc 128.Sh DESCRIPTION 129.Fn EVP_MD_nid 130and 131.Fn EVP_MD_type 132are identical and return the numerical identifier (NID) of 133.Fa md . 134The NID is an internal value which may or may not have 135a corresponding ASN.1 OBJECT IDENTIFIER; see 136.Xr OBJ_nid2obj 3 137for details. 138For example , 139.Fn EVP_MD_type EVP_sha512() 140returns 141.Dv NID_sha512 . 142.Fn EVP_MD_CTX_type 143returns the NID of the message digest algorithm that 144.Fa ctx 145is configured to use. 146These functions are normally used when setting ASN.1 OIDs. 147.Pp 148.Fn EVP_MD_name 149converts the NID of 150.Fa md 151to its short name with 152.Xr OBJ_nid2sn 3 . 153.Pp 154.Fn EVP_MD_size 155returns the size in bytes of the message digests (hashes) produced by 156.Fa md . 157.Fn EVP_MD_CTX_size 158return the size of the hashes produced by the message digest algorithm that 159.Fa ctx 160is configured to use. 161.Pp 162.Fn EVP_MD_block_size 163returns the block size in bytes of 164.Fa md . 165.Fn EVP_MD_CTX_block_size 166returns the block size of the message digest algorithm that 167.Fa ctx 168is configured to use. 169.Pp 170.Fn EVP_MD_flags 171returns the message digest flags used by 172.Fa md . 173Be careful to not confuse these flags with the unrelated 174message digest context flags that can be inspected with 175.Xr EVP_MD_CTX_test_flags 3 . 176The available flags are: 177.Bl -tag -width Ds 178.It Dv EVP_MD_FLAG_DIGALGID_NULL 179The parameters in a 180.Vt DigestAlgorithmIdentifier 181are encoded using an explicit ASN.1 182.Dv NULL 183rather than omitting them. 184This is the default, which means that it takes effect for 185.Vt EVP_MD 186objects that do not have 187.Dv EVP_MD_FLAG_DIGALGID_ABSENT 188set. 189.It Dv EVP_MD_FLAG_DIGALGID_ABSENT 190The parameters in a 191.Vt DigestAlgorithmIdentifier 192are omitted from the ASN.1 encoding. 193This is used by the 194.Vt EVP_MD 195objects documented in the manual page 196.Xr EVP_sha3_224 3 197and by the objects returned from 198.Xr EVP_sha512 3 , 199.Xr EVP_sha512_256 3 , 200.Xr EVP_sha512_224 3 , 201.Xr EVP_sha384 3 , 202.Xr EVP_sha256 3 , 203.Xr EVP_sha224 3 , 204.Xr EVP_sha1 3 , 205and 206.Xr EVP_sm3 3 . 207.It Dv EVP_MD_FLAG_DIGALGID_CUSTOM 208This flag is reserved for user-defined 209.Vt EVP_MD 210objects supporting custom 211.Vt DigestAlgorithmIdentifier 212handling via 213.Xr EVP_MD_CTX_ctrl 3 , 214but actually, it is ignored by both LibreSSL and OpenSSL 215and such user-defined behaviour is not supported by the libraries. 216.It Dv EVP_MD_FLAG_FIPS 217Mark the digest method as suitable for FIPS mode. 218This flag is ignored by both LibreSSL and OpenSSL. 219.It Dv EVP_MD_FLAG_ONESHOT 220Intended to indicate that the digest method can only handle one block 221of input, but actually, this flag is ignored by both LibreSSL and OpenSSL. 222.El 223.Pp 224.Fn EVP_MD_pkey_type 225returns the NID of the public key signing algorithm associated with this 226digest. 227For example, 228.Xr EVP_sha512 3 229is associated with RSA, so this returns 230.Dv NID_sha512WithRSAEncryption . 231Since digests and signature algorithms are no longer linked, this 232function is only retained for compatibility reasons. 233.Pp 234.Fn EVP_MD_nid , 235.Fn EVP_MD_CTX_type , 236.Fn EVP_MD_name , 237.Fn EVP_MD_CTX_size , 238and 239.Fn EVP_MD_CTX_block_size 240are implemented as macros. 241.Sh RETURN VALUES 242.Fn EVP_MD_nid , 243.Fn EVP_MD_type , 244.Fn EVP_MD_CTX_type , 245and 246.Fn EVP_MD_pkey_type 247return the NID of the corresponding OBJECT IDENTIFIER or 248.Dv NID_undef 249if none exists. 250.Pp 251.Fn EVP_MD_name 252returns a pointer to a string 253that is owned by an internal library object or 254.Dv NULL 255if the NID is neither built into the library nor added to the global 256object table by one of the functions documented in the manual page 257.Xr OBJ_create 3 , 258or if the object does not contain a short name. 259.Pp 260.Fn EVP_MD_size , 261.Fn EVP_MD_CTX_size , 262.Fn EVP_MD_block_size , 263and 264.Fn EVP_MD_CTX_block_size 265return the digest or block size in bytes. 266.Sh SEE ALSO 267.Xr evp 3 , 268.Xr EVP_DigestInit 3 , 269.Xr EVP_MD_CTX_ctrl 3 , 270.Xr OBJ_nid2obj 3 271.Sh STANDARDS 272RFC 5754: Using SHA2 Algorithms with Cryptographic Message Syntax 273.Bl -dash -compact -offset indent 274.It 275section 2: Message Digest Algorithms 276.El 277.Sh HISTORY 278.Fn EVP_MD_size 279first appeared in SSLeay 0.6.6, 280.Fn EVP_MD_CTX_size 281and 282.Fn EVP_MD_CTX_type 283in SSLeay 0.8.0, 284.Fn EVP_MD_type 285and 286.Fn EVP_MD_pkey_type 287in SSLeay 0.8.1, and 288.Fn EVP_MD_block_size 289and 290.Fn EVP_MD_CTX_block_size 291in SSLeay 0.9.0. 292All these functions have been available since 293.Ox 2.4 . 294.Pp 295.Fn EVP_MD_nid 296and 297.Fn EVP_MD_name 298first appeared in OpenSSL 0.9.7 and have been available since 299.Ox 3.2 . 300.Pp 301.Fn EVP_MD_flags 302first appeared in OpenSSL 1.0.0 303and has been available since 304.Ox 4.9 . 305.Sh CAVEATS 306The behaviour of the functions taking an 307.Vt EVP_MD_CTX 308argument is undefined if they are called on a 309.Fa ctx 310that has no message digest configured yet, 311for example one freshly returned from 312.Xr EVP_MD_CTX_new 3 . 313In that case, the program may for example be terminated by a 314.Dv NULL 315pointer access. 316