Initial revision
[LeanCalc.git] / calc / calc / md5.h
1 /*
2  * md5 - RSA Data Security, Inc. MD5 Message-Digest Algorithm
3  *
4  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH  REGARD  TO
5  * THIS  SOFTWARE,  INCLUDING  ALL IMPLIED WARRANTIES OF MER-
6  * CHANTABILITY AND FITNESS.  IN NO EVENT SHALL  LANDON  CURT
7  * NOLL  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
8  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM  LOSS  OF
9  * USE,  DATA  OR  PROFITS, WHETHER IN AN ACTION OF CONTRACT,
10  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR  IN
11  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12  *
13  * @(#) $Revision$
14  * @(#) $Id$
15  * @(#) $Source$
16  *
17  * This file is not covered under version 2.1 of the GNU LGPL.
18  */
19
20 /*
21  ***********************************************************************
22  ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
23  **                                                                   **
24  ** License to copy and use this software is granted provided that    **
25  ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
26  ** Digest Algorithm" in all material mentioning or referencing this  **
27  ** software or this function.                                        **
28  **                                                                   **
29  ** License is also granted to make and use derivative works          **
30  ** provided that such works are identified as "derived from the RSA  **
31  ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
32  ** material mentioning or referencing the derived work.              **
33  **                                                                   **
34  ** RSA Data Security, Inc. makes no representations concerning       **
35  ** either the merchantability of this software or the suitability    **
36  ** of this software for any particular purpose.  It is provided "as  **
37  ** is" without express or implied warranty of any kind.              **
38  **                                                                   **
39  ** These notices must be retained in any copies of any part of this  **
40  ** documentation and/or software.                                    **
41  ***********************************************************************
42  */
43
44 #if !defined(__MD5_H__)
45 #define __MD5_H__
46
47 /* MD5_CHUNKSIZE must be a power of 2 - fixed value defined by the algorithm */
48 #define MD5_CHUNKSIZE   (1<<6)
49 #define MD5_CHUNKWORDS (MD5_CHUNKSIZE/sizeof(USB32))
50
51 /* MD5_DIGESTSIZE is a the length of the digest as defined by the algorithm */
52 #define MD5_DIGESTSIZE  (16)
53 #define MD5_DIGESTWORDS (MD5_DIGESTSIZE/sizeof(USB32))
54
55 /* MD5_LOW - where low 32 bits of 64 bit count is stored during final */
56 #define MD5_LOW 14
57
58 /* MD5_HIGH - where high 32 bits of 64 bit count is stored during final */
59 #define MD5_HIGH 15
60
61 /*
62  * MD5COUNT(MD5_CTX*, USB32) - update the 64 bit count in an MD5_CTX
63  *
64  * We will count bytes and convert to bit count during the final
65  * transform.
66  */
67 #define MD5COUNT(md5info, count) {                                      \
68         USB32 tmp_countLo;                                              \
69         tmp_countLo = (md5info)->countLo;                               \
70         if (((md5info)->countLo += (count)) < tmp_countLo) {            \
71                 (md5info)->countHi++;                                   \
72         }                                                               \
73 }
74
75 /*
76  * Data structure for MD5 (Message-Digest) computation
77  */
78 typedef struct {
79         USB32 digest[MD5_DIGESTWORDS];          /* message digest */
80         USB32 countLo;          /* 64 bit count: bits 3-34 */
81         USB32 countHi;          /* 64 bit count: bits 35-63 (64-66 ignored) */
82         USB32 datalen;          /* length of data in inp.inp_USB8 */
83         USB32 data[MD5_CHUNKWORDS];  /* USB32 chunk buffer */
84 } MD5_CTX;
85
86 #endif /* __MD5_H__ */