Skip to content

Commit bf34442

Browse files
committed
Implemented RFC "Always available hash extension"
1 parent 3e2549d commit bf34442

File tree

5 files changed

+87
-72
lines changed

5 files changed

+87
-72
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #76480 (Use curl_multi_wait() so that timeouts are respected).
77
(Pierrick)
88

9+
- Hash:
10+
. The hash extension is now an integral part of PHP and cannot be disabled
11+
as per RFC: https://wiki.php.net/rfc/permanent_hash_ext. (Kalle)
12+
913
- Intl:
1014
. Lifted requirements to ICU ≥ 50.1. (cmb)
1115
. Changed default of $variant parameter of idn_to_ascii() and idn_to_utf8().

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ PHP 7.4 UPGRADE NOTES
7575
9. Other Changes to Extensions
7676
========================================
7777

78+
- Hash:
79+
. The hash extension cannot be disabled anymore and is always an integral
80+
part of any PHP build, similar to the date extension.
81+
7882
- Intl:
7983
. The Intl extension now requires at least ICU 50.1.
8084

UPGRADING.INTERNALS

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ PHP 7.4 INTERNALS UPGRADE NOTES
77
d. Removed zend_check_private()
88

99
2. Build system changes
10-
a. Unix build system changes
11-
b. Windows build system changes
10+
a. Abstract
11+
b. Unix build system changes
12+
c. Windows build system changes
1213

1314
3. Module changes
1415
a. ext/xml
16+
b. ext/hash
1517

1618
========================
1719
1. Internal API changes
@@ -52,14 +54,18 @@ PHP 7.4 INTERNALS UPGRADE NOTES
5254
2. Build system changes
5355
========================
5456

55-
a. Unix build system changes
57+
a. Abstract
58+
- The hash extension is now always available, meaning the --enable-hash
59+
configure argument has been removed.
60+
61+
b. Unix build system changes
5662
- configure --help now also outputs --program-suffix and --program-prefix
5763
information by using the Autoconf AC_ARG_PROGRAM macro.
5864
- Obsolescent macros AC_FUNC_VPRINTF and AC_FUNC_UTIME_NULL have been
5965
removed. Symbols HAVE_VPRINTF and HAVE_UTIME_NULL are no longer defined
6066
since they are not needed on the current systems.
6167

62-
b. Windows build system changes
68+
c. Windows build system changes
6369

6470
========================
6571
3. Module changes
@@ -68,3 +74,7 @@ PHP 7.4 INTERNALS UPGRADE NOTES
6874
a. ext/xml
6975
- The public (internal) API of the ext/xml extension has been removed. All
7076
functions and structures are private to the extension now.
77+
78+
b. ext/hash
79+
- The hash extension is now always available, allowing extensions to rely
80+
on its functionality to be available without compile time checks.

ext/hash/config.m4

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ dnl config.m4 for extension hash
33
PHP_ARG_WITH(mhash, for mhash support,
44
[ --with-mhash[=DIR] Include mhash support])
55

6-
PHP_ARG_ENABLE(hash, whether to enable hash support,
7-
[ --disable-hash Disable hash support], yes)
8-
96
if test "$PHP_MHASH" != "no"; then
107
if test "$PHP_HASH" = "no"; then
118
PHP_HASH="yes"
@@ -14,44 +11,42 @@ if test "$PHP_MHASH" != "no"; then
1411
AC_DEFINE(PHP_MHASH_BC, 1, [ ])
1512
fi
1613

