Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught Crypto\HashException: Initialization of hash failed at a few algoritm #41

Open
mrxtraf opened this issue May 29, 2024 · 2 comments

Comments

@mrxtraf
Copy link

mrxtraf commented May 29, 2024

Several algorithms produce an error when calling the update method.

Fatal error: Uncaught Crypto\HashException: Initialization of hash failed

In particular, the following algorithms.
md4
whirlpool

The rest of the functions are fine.
The module is assembled via phpize.

Version PHP
PHP 8.3.6 (cli) (built: Apr 15 2024 19:21:47) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, Copyright (c) Zend Technologies with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

OS
Linux server99 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Code
$StringForTest = '12345';//Any string gives such an error on these methods.
$OneNameCryptoHash = 'md4';//Or 'whirlpool'
$ClHash = new Crypto\Hash($OneNameCryptoHash);
$ClHash->update($StringForTest);//On this string Fatal Error
$OneHash = $ClHash->hexdigest();
unset($ClHash);

@mrxtraf
Copy link
Author

mrxtraf commented May 29, 2024

Update

make test
......
PASS Crypto\Hash::hexdigest basic usage. [tests/Hash_hexdigest_basic.phpt]
PASS Crypto\Hash::update basic usage. [tests/Hash_update_basic.phpt] //In sourcer sha256
FAIL Crypto\Hash::update basic usage. [tests/Hash_update_basic_md4.phpt]
FAIL Crypto\Hash::update basic usage. [tests/Hash_update_basic_whirlpool.phpt]
PASS Crypto\KDF::__clone basic usage. [tests/KDF___clone_basic.phpt]
PASS Crypto\KDF::__construct basic usage. [tests/KDF___construct_basic.phpt]
......

cat Hash_update_basic_**md4**.phpt

--TEST--
Crypto\Hash::update basic usage.
--FILE--
<?php
$hash = new Crypto\Hash('md4');
$hash->update('data');
echo "SUCCESS\n";
?>
--EXPECT--
SUCCESS

File Hash_update_basic_whirlpool.phpt the same with algoritm whirlpool

cat Hash_update_basic_md4.diff
001- SUCCESS
001+ Fatal error: Uncaught Crypto\HashException: Initialization of hash failed in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php:3
002+ Stack trace:
003+ #0 /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php(3): Crypto\Hash->update('data')
004+ #1 {main}
005+ thrown in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php on line 3

cat Hash_update_basic_md4.exp
SUCCESS

cat Hash_update_basic_md4.log

---- EXPECTED OUTPUT
SUCCESS
---- ACTUAL OUTPUT
Fatal error: Uncaught Crypto\HashException: Initialization of hash failed in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php:3
Stack trace:
#0 /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php(3): Crypto\Hash->update('data')
#1 {main}
thrown in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php on line 3
---- FAILED

cat Hash_update_basic_md4.out
Fatal error: Uncaught Crypto\HashException: Initialization of hash failed in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php:3
Stack trace:
#0 /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php(3): Crypto\Hash->update('data')
#1 {main}
thrown in /home/mrsol/tmp/src/php-crypto/tests/Hash_update_basic_md4.php on line 3

cat Hash_update_basic_md4.php

<?php
$hash = new Crypto\Hash('md4');
$hash->update('data');
echo "SUCCESS\n";
?>

cat Hash_update_basic_md4.sh

#!/bin/sh

export TEST_PHP_SRCDIR='/home/myhome/tmp/src/php-crypto'
export CC='cc'
export TEST_PHP_EXECUTABLE='/usr/bin/php8.3'
export SHELL='/bin/bash'
export HISTCONTROL='ignoreboth'
export MAKE_TERMOUT='/dev/pts/7'
export PWD='/home/myhome/tmp/src/php-crypto'
export LOGNAME='myhome'
export XDG_SESSION_TYPE='tty'
export MC_TMPDIR='/tmp/mc-myhome'
export MC_SID='4182'
export HOME='/home/myhome'
export LANG='ru_RU.UTF-8'
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:'
export SSH_CONNECTION='deleted'
export MFLAGS=''
export LESSCLOSE='/usr/bin/lesspipe %s %s'
export XDG_SESSION_CLASS='user'
export MAKEFLAGS=''
export TERM='xterm-256color'
export LESSOPEN='| /usr/bin/lesspipe %s'
export USER='myhome'
export MAKE_TERMERR='/dev/pts/7'
export SHLVL='3'
export MAKELEVEL='1'
export XDG_SESSION_ID='36'
export XDG_RUNTIME_DIR='/run/user/1000'
export SSH_CLIENT='deleted'
export XDG_DATA_DIRS='/usr/local/share:/usr/share:/var/lib/snapd/desktop'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
export DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1000/bus'
export SSH_TTY='deleted'
export OLDPWD='/home/myhome'
export _='/usr/bin/php8.3'
export SSH_AUTH_SOCK='deleted'
export TEMP='/tmp'
export TEST_PHP_EXECUTABLE_ESCAPED=''\''/usr/bin/php8.3'\'''
export TEST_PHP_CGI_EXECUTABLE=''
export TEST_PHP_CGI_EXECUTABLE_ESCAPED=''\'''\'''
export TEST_PHPDBG_EXECUTABLE=''
export TEST_PHPDBG_EXECUTABLE_ESCAPED=''\'''\'''
export REDIRECT_STATUS='1'
export QUERY_STRING=''
export PATH_TRANSLATED='/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php'
export SCRIPT_FILENAME='/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php'
export REQUEST_METHOD='GET'
export CONTENT_TYPE=''
export CONTENT_LENGTH=''
export TZ=''
export TEST_PHP_EXTRA_ARGS=' -n -c '\''/home/myhome/tmp/src/php-crypto/tmp-php.ini'\''  -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off"'
export HTTP_COOKIE=''

case "$1" in
"gdb")
    gdb --args '/usr/bin/php8.3'  -n -c '/home/myhome/tmp/src/php-crypto/tmp-php.ini'   -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php"  2>&1
    ;;
"lldb")
    lldb -- '/usr/bin/php8.3'  -n -c '/home/myhome/tmp/src/php-crypto/tmp-php.ini'   -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php"  2>&1
    ;;
"valgrind")
    USE_ZEND_ALLOC=0 valgrind $2 '/usr/bin/php8.3'  -n -c '/home/myhome/tmp/src/php-crypto/tmp-php.ini'   -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php"  2>&1
    ;;
"rr")
    rr record $2 '/usr/bin/php8.3'  -n -c '/home/myhome/tmp/src/php-crypto/tmp-php.ini'   -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php"  2>&1
    ;;
*)
    '/usr/bin/php8.3'  -n -c '/home/myhome/tmp/src/php-crypto/tmp-php.ini'   -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "serialize_precision=-1" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "opcache.jit_hot_loop=1" -d "opcache.jit_hot_func=1" -d "opcache.jit_hot_return=1" -d "opcache.jit_hot_side_exit=1" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "zend.exception_string_param_max_len=15" -d "short_open_tag=0" -d "extension_dir=/home/myhome/tmp/src/php-crypto/modules/" -d "extension=crypto.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/myhome/tmp/src/php-crypto/tests/Hash_update_basic_md4.php"  2>&1
    ;;
esac

@mrxtraf
Copy link
Author

mrxtraf commented May 29, 2024

Task may close.
This is problem in openssl. Depricated this function in new version.
Description here.
openssl/openssl#21247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant