php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27062 mdecrypt_generic() doesn't decrypt anything
Submitted: 2004-01-27 13:16 UTC Modified: 2004-02-05 13:09 UTC
From: yu at csh dot dp dot ua Assigned: edink (profile)
Status: Closed Package: mcrypt related
PHP Version: 4.3.4 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-01-27 13:16 UTC] yu at csh dot dp dot ua
Description:
------------
Server is localhost.
Function mdecrypt_generic() doesn't decrypt anything.
Instead it returns value of the encrypted string without changing.
Crypt-library loaded from http://ftp.emini.dk/pub/php/win32/mcrypt/libmcrypt.dll , as specified in the php_manual for mcrypt functions.

Same problem reports other users:
http://bugs.php.net/bug.php?id=3165&edit=2 - Bug #3165: encrypt/decrypt not a function?
http://www.forbiddenweb.org/viewtopic.php?t=4556

here is another link to crypt-libraries, that point as functional:
http://ftp.proventum.net/pub/php/win32/misc/mcrypt/ 
, but i don't check it functionality.


Additionaly mcrypt_create_iv() produces same iv for every time script is runing. But this not problem when, for example, 
<? 
...
$iv=substr(pack('h*',sha1(uniqid(rand())), 0, mcrypt_enc_get_iv_size($td)); 
...
?>


Reproduce code:
---------------
<?php 
#Example to mcrypt_module_open() from php_manual_ru.html
#almost without changes
srand();
$td = mcrypt_module_open('rijndael-256', '', 'cbc', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$ks = mcrypt_enc_get_key_size($td);
$key = substr(md5('very secret key'), 0, $ks);
mcrypt_generic_init($td, $key, $iv);
$encrypted = mcrypt_generic($td, 'This is my data');
mcrypt_generic_deinit($td);
mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encrypted);
mcrypt_generic_deinit($td);    
mcrypt_module_close($td);   
echo trim($decrypted) . "\n";?>

Expected result:
----------------
"This is my data"

Actual result:
--------------
$encrypted value

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-27 15:47 UTC] derick@php.net
Works fine for me on Linux.
 [2004-01-27 15:56 UTC] sniper@php.net
It's ZTS issue, I bet. Try a bit harder, Derick..

 [2004-01-27 16:16 UTC] derick@php.net
But there is no ZTS specific code at all; and I just tested, it works fine on Linux with ZTS enabled.
 [2004-01-27 16:26 UTC] sniper@php.net
CLI != ZTS enabled webserver, e.g. Apache2 with worker MPM..

 [2004-01-27 16:32 UTC] derick@php.net
Must be a library issue then, it's not thread safe AFAIK.
 [2004-01-28 06:51 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Works fine with latest CVS snapshot on windows for me..
Maybe this was (s)rand() related? (there was some stuff fixed relating to it)

 [2004-01-29 13:59 UTC] yu at csh dot dp dot ua
Problem have been localized - this libmcrypt.dll v.2.5.7, downloaded from http://ftp.emini.dk/pub/php/win32/mcrypt/. This DLL is damaged and need recompilation. Additionally it makes error "Memory can't be read at adress ..." and server closes connection on some functions. 

Usage the libmcrypt.dll v.2.5.5 from http://ftp.proventum.net/pub/php/win32/misc/mcrypt/ 
decides this problem. But this is older version - it doesn't have mcrypt_generic_deinit() function (I don't know how mcrypt_generic_init() will work without mcrypt_generic_deinit()). Additionally mcrypt_list_algorithms() has little error, BUT old-type encryption functions (mcrypt_encrypt() and mcrypt_decrypt()) work well!!!
 
I am not C-programmer to recompile source and can't to find into Internet correct libmcrypt.dll v.2.5.7.
 [2004-01-29 15:01 UTC] derick@php.net
Bug for you Edin :)

To reporter:
DON'T USE THE OLD FUNCTIONS, just don't use _deinit and you'll be fine.
 [2004-01-29 19:06 UTC] edink@php.net
DLL is damaged? Can you be a bit more specific? And you 
will not be able to find libmcrypt.dll v.2.5.7 on the 
internet because mcrypt people don't support windows at 
all.
 [2004-01-29 20:36 UTC] edink@php.net
Just re-tested your test script and it worked fine here with the latest lib from ftp.emini.dk.

Are you sure you're using latest stable snapshot and that your system is finding the correct libmcrypt.dll?
 [2004-02-03 10:15 UTC] yu at csh dot dp dot ua
File libmcrypt.dll reloaded again. And problem is repeated -
v.2.5.5 works but v.2.5.7 from http://ftp.emini.dk doesn't.
I haven't been reinstall PHP 4.3.4 to http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
- planing do it this week.
But one more question for today - who has positive result with libmcrypt v.2.5.7 on Windows, publish here its md5 or sha1 hash please.
 [2004-02-03 10:26 UTC] sniper@php.net
You're not using the suggested snapshot -> bogus.
(yes, it works)

Easiest way to get everything to work: Delete all old dlls, etc. related to PHP..then reinstall.

 [2004-02-05 13:09 UTC] yu at csh dot dp dot ua
Reinstalation of the http://snaps.php.net/win32/php4-win32-STABLE-latest.zip decides the problem. Thank you !!!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 15:01:33 2024 UTC