Skip to content

Commit 187c8e9

Browse files
committed
add BLAKE3 hash
BLAKE3 is a very fast cryptograpically secure hash. It is the latest iteration of the BLAKE hash, which was a SHA3 finalist (but lost to Keccak in the final round, for being too similar to SHA2). Check this speed chart: https://raw.githubusercontent.com/BLAKE3-team/BLAKE3/master/media/speed.svg and this bench.php run where BLAKE3 is much faster than every secure hash, and beats several non-cryptographic hashes: $ sapi/cli/php ext/hash/bench.php crc32b 0.001195 crc32c 0.001202 crc32 0.001202 xxh3 0.001234 xxh128 0.001289 xxh64 0.001475 xxh32 0.002235 murmur3f 0.002459 murmur3c 0.003681 murmur3a 0.004289 adler32 0.007718 blake3 0.007752 md4 0.013109 fnv132 0.015075 fnv164 0.015109 fnv1a64 0.015116 fnv1a32 0.015251 joaat 0.018858 md5 0.019797 sha1 0.020472 tiger160,3 0.021290 tiger192,3 0.021363 tiger128,3 0.021366 tiger128,4 0.027518 tiger160,4 0.027743 tiger192,4 0.027870 ripemd128 0.029190 ripemd256 0.029378 sha3-224 0.029787 sha3-256 0.031518 haval256,3 0.038328 haval224,3 0.038479 haval128,3 0.038483 sha3-384 0.038559 haval192,3 0.038564 haval160,3 0.039068 sha512/256 0.039302 sha512 0.039307 sha512/224 0.039472 sha384 0.039508 ripemd160 0.042287 ripemd320 0.043036 sha3-512 0.054044 haval192,4 0.055699 haval224,4 0.055902 haval160,4 0.055925 haval256,4 0.055948 haval128,4 0.056165 sha256 0.057846 sha224 0.058139 haval128,5 0.070442 haval224,5 0.070503 haval256,5 0.070569 haval192,5 0.070576 haval160,5 0.071109 whirlpool 0.086256 gost 0.200251 gost-crypto 0.200709 snefru256 0.449650 snefru 0.451111 md2 1.237880
1 parent ffc250d commit 187c8e9

38 files changed

+31181
-135
lines changed

build/php.m4

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,3 +2846,76 @@ AC_DEFUN([PHP_CHECK_AVX512_VBMI_SUPPORTS], [
28462846
AC_DEFINE_UNQUOTED([PHP_HAVE_AVX512_VBMI_SUPPORTS],
28472847
[$have_avx512_vbmi_supports], [Whether the compiler supports AVX512 VBMI])
28482848
])
2849+
2850+
2851+
dnl
2852+
dnl PHP_CHECK_X86_TARGET
2853+
dnl
2854+
dnl check if we're compiling for x86/x86_64
2855+
dnl
2856+
AC_DEFUN([PHP_CHECK_X86_TARGET], [
2857+
AC_CACHE_CHECK([for x86 target],ac_cv_target_x86,[
2858+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
2859+
int main(void) {
2860+
#if defined(__x86_64__) || defined(__i386__)
2861+
return 0;
2862+
#else
2863+
return 1;
2864+
#endif
2865+
}
2866+
]])],[
2867+
ac_cv_target_x86=yes
2868+
],[
2869+
ac_cv_target_x86=no
2870+
],[
2871+
ac_cv_target_x86=no
2872+
])])
2873+
])
2874+
2875+
dnl
2876+
dnl PHP_CHECK_WINDOWS_TARGET
2877+
dnl
2878+
dnl check if we're compiling for windows
2879+
dnl
2880+
AC_DEFUN([PHP_CHECK_WINDOWS_TARGET], [
2881+
AC_CACHE_CHECK([for windows target],ac_cv_target_windows,[
2882+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
2883+
int main(void) {
2884+
#if defined(_WIN32)
2885+
return 0;
2886+
#else
2887+
return 1;
2888+
#endif
2889+
}
2890+
]])],[
2891+
ac_cv_target_windows=yes
2892+
],[
2893+
ac_cv_target_windows=no
2894+
],[
2895+
ac_cv_target_windows=no
2896+
])])
2897+
])
2898+
2899+
dnl
2900+
dnl PHP_CHECK_UNIX_TARGET
2901+
dnl
2902+
dnl check if we're compiling for a unix-ish target
2903+
dnl
2904+
AC_DEFUN([PHP_CHECK_UNIX_TARGET], [
2905+
AC_CACHE_CHECK([for unix-ish target],ac_cv_target_unix,[
2906+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
2907+
int main(void) {
2908+
#if defined(unix) || defined(__unix) || defined(__unix__)
2909+
return 0;
2910+
#else
2911+
return 1;
2912+
#endif
2913+
}
2914+
]])],[
2915+
ac_cv_target_unix=yes
2916+
],[
2917+
ac_cv_target_unix=no
2918+
],[
2919+
ac_cv_target_unix=no
2920+
])])
2921+
])

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ PHP_EBCDIC
339339
dnl Check whether the system byte ordering is bigendian.
340340
PHP_C_BIGENDIAN
341341

342+
dnl Check if we're targeting x86 / x86_64
343+
PHP_CHECK_X86_TARGET
344+
345+
dnl Check if we're targeting Windows
346+
PHP_CHECK_WINDOWS_TARGET
347+
348+
dnl Check whether we're targeting a unix-ish system
349+
PHP_CHECK_UNIX_TARGET
350+
342351
dnl Check whether writing to stdout works.
343352
PHP_TEST_WRITE_STDOUT
344353

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
# afaik the PHP project doesn't allow git submodules, so we do this fetcher script instead.
3+
cd "$(dirname "$0")"
4+
rm -rf upstream_blake3
5+
# fancy way of just fetching the "c" folder (the only thing we want)
6+
git clone --branch '1.5.0' -n --depth=1 --filter=tree:0 'https://github.com/BLAKE3-team/BLAKE3.git' 'upstream_blake3'
7+
cd upstream_blake3
8+
git sparse-checkout set --no-cone c
9+
git checkout
10+
rm -rf .git
11+
cd c
12+
# some stuff we don't need
13+
rm -rf blake3_c_rust_bindings test.py example.c main.c Makefile.testing CMakeLists.txt blake3-config.cmake.in README.md .gitignore

0 commit comments

Comments
 (0)