Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions ext/hash/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,73 @@ PHP_ARG_WITH([mhash],
[AS_HELP_STRING([--with-mhash],
[Include mhash support])])

PHP_ARG_WITH([crc-fast],
[for crc-fast support],
[AS_HELP_STRING([--with-crc-fast[=DIR]],
[Include crc-fast support. DIR is the crc-fast install prefix.])])

AS_VAR_IF([PHP_MHASH], [no],, [
AC_MSG_WARN([The --with-mhash option and mhash* functions are deprecated as of PHP 8.1.0])
AC_DEFINE([PHP_MHASH_BC], [1], [Define to 1 if mhash support is enabled.])
])

dnl Check for crc-fast library support
AS_VAR_IF([PHP_CRC_FAST], [no],, [
AC_MSG_CHECKING([for crc-fast support])

dnl Set default search paths
CRC_FAST_SEARCH_PATHS="/usr/local /usr /opt/local"

dnl If a path was specified, use it
AS_VAR_IF([PHP_CRC_FAST], [yes], [
CRC_FAST_SEARCH_PATHS="/usr/local /usr /opt/local"
], [
CRC_FAST_SEARCH_PATHS="$PHP_CRC_FAST /usr/local /usr /opt/local"
])

dnl Search for header file
CRC_FAST_HEADER_FOUND=no
for i in $CRC_FAST_SEARCH_PATHS; do
AS_IF([test -f "$i/include/libcrc_fast.h"], [
CRC_FAST_INCDIR="$i/include"
CRC_FAST_HEADER_FOUND=yes
break
])
done

AS_VAR_IF([CRC_FAST_HEADER_FOUND], [no], [
AC_MSG_ERROR([crc-fast header file libcrc_fast.h not found. Please install crc-fast library or specify correct path with --with-crc-fast=DIR])
])

dnl Search for library file
CRC_FAST_LIB_FOUND=no
for i in $CRC_FAST_SEARCH_PATHS; do
for j in lib lib64; do
AS_IF([test -f "$i/$j/libcrc_fast.dylib" -o -f "$i/$j/libcrc_fast.so" -o -f "$i/$j/libcrc_fast.a"], [
CRC_FAST_LIBDIR="$i/$j"
CRC_FAST_LIB_FOUND=yes
break 2
])
done
done

AS_VAR_IF([CRC_FAST_LIB_FOUND], [no], [
AC_MSG_ERROR([crc-fast library libcrc_fast not found. Please install crc-fast library or specify correct path with --with-crc-fast=DIR])
])

dnl Test compilation and linking
PHP_CHECK_LIBRARY([crc_fast], [crc_fast_checksum], [
AC_DEFINE([HAVE_CRC_FAST], [1], [Define to 1 if crc-fast support is enabled.])
PHP_ADD_LIBRARY_WITH_PATH([crc_fast], [$CRC_FAST_LIBDIR], [HASH_SHARED_LIBADD])
PHP_ADD_INCLUDE([$CRC_FAST_INCDIR])
AC_MSG_RESULT([yes])
], [
AC_MSG_ERROR([crc-fast library test compilation failed. Please check that crc-fast is properly installed.])
], [
-L$CRC_FAST_LIBDIR -I$CRC_FAST_INCDIR
])
])

