1 /* @(#)sha1.h	1.4 10/08/27 2010 J. Schilling */
2 /*
3  * SHA1 hash code taken from OpenBSD
4  *
5  * Portions Copyright (c) 2010 J. Schilling
6  */
7 
8 /*	$OpenBSD: sha1.h,v 1.23 2004/06/22 01:57:30 jfb Exp $	*/
9 
10 /*
11  * SHA-1 in C
12  * By Steve Reid <steve@edmweb.com>
13  * 100% Public Domain
14  */
15 
16 #ifndef	_SCHILY_SHA1_H
17 #define	_SCHILY_SHA1_H
18 
19 #ifndef _SCHILY_MCONFIG_H
20 #include <schily/mconfig.h>
21 #endif
22 #ifndef _SCHILY_UTYPES_H
23 #include <schily/utypes.h>
24 #endif
25 
26 #define	SHA1_BLOCK_LENGTH		64
27 #define	SHA1_DIGEST_LENGTH		20
28 #define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
29 
30 typedef struct {
31 	UInt32_t state[5];
32 	UInt32_t count[2];
33 	UInt8_t	 buffer[SHA1_BLOCK_LENGTH];
34 } SHA1_CTX;
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 extern	void	SHA1Init	__PR((SHA1_CTX *));
41 extern	void	SHA1Pad		__PR((SHA1_CTX *));
42 extern	void	SHA1Transform	__PR((UInt32_t [5],
43 					const UInt8_t [SHA1_BLOCK_LENGTH]));
44 extern	void	SHA1Update	__PR((SHA1_CTX *, const UInt8_t *, size_t));
45 extern	void	SHA1Final	__PR((UInt8_t [SHA1_DIGEST_LENGTH],
46 					SHA1_CTX *));
47 extern	char	*SHA1End	__PR((SHA1_CTX *, char *));
48 extern	char	*SHA1File	__PR((const char *, char *));
49 extern	char	*SHA1FileChunk	__PR((const char *, char *, off_t, off_t));
50 extern	char	*SHA1Data	__PR((const UInt8_t *, size_t, char *));
51 
52 #ifdef	__cplusplus
53 }
54 #endif
55 
56 #define	HTONDIGEST(x) do {                                              \
57 	x[0] = htonl(x[0]);                                             \
58 	x[1] = htonl(x[1]);                                             \
59 	x[2] = htonl(x[2]);                                             \
60 	x[3] = htonl(x[3]);                                             \
61 	x[4] = htonl(x[4]); } while (0)
62 
63 #define	NTOHDIGEST(x) do {                                              \
64 	x[0] = ntohl(x[0]);                                             \
65 	x[1] = ntohl(x[1]);                                             \
66 	x[2] = ntohl(x[2]);                                             \
67 	x[3] = ntohl(x[3]);                                             \
68 	x[4] = ntohl(x[4]); } while (0)
69 
70 #endif /* _SCHILY_SHA1_H */
71