From 26f7d7dc29cd079d8c58f8c5cf59e6b45338234d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 10 Apr 2026 10:23:27 +0200 Subject: improve algo availability check --- CHANGELOG.md | 2 ++ config.m4 | 33 ++++++++++++++++++++++++--------- package.xml | 4 +--- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d0ef8..93c5a08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- improve algo availability check + # Version 1.2.0 - 2026-01-13 - add SM3 hash algos available in libxcrypt 4.5 diff --git a/config.m4 b/config.m4 index a4156a0..ecaa8ed 100644 --- a/config.m4 +++ b/config.m4 @@ -22,9 +22,14 @@ if test "$PHP_XPASS" != "no"; then #include int main(void) { - char salt[8]; - salt[0]='$'; salt[1]='y'; salt[2]='$'; salt[3]=0; - return crypt_gensalt(salt, 0, NULL, 0) ? 0 : 1; + char algo[8], *salt, *hash; + algo[0]='$'; algo[1]='y'; algo[2]='$'; algo[3]=0; + salt = crypt_gensalt(algo, 0, NULL, 0); + if (salt) { + hash = crypt("secret", salt); + return (hash && strlen(hash) == 73 && !memcmp(hash, algo, 3) ? 0 : 1); + } + return 1; }]])],[ AC_DEFINE([HAVE_CRYPT_YESCRYPT], [1], [ Have yescrypt hash support ]) AC_MSG_RESULT([available]) @@ -40,9 +45,14 @@ int main(void) { #include int main(void) { - char salt[8]; - salt[0]='$'; salt[1]='6'; salt[2]='$'; salt[3]=0; - return crypt_gensalt(salt, 0, NULL, 0) ? 0 : 1; + char algo[8], *salt, *hash; + algo[0]='$'; algo[1]='6'; algo[2]='$'; algo[3]=0; + salt = crypt_gensalt(algo, 0, NULL, 0); + if (salt) { + hash = crypt("secret", salt); + return (hash && strlen(hash) == 106 && !memcmp(hash, algo, 3) ? 0 : 1); + } + return 1; }]])],[ AC_DEFINE([HAVE_CRYPT_SHA512], [1], [ Have sha512 hash support ]) AC_MSG_RESULT([available]) @@ -58,9 +68,14 @@ int main(void) { #include int main(void) { - char salt[8]; - salt[0]='$'; salt[1]='s'; salt[2]='m'; salt[3]='3'; salt[4]='$'; salt[5]=0; - return crypt_gensalt(salt, 0, NULL, 0) ? 0 : 1; + char algo[8], *salt, *hash; + algo[0]='$'; algo[1]='s'; algo[2]='m'; algo[3]='3'; algo[4]='$'; algo[5]=0; + salt = crypt_gensalt(algo, 0, NULL, 0); + if (salt) { + hash = crypt("secret", salt); + return (hash && strlen(hash) == 65 && !memcmp(hash, algo, 5) ? 0 : 1); + } + return 1; }]])],[ AC_DEFINE([HAVE_CRYPT_SM3], [1], [ Have sm3 hash support ]) AC_MSG_RESULT([available]) diff --git a/package.xml b/package.xml index 7c1a7b3..d171dbc 100644 --- a/package.xml +++ b/package.xml @@ -37,9 +37,7 @@ See PHP documentation on https://www.php.net/xpass PHP-3.01 -- cgit