if test "$PHP_HASH" != "no"; then
AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
+
+ AC_CHECK_SIZEOF(short, 2)
+ AC_CHECK_SIZEOF(int, 4)
+ AC_CHECK_SIZEOF(long, 4)
+ AC_CHECK_SIZEOF(long long, 8)
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
hash_crc32.c"
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
- php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h"
+ php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_types.h"
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared)
ifdef([PHP_INSTALL_HEADERS], [
PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len)
{
- php_uint32 i, s[2] = { context->state & 0xffff, (context->state >> 16) & 0xffff };
+ php_hash_uint32 i, s[2] = { context->state & 0xffff, (context->state >> 16) & 0xffff };
for (i = 0; i < len; ++i) {
s[0] = (s[0] + input[i]) % 65521;
AA(v, l, r); \
}
-static inline void Gost(php_uint32 state[8], php_uint32 data[8])
+static inline void Gost(php_hash_uint32 state[8], php_hash_uint32 data[8])
{
int i;
- php_uint32 l, r, t, key[8], u[8], v[8], w[8], s[8], *h = state, *m = data;
+ php_hash_uint32 l, r, t, key[8], u[8], v[8], w[8], s[8], *h = state, *m = data;
memcpy(u, state, sizeof(u));
memcpy(v, data, sizeof(v));
static inline void GostTransform(PHP_GOST_CTX *context, const unsigned char input[32])
{
int i, j;
- php_uint32 data[8], temp = 0, save = 0;
+ php_hash_uint32 data[8], temp = 0, save = 0;
for (i = 0, j = 0; i < 8; ++i, j += 4) {
- data[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
+ data[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
+ (((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
save = context->state[i + 8];
context->state[i + 8] += data[i] + temp;
temp = ((context->state[i + 8] < data[i]) || (context->state[i + 8] < save)) ? 1 : 0;
memset(context, 0, sizeof(*context));
}
-static const php_uint32 MAX32 = 0xffffffffLU;
+static const php_hash_uint32 MAX32 = 0xffffffffLU;
PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *context, const unsigned char *input, size_t len)
{
PHP_HASH_API void PHP_GOSTFinal(unsigned char digest[32], PHP_GOST_CTX *context)
{
- php_uint32 i, j, l[8] = {0};
+ php_hash_uint32 i, j, l[8] = {0};
if (context->length) {
GostTransform(context, context->buffer);
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-static php_uint32 D0[8] = {
+static php_hash_uint32 D0[8] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89 };
-static php_uint32 K2[32] = {
+static php_hash_uint32 K2[32] = {
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
0x9216D5D9, 0x8979FB1B, 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69,
0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5 };
-static php_uint32 K3[32] = {
+static php_hash_uint32 K3[32] = {
0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E,
0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 0xE65525F3, 0xAA55AB94,
0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993,
0xB3EE1411, 0x636FBC2A, 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C };
-static php_uint32 K4[32] = {
+static php_hash_uint32 K4[32] = {
0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 0x61D809CC, 0xFB21A991,
0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5,
0x0F6D6FF3, 0x83F44239, 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A,
0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3, 0x6EEF0B6C, 0x137A3BE4 };
-static php_uint32 K5[32] = {
+static php_hash_uint32 K5[32] = {
0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4,
0x7D84A5C3, 0x3B8B5EBE, 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706,
0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, 0x075372C9, 0x80991B7B,
7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0 };
/* {{{ Encode
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
+ Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
a multiple of 4.
*/
-static void Encode(unsigned char *output, php_uint32 *input, unsigned int len)
+static void Encode(unsigned char *output, php_hash_uint32 *input, unsigned int len)
{
unsigned int i, j;
/* }}} */
/* {{{ Decode
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
+ Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
a multiple of 4.
*/
-static void Decode(php_uint32 *output, const unsigned char *input, unsigned int len)
+static void Decode(php_hash_uint32 *output, const unsigned char *input, unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
- output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
+ output[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
+ (((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
}
}
/* }}} */
/* {{{ PHP_3HAVALTransform
*/
-static void PHP_3HAVALTransform(php_uint32 state[8], const unsigned char block[128])
+static void PHP_3HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
{
- php_uint32 E[8];
- php_uint32 x[32];
+ php_hash_uint32 E[8];
+ php_hash_uint32 x[32];
int i;
Decode(x, block, 128);
/* {{{ PHP_4HAVALTransform
*/
-static void PHP_4HAVALTransform(php_uint32 state[8], const unsigned char block[128])
+static void PHP_4HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
{
- php_uint32 E[8];
- php_uint32 x[32];
+ php_hash_uint32 E[8];
+ php_hash_uint32 x[32];
int i;
Decode(x, block, 128);
/* {{{ PHP_5HAVALTransform
*/
-static void PHP_5HAVALTransform(php_uint32 state[8], const unsigned char block[128])
+static void PHP_5HAVALTransform(php_hash_uint32 state[8], const unsigned char block[128])
{
- php_uint32 E[8];
- php_uint32 x[32];
+ php_hash_uint32 E[8];
+ php_hash_uint32 x[32];
int i;
Decode(x, block, 128);
/* Compute number of bytes mod 128 */
index = (unsigned int) ((context->count[0] >> 3) & 0x7F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3)) < ((php_uint32) inputLen << 3)) {
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
context->count[1]++;
}
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 128 - index;
#define S43 15
#define S44 21
-static void MD5Transform(php_uint32[4], const unsigned char[64]);
-static void Encode(unsigned char *, php_uint32 *, unsigned int);
-static void Decode(php_uint32 *, const unsigned char *, unsigned int);
+static void MD5Transform(php_hash_uint32[4], const unsigned char[64]);
+static void Encode(unsigned char *, php_hash_uint32 *, unsigned int);
+static void Decode(php_hash_uint32 *, const unsigned char *, unsigned int);
static unsigned char PADDING[64] =
{
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (php_uint32)(ac); \
+ (a) += F ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (php_uint32)(ac); \
+ (a) += G ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (php_uint32)(ac); \
+ (a) += H ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (php_uint32)(ac); \
+ (a) += I ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3))
- < ((php_uint32) inputLen << 3))
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3))
+ < ((php_hash_uint32) inputLen << 3))
context->count[1]++;
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 64 - index;
* MD5 basic transformation. Transforms state based on block.
*/
static void MD5Transform(state, block)
-php_uint32 state[4];
+php_hash_uint32 state[4];
const unsigned char block[64];
{
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
Decode(x, block, 64);
/* }}} */
/* {{{ Encode
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
+ Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
a multiple of 4.
*/
static void Encode(output, input, len)
unsigned char *output;
-php_uint32 *input;
+php_hash_uint32 *input;
unsigned int len;
{
unsigned int i, j;
/* }}} */
/* {{{ Decode
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
+ Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
a multiple of 4.
*/
static void Decode(output, input, len)
-php_uint32 *output;
+php_hash_uint32 *output;
const unsigned char *input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
+ output[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
+ (((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
}
/* }}} */
#define F3(x,y,z) (((x) & (z)) | ((y) & (~(z))))
#define F4(x,y,z) ((x) ^ ((y) | (~(z))))
-static php_uint32 K_values[5] = { 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E };
-static php_uint32 KK_values[4] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x00000000 };
-static php_uint32 KK160_values[5] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000 };
+static php_hash_uint32 K_values[5] = { 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E };
+static php_hash_uint32 KK_values[4] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x00000000 };
+static php_hash_uint32 KK160_values[5] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000 };
#define K(n) K_values[ (n) >> 4]
#define KK(n) KK_values[(n) >> 4]
#define ROL(n, x) (((x) << n) | ((x) >> (32 - n)))
/* {{{ RIPEMDDecode
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
+ Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
a multiple of 4.
*/
-static void RIPEMDDecode(php_uint32 *output, const unsigned char *input, unsigned int len)
+static void RIPEMDDecode(php_hash_uint32 *output, const unsigned char *input, unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((php_uint32) input[j + 0]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
+ output[i] = ((php_hash_uint32) input[j + 0]) | (((php_hash_uint32) input[j + 1]) << 8) |
+ (((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
}
/* }}} */
/* {{{ RIPEMD128Transform
* ripemd128 basic transformation. Transforms state based on block.
*/
-static void RIPEMD128Transform(php_uint32 state[4], const unsigned char block[64])
+static void RIPEMD128Transform(php_hash_uint32 state[4], const unsigned char block[64])
{
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3];
- php_uint32 aa = state[0], bb = state[1], cc = state[2], dd = state[3];
- php_uint32 tmp, x[16];
+ php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3];
+ php_hash_uint32 aa = state[0], bb = state[1], cc = state[2], dd = state[3];
+ php_hash_uint32 tmp, x[16];
int j;
RIPEMDDecode(x, block, 64);
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3)) < ((php_uint32) inputLen << 3)) {
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
context->count[1]++;
}
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 64 - index;
/* {{{ RIPEMD160Transform
* ripemd160 basic transformation. Transforms state based on block.
*/
-static void RIPEMD160Transform(php_uint32 state[5], const unsigned char block[64])
+static void RIPEMD160Transform(php_hash_uint32 state[5], const unsigned char block[64])
{
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
- php_uint32 aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4];
- php_uint32 tmp, x[16];
+ php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
+ php_hash_uint32 aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4];
+ php_hash_uint32 tmp, x[16];
int j;
RIPEMDDecode(x, block, 64);
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3)) < ((php_uint32) inputLen << 3)) {
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
context->count[1]++;
}
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 64 - index;
};
/* {{{ RIPEMDEncode
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
+ Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
a multiple of 4.
*/
-static void RIPEMDEncode(unsigned char *output, php_uint32 *input, unsigned int len)
+static void RIPEMDEncode(unsigned char *output, php_hash_uint32 *input, unsigned int len)
{
unsigned int i, j;
D.J.Bernstein
*/
-static void Salsa10(php_uint32 x[16], php_uint32 in[16])
+static void Salsa10(php_hash_uint32 x[16], php_hash_uint32 in[16])
{
int i;
D.J.Bernstein
*/
-static void Salsa20(php_uint32 x[16], php_uint32 in[16])
+static void Salsa20(php_hash_uint32 x[16], php_hash_uint32 in[16])
{
int i;
static inline void SalsaTransform(PHP_SALSA_CTX *context, const unsigned char input[64])
{
- php_uint32 i, j, a[16];
+ php_hash_uint32 i, j, a[16];
#if 0
fprintf(stderr, "> INPUT: %.*s\n", 64, input);
#endif
for (i = 0, j = 0; j < 64; i++, j += 4) {
- a[i] = ((php_uint32) input[j + 3]) | (((php_uint32) input[j + 2]) << 8) |
- (((php_uint32) input[j + 1]) << 16) | (((php_uint32) input[j]) << 24);
+ a[i] = ((php_hash_uint32) input[j + 3]) | (((php_hash_uint32) input[j + 2]) << 8) |
+ (((php_hash_uint32) input[j + 1]) << 16) | (((php_hash_uint32) input[j]) << 24);
}
if (!context->init) {
PHP_HASH_API void PHP_SALSAFinal(unsigned char digest[64], PHP_SALSA_CTX *context)
{
- php_uint32 i, j;
+ php_hash_uint32 i, j;
if (context->length) {
SalsaTransform(context, context->buffer);
#include "php_hash.h"
#include "php_hash_sha.h"
-#if defined(SIZEOF_LONG) && SIZEOF_LONG >= 8
-#define L64(n) (n)
-#else
-# ifdef PHP_WIN32
-#define L64(n) (n##i64)
-# else
-#define L64(n) (n##LL)
-# endif
-#endif
-
static unsigned char PADDING[128] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
/* {{{ SHAEncode32
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
+ Encodes input (php_hash_uint32) into output (unsigned char). Assumes len is
a multiple of 4.
*/
-static void SHAEncode32(unsigned char *output, php_uint32 *input, unsigned int len)
+static void SHAEncode32(unsigned char *output, php_hash_uint32 *input, unsigned int len)
{
unsigned int i, j;
/* {{{ SHADecode32
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
+ Decodes input (unsigned char) into output (php_hash_uint32). Assumes len is
a multiple of 4.
*/
-static void SHADecode32(php_uint32 *output, const unsigned char *input, unsigned int len)
+static void SHADecode32(php_hash_uint32 *output, const unsigned char *input, unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((php_uint32) input[j + 3]) | (((php_uint32) input[j + 2]) << 8) |
- (((php_uint32) input[j + 1]) << 16) | (((php_uint32) input[j]) << 24);
+ output[i] = ((php_hash_uint32) input[j + 3]) | (((php_hash_uint32) input[j + 2]) << 8) |
+ (((php_hash_uint32) input[j + 1]) << 16) | (((php_hash_uint32) input[j]) << 24);
}
/* }}} */
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
*/
#define FF(a, b, c, d, e, w) { \
- (e) += F ((b), (c), (d)) + (w) + (php_uint32)(0x5A827999); \
+ (e) += F ((b), (c), (d)) + (w) + (php_hash_uint32)(0x5A827999); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define GG(a, b, c, d, e, w) { \
- (e) += G ((b), (c), (d)) + (w) + (php_uint32)(0x6ED9EBA1); \
+ (e) += G ((b), (c), (d)) + (w) + (php_hash_uint32)(0x6ED9EBA1); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define HH(a, b, c, d, e, w) { \
- (e) += H ((b), (c), (d)) + (w) + (php_uint32)(0x8F1BBCDC); \
+ (e) += H ((b), (c), (d)) + (w) + (php_hash_uint32)(0x8F1BBCDC); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define II(a, b, c, d, e, w) { \
- (e) += I ((b), (c), (d)) + (w) + (php_uint32)(0xCA62C1D6); \
+ (e) += I ((b), (c), (d)) + (w) + (php_hash_uint32)(0xCA62C1D6); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
/* {{{ SHA1Transform
* SHA1 basic transformation. Transforms state based on block.
*/
-static void SHA1Transform(php_uint32 state[5], const unsigned char block[64])
+static void SHA1Transform(php_hash_uint32 state[5], const unsigned char block[64])
{
- php_uint32 a = state[0], b = state[1], c = state[2];
- php_uint32 d = state[3], e = state[4], x[16], tmp;
+ php_hash_uint32 a = state[0], b = state[1], c = state[2];
+ php_hash_uint32 d = state[3], e = state[4], x[16], tmp;
SHADecode32(x, block, 64);
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3))
- < ((php_uint32) inputLen << 3))
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3))
+ < ((php_hash_uint32) inputLen << 3))
context->count[1]++;
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 64 - index;
/* OM1 */
#define SHA256_F5(x) (ROTR32(17,(x)) ^ ROTR32(19,(x)) ^ SHR(10,(x)))
-static php_uint32 SHA256_K[64] = {
+static php_hash_uint32 SHA256_K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
/* {{{ SHA256Transform
* SHA256 basic transformation. Transforms state based on block.
*/
-static void SHA256Transform(php_uint32 state[8], const unsigned char block[64])
+static void SHA256Transform(php_hash_uint32 state[8], const unsigned char block[64])
{
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3];
- php_uint32 e = state[4], f = state[5], g = state[6], h = state[7];
- php_uint32 x[16], T1, T2, W[64];
+ php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3];
+ php_hash_uint32 e = state[4], f = state[5], g = state[6], h = state[7];
+ php_hash_uint32 x[16], T1, T2, W[64];
int i;
SHADecode32(x, block, 64);
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3)) < ((php_uint32) inputLen << 3)) {
+ if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
context->count[1]++;
}
- context->count[1] += ((php_uint32) inputLen >> 29);
+ context->count[1] += ((php_hash_uint32) inputLen >> 29);
partLen = 64 - index;
#endif
#if DBG_SNEFRU
-void ph(php_uint32 h[16])
+void ph(php_hash_uint32 h[16])
{
int i;
for (i = 0; i < 16; i++)
}
#endif
-static inline void Snefru(php_uint32 input[16])
+static inline void Snefru(php_hash_uint32 input[16])
{
static int shifts[4] = {16, 8, 16, 24};
int b, index, rshift, lshift;
- const php_uint32 *t0,*t1;
- php_uint32 SBE,B00,B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B13,B14,B15;
+ const php_hash_uint32 *t0,*t1;
+ php_hash_uint32 SBE,B00,B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B13,B14,B15;
B00 = input[0];
B01 = input[1];
((input[i+2] & 0xff) << 8) | (input[i+3] & 0xff);
}
Snefru(context->state);
- memset(&context->state[8], 0, sizeof(php_uint32) * 8);
+ memset(&context->state[8], 0, sizeof(php_hash_uint32) * 8);
}
PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *context)
memset(context, 0, sizeof(*context));
}
-static const php_uint32 MAX32 = 0xffffffffLU;
+static const php_hash_uint32 MAX32 = 0xffffffffLU;
PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *context, const unsigned char *input, size_t len)
{
PHP_HASH_API void PHP_SNEFRUFinal(unsigned char digest[32], PHP_SNEFRU_CTX *context)
{
- php_uint32 i, j;
+ php_hash_uint32 i, j;
if (context->length) {
SnefruTransform(context, context->buffer);
#define round(a,b,c,x,mul) \
c ^= x; \
a -= t1[(unsigned char)(c)] ^ \
- t2[(unsigned char)(((php_uint32)(c))>>(2*8))] ^ \
+ t2[(unsigned char)(((php_hash_uint32)(c))>>(2*8))] ^ \
t3[(unsigned char)((c)>>(4*8))] ^ \
- t4[(unsigned char)(((php_uint32)((c)>>(4*8)))>>(2*8))] ; \
- b += t4[(unsigned char)(((php_uint32)(c))>>(1*8))] ^ \
- t3[(unsigned char)(((php_uint32)(c))>>(3*8))] ^ \
- t2[(unsigned char)(((php_uint32)((c)>>(4*8)))>>(1*8))] ^ \
- t1[(unsigned char)(((php_uint32)((c)>>(4*8)))>>(3*8))]; \
+ t4[(unsigned char)(((php_hash_uint32)((c)>>(4*8)))>>(2*8))] ; \
+ b += t4[(unsigned char)(((php_hash_uint32)(c))>>(1*8))] ^ \
+ t3[(unsigned char)(((php_hash_uint32)(c))>>(3*8))] ^ \
+ t2[(unsigned char)(((php_hash_uint32)((c)>>(4*8)))>>(1*8))] ^ \
+ t1[(unsigned char)(((php_hash_uint32)((c)>>(4*8)))>>(3*8))]; \
b *= mul;
#define pass(a,b,c,mul) \
unsigned char *bitLength = context->bitlength;
int bufferBits = context->buffer.bits;
int bufferPos = context->buffer.pos;
- php_uint32 b, carry;
+ php_hash_uint32 b, carry;
int i;
/*
*/
php_hash_uint64 value = sourceBits;
for (i = 31, carry = 0; i >= 0 && (carry != 0 || value != L64(0)); i--) {
- carry += bitLength[i] + ((php_uint32)value & 0xff);
+ carry += bitLength[i] + ((php_hash_uint32)value & 0xff);
bitLength[i] = (unsigned char)carry;
carry >>= 8;
value >>= 8;
<file role="src" name="config.w32"/>
<file role="src" name="hash.c"/>
<file role="src" name="php_hash.h"/>
+ <file role="src" name="php_hash_types.h"/>
<file role="src" name="hash_md.c"/>
<file role="src" name="php_hash_md.h"/>
<file role="src" name="hash_sha.c"/>
#define PHP_HASH_H
#include "php.h"
+#include "php_hash_types.h"
#define PHP_HASH_EXTNAME "hash"
#define PHP_HASH_EXTVER "0.1"
#include "ext/standard/basic_functions.h"
typedef struct {
- php_uint32 state;
+ php_hash_uint32 state;
} PHP_ADLER32_CTX;
PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context);
#include "ext/standard/basic_functions.h"
typedef struct {
- php_uint32 state;
+ php_hash_uint32 state;
} PHP_CRC32_CTX;
PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context);
/* $Id$ */
-static const php_uint32 crc32_table[] = { 0x0,
+static const php_hash_uint32 crc32_table[] = { 0x0,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
-static const php_uint32 crc32b_table[] = {
+static const php_hash_uint32 crc32b_table[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
/* GOST context */
typedef struct {
- php_uint32 state[16];
- php_uint32 count[2];
+ php_hash_uint32 state[16];
+ php_hash_uint32 count[2];
unsigned char length;
unsigned char buffer[32];
} PHP_GOST_CTX;
-static const php_uint32 tables[4][256] = {
+static const php_hash_uint32 tables[4][256] = {
{ /* table 1 */
0x00072000LU, 0x00075000LU, 0x00074800LU, 0x00071000LU, 0x00076800LU, 0x00074000LU, 0x00070000LU, 0x00077000LU,
0x00073000LU, 0x00075800LU, 0x00070800LU, 0x00076000LU, 0x00073800LU, 0x00077800LU, 0x00072800LU, 0x00071800LU,
#include "ext/standard/basic_functions.h"
/* HAVAL context. */
typedef struct {
- php_uint32 state[8];
- php_uint32 count[2];
+ php_hash_uint32 state[8];
+ php_hash_uint32 count[2];
unsigned char buffer[128];
char passes;
short output;
- void (*Transform)(php_uint32 state[8], const unsigned char block[128]);
+ void (*Transform)(php_hash_uint32 state[8], const unsigned char block[128]);
} PHP_HAVAL_CTX;
#define PHP_HASH_HAVAL_INIT_DECL(p,b) PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *); \
#include "ext/standard/basic_functions.h"
/* MD5 context. */
typedef struct {
- php_uint32 state[4]; /* state (ABCD) */
- php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ php_hash_uint32 state[4]; /* state (ABCD) */
+ php_hash_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} PHP_MD5_CTX;
/* RIPEMD context. */
typedef struct {
- php_uint32 state[4]; /* state (ABCD) */
- php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ php_hash_uint32 state[4]; /* state (ABCD) */
+ php_hash_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} PHP_RIPEMD128_CTX;
typedef struct {
- php_uint32 state[5]; /* state (ABCD) */
- php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ php_hash_uint32 state[5]; /* state (ABCD) */
+ php_hash_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} PHP_RIPEMD160_CTX;
/* SALSA context */
typedef struct {
- php_uint32 state[16];
+ php_hash_uint32 state[16];
unsigned char init:1;
unsigned char length:7;
unsigned char buffer[64];
- void (*Transform)(php_uint32 state[16], php_uint32 data[16]);
+ void (*Transform)(php_hash_uint32 state[16], php_hash_uint32 data[16]);
} PHP_SALSA_CTX;
#define PHP_SALSAInit PHP_SALSA20Init
/* SHA1 context. */
typedef struct {
- php_uint32 state[5]; /* state (ABCD) */
- php_uint32 count[2]; /* number of bits, modulo 2^64 */
+ php_hash_uint32 state[5]; /* state (ABCD) */
+ php_hash_uint32 count[2]; /* number of bits, modulo 2^64 */
unsigned char buffer[64]; /* input buffer */
} PHP_SHA1_CTX;
/* SHA256 context. */
typedef struct {
- php_uint32 state[8]; /* state */
- php_uint32 count[2]; /* number of bits, modulo 2^64 */
+ php_hash_uint32 state[8]; /* state */
+ php_hash_uint32 count[2]; /* number of bits, modulo 2^64 */
unsigned char buffer[64]; /* input buffer */
} PHP_SHA256_CTX;
PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, unsigned int);
PHP_HASH_API void PHP_SHA256Final(unsigned char[32], PHP_SHA256_CTX *);
-#if defined(SIZEOF_LONG) && SIZEOF_LONG >= 8
-typedef unsigned long php_hash_uint64;
-#else
-# ifdef PHP_WIN32
-typedef unsigned __int64 php_hash_uint64;
-# else
-typedef unsigned long long php_hash_uint64;
-# endif
-#endif
-
/* SHA384 context */
typedef struct {
php_hash_uint64 state[8]; /* state */
/* SNEFRU context */
typedef struct {
- php_uint32 state[16];
- php_uint32 count[2];
+ php_hash_uint32 state[16];
+ php_hash_uint32 count[2];
unsigned char length;
unsigned char buffer[32];
} PHP_SNEFRU_CTX;
/* $Id$ */
-static const php_uint32 tables[16][256]= {
+static const php_hash_uint32 tables[16][256]= {
{ /* Start of S Box 0 */
#ifndef PHP_HASH_TIGER_H
#define PHP_HASH_TIGER_H
-#include "ext/standard/basic_functions.h"
-
-#if defined(SIZEOF_LONG) && (SIZEOF_LONG >= 8)
-# define L64(n) (n##L)
-typedef unsigned long php_hash_uint64;
-#else
-# ifdef PHP_WIN32
-# define L64(n) (n##i64)
-typedef unsigned __int64 php_hash_uint64;
-# else
-# define L64(n) (n##LL)
-typedef unsigned long long php_hash_uint64;
-# endif
-#endif
-
/* TIGER context */
typedef struct {
php_hash_uint64 state[3];
--- /dev/null
+
+/* $Id$ */
+
+#ifndef PHP_HASH_TYPES_H
+#define PHP_HASH_TYPES_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef _MSC_VER
+#if SIZEOF_LONG == 8
+#define L64(x) x
+typedef unsigned long php_hash_uint64;
+#if SIZEOF_INT == 4
+typedef unsigned int php_hash_uint32;
+#elif SIZEOF_SHORT == 4
+typedef unsigned short php_hash_uint32;
+#else
+#error "Need a 32bit integer type"
+#endif
+#elif SIZEOF_LONG_LONG == 8
+#define L64(x) x##LL
+typedef unsigned long long php_hash_uint64;
+#if SIZEOF_INT == 4
+typedef unsigned int php_hash_uint32;
+#elif SIZEOF_LONG == 4
+typedef unsigned long php_hash_uint32;
+#else
+#error "Need a 32bit integer type"
+#endif
+#endif
+#else
+#define L64(x) x##i64
+typedef unsigned __int64 php_hash_uint64;
+typedef unsigned __int32 php_hash_uint32;
+#endif
+
+#endif
+
#ifndef PHP_HASH_WHIRLPOOL_H
#define PHP_HASH_WHIRLPOOL_H
-#include "ext/standard/basic_functions.h"
-
-#if defined(SIZEOF_LONG) && (SIZEOF_LONG >= 8)
-# define L64(n) (n##L)
-typedef unsigned long php_hash_uint64;
-#else
-# ifdef PHP_WIN32
-# define L64(n) (n##i64)
-typedef unsigned __int64 php_hash_uint64;
-# else
-# define L64(n) (n##LL)
-typedef unsigned long long php_hash_uint64;
-# endif
-#endif
-
/* WHIRLPOOL context */
typedef struct {
php_hash_uint64 state[8];