modified: makefile
[GalaxyCodeBases.git] / c_cpp / etc / md5_sha / shs1.h
blob0c88eaf9f2080bc510bf263a2d05e6e96be9953a
1 /*
2 * shs1 - new NIST Secure Hash Standard-1 (SHS1)
4 * @(#) $Revision: 13.6 $
5 * @(#) $Id: shs1.h,v 13.6 2010/10/12 21:10:17 chongo Exp $
6 * @(#) $Source: /usr/local/src/cmd/hash/RCS/shs1.h,v $
8 * Written 2 September 1992, Peter C. Gutmann.
10 * This file was written by Landon Curt Noll.
12 * This code has been placed in the public domain. Please do not
13 * copyright this code.
15 * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
17 * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
18 * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
19 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * chongo (was here) /\oo/\
25 * http://www.isthe.com/chongo/index.html
27 * Share and enjoy! :-)
29 * See shs1drvr.c for version and modification history.
32 #if !defined(SHS1_H)
33 #define SHS1_H
35 #include <sys/types.h>
36 #include <sys/stat.h>
39 * our version
41 #define SHS1_VERSION "$Revision: 13.6 $"
44 * These macros are in common with shs.h, shs1.h and md5.h. We use
45 * HASH_MACROS to gaurd against multiple inclusion by external progs
46 * that may want to use multiple hash codes in one module.
48 #if !defined(HASH_MACROS)
49 #define HASH_MACROS
52 * Useful defines/typedefs
54 typedef u_int8_t BYTE; /* must be 1 byte unsigned value */
55 typedef u_int16_t UINT; /* must be 2 byte unsigned value */
56 typedef u_int32_t ULONG; /* must be 4 byte unsigned value */
57 typedef u_int64_t ULLONG; /* must be 8 byte unsigned value */
59 #endif /* HASH_MACROS */
61 /* SHS1_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */
62 #define SHS1_CHUNKSIZE (1<<6)
63 #define SHS1_CHUNKMASK (SHS1_CHUNKSIZE-1)
64 #define SHS1_CHUNKWORDS (SHS1_CHUNKSIZE/sizeof(ULONG))
66 /* SHS1_DIGESTSIZE is a the length of the digest as defined by the algorithm */
67 #define SHS1_DIGESTSIZE (20)
68 #define SHS1_DIGESTWORDS (SHS1_DIGESTSIZE/sizeof(ULONG))
70 /* SHS_HIGH - the ULONG where the 64 bit count of bits processed is stored */
71 #define SHS1_HIGH (SHS1_CHUNKWORDS-2)
73 /* SHS1_BLOCKSIZE is how large a chunk multiStream processes at a time */
74 #define SHS1_BLOCKSIZE (SHS1_CHUNKSIZE<<8)
76 /* SHS1_READSIZE must be a multiple of SHS1_BLOCKSIZE */
77 #define SHS1_READSIZE (SHS1_BLOCKSIZE<<2)
78 #define SHS1_READWORDS (SHS1_READSIZE/sizeof(ULONG))
80 /* maximum part of pre_file used */
81 #define SHS1_MAX_PRE_FILE 32768
84 * SHS1_ROUNDUP(x,y) - round x up to the next multiple of y
86 #define SHS1_ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
89 * SHS1COUNT(SHS1_INFO*, ULONG) - update the 64 bit count in an SHS1_INFO
91 * We will count bytes and convert to bit count during the final
92 * transform.
94 #define SHS1COUNT(shs1info, count) { \
95 ULONG tmp_countLo; \
96 tmp_countLo = (shs1info)->countLo; \
97 if (((shs1info)->countLo += (count)) < tmp_countLo) { \
98 (shs1info)->countHi++; \
99 } \
103 * The structure for storing SHS1 info
105 * We will assume that bit count is a multiple of 8.
107 typedef struct {
108 ULONG digest[SHS1_DIGESTWORDS]; /* message digest */
109 ULLONG octets; /* count of octets processed */
110 ULONG datalen; /* length of data in data */
111 ULONG data[SHS1_CHUNKWORDS]; /* SHS1 chunk buffer */
112 } SHS1_INFO;
115 * elements of the stat structure that we will process
117 struct shs1_stat {
118 dev_t stat_dev;
119 ino_t stat_ino;
120 mode_t stat_mode;
121 nlink_t stat_nlink;
122 uid_t stat_uid;
123 gid_t stat_gid;
124 off_t stat_size;
125 time_t stat_mtime;
126 time_t stat_ctime;
129 /* shs1.c */
130 void shs1Init(SHS1_INFO*);
131 void shs1Transform(ULONG *digest, ULONG *W);
132 void shs1Update(SHS1_INFO*, BYTE*, ULONG);
133 void shs1fullUpdate(SHS1_INFO*, BYTE*, ULONG);
134 void shs1Final(SHS1_INFO*);
135 extern char *shs1_what;
138 * Some external programs use the functions found in shs1.c and shs1io.c.
139 * These routines define SHS1_IO so that such external programs will not
140 * pick up the following declarations.
143 #if !defined(SHS1_IO)
145 /* shs1io.c */
146 void shs1Stream(BYTE*, UINT, FILE*, SHS1_INFO*);
147 void shs1File(BYTE*, UINT, char*, int, SHS1_INFO*);
148 extern ULONG shs1_zero[];
150 /* shs1dual.c */
151 void multiMain(int, char**, BYTE*, UINT, char*, int, UINT);
152 void multiTest(void);
153 extern char *shs1dual_what;
155 /* shs1drvr.c */
156 void shs1Print(int, int, SHS1_INFO*);
157 extern int c_flag;
158 extern int i_flag;
159 extern int q_flag;
160 extern int dot_zero;
161 #endif /* SHS1_IO */
162 extern int debug;
163 extern char *program;
165 #endif /* SHS1_H */