]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libmd/sha512.3
MFC r292782: Replace sys/crypto/sha2/sha2.c with lib/libmd/sha512c.c
[FreeBSD/stable/10.git] / lib / libmd / sha512.3
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 October 17, 2015
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 .Nm SHA384_Init ,
24 .Nm SHA384_Update ,
25 .Nm SHA384_Final ,
26 .Nm SHA384_End ,
27 .Nm SHA384_File ,
28 .Nm SHA384_FileChunk ,
29 .Nm SHA384_Data
30 .Nd calculate the FIPS 180-4 ``SHA-512'' family of message digests
31 .Sh LIBRARY
32 .Lb libmd
33 .Sh SYNOPSIS
34 .In sys/types.h
35 .In sha512.h
36 .Ft void
37 .Fn SHA512_Init "SHA512_CTX *context"
38 .Ft void
39 .Fn SHA512_Update "SHA512_CTX *context" "const unsigned char *data" "size_t len"
40 .Ft void
41 .Fn SHA512_Final "unsigned char digest[64]" "SHA512_CTX *context"
42 .Ft "char *"
43 .Fn SHA512_End "SHA512_CTX *context" "char *buf"
44 .Ft "char *"
45 .Fn SHA512_File "const char *filename" "char *buf"
46 .Ft "char *"
47 .Fn SHA512_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
48 .Ft "char *"
49 .Fn SHA512_Data "const unsigned char *data" "unsigned int len" "char *buf"
50 .Ft void
51 .Fn SHA384_Init "SHA384_CTX *context"
52 .Ft void
53 .Fn SHA384_Update "SHA384_CTX *context" "const unsigned char *data" "size_t len"
54 .Ft void
55 .Fn SHA384_Final "unsigned char digest[48]" "SHA384_CTX *context"
56 .Ft "char *"
57 .Fn SHA384_End "SHA384_CTX *context" "char *buf"
58 .Ft "char *"
59 .Fn SHA384_File "const char *filename" "char *buf"
60 .Ft "char *"
61 .Fn SHA384_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
62 .Ft "char *"
63 .Fn SHA384_Data "const unsigned char *data" "unsigned int len" "char *buf"
64 .Sh DESCRIPTION
65 The
66 .Li SHA512_
67 functions calculate a 512-bit cryptographic checksum (digest)
68 for any number of input bytes.
69 A cryptographic checksum is a one-way
70 hash function; that is, it is computationally impractical to find
71 the input corresponding to a particular output.
72 This net result is
73 a
74 .Dq fingerprint
75 of the input-data, which does not disclose the actual input.
76 .Pp
77 The
78 .Fn SHA512_Init ,
79 .Fn SHA512_Update ,
80 and
81 .Fn SHA512_Final
82 functions are the core functions.
83 Allocate an
84 .Vt SHA512_CTX ,
85 initialize it with
86 .Fn SHA512_Init ,
87 run over the data with
88 .Fn SHA512_Update ,
89 and finally extract the result using
90 .Fn SHA512_Final .
91 .Pp
92 .Fn SHA512_End
93 is a wrapper for
94 .Fn SHA512_Final
95 which converts the return value to a 65-character
96 (including the terminating '\e0')
97 .Tn ASCII
98 string which represents the 512 bits in hexadecimal.
99 .Pp
100 .Fn SHA512_File
101 calculates the digest of a file, and uses
102 .Fn SHA512_End
103 to return the result.
104 If the file cannot be opened, a null pointer is returned.
105 .Fn SHA512_FileChunk
106 is similar to
107 .Fn SHA512_File ,
108 but it only calculates the digest over a byte-range of the file specified,
109 starting at
110 .Fa offset
111 and spanning
112 .Fa length
113 bytes.
114 If the
115 .Fa length
116 parameter is specified as 0, or more than the length of the remaining part
117 of the file,
118 .Fn SHA512_FileChunk
119 calculates the digest from
120 .Fa offset
121 to the end of file.
122 .Fn SHA512_Data
123 calculates the digest of a chunk of data in memory, and uses
124 .Fn SHA512_End
125 to return the result.
126 .Pp
127 When using
128 .Fn SHA512_End ,
129 .Fn SHA512_File ,
130 or
131 .Fn SHA512_Data ,
132 the
133 .Fa buf
134 argument can be a null pointer, in which case the returned string
135 is allocated with
136 .Xr malloc 3
137 and subsequently must be explicitly deallocated using
138 .Xr free 3
139 after use.
140 If the
141 .Fa buf
142 argument is non-null it must point to at least 65 characters of buffer space.
143 .Pp
144 The
145 .Li SHA384_
146 functions are identical to the
147 .Li SHA512_
148 functions except they use a different initial hash value and the output is
149 truncated to 384 bits.
150 .Pp
151 .Fn SHA384_End
152 is a wrapper for
153 .Fn SHA384_Final
154 which converts the return value to a 49-character
155 (including the terminating '\e0')
156 .Tn ASCII
157 string which represents the 384 bits in hexadecimal.
158 .Sh SEE ALSO
159 .Xr md4 3 ,
160 .Xr md5 3 ,
161 .Xr ripemd 3 ,
162 .Xr sha 3
163 .Sh HISTORY
164 These functions appeared in
165 .Fx 9.0 .
166 .Sh AUTHORS
167 The core hash routines were implemented by Colin Percival based on
168 the published
169 .Tn FIPS 180-2
170 standard.
171 .Sh BUGS
172 No method is known to exist which finds two files having the same hash value,
173 nor to find a file with a specific hash value.
174 There is on the other hand no guarantee that such a method does not exist.