1/********************************************************************\
2 *
3 *      FILE:     rmd160.h
4 *
5 *      CONTENTS: Header file for a sample C-implementation of the
6 *                RIPEMD-160 hash-function.
7 *      TARGET:   any computer with an ANSI C compiler
8 *
9 *      AUTHOR:   Antoon Bosselaers, ESAT-COSIC
10 *      DATE:     1 March 1996
11 *      VERSION:  1.0
12 *
13 *      Copyright (c) Katholieke Universiteit Leuven
14 *      1996, All Rights Reserved
15 *
16\********************************************************************/
17/* AKU:
18 * <> added __alpha,
19 * <> unique prefix for function names
20 * <> using tcl.h, _ANSI_ARGS_
21 */
22
23#ifndef  RMD160H           /* make sure this file is read only once */
24#define  RMD160H
25
26/********************************************************************/
27
28#include <tcl.h>
29
30/* typedef 8, 16 and 32 bit types, resp.  */
31/* adapt these, if necessary,
32   for your operating system and compiler */
33typedef    unsigned char        byte;   /* unsigned 8-bit integer */
34typedef    unsigned short       word;   /* unsigned 16-bit integer */
35
36#if defined(__alpha) || defined(__LP64__)
37typedef    unsigned int         dword;  /* unsigned 32-bit integer (AXP) */
38#else
39typedef    unsigned long        dword;  /* unsigned 32-bit integer */
40#endif
41
42/********************************************************************/
43
44/* macro definitions */
45
46/* collect four bytes into one word: */
47#define BYTES_TO_DWORD(strptr)                    \
48            (((dword) *((strptr)+3) << 24) | \
49             ((dword) *((strptr)+2) << 16) | \
50             ((dword) *((strptr)+1) <<  8) | \
51             ((dword) *(strptr)))
52
53/* ROL(x, n) cyclically rotates x over n bits to the left */
54/* x must be of an unsigned 32 bits type and 0 <= n < 32. */
55#define ROL(x, n)        (((x) << (n)) | ((x) >> (32-(n))))
56
57/* the three basic functions F(), G() and H() */
58#define F(x, y, z)        ((x) ^ (y) ^ (z))
59#define G(x, y, z)        (((x) & (y)) | (~(x) & (z)))
60#define H(x, y, z)        (((x) | ~(y)) ^ (z))
61#define I(x, y, z)        (((x) & (z)) | ((y) & ~(z)))
62#define J(x, y, z)        ((x) ^ ((y) | ~(z)))
63
64/* the eight basic operations FF() through III() */
65#define FF(a, b, c, d, e, x, s)        {\
66      (a) += F((b), (c), (d)) + (x);\
67      (a) = ROL((a), (s)) + (e);\
68      (c) = ROL((c), 10);\
69   }
70#define GG(a, b, c, d, e, x, s)        {\
71      (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
72      (a) = ROL((a), (s)) + (e);\
73      (c) = ROL((c), 10);\
74   }
75#define HH(a, b, c, d, e, x, s)        {\
76      (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
77      (a) = ROL((a), (s)) + (e);\
78      (c) = ROL((c), 10);\
79   }
80#define II(a, b, c, d, e, x, s)        {\
81      (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
82      (a) = ROL((a), (s)) + (e);\
83      (c) = ROL((c), 10);\
84   }
85#define JJ(a, b, c, d, e, x, s)        {\
86      (a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
87      (a) = ROL((a), (s)) + (e);\
88      (c) = ROL((c), 10);\
89   }
90#define FFF(a, b, c, d, e, x, s)        {\
91      (a) += F((b), (c), (d)) + (x);\
92      (a) = ROL((a), (s)) + (e);\
93      (c) = ROL((c), 10);\
94   }
95#define GGG(a, b, c, d, e, x, s)        {\
96      (a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
97      (a) = ROL((a), (s)) + (e);\
98      (c) = ROL((c), 10);\
99   }
100#define HHH(a, b, c, d, e, x, s)        {\
101      (a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
102      (a) = ROL((a), (s)) + (e);\
103      (c) = ROL((c), 10);\
104   }
105#define III(a, b, c, d, e, x, s)        {\
106      (a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
107      (a) = ROL((a), (s)) + (e);\
108      (c) = ROL((c), 10);\
109   }
110#define JJJ(a, b, c, d, e, x, s)        {\
111      (a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
112      (a) = ROL((a), (s)) + (e);\
113      (c) = ROL((c), 10);\
114   }
115
116/********************************************************************/
117
118/* function prototypes */
119
120void
121ripemd160_MDinit _ANSI_ARGS_ ((dword *MDbuf));
122/*
123 *  initializes MDbuffer to "magic constants"
124 */
125
126void
127ripemd160_compress _ANSI_ARGS_ ((dword *MDbuf, dword *X));
128/*
129 *  the compression function.
130 *  transforms MDbuf using message bytes X[0] through X[15]
131 */
132
133void
134ripemd160_MDfinish _ANSI_ARGS_ ((dword *MDbuf, byte *strptr, dword lswlen, dword mswlen));
135/*
136 *  puts bytes from strptr into X and pad out; appends length
137 *  and finally, compresses the last block(s)
138 *  note: length in bits == 8 * (lswlen + 2^32 mswlen).
139 *  note: there are (lswlen mod 64) bytes left in strptr.
140 */
141
142#endif  /* RMD160H */
143
144/*********************** end of file rmd160.h ***********************/
145
146