xref: /freebsd/lib/libmd/sha256.3 (revision 8ff3cdd1b52f1a7baa92226eb73ab448afc974e8)
1186c183cSColin Percival.\"
2186c183cSColin Percival.\" ----------------------------------------------------------------------------
3186c183cSColin Percival.\" "THE BEER-WARE LICENSE" (Revision 42):
4186c183cSColin Percival.\" <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5186c183cSColin Percival.\" can do whatever you want with this stuff. If we meet some day, and you think
6186c183cSColin Percival.\" this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7186c183cSColin Percival.\" ----------------------------------------------------------------------------
8186c183cSColin Percival.\"
9186c183cSColin Percival.\" 	From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp
10186c183cSColin Percival.\" $FreeBSD$
11186c183cSColin Percival.\"
12*8ff3cdd1SConrad Meyer.Dd July 9, 2018
13186c183cSColin Percival.Dt SHA256 3
14186c183cSColin Percival.Os
15186c183cSColin Percival.Sh NAME
16*8ff3cdd1SConrad Meyer.Nm SHA224_Init ,
17*8ff3cdd1SConrad Meyer.Nm SHA224_Update ,
18*8ff3cdd1SConrad Meyer.Nm SHA224_Final ,
19*8ff3cdd1SConrad Meyer.Nm SHA224_End ,
20*8ff3cdd1SConrad Meyer.Nm SHA224_File ,
21*8ff3cdd1SConrad Meyer.Nm SHA224_FileChunk ,
22*8ff3cdd1SConrad Meyer.Nm SHA224_Data ,
23186c183cSColin Percival.Nm SHA256_Init ,
24186c183cSColin Percival.Nm SHA256_Update ,
25186c183cSColin Percival.Nm SHA256_Final ,
26186c183cSColin Percival.Nm SHA256_End ,
27186c183cSColin Percival.Nm SHA256_File ,
28186c183cSColin Percival.Nm SHA256_FileChunk ,
29186c183cSColin Percival.Nm SHA256_Data
30*8ff3cdd1SConrad Meyer.Nd calculate the FIPS 180-2 ``SHA-256'' (or SHA-224) message digest
31186c183cSColin Percival.Sh LIBRARY
32186c183cSColin Percival.Lb libmd
33186c183cSColin Percival.Sh SYNOPSIS
34186c183cSColin Percival.In sys/types.h
35*8ff3cdd1SConrad Meyer.In sha224.h
36*8ff3cdd1SConrad Meyer.Ft void
37*8ff3cdd1SConrad Meyer.Fn SHA224_Init "SHA224_CTX *context"
38*8ff3cdd1SConrad Meyer.Ft void
39*8ff3cdd1SConrad Meyer.Fn SHA224_Update "SHA224_CTX *context" "const unsigned char *data" "size_t len"
40*8ff3cdd1SConrad Meyer.Ft void
41*8ff3cdd1SConrad Meyer.Fn SHA224_Final "unsigned char digest[32]" "SHA224_CTX *context"
42*8ff3cdd1SConrad Meyer.Ft "char *"
43*8ff3cdd1SConrad Meyer.Fn SHA224_End "SHA224_CTX *context" "char *buf"
44*8ff3cdd1SConrad Meyer.Ft "char *"
45*8ff3cdd1SConrad Meyer.Fn SHA224_File "const char *filename" "char *buf"
46*8ff3cdd1SConrad Meyer.Ft "char *"
47*8ff3cdd1SConrad Meyer.Fn SHA224_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
48*8ff3cdd1SConrad Meyer.Ft "char *"
49*8ff3cdd1SConrad Meyer.Fn SHA224_Data "const unsigned char *data" "unsigned int len" "char *buf"
50186c183cSColin Percival.In sha256.h
51186c183cSColin Percival.Ft void
52febd1f4dSPawel Jakub Dawidek.Fn SHA256_Init "SHA256_CTX *context"
53186c183cSColin Percival.Ft void
54febd1f4dSPawel Jakub Dawidek.Fn SHA256_Update "SHA256_CTX *context" "const unsigned char *data" "size_t len"
55186c183cSColin Percival.Ft void
56febd1f4dSPawel Jakub Dawidek.Fn SHA256_Final "unsigned char digest[32]" "SHA256_CTX *context"
57186c183cSColin Percival.Ft "char *"
58febd1f4dSPawel Jakub Dawidek.Fn SHA256_End "SHA256_CTX *context" "char *buf"
59186c183cSColin Percival.Ft "char *"
60186c183cSColin Percival.Fn SHA256_File "const char *filename" "char *buf"
61186c183cSColin Percival.Ft "char *"
62186c183cSColin Percival.Fn SHA256_FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
63186c183cSColin Percival.Ft "char *"
64186c183cSColin Percival.Fn SHA256_Data "const unsigned char *data" "unsigned int len" "char *buf"
65186c183cSColin Percival.Sh DESCRIPTION
66186c183cSColin PercivalThe
67186c183cSColin Percival.Li SHA256_
68186c183cSColin Percivalfunctions calculate a 256-bit cryptographic checksum (digest)
69186c183cSColin Percivalfor any number of input bytes.
70186c183cSColin PercivalA cryptographic checksum is a one-way
71186c183cSColin Percivalhash function; that is, it is computationally impractical to find
72186c183cSColin Percivalthe input corresponding to a particular output.
73186c183cSColin PercivalThis net result is
74186c183cSColin Percivala
75186c183cSColin Percival.Dq fingerprint
76186c183cSColin Percivalof the input-data, which does not disclose the actual input.
77186c183cSColin Percival.Pp
78186c183cSColin PercivalThe
79186c183cSColin Percival.Fn SHA256_Init ,
80186c183cSColin Percival.Fn SHA256_Update ,
81186c183cSColin Percivaland
82186c183cSColin Percival.Fn SHA256_Final
83186c183cSColin Percivalfunctions are the core functions.
84186c183cSColin PercivalAllocate an
85186c183cSColin Percival.Vt SHA256_CTX ,
86186c183cSColin Percivalinitialize it with
87186c183cSColin Percival.Fn SHA256_Init ,
88186c183cSColin Percivalrun over the data with
89186c183cSColin Percival.Fn SHA256_Update ,
90186c183cSColin Percivaland finally extract the result using
91186c183cSColin Percival.Fn SHA256_Final .
92186c183cSColin Percival.Pp
93186c183cSColin Percival.Fn SHA256_End
94186c183cSColin Percivalis a wrapper for
95186c183cSColin Percival.Fn SHA256_Final
96186c183cSColin Percivalwhich converts the return value to a 65-character
97186c183cSColin Percival(including the terminating '\e0')
98186c183cSColin Percival.Tn ASCII
99186c183cSColin Percivalstring which represents the 256 bits in hexadecimal.
100186c183cSColin Percival.Pp
101186c183cSColin Percival.Fn SHA256_File
102186c183cSColin Percivalcalculates the digest of a file, and uses
103186c183cSColin Percival.Fn SHA256_End
104186c183cSColin Percivalto return the result.
105186c183cSColin PercivalIf the file cannot be opened, a null pointer is returned.
106186c183cSColin Percival.Fn SHA256_FileChunk
107186c183cSColin Percivalis similar to
108186c183cSColin Percival.Fn SHA256_File ,
109186c183cSColin Percivalbut it only calculates the digest over a byte-range of the file specified,
110186c183cSColin Percivalstarting at
111186c183cSColin Percival.Fa offset
112186c183cSColin Percivaland spanning
113186c183cSColin Percival.Fa length
114186c183cSColin Percivalbytes.
115186c183cSColin PercivalIf the
116186c183cSColin Percival.Fa length
117186c183cSColin Percivalparameter is specified as 0, or more than the length of the remaining part
118186c183cSColin Percivalof the file,
119186c183cSColin Percival.Fn SHA256_FileChunk
120186c183cSColin Percivalcalculates the digest from
121186c183cSColin Percival.Fa offset
122186c183cSColin Percivalto the end of file.
123186c183cSColin Percival.Fn SHA256_Data
124186c183cSColin Percivalcalculates the digest of a chunk of data in memory, and uses
125186c183cSColin Percival.Fn SHA256_End
126186c183cSColin Percivalto return the result.
127186c183cSColin Percival.Pp
128186c183cSColin PercivalWhen using
129186c183cSColin Percival.Fn SHA256_End ,
130186c183cSColin Percival.Fn SHA256_File ,
131186c183cSColin Percivalor
132186c183cSColin Percival.Fn SHA256_Data ,
133186c183cSColin Percivalthe
134186c183cSColin Percival.Fa buf
135186c183cSColin Percivalargument can be a null pointer, in which case the returned string
136186c183cSColin Percivalis allocated with
137186c183cSColin Percival.Xr malloc 3
138186c183cSColin Percivaland subsequently must be explicitly deallocated using
139186c183cSColin Percival.Xr free 3
140186c183cSColin Percivalafter use.
141186c183cSColin PercivalIf the
142186c183cSColin Percival.Fa buf
143186c183cSColin Percivalargument is non-null it must point to at least 65 characters of buffer space.
144*8ff3cdd1SConrad Meyer.Pp
145*8ff3cdd1SConrad MeyerSHA224 is identical SHA256, except it has slightly different initialization
146*8ff3cdd1SConrad Meyervectors, and is truncated to a shorter digest.
147186c183cSColin Percival.Sh SEE ALSO
148186c183cSColin Percival.Xr md4 3 ,
149186c183cSColin Percival.Xr md5 3 ,
150186c183cSColin Percival.Xr ripemd 3 ,
151b468a9ffSAllan Jude.Xr sha 3 ,
152b468a9ffSAllan Jude.Xr sha512 3 ,
153b468a9ffSAllan Jude.Xr skein 3
154186c183cSColin Percival.Sh HISTORY
155186c183cSColin PercivalThese functions appeared in
15602d98cd4SColin Percival.Fx 6.0 .
157186c183cSColin Percival.Sh AUTHORS
158186c183cSColin PercivalThe core hash routines were implemented by Colin Percival based on
159186c183cSColin Percivalthe published
160186c183cSColin Percival.Tn FIPS 180-2
161186c183cSColin Percivalstandard.
162186c183cSColin Percival.Sh BUGS
163186c183cSColin PercivalNo method is known to exist which finds two files having the same hash value,
164186c183cSColin Percivalnor to find a file with a specific hash value.
165186c183cSColin PercivalThere is on the other hand no guarantee that such a method does not exist.
166