Mobile API Reference  MicroStrategy 2019
rmd160.h
Go to the documentation of this file.
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 
18 #ifndef RMD160H /* make sure this file is read only once */
19 #define RMD160H
20 
21 /********************************************************************/
22 
23 /* typedef 8 and 32 bit types, resp. */
24 /* adapt these, if necessary,
25  for your operating system and compiler */
26 typedef unsigned char byte;
27 typedef unsigned int dword;
28 
29 
30 /********************************************************************/
31 
32 /* macro definitions */
33 
34 /* collect four bytes into one word: */
35 #define BYTES_TO_DWORD(strptr) \
36  (((dword) *((strptr)+3) << 24) | \
37  ((dword) *((strptr)+2) << 16) | \
38  ((dword) *((strptr)+1) << 8) | \
39  ((dword) *(strptr)))
40 
41 /* ROL(x, n) cyclically rotates x over n bits to the left */
42 /* x must be of an unsigned 32 bits type and 0 <= n < 32. */
43 #define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n))))
44 
45 /* the five basic functions F(), G() and H() */
46 #define F(x, y, z) ((x) ^ (y) ^ (z))
47 #define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
48 #define H(x, y, z) (((x) | ~(y)) ^ (z))
49 #define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
50 #define J(x, y, z) ((x) ^ ((y) | ~(z)))
51 
52 /* the ten basic operations FF() through III() */
53 #define FF(a, b, c, d, e, x, s) {\
54  (a) += F((b), (c), (d)) + (x);\
55  (a) = ROL((a), (s)) + (e);\
56  (c) = ROL((c), 10);\
57  }
58 #define GG(a, b, c, d, e, x, s) {\
59  (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
60  (a) = ROL((a), (s)) + (e);\
61  (c) = ROL((c), 10);\
62  }
63 #define HH(a, b, c, d, e, x, s) {\
64  (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
65  (a) = ROL((a), (s)) + (e);\
66  (c) = ROL((c), 10);\
67  }
68 #define II(a, b, c, d, e, x, s) {\
69  (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
70  (a) = ROL((a), (s)) + (e);\
71  (c) = ROL((c), 10);\
72  }
73 #define JJ(a, b, c, d, e, x, s) {\
74  (a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
75  (a) = ROL((a), (s)) + (e);\
76  (c) = ROL((c), 10);\
77  }
78 #define FFF(a, b, c, d, e, x, s) {\
79  (a) += F((b), (c), (d)) + (x);\
80  (a) = ROL((a), (s)) + (e);\
81  (c) = ROL((c), 10);\
82  }
83 #define GGG(a, b, c, d, e, x, s) {\
84  (a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
85  (a) = ROL((a), (s)) + (e);\
86  (c) = ROL((c), 10);\
87  }
88 #define HHH(a, b, c, d, e, x, s) {\
89  (a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
90  (a) = ROL((a), (s)) + (e);\
91  (c) = ROL((c), 10);\
92  }
93 #define III(a, b, c, d, e, x, s) {\
94  (a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
95  (a) = ROL((a), (s)) + (e);\
96  (c) = ROL((c), 10);\
97  }
98 #define JJJ(a, b, c, d, e, x, s) {\
99  (a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
100  (a) = ROL((a), (s)) + (e);\
101  (c) = ROL((c), 10);\
102  }
103 /********************************************************************/
104 
105 /* function prototypes */
106 
107 void MDinit(dword *MDbuf);
108 /*
109  * initializes MDbuffer to "magic constants"
110  */
111 
112 void compress(dword *MDbuf, const dword *X, bool ibConvert = true);
113 /*
114  * the compression function.
115  * transforms MDbuf using message bytes X[0] through X[15]
116  * perform endian conversion if ibConvert is true
117  */
118 
119 void compressH(dword *MDbuf, const dword *X);
120 /*
121  * The actual transformation is performed with this function.
122  */
123 
124 void MDfinish(dword *MDbuf, const byte *strptr, dword lswlen, dword mswlen);
125 /*
126  * puts bytes from strptr into X and pad out; appends length
127  * and finally, compresses the last block(s)
128  * note: length in bits == 8 * (lswlen + 2^32 mswlen).
129  * note: there are (lswlen mod 64) bytes left in strptr.
130  */
131 
132 #endif /* RMD160H */
133 
134 /*********************** end of file rmd160.h ***********************/
135 
unsigned char byte
Definition: rmd160.h:26
void compress(dword *MDbuf, const dword *X, bool ibConvert=true)
void compressH(dword *MDbuf, const dword *X)
void MDinit(dword *MDbuf)
void MDfinish(dword *MDbuf, const byte *strptr, dword lswlen, dword mswlen)
unsigned int dword
Definition: rmd160.h:27