1 .\" $NetBSD: sha1.3,v 1.4 2009/10/22 01:38:18 snj Exp $
2 .\" $OpenBSD: sha1.3,v 1.9 1998/03/07 22:18:12 millert Exp $
4 .\" Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
6 .\" Permission to use, copy, modify, and distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 .\" See http://csrc.nist.gov/fips/fip180-1.txt for the detailed standard
31 .Nd calculate the NIST Secure Hash Algorithm
36 .Fn SHA1Init "SHA1_CTX *context"
38 .Fn SHA1Update "SHA1_CTX *context" "const uint8_t *data" "u_int len"
40 .Fn SHA1Final "uint8_t digest[20]" "SHA1_CTX *context"
42 .Fn SHA1Transform "uint32_t state[5]" "uint8_t buffer[64]"
44 .Fn SHA1End "SHA1_CTX *context" "char *buf"
46 .Fn SHA1File "char *filename" "char *buf"
48 .Fn SHA1Data "uint8_t *data" "size_t len" "char *buf"
50 The SHA1 functions implement the NIST Secure Hash Algorithm (SHA-1),
52 SHA-1 is used to generate a condensed representation
53 of a message called a message digest.
55 message less than 2^64 bits as input and produces a 160-bit digest
56 suitable for use as a digital signature.
58 The SHA1 functions are considered to be more secure than the
62 functions with which they share a similar interface.
66 function initializes a SHA1_CTX
78 to the SHA1_CTX specified by
81 is called when all data has been added via
83 and stores a message digest in the
86 When a null pointer is passed to
88 as first argument only the final padding will be applied and the
89 current context can still be used with
96 to hash 512-bit blocks and forms the core of the algorithm.
97 Most programs should use the interface provided by
108 function is a front end for
110 which converts the digest into an
112 representation of the 160 bit digest in hexadecimal.
116 function calculates the digest for a file and returns the result via
120 is unable to open the file a NULL pointer is returned.
125 calculates the digest of an arbitrary string and returns the result via
135 parameter should either be a string of at least 41 characters in
136 size or a NULL pointer.
137 In the latter case, space will be dynamically
140 and should be freed using
142 when it is no longer needed.
144 The follow code fragment will calculate the digest for
145 the string "abc" which is ``0xa9993e36476816aba3e25717850c26c9cd0d89d''.
146 .Bd -literal -offset indent
155 SHA1Update(\*[Am]sha, (uint8_t *)buf, n);
156 SHA1Final(results, \*[Am]sha);
158 /* Print the digest as one long hex value */
160 for (n = 0; n \*[Lt] 20; n++)
161 printf("%02x", results[n]);
165 Alternately, the helper functions could be used in the following way:
166 .Bd -literal -offset indent
171 printf("0x%s", SHA1Data(buf, strlen(buf), output));
181 .%T The Secure Hash Standard
185 The SHA-1 functions appeared in
188 This implementation of SHA-1 was written by Steve Reid.
195 helper functions are derived from code written by Poul-Henning Kamp.
197 This implementation of SHA-1 has not been validated by NIST
198 and as such is not in official compliance with the standard.
200 If a message digest is to be copied to a multi-byte type (ie:
201 an array of five 32-bit integers) it will be necessary to
202 perform byte swapping on little endian machines such as the i386, alpha,