xref: /freebsd/lib/libmd/sha512.3 (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
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.\" $FreeBSD$
11.\"
12.Dd March 28, 2014
13.Dt SHA512 3
14.Os
15.Sh NAME
16.Nm SHA512_Init ,
17.Nm SHA512_Update ,
18.Nm SHA512_Final ,
19.Nm SHA512_End ,
20.Nm SHA512_File ,
21.Nm SHA512_FileChunk ,
22.Nm SHA512_Data
23.Nd calculate the FIPS 180-2 ``SHA-512'' message digest
24.Sh LIBRARY
25.Lb libmd
26.Sh SYNOPSIS
27.In sys/types.h
28.In sha512.h
29.Ft void
30.Fn SHA512_Init "SHA512_CTX *context"
31.Ft void
32.Fn SHA512_Update "SHA512_CTX *context" "const unsigned char *data" "size_t len"
33.Ft void
34.Fn SHA512_Final "unsigned char digest[64]" "SHA512_CTX *context"
35.Ft "char *"
36.Fn SHA512_End "SHA512_CTX *context" "char *buf"
37.Ft "char *"
38.Fn SHA512_File "const char *filename" "char *buf"
39.Ft "char *"
40.Fn SHA512_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
41.Ft "char *"
42.Fn SHA512_Data "const unsigned char *data" "unsigned int len" "char *buf"
43.Sh DESCRIPTION
44The
45.Li SHA512_
46functions calculate a 512-bit cryptographic checksum (digest)
47for any number of input bytes.
48A cryptographic checksum is a one-way
49hash function; that is, it is computationally impractical to find
50the input corresponding to a particular output.
51This net result is
52a
53.Dq fingerprint
54of the input-data, which does not disclose the actual input.
55.Pp
56The
57.Fn SHA512_Init ,
58.Fn SHA512_Update ,
59and
60.Fn SHA512_Final
61functions are the core functions.
62Allocate an
63.Vt SHA512_CTX ,
64initialize it with
65.Fn SHA512_Init ,
66run over the data with
67.Fn SHA512_Update ,
68and finally extract the result using
69.Fn SHA512_Final .
70.Pp
71.Fn SHA512_End
72is a wrapper for
73.Fn SHA512_Final
74which converts the return value to a 65-character
75(including the terminating '\e0')
76.Tn ASCII
77string which represents the 512 bits in hexadecimal.
78.Pp
79.Fn SHA512_File
80calculates the digest of a file, and uses
81.Fn SHA512_End
82to return the result.
83If the file cannot be opened, a null pointer is returned.
84.Fn SHA512_FileChunk
85is similar to
86.Fn SHA512_File ,
87but it only calculates the digest over a byte-range of the file specified,
88starting at
89.Fa offset
90and spanning
91.Fa length
92bytes.
93If the
94.Fa length
95parameter is specified as 0, or more than the length of the remaining part
96of the file,
97.Fn SHA512_FileChunk
98calculates the digest from
99.Fa offset
100to the end of file.
101.Fn SHA512_Data
102calculates the digest of a chunk of data in memory, and uses
103.Fn SHA512_End
104to return the result.
105.Pp
106When using
107.Fn SHA512_End ,
108.Fn SHA512_File ,
109or
110.Fn SHA512_Data ,
111the
112.Fa buf
113argument can be a null pointer, in which case the returned string
114is allocated with
115.Xr malloc 3
116and subsequently must be explicitly deallocated using
117.Xr free 3
118after use.
119If the
120.Fa buf
121argument is non-null it must point to at least 65 characters of buffer space.
122.Sh SEE ALSO
123.Xr md4 3 ,
124.Xr md5 3 ,
125.Xr ripemd 3 ,
126.Xr sha 3
127.Sh HISTORY
128These functions appeared in
129.Fx 9.0 .
130.Sh AUTHORS
131The core hash routines were implemented by Colin Percival based on
132the published
133.Tn FIPS 180-2
134standard.
135.Sh BUGS
136No method is known to exist which finds two files having the same hash value,
137nor to find a file with a specific hash value.
138There is on the other hand no guarantee that such a method does not exist.
139