AS_VAR_IF([ac_cv_c_bigendian_php], [yes], [
EXT_HASH_SHA3_SOURCES=
AC_DEFINE([HAVE_SLOW_HASH3], [1],
Expand All @@ -33,10 +95,20 @@ AS_VAR_IF([ac_cv_c_bigendian_php], [yes], [
PHP_HASH_CFLAGS="$PHP_HASH_CFLAGS -I@ext_srcdir@/$SHA3_DIR -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded"
])

dnl Set crc-fast sources if enabled
AS_VAR_IF([PHP_CRC_FAST], [no], [
EXT_HASH_CRC_FAST_SOURCES=""
], [
EXT_HASH_CRC_FAST_SOURCES="hash_crc_fast.c"
])

PHP_NEW_EXTENSION([hash], m4_normalize([
$EXT_HASH_SHA3_SOURCES
$EXT_HASH_CRC_FAST_SOURCES
hash_adler32.c
hash_crc_common.c
hash_crc32.c
hash_crc64.c
hash_fnv.c
hash_gost.c
hash_haval.c
Expand All @@ -60,9 +132,19 @@ PHP_NEW_EXTENSION([hash], m4_normalize([
[$PHP_HASH_CFLAGS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
PHP_ADD_BUILD_DIR([$ext_builddir/murmur])
AS_VAR_IF([SHA3_DIR],,, [PHP_ADD_BUILD_DIR([$ext_builddir/$SHA3_DIR])])
dnl Set crc-fast headers if enabled
AS_VAR_IF([PHP_CRC_FAST], [no], [
EXT_HASH_CRC_FAST_HEADERS=""
], [
EXT_HASH_CRC_FAST_HEADERS="php_hash_crc_fast.h php_hash_crc_common.h"
])

PHP_INSTALL_HEADERS([ext/hash], m4_normalize([
php_hash_adler32.h
php_hash_crc32.h
php_hash_crc64.h
php_hash_crc64_tables.h
$EXT_HASH_CRC_FAST_HEADERS
php_hash_fnv.h
php_hash_gost.h
php_hash_haval.h
Expand Down
103 changes: 97 additions & 6 deletions ext/hash/config.w32
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// vim:ft=javascript

ARG_WITH('mhash', 'mhash support (BC via hash)', 'no');
ARG_WITH('crc-fast', 'crc-fast support', 'no');

if (PHP_MHASH != 'no') {
WARNING("mhash* functions are deprecated as of PHP 8.1.0");
Expand All @@ -9,10 +10,93 @@ if (PHP_MHASH != 'no') {

PHP_HASH = 'yes';

EXTENSION('hash', 'hash.c hash_md.c hash_sha.c hash_sha_sse2.c hash_sha_ni.c hash_ripemd.c hash_haval.c ' +
// Check for crc-fast library support
var CRC_FAST_ENABLED = false;
if (PHP_CRC_FAST != 'no') {
var lib_found = false;
var header_found = false;

// Build search paths for library and headers
var lib_search_path = PHP_CRC_FAST;
var include_search_path = PHP_CRC_FAST;

// Add vcpkg paths if VCPKG_ROOT is set
var vcpkg_root = WshShell.Environment("Process").Item("VCPKG_ROOT");
if (vcpkg_root) {
lib_search_path += ";" + vcpkg_root + "\\installed\\x64-windows\\lib";
lib_search_path += ";" + vcpkg_root + "\\installed\\x86-windows\\lib";
include_search_path += ";" + vcpkg_root + "\\installed\\x64-windows\\include";
include_search_path += ";" + vcpkg_root + "\\installed\\x86-windows\\include";
}

// Add common installation paths
lib_search_path += ";C:\\crc-fast\\lib;C:\\Program Files\\crc-fast\\lib;C:\\Program Files (x86)\\crc-fast\\lib";
lib_search_path += ";..\\crc-fast\\lib;..\\..\\crc-fast\\lib";
include_search_path += ";C:\\crc-fast\\include;C:\\Program Files\\crc-fast\\include;C:\\Program Files (x86)\\crc-fast\\include";
include_search_path += ";..\\crc-fast\\include;..\\..\\crc-fast\\include";

// Add parent directory for header search when specific path is given
if (PHP_CRC_FAST != "yes") {
var parent_dir = PHP_CRC_FAST.replace(/\\[^\\]*$/, "");
include_search_path += ";" + parent_dir;
}

// Search for library and header
STDOUT.WriteLine("Searching for crc-fast library in: " + lib_search_path);
if (CHECK_LIB("crc_fast.lib", "hash", lib_search_path)) {
lib_found = true;
STDOUT.WriteLine("Found crc-fast library");

if (CHECK_HEADER_ADD_INCLUDE("libcrc_fast.h", "CFLAGS_HASH", include_search_path)) {
header_found = true;
}
}

if (lib_found && header_found) {
AC_DEFINE('HAVE_CRC_FAST', 1, 'Define to 1 if crc-fast support is enabled.');
CRC_FAST_ENABLED = true;
STDOUT.WriteLine("crc-fast support enabled");

// Add required system libraries for Rust crc-fast static library
CHECK_LIB("userenv.lib", "hash");
CHECK_LIB("ntdll.lib", "hash");
} else {
var error_msg = "crc-fast library not found. ";

if (!lib_found) {
error_msg += "Could not find crc_fast.lib. ";
} else {
error_msg += "Library found but libcrc_fast.h header not found. ";
}

error_msg += "Please ensure crc-fast is properly installed";
if (PHP_CRC_FAST != "yes") {
error_msg += " in the specified path: " + PHP_CRC_FAST;
} else {
error_msg += ". Consider using vcpkg (vcpkg install crc-fast) or specify the path with --with-crc-fast=<path>";
}
error_msg += ".";

// If explicitly requested with a path (not just "yes"), this is a fatal error
if (PHP_CRC_FAST != "yes") {
ERROR(error_msg);
} else {
WARNING(error_msg);
}
}
}

var hash_sources = 'hash.c hash_md.c hash_sha.c hash_sha_sse2.c hash_sha_ni.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 hash_joaat.c hash_fnv.c ' +
'hash_sha3.c hash_murmur.c hash_xxhash.c', false);
'hash_adler32.c hash_crc32.c hash_crc64.c hash_joaat.c hash_fnv.c ' +
'hash_sha3.c hash_murmur.c hash_xxhash.c';

// Add crc-fast sources if successfully configured
if (CRC_FAST_ENABLED) {
hash_sources += ' hash_crc_fast.c hash_crc_common.c';
}

EXTENSION('hash', hash_sources, false);

var hash_sha3_dir = 'ext/hash/sha3/generic' + (X64 ? '64' : '32') + 'lc';

Expand All @@ -31,9 +115,16 @@ ADD_FLAG('CFLAGS_HASH', '/DKeccakP200_excluded /DKeccakP400_excluded /DKeccakP80

ADD_SOURCES('ext/hash/murmur', 'PMurHash.c PMurHash128.c', 'hash');

PHP_INSTALL_HEADERS('ext/hash', 'php_hash.h php_hash_md.h php_hash_sha.h ' +
var 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_sha3.h ' +
'php_hash_adler32.h php_hash_crc32.h php_hash_crc64.h php_hash_crc64_tables.h php_hash_sha3.h ' +
'php_hash_murmur.h php_hash_xxhash.h php_hash_fnv.h ' +
'php_hash_joaat.h xxhash/xxhash.h');
'php_hash_joaat.h xxhash/xxhash.h';

// Add crc-fast headers if successfully configured
if (CRC_FAST_ENABLED) {
hash_headers += ' php_hash_crc_fast.h php_hash_crc_common.h';
}

PHP_INSTALL_HEADERS('ext/hash', hash_headers);
26 changes: 24 additions & 2 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sara Golemon <pollita@php.net> |
| Scott MacVicar <scottmac@php.net> |
| Authors: Sara Golemon <pollita@php.net> |
| Scott MacVicar <scottmac@php.net> |
| Don MacAskill <don@smugmug.com> |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't probably get update as it added just few lines to this file

+----------------------------------------------------------------------+
*/

Expand All @@ -32,6 +33,10 @@

#include "hash_arginfo.h"

#ifdef HAVE_CRC_FAST
#include <libcrc_fast.h>
#endif

#ifdef PHP_WIN32
# define __alignof__ __alignof
#else
Expand Down Expand Up @@ -1624,6 +1629,11 @@ PHP_MINIT_FUNCTION(hash)
php_hash_register_algo("crc32", &php_hash_crc32_ops);
php_hash_register_algo("crc32b", &php_hash_crc32b_ops);
php_hash_register_algo("crc32c", &php_hash_crc32c_ops);
php_hash_register_algo("crc32-iso-hdlc", &php_hash_crc32_iso_hdlc_ops);
php_hash_register_algo("crc32-iscsi", &php_hash_crc32_iscsi_ops);
php_hash_register_algo("crc32-php", &php_hash_crc32_php_ops);
php_hash_register_algo("crc64-nvme", &php_hash_crc64_nvme_ops);
php_hash_register_algo("crc64-ecma-182", &php_hash_crc64_ecma182_ops);
php_hash_register_algo("fnv132", &php_hash_fnv132_ops);
php_hash_register_algo("fnv1a32", &php_hash_fnv1a32_ops);
php_hash_register_algo("fnv164", &php_hash_fnv164_ops);
Expand Down Expand Up @@ -1698,8 +1708,20 @@ PHP_MINFO_FUNCTION(hash)
php_info_print_table_start();
php_info_print_table_row(2, "hash support", "enabled");
php_info_print_table_row(2, "Hashing Engines", buffer);
#ifdef HAVE_CRC_FAST
php_info_print_table_row(2, "crc-fast support", "enabled");
#else
php_info_print_table_row(2, "crc-fast support", "disabled");
#endif
php_info_print_table_end();

#ifdef HAVE_CRC_FAST
php_info_print_table_start();
php_info_print_table_row(2, "crc-fast library version", crc_fast_get_version());
php_info_print_table_row(2, "crc-fast target", crc_fast_get_calculator_target(Crc32Iscsi));
php_info_print_table_end();
#endif

#ifdef PHP_MHASH_BC
php_info_print_table_start();
php_info_print_table_row(2, "MHASH support", "Enabled");
Expand Down
Loading
Loading