Skip to content

Commit 950de07

Browse files
author
Ilia Alshanetsky
committed
Added hash extension to PHP 5.1
1 parent 20c3b72 commit 950de07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8373
-0
lines changed

ext/hash/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PHP hash
2+
Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner

ext/hash/EXPERIMENTAL

Whitespace-only changes.

ext/hash/README

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Generic hashing framework for PHP
2+
3+
Simplest usages:
4+
5+
$digest = hash($algoname, $message);
6+
$digest = hash_file($algoname, $filename);
7+
8+
Examples:
9+
10+
$digest = hash('md5', 'The quick brown fox jumped over the lazy dog.');
11+
12+
Feeder usage:
13+
14+
$context = hash_init($algoname);
15+
hash_update($context, $message);
16+
$digest = hash_final($context);
17+
18+
hash(), hash_file(), and hash_final() each support an optional boolean parameter $raw_output which behaves in the same
19+
manner as sha1()'s optional parameter.

ext/hash/bench.php

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/* $Id$ */
3+
4+
/*
5+
This gives rather interesting results :)
6+
7+
Measures on a Notebook P4M-1.7 256MB Windows 2000:
8+
sha1 0.556691
9+
tiger160,3 0.774469
10+
tiger192,3 0.776314
11+
tiger128,3 0.777004
12+
ripemd128 0.896674
13+
sha256 1.011164
14+
md5 1.016032
15+
tiger160,4 1.056617
16+
tiger128,4 1.063101
17+
tiger192,4 1.069258
18+
haval160,3 1.125099
19+
haval128,3 1.125679
20+
haval224,3 1.128017
21+
haval192,3 1.130026
22+
haval256,3 1.134846
23+
ripemd160 1.150693
24+
haval128,4 1.686261
25+
haval192,4 1.687274
26+
haval160,4 1.693091
27+
haval256,4 1.699323
28+
haval224,4 1.743094
29+
haval160,5 2.003452
30+
haval192,5 2.008341
31+
haval256,5 2.009048
32+
haval128,5 2.009555
33+
haval224,5 2.015539
34+
sha384 3.370734
35+
sha512 3.381121
36+
whirlpool 6.912327
37+
snefru 9.268168
38+
39+
Measures on a Desktop P4-2.4 512MB Debian (Linux-2.4):
40+
md5 0.147739
41+
haval128,3 0.317006
42+
haval192,3 0.317524
43+
haval256,3 0.317526
44+
haval160,3 0.323035
45+
haval224,3 0.333318
46+
ripemd128 0.353447
47+
sha1 0.376200
48+
ripemd160 0.413758
49+
sha256 0.435957
50+
haval160,4 0.452357
51+
haval224,4 0.454531
52+
haval128,4 0.458026
53+
haval256,4 0.459051
54+
haval192,4 0.468094
55+
haval128,5 0.524262
56+
haval160,5 0.529573
57+
haval224,5 0.533655
58+
haval256,5 0.534446
59+
haval192,5 0.543726
60+
tiger128,3 0.577975
61+
tiger160,3 0.579951
62+
tiger192,3 0.597111
63+
tiger192,4 0.781408
64+
tiger160,4 0.801243
65+
tiger128,4 0.812239
66+
sha512 1.298627
67+
sha384 1.313607
68+
whirlpool 1.556159
69+
snefru 5.703742
70+
71+
*/
72+
73+
error_reporting(E_ALL&~E_NOTICE);
74+
75+
$data = file_get_contents(__FILE__);
76+
$time = array();
77+
78+
for ($j = 0; $j < 10; $j++) {
79+
foreach (hash_algos() as $algo) {
80+
$start = microtime(true);
81+
for ($i = 0; $i < 1000; $i++) {
82+
hash($algo, $data);
83+
}
84+
$time[$algo] += microtime(true)-$start;
85+
}
86+
}
87+
88+
asort($time, SORT_NUMERIC);
89+
foreach ($time as $a => $t) {
90+
printf("%-12s %02.6f\n", $a, $t);
91+
}
92+
?>

ext/hash/config.m4

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dnl $Id$
2+
dnl config.m4 for extension hash
3+
4+
PHP_ARG_ENABLE(hash, whether to enable hash support,
5+
[ --enable-hash Enable hash support])
6+
7+
if test "$PHP_HASH" != "no"; then
8+
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)
14+
15+
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
16+
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
17+
hash_crc32.c"
18+
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
19+
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
20+
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_types.h"
21+
22+
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared)
23+
ifdef([PHP_INSTALL_HEADERS], [
24+
PHP_INSTALL_HEADERS(ext/hash, $EXT_HASH_HEADERS)
25+
])
26+
fi

ext/hash/config.w32

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
ARG_ENABLE("hash", "enable hash support", "no");
5+
6+
if (PHP_HASH != "no") {
7+
AC_DEFINE('HAVE_HASH_EXT', 1);
8+
EXTENSION("hash", "hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c "
9+
+ "hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c "
10+
+ "hash_adler32.c hash_crc32.c");
11+
}
12+

0 commit comments

Comments
 (0)