69static const unsigned char PADDING[64] =
71 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
80static void Encode(
unsigned char *output, uint32_t *input,
unsigned int len)
84 for (i = 0,
j = 0;
j <
len; i++,
j += 4) {
85 output[
j] = (
unsigned char) (input[i] & 0xff);
86 output[
j + 1] = (
unsigned char) ((input[i] >> 8) & 0xff);
87 output[
j + 2] = (
unsigned char) ((input[i] >> 16) & 0xff);
88 output[
j + 3] = (
unsigned char) ((input[i] >> 24) & 0xff);
97static void Decode(uint32_t *output,
const unsigned char *input,
unsigned int len)
101 for (i = 0,
j = 0;
j <
len; i++,
j += 4)
102 output[i] = ((uint32_t) input[
j]) | (((uint32_t) input[
j + 1]) << 8) |
103 (((uint32_t) input[
j + 2]) << 16) | (((uint32_t) input[
j + 3]) << 24);
109#define MD4_F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
110#define MD4_G(x,y,z) (((x) & ((y) | (z))) | ((y) & (z)))
111#define MD4_H(x,y,z) ((x) ^ (y) ^ (z))
113#define ROTL32(s,v) (((v) << (s)) | ((v) >> (32 - (s))))
115#define MD4_R1(a,b,c,d,k,s) a = ROTL32(s, a + MD4_F(b,c,d) + x[k])
116#define MD4_R2(a,b,c,d,k,s) a = ROTL32(s, a + MD4_G(b,c,d) + x[k] + 0x5A827999)
117#define MD4_R3(a,b,c,d,k,s) a = ROTL32(s, a + MD4_H(b,c,d) + x[k] + 0x6ED9EBA1)
119static void MD4Transform(uint32_t
state[4],
const unsigned char block[64])
123 Decode(x, block, 64);
193 context->state[0] = 0x67452301;
194 context->state[1] = 0xefcdab89;
195 context->state[2] = 0x98badcfe;
196 context->state[3] = 0x10325476;
207 unsigned int index, partLen;
211 index = (
unsigned int) ((
context->count[0] >> 3) & 0x3F);
214 if ((
context->count[0] += ((uint32_t) inputLen << 3))
215 < ((uint32_t) inputLen << 3))
217 context->count[1] += (uint32_t) (inputLen >> 29);
219 partLen = 64 - index;
223 if (inputLen >= partLen) {
224 memcpy((
unsigned char*) &
context->buffer[index], (
unsigned char*) input, partLen);
227 for (i = partLen; i + 63 < inputLen; i += 64) {
228 MD4Transform(
context->state, &input[i]);
237 memcpy((
unsigned char*) &
context->buffer[index], (
unsigned char*) & input[i], inputLen - i);
247 unsigned char bits[8];
248 unsigned int index, padLen;
251 Encode(bits,
context->count, 8);
255 index = (
unsigned int) ((
context->count[0] >> 3) & 0x3f);
256 padLen = (index < 56) ? (56 - index) : (120 - index);
263 Encode(digest,
context->state, 16);
273static const unsigned char MD2_S[256] = {
274 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19,
275 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202,
276 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18,
277 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, 245, 142, 187, 47, 238, 122,
278 169, 104, 121, 145, 21, 178, 7, 63, 148, 194, 16, 137, 11, 34, 95, 33,
279 128, 127, 93, 154, 90, 144, 50, 39, 53, 62, 204, 231, 191, 247, 151, 3,
280 255, 25, 48, 179, 72, 165, 181, 209, 215, 94, 146, 42, 172, 86, 170, 198,
281 79, 184, 56, 210, 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241,
282 69, 157, 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2,
283 27, 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
284 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, 234, 38,
285 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, 129, 77, 82,
286 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, 8, 12, 189, 177, 74,
287 120, 136, 149, 139, 227, 99, 232, 109, 233, 203, 213, 254, 59, 0, 29, 57,
288 242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10,
289 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 };
298 unsigned char i,
j,t = 0;
300 for(i = 0; i < 16; i++) {
301 context->state[16+i] = block[i];
305 for(i = 0; i < 18; i++) {
306 for(
j = 0;
j < 48;
j++) {
314 for(i = 0; i < 16; i++) {
315 t =
context->checksum[i] ^= MD2_S[block[i] ^ t];
338 while ((
p + 16) <= e) {
346 context->in_buffer = (char) (e -
p);
365 && (
unsigned char) ctx->in_buffer <
sizeof(ctx->buffer)) {
368 return r !=
SUCCESS ? r : -2000;
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
PHP_HASH_API zend_result php_hash_serialize(const php_hashcontext_object *hash, zend_long *magic, zval *zv)
PHP_HASH_API zend_result php_hash_copy(const void *ops, const void *orig_context, void *dest_context)
PHP_HASH_API int php_hash_unserialize_spec(php_hashcontext_object *hash, const zval *zv, const char *spec)
PHP_HASH_API int php_hash_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv)
hash(string $algo, string $data, bool $binary=false, array $options=[])
#define MD4_R2(a, b, c, d, k, s)
const php_hash_ops php_hash_md2_ops
PHP_HASH_API void PHP_MD4Update(PHP_MD4_CTX *context, const unsigned char *input, size_t inputLen)
PHP_HASH_API void PHP_MD2InitArgs(PHP_MD2_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
#define MD4_R3(a, b, c, d, k, s)
PHP_HASH_API void PHP_MD2Update(PHP_MD2_CTX *context, const unsigned char *buf, size_t len)
#define MD4_R1(a, b, c, d, k, s)
PHP_HASH_API void PHP_MD4InitArgs(PHP_MD4_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
const php_hash_ops php_hash_md4_ops
PHP_HASH_API void PHP_MD2Final(unsigned char output[16], PHP_MD2_CTX *context)
const php_hash_ops php_hash_md5_ops
PHP_HASH_API void PHP_MD4Final(unsigned char digest[16], PHP_MD4_CTX *context)
PHPAPI void PHP_MD5InitArgs(PHP_MD5_CTX *ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args)
PHPAPI void PHP_MD5Final(unsigned char *result, PHP_MD5_CTX *ctx)
PHPAPI void PHP_MD5Update(PHP_MD5_CTX *ctx, const void *data, size_t size)
void(* php_hash_final_func_t)(unsigned char *digest, void *context)
struct _php_hashcontext_object php_hashcontext_object
void(* php_hash_init_func_t)(void *context, HashTable *args)
void(* php_hash_update_func_t)(void *context, const unsigned char *buf, size_t count)
struct _php_hash_ops php_hash_ops
#define PHP_HASH_SERIALIZE_MAGIC_SPEC
#define ZEND_ATTRIBUTE_UNUSED
#define ZEND_SECURE_ZERO(var, size)
struct _zend_array HashTable