1.\" 2.\" ---------------------------------------------------------------------------- 3.\" "THE BEER-WARE LICENSE" (Revision 42): 4.\" <phk@FreeBSD.org> wrote this file. As long as you retain this notice you 5.\" can do whatever you want with this stuff. If we meet some day, and you think 6.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 7.\" ---------------------------------------------------------------------------- 8.\" 9.\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp 10.\" 11.Dd March 8, 2022 12.Dt RIPEMD 3 13.Os 14.Sh NAME 15.Nm RIPEMD160_Init , 16.Nm RIPEMD160_Update , 17.Nm RIPEMD160_Final , 18.Nm RIPEMD160_End , 19.Nm RIPEMD160_Fd , 20.Nm RIPEMD160_FdChunk , 21.Nm RIPEMD160_File , 22.Nm RIPEMD160_FileChunk , 23.Nm RIPEMD160_Data 24.Nd calculate the RIPEMD160 message digest 25.Sh LIBRARY 26.Lb libmd 27.Sh SYNOPSIS 28.In sys/types.h 29.In ripemd.h 30.Ft void 31.Fn RIPEMD160_Init "RIPEMD160_CTX *context" 32.Ft void 33.Fn RIPEMD160_Update "RIPEMD160_CTX *context" "const unsigned char *data" "unsigned int len" 34.Ft void 35.Fn RIPEMD160_Final "unsigned char digest[20]" "RIPEMD160_CTX *context" 36.Ft "char *" 37.Fn RIPEMD160_End "RIPEMD160_CTX *context" "char *buf" 38.Ft "char *" 39.Fn RIPEMD160_Fd "int fd" "char *buf" 40.Ft "char *" 41.Fn RIPEMD160_FdChunk "int fd" "char *buf" "off_t offset" "off_t length" 42.Ft "char *" 43.Fn RIPEMD160_File "const char *filename" "char *buf" 44.Ft "char *" 45.Fn RIPEMD160_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length" 46.Ft "char *" 47.Fn RIPEMD160_Data "const unsigned char *data" "unsigned int len" "char *buf" 48.Sh DESCRIPTION 49The 50.Li RIPEMD160_ 51functions calculate a 160-bit cryptographic checksum (digest) 52for any number of input bytes. 53A cryptographic checksum is a one-way 54hash function; that is, it is computationally impractical to find 55the input corresponding to a particular output. 56This net result is a 57.Dq fingerprint 58of the input-data, which does not disclose the actual input. 59.Pp 60The 61.Fn RIPEMD160_Init , 62.Fn RIPEMD160_Update , 63and 64.Fn RIPEMD160_Final 65functions are the core functions. 66Allocate an 67.Vt RIPEMD160_CTX , 68initialize it with 69.Fn RIPEMD160_Init , 70run over the data with 71.Fn RIPEMD160_Update , 72and finally extract the result using 73.Fn RIPEMD160_Final , 74which will also erase the 75.Vt RIPEMD160_CTX . 76.Pp 77The 78.Fn RIPEMD160_End 79function is a wrapper for 80.Fn RIPEMD160_Final 81which converts the return value to a 41-character 82(including the terminating '\e0') 83ASCII string which represents the 160 bits in hexadecimal. 84.Pp 85The 86.Fn RIPEMD160_File 87function calculates the digest of a file, and uses 88.Fn RIPEMD160_End 89to return the result. 90If the file cannot be opened, a null pointer is returned. 91The 92.Fn RIPEMD160_FileChunk 93function is similar to 94.Fn RIPEMD160_File , 95but it only calculates the digest over a byte-range of the file specified, 96starting at 97.Fa offset 98and spanning 99.Fa length 100bytes. 101If the 102.Fa length 103parameter is specified as 0, or more than the length of the remaining part 104of the file, 105.Fn RIPEMD160_FileChunk 106calculates the digest from 107.Fa offset 108to the end of file. 109The 110.Fn RIPEMD160_Data 111function calculates the digest of a chunk of data in memory, and uses 112.Fn RIPEMD160_End 113to return the result. 114.Pp 115The 116.Fn RIPEMD160_Fd 117and 118.Fn RIPEMD160_FdChunk 119functions are identical to their 120.Fn RIPEMD160_File 121and 122.Fn RIPEMD160_FileChunk 123counterparts, with the exception that the first argument is an 124.Fa fd 125instead of a 126.Fa filename . 127.Pp 128When using 129.Fn RIPEMD160_End , 130.Fn RIPEMD160_File , 131or 132.Fn RIPEMD160_Data , 133the 134.Fa buf 135argument can be a null pointer, in which case the returned string 136is allocated with 137.Xr malloc 3 138and subsequently must be explicitly deallocated using 139.Xr free 3 140after use. 141If the 142.Fa buf 143argument is non-null it must point to at least 41 characters of buffer space. 144.Sh ERRORS 145The 146.Fn RIPEMD160_End 147function called with a null buf argument may fail and return NULL if: 148.Bl -tag -width Er 149.It Bq Er ENOMEM 150Insufficient storage space is available. 151.El 152.Pp 153The 154.Fn RIPEMD160_File 155and 156.Fn RIPEMD160_FileChunk 157may return NULL when underlying 158.Xr open 2 , 159.Xr fstat 2 , 160.Xr lseek 2 , 161or 162.Xr RIPEMD160_End 3 163fail. 164.Sh SEE ALSO 165.Xr md4 3 , 166.Xr md5 3 , 167.Xr sha 3 , 168.Xr sha256 3 , 169.Xr sha512 3 , 170.Xr skein 3 171.Sh HISTORY 172These functions appeared in 173.Fx 4.0 . 174.Sh AUTHORS 175The core hash routines were implemented by Eric Young based on the 176published RIPEMD160 specification. 177.Sh BUGS 178No method is known to exist which finds two files having the same hash value, 179nor to find a file with a specific hash value. 180There is on the other hand no guarantee that such a method does not exist. 181