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