Skip to content

Commit a278e9a

Browse files
committed
- use php_hash_* types
# ok with everybody?
1 parent 117753d commit a278e9a

28 files changed

+186
-189
lines changed

ext/hash/config.m4

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ PHP_ARG_ENABLE(hash, whether to enable hash support,
66

77
if test "$PHP_HASH" != "no"; then
88
AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
9+
10+
AC_CHECK_SIZEOF(short, 2)
11+
AC_CHECK_SIZEOF(int, 4)
12+
AC_CHECK_SIZEOF(long, 4)
13+
AC_CHECK_SIZEOF(long long, 8)
914

1015
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
1116
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
1217
hash_crc32.c"
1318
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
1419
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
15-
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h"
20+
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_types.h"
1621

1722
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared)
1823
ifdef([PHP_INSTALL_HEADERS], [

ext/hash/hash_adler32.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context)
2929

3030
PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
3131
{
32-
php_uint32 i, s[2] = { context->state & 0xffff, (context->state >> 16) & 0xffff };
32+
php_hash_uint32 i, s[2] = { context->state & 0xffff, (context->state >> 16) & 0xffff };
3333

3434
for (i = 0; i < len; ++i) {
3535
s[0] = (s[0] + input[i]) % 65521;

ext/hash/hash_gost.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@
207207
AA(v, l, r); \
208208
}
209209

210-
static inline void Gost(php_uint32 state[8], php_uint32 data[8])
210+
static inline void Gost(php_hash_uint32 state[8], php_hash_uint32 data[8])
211211
{
212212
int i;
213-
php_uint32 l, r, t, key[8], u[8], v[8], w[8], s[8], *h = state, *m = data;
213+
php_hash_uint32 l, r, t, key[8], u[8], v[8], w[8], s[8], *h = state, *m = data;
214214

215215
memcpy(u, state, sizeof(u));
216216
memcpy(v, data, sizeof(v));
@@ -227,11 +227,11 @@ static inline void Gost(php_uint32 state[8], php_uint32 data[8])
227227
static inline void GostTransform(PHP_GOST_CTX *context, const unsigned char input[32])
228228
{
229229
int i, j;
230-
php_uint32 data[8], temp = 0, save = 0;
230+
php_hash_uint32 data[8], temp = 0, save = 0;
231231

232232
for (i = 0, j = 0; i < 8; ++i, j += 4) {
233-
data[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
234-
(((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
233+
data[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
234+
(((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
235235
save = context->state[i + 8];
236236
context->state[i + 8] += data[i] + temp;
237237
temp = ((context->state[i + 8] < data[i]) || (context->state[i + 8] < save)) ? 1 : 0;
@@ -245,7 +245,7 @@ PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *context)
245245
memset(context, 0, sizeof(*context));
246246
}
247247

248-
static const php_uint32 MAX32 = 0xffffffffLU;
248+
static const php_hash_uint32 MAX32 = 0xffffffffLU;
249249

250250
PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *context, const unsigned char *input, size_t len)
251251
{
@@ -281,7 +281,7 @@ PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *context, const unsigned char *inp
281281

282282
PHP_HASH_API void PHP_GOSTFinal(unsigned char digest[32], PHP_GOST_CTX *context)
283283
{
284-
php_uint32 i, j, l[8] = {0};
284+
php_hash_uint32 i, j, l[8] = {0};
285285

286286
if (context->length) {
287287
GostTransform(context, context->buffer);

ext/hash/hash_haval.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ static unsigned char PADDING[128] ={
3131
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3232
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
3333

34-
static php_uint32 D0[8] = {
34+
static php_hash_uint32 D0[8] = {
3535
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89 };
3636

37-
static php_uint32 K2[32] = {
37+
static php_hash_uint32 K2[32] = {
3838
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
3939
0x9216D5D9, 0x8979FB1B, 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
4040
0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69,
4141
0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5 };
4242

43-
static php_uint32 K3[32] = {
43+
static php_hash_uint32 K3[32] = {
4444
0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E,
4545
0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 0xE65525F3, 0xAA55AB94,
4646
0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993,
4747
0xB3EE1411, 0x636FBC2A, 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C };
4848

49-
static php_uint32 K4[32] = {
49+
static php_hash_uint32 K4[32] = {
5050
0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 0x61D809CC, 0xFB21A991,
5151
0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5,
5252
0x0F6D6FF3, 0x83F44239, 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A,
5353
0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3, 0x6EEF0B6C, 0x137A3BE4 };
5454

55-
static php_uint32 K5[32] = {
55+
static php_hash_uint32 K5[32] = {
5656
0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4,
5757
0x7D84A5C3, 0x3B8B5EBE, 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706,
5858
0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, 0x075372C9, 0x80991B7B,
@@ -95,10 +95,10 @@ static short M7[32] = { 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0,
9595
7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0 };
9696

9797
/* {{{ Encode
98-
Encodes input (php_uint32) into output (unsigned char). Assumes len is
98+
Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
9999
a multiple of 4.
100100
*/
101-
static void Encode(unsigned char *output, php_uint32 *input, unsigned int len)
101+
static void Encode(unsigned char *output, php_hash_uint32 *input, unsigned int len)
102102
{
103103
unsigned int i, j;
104104

@@ -112,16 +112,16 @@ static void Encode(unsigned char *output, php_uint32 *input, unsigned int len)
112112
/* }}} */
113113

114114
/* {{{ Decode
115-
Decodes input (unsigned char) into output (php_uint32). Assumes len is
115+
Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
116116
a multiple of 4.
117117
*/
118-
static void Decode(php_uint32 *output, const unsigned char *input, unsigned int len)
118+
static void Decode(php_hash_uint32 *output, const unsigned char *input, unsigned int len)
119119
{
120120
unsigned int i, j;
121121

122122
for (i = 0, j = 0; j < len; i++, j += 4) {
123-
output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
124-
(((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
123+
output[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
124+
(((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
125125
}
126126
}
127127
/* }}} */
@@ -141,10 +141,10 @@ static void Decode(php_uint32 *output, const unsigned char *input, unsigned int
141141

142142
/* {{{ PHP_3HAVALTransform
143143
*/
144-
static void PHP_3HAVALTransform(php_uint32 state[8], const unsigned char block[128])
144+
static void PHP_3HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
145145
{
146-
php_uint32 E[8];
147-
php_uint32 x[32];
146+
php_hash_uint32 E[8];
147+
php_hash_uint32 x[32];
148148
int i;
149149

150150
Decode(x, block, 128);
@@ -175,10 +175,10 @@ static void PHP_3HAVALTransform(php_uint32 state[8], const unsigned char block[1
175175

176176
/* {{{ PHP_4HAVALTransform
177177
*/
178-
static void PHP_4HAVALTransform(php_uint32 state[8], const unsigned char block[128])
178+
static void PHP_4HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
179179
{
180-
php_uint32 E[8];
181-
php_uint32 x[32];
180+
php_hash_uint32 E[8];
181+
php_hash_uint32 x[32];
182182
int i;
183183

184184
Decode(x, block, 128);
@@ -212,10 +212,10 @@ static void PHP_4HAVALTransform(php_uint32 state[8], const unsigned char block[1
212212

213213
/* {{{ PHP_5HAVALTransform
214214
*/
215-
static void PHP_5HAVALTransform(php_uint32 state[8], const unsigned char block[128])
215+
static void PHP_5HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
216216
{
217-
php_uint32 E[8];
218-
php_uint32 x[32];
217+
php_hash_uint32 E[8];
218+
php_hash_uint32 x[32];
219219
int i;
220220

221221
Decode(x, block, 128);
@@ -288,10 +288,10 @@ PHP_HASH_API void PHP_HAVALUpdate(PHP_HAVAL_CTX *context, const unsigned char *i
288288
/* Compute number of bytes mod 128 */
289289
index = (unsigned int) ((context->count[0] >> 3) & 0x7F);
290290
/* Update number of bits */
291-
if ((context->count[0] += ((php_uint32) inputLen << 3)) < ((php_uint32) inputLen << 3)) {
291+
if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
292292
context->count[1]++;
293293
}
294-
context->count[1] += ((php_uint32) inputLen >> 29);
294+
context->count[1] += ((php_hash_uint32) inputLen >> 29);
295295

296296
partLen = 128 - index;
297297

ext/hash/hash_md.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
162162
#define S43 15
163163
#define S44 21
164164

165-
static void MD5Transform(php_uint32[4], const unsigned char[64]);
166-
static void Encode(unsigned char *, php_uint32 *, unsigned int);
167-
static void Decode(php_uint32 *, const unsigned char *, unsigned int);
165+
static void MD5Transform(php_hash_uint32[4], const unsigned char[64]);
166+
static void Encode(unsigned char *, php_hash_uint32 *, unsigned int);
167+
static void Decode(php_hash_uint32 *, const unsigned char *, unsigned int);
168168

169169
static unsigned char PADDING[64] =
170170
{
@@ -188,22 +188,22 @@ static unsigned char PADDING[64] =
188188
Rotation is separate from addition to prevent recomputation.
189189
*/
190190
#define FF(a, b, c, d, x, s, ac) { \
191-
(a) += F ((b), (c), (d)) + (x) + (php_uint32)(ac); \
191+
(a) += F ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
192192
(a) = ROTATE_LEFT ((a), (s)); \
193193
(a) += (b); \
194194
}
195195
#define GG(a, b, c, d, x, s, ac) { \
196-
(a) += G ((b), (c), (d)) + (x) + (php_uint32)(ac); \
196+
(a) += G ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
197197
(a) = ROTATE_LEFT ((a), (s)); \
198198
(a) += (b); \
199199
}
200200
#define HH(a, b, c, d, x, s, ac) { \
201-
(a) += H ((b), (c), (d)) + (x) + (php_uint32)(ac); \
201+
(a) += H ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
202202
(a) = ROTATE_LEFT ((a), (s)); \
203203
(a) += (b); \
204204
}
205205
#define II(a, b, c, d, x, s, ac) { \
206-
(a) += I ((b), (c), (d)) + (x) + (php_uint32)(ac); \
206+
(a) += I ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
207207
(a) = ROTATE_LEFT ((a), (s)); \
208208
(a) += (b); \
209209
}
@@ -237,10 +237,10 @@ PHP_HASH_API void PHP_MD5Update(PHP_MD5_CTX * context, const unsigned char *inpu
237237
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
238238

239239
/* Update number of bits */
240-
if ((context->count[0] += ((php_uint32) inputLen << 3))
241-
< ((php_uint32) inputLen << 3))
240+
if ((context->count[0] += ((php_hash_uint32) inputLen << 3))
241+
< ((php_hash_uint32) inputLen << 3))
242242
context->count[1]++;
243-
context->count[1] += ((php_uint32) inputLen >> 29);
243+
context->count[1] += ((php_hash_uint32) inputLen >> 29);
244244

245245
partLen = 64 - index;
246246

@@ -299,10 +299,10 @@ PHP_HASH_API void PHP_MD5Final(unsigned char digest[16], PHP_MD5_CTX * context)
299299
* MD5 basic transformation. Transforms state based on block.
300300
*/
301301
static void MD5Transform(state, block)
302-
php_uint32 state[4];
302+
php_hash_uint32 state[4];
303303
const unsigned char block[64];
304304
{
305-
php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
305+
php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
306306

307307
Decode(x, block, 64);
308308

@@ -389,12 +389,12 @@ const unsigned char block[64];
389389
/* }}} */
390390

391391
/* {{{ Encode
392-
Encodes input (php_uint32) into output (unsigned char). Assumes len is
392+
Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
393393
a multiple of 4.
394394
*/
395395
static void Encode(output, input, len)
396396
unsigned char *output;
397-
php_uint32 *input;
397+
php_hash_uint32 *input;
398398
unsigned int len;
399399
{
400400
unsigned int i, j;
@@ -409,19 +409,19 @@ unsigned int len;
409409
/* }}} */
410410

411411
/* {{{ Decode
412-
Decodes input (unsigned char) into output (php_uint32). Assumes len is
412+
Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
413413
a multiple of 4.
414414
*/
415415
static void Decode(output, input, len)
416-
php_uint32 *output;
416+
php_hash_uint32 *output;
417417
const unsigned char *input;
418418
unsigned int len;
419419
{
420420
unsigned int i, j;
421421

422422
for (i = 0, j = 0; j < len; i++, j += 4)
423-
output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
424-
(((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
423+
output[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
424+
(((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
425425
}
426426
/* }}} */
427427

0 commit comments

Comments
 (0)