17-
if test "$PHP_HASH" != "no"; then
18-
AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
19-
20-
PHP_C_BIGENDIAN
21-
22-
AC_CHECK_SIZEOF(short, 2)
23-
AC_CHECK_SIZEOF(int, 4)
24-
AC_CHECK_SIZEOF(long, 4)
25-
AC_CHECK_SIZEOF(long long, 8)
26-
27-
if test $ac_cv_c_bigendian_php = yes; then
28-
EXT_HASH_SHA3_SOURCES="hash_sha3.c"
29-
AC_DEFINE(HAVE_SLOW_HASH3, 1, [Define is hash3 algo is available])
30-
AC_MSG_WARN("Use SHA3 slow implementation on bigendian")
31-
else
32-
PHP_CHECK_64BIT([
33-
SHA3_DIR="sha3/generic32lc"
34-
SHA3_OPT_SRC="$SHA3_DIR/KeccakP-1600-inplace32BI.c"
35-
],[
36-
SHA3_DIR="sha3/generic64lc"
37-
SHA3_OPT_SRC="$SHA3_DIR/KeccakP-1600-opt64.c"
38-
])
39-
EXT_HASH_SHA3_SOURCES="$SHA3_OPT_SRC $SHA3_DIR/KeccakHash.c $SHA3_DIR/KeccakSponge.c hash_sha3.c"
40-
PHP_HASH_CFLAGS="-I@ext_srcdir@/$SHA3_DIR -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded"
41-
42-
PHP_ADD_BUILD_DIR(ext/hash/$SHA3_DIR, 1)
43-
fi
44-
45-
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
46-
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
47-
hash_crc32.c hash_fnv.c hash_joaat.c $EXT_HASH_SHA3_SOURCES"
48-
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
49-
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
50-
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h \
51-
php_hash_fnv.h php_hash_joaat.h php_hash_sha3.h"
52-
53-
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared,,$PHP_HASH_CFLAGS)
54-
ifdef([PHP_INSTALL_HEADERS], [
55-
PHP_INSTALL_HEADERS(ext/hash, $EXT_HASH_HEADERS)
14+
AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
15+
16+
PHP_C_BIGENDIAN
17+
18+
AC_CHECK_SIZEOF(short, 2)
19+
AC_CHECK_SIZEOF(int, 4)
20+
AC_CHECK_SIZEOF(long, 4)
21+
AC_CHECK_SIZEOF(long long, 8)
22+
23+
if test $ac_cv_c_bigendian_php = yes; then
24+
EXT_HASH_SHA3_SOURCES="hash_sha3.c"
25+
AC_DEFINE(HAVE_SLOW_HASH3, 1, [Define is hash3 algo is available])
26+
AC_MSG_WARN("Use SHA3 slow implementation on bigendian")
27+
else
28+
PHP_CHECK_64BIT([
29+
SHA3_DIR="sha3/generic32lc"
30+
SHA3_OPT_SRC="$SHA3_DIR/KeccakP-1600-inplace32BI.c"
31+
],[
32+
SHA3_DIR="sha3/generic64lc"
33+
SHA3_OPT_SRC="$SHA3_DIR/KeccakP-1600-opt64.c"
5634
])
35+
EXT_HASH_SHA3_SOURCES="$SHA3_OPT_SRC $SHA3_DIR/KeccakHash.c $SHA3_DIR/KeccakSponge.c hash_sha3.c"
36+
PHP_HASH_CFLAGS="-I@ext_srcdir@/$SHA3_DIR -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded"
37+
38+
PHP_ADD_BUILD_DIR(ext/hash/$SHA3_DIR, 1)
5739
fi
40+
41+
EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \
42+
hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \
43+
hash_crc32.c hash_fnv.c hash_joaat.c $EXT_HASH_SHA3_SOURCES"
44+
EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \
45+
php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \
46+
php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h \
47+
php_hash_fnv.h php_hash_joaat.h php_hash_sha3.h"
48+
49+
PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared,,$PHP_HASH_CFLAGS)
50+
ifdef([PHP_INSTALL_HEADERS], [
51+
PHP_INSTALL_HEADERS(ext/hash, $EXT_HASH_HEADERS)
52+
])

ext/hash/config.w32

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
// vim:ft=javascript
22

3-
ARG_ENABLE("hash", "enable hash support", "yes");
4-
ARG_WITH("mhash", "mhash support", "no");
3+
ARG_WITH('mhash', 'mhash support (BC via hash)', 'no');
54

6-
if (PHP_MHASH != "no") {
7-
if (PHP_HASH == "no") {
8-
PHP_HASH = "yes";
9-
}
5+
if (PHP_MHASH != 'no') {
106
AC_DEFINE('PHP_MHASH_BC', 1);
117
}
128

13-
if (PHP_HASH != "no") {
14-
var sha3_arch_dir = "sha3/" + (X64 ? "generic64lc" : "generic32lc");
15-
var sha3_dir = "ext/hash/" + sha3_arch_dir;
16-
if (CHECK_HEADER_ADD_INCLUDE("KeccakHash.h", "CFLAGS_HASH", PHP_HASH + ";" + sha3_dir)) {
17-
AC_DEFINE('HAVE_HASH_EXT', 1);
18-
EXTENSION("hash", "hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c "
19-
+ "hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c "
20-
+ "hash_adler32.c hash_crc32.c hash_joaat.c hash_fnv.c hash_sha3.c");
21-
22-
ADD_SOURCES(sha3_dir, "KeccakHash.c KeccakSponge.c " + (X64 ? "KeccakP-1600-opt64.c" : "KeccakP-1600-inplace32BI.c"),
23-
"hash");
24-
ADD_FLAG("CFLAGS_HASH", "/DKeccakP200_excluded /DKeccakP400_excluded /DKeccakP800_excluded");
25-
26-
27-
PHP_INSTALL_HEADERS("ext/hash/", "php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h " +
28-
"php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h " +
29-
"php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_sha3.h ");
30-
} else {
31-
WARNING("hash not enabled; libraries and headers not found");
32-
}
9+
AC_DEFINE('HAVE_HASH_EXT', 1);
10+
11+
PHP_HASH = 'yes';
12+
13+
EXTENSION('hash', 'hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c ' +
14+
'hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c ' +
15+
'hash_adler32.c hash_crc32.c hash_joaat.c hash_fnv.c ' +
16+
'hash_sha3.c', false);
17+
18+
var hash_sha3_dir = 'ext/hash/sha3/generic' + (X64 ? '64' : '32') + 'lc';
19+
20+
if(X64) {
21+
ADD_SOURCES(hash_sha3_dir, 'KeccakHash.c KeccakSponge.c KeccakP-1600-opt64.c', 'hash');
22+
} else {
23+
ADD_SOURCES(hash_sha3_dir, 'KeccakHash.c KeccakSponge.c KeccakP-1600-inplace32BI.c', 'hash');
3324
}
3425

26+
if (!CHECK_HEADER_ADD_INCLUDE('KeccakHash.h', 'CFLAGS_HASH', hash_sha3_dir)) {
27+
// Should NEVER happen
28+
ERROR('Unable to locate SHA3 headers');
29+
}
30+
31+
ADD_FLAG('CFLAGS_HASH', '/DKeccakP200_excluded /DKeccakP400_excluded /DKeccakP800_excluded');
32+
33+
PHP_INSTALL_HEADERS('ext/hash/', 'php_hash.h php_hash_md.h php_hash_sha.h ' +
34+
'php_hash_ripemd.h php_hash_haval.h php_hash_tiger.h ' +
35+
'php_hash_gost.h php_hash_snefru.h php_hash_whirlpool.h ' +
36+
'php_hash_adler32.h php_hash_crc32.h php_hash_sha3.h');

0 commit comments

Comments
 (0)