Initial revision
[LeanCalc.git] / calc / calc / shs.h
1 /*
2  * shs - old Secure Hash Standard
3  *
4  **************************************************************************
5  * This version implements the old Secure Hash Algorithm specified by     *
6  * (FIPS Pub 180).  This version is kept for backward compatibility with  *
7  * shs version 2.10.1.  See the shs utility for the new standard.         *
8  **************************************************************************
9  *
10  * Written 2 September 1992, Peter C. Gutmann.
11  *
12  * This file was Modified by:
13  *
14  *      Landon Curt Noll
15  *      http://www.isthe.com/chongo/
16  *
17  *      chongo <was here> /\../\
18  *
19  * This code has been placed in the public domain.  Please do not
20  * copyright this code.
21  *
22  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH  REGARD  TO
23  * THIS  SOFTWARE,  INCLUDING  ALL IMPLIED WARRANTIES OF MER-
24  * CHANTABILITY AND FITNESS.  IN NO EVENT SHALL  LANDON  CURT
25  * NOLL  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
26  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM  LOSS  OF
27  * USE,  DATA  OR  PROFITS, WHETHER IN AN ACTION OF CONTRACT,
28  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR  IN
29  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30  *
31  * @(#) $Revision$
32  * @(#) $Id$
33  * @(#) $Source$
34  *
35  * This file is not covered under version 2.1 of the GNU LGPL.
36  */
37
38
39 #if !defined(__SHS_H__)
40 #define __SHS_H__
41
42
43 /* SHS_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */
44 #define SHS_CHUNKSIZE (1<<6)
45 #define SHS_CHUNKWORDS (SHS_CHUNKSIZE/sizeof(USB32))
46
47 /* SHS_DIGESTSIZE is a the length of the digest as defined by the algorithm */
48 #define SHS_DIGESTSIZE (20)
49 #define SHS_DIGESTWORDS (SHS_DIGESTSIZE/sizeof(USB32))
50
51 /* SHS_LOW - where low 32 bits of 64 bit count is stored during final */
52 #define SHS_LOW 15
53
54 /* SHS_HIGH - where high 32 bits of 64 bit count is stored during final */
55 #define SHS_HIGH 14
56
57 /*
58  * The structure for storing SHS info
59  *
60  * We will assume that bit count is a multiple of 8.
61  */
62 typedef struct {
63         USB32 digest[SHS_DIGESTWORDS];  /* message digest */
64         USB32 countLo;                  /* 64 bit count: bits 3-34 */
65         USB32 countHi;                  /* 64 bit count: bits 35-63 */
66         USB32 datalen;                  /* length of data in data */
67         USB32 data[SHS_CHUNKWORDS];     /* SHS chunk buffer */
68 } SHS_INFO;
69
70 /*
71  * SHSCOUNT(SHS_INFO*, USB32) - update the 64 bit count in an SHS_INFO
72  *
73  * We will count bytes and convert to bit count during the final
74  * transform.  This assumes that the count is < 2^32.
75  */
76 #define SHSCOUNT(shsinfo, count) {                                      \
77         USB32 tmp_countLo;                                              \
78         tmp_countLo = (shsinfo)->countLo;                               \
79         if (((shsinfo)->countLo += (count)) < tmp_countLo) {            \
80                 (shsinfo)->countHi++;                                   \
81         }                                                               \
82 }
83
84
85 #endif /* !__SHS_H__ */