473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mcrypt problem on PHP 4.3.1 / FreeBSD 5.3

Hi,

I'm getting some strange errors that I cannot pin down:

Warning: mcrypt_generic_init(): Iv size incorrect; supplied length: 7,
needed: 8 in......

This is strange because the data is encrypted, inserted into the
databse, then later retrieved and decrypted with the necessary hash and
ivector keys.

The data itself is decrypted OK. But the error comes up.

The error does not occur when I run the same code on another machine
running on Mac OS X.

Is this a known bug on this FreeBSD build ?

As this is for a production site, I'm just tempted to set the
error_reporting directive in php.ini to off, as this looks bad when the
error flashes up, but is actually not causing any errors.

I did change alter the initialisation function to:

@mcrypt_generic_init()

but it still displays the error regardless.

This may be a bit obscure, but has anybody else encountered a similar
problem ?

Thanks
SS.

Oct 17 '05 #1
5 3036
Warning: mcrypt_generic_init(): Iv size incorrect; supplied length: 7,
needed: 8 in......


Can you post a minimal example of code that produces the warning
message.

---
Steve

Oct 17 '05 #2
OK,

I use the following settings:

$cipher = MCRYPT_GOST;
$mode = MCRYPT_MODE_ECB;
$rand_src = MCRYPT_RAND;

I then randomly generate a hash and assign it to variable $hash, run it
through addslashes(), and use the following to encrypt:

$handle = mcrypt_module_open ($cipher, '', $mode, '');

if (!$handle)
die ("Couldn't locate open mcrypt module.");
$ivector =
mcrypt_create_iv(mcrypt_get_iv_size($cipher,$mode) ,$rand_src);

if (mcrypt_generic_init ($handle, $hash, $ivector) == -1)
die ("Error: mcrypt failure.");

$address1 = addslashes(mcrypt_generic($handle,$address1));
$address2 = addslashes(mcrypt_generic($handle,$address2));
$address3 = addslashes(mcrypt_generic($handle,$address3));
$address4 = addslashes(mcrypt_generic($handle,$address4));
$address5 = addslashes(mcrypt_generic($handle,$address5));
$postcode = addslashes(mcrypt_generic($handle,$postcode));
$firstname = addslashes(mcrypt_generic($handle,$firstname));
$surname = addslashes(mcrypt_generic($handle,$surname));
$telephone = addslashes(mcrypt_generic($handle,$telephone));
$em = addslashes(mcrypt_generic($handle,$email));
$ivector = addslashes($ivector);
$username = addslashes($email);

mcrypt_generic_deinit($handle);
These are inserted into the database tables, then I later decrypt with:
$site_sql="SELECT * FROM security WHERE client_id ='$client_id' LIMIT
1";

$site_get = mysql_query($site_sql) or die (mysql_error());
while ($row = mysql_fetch_array($site_get))
{
$hash_temp = stripslashes($row['hash']);
$iv_temp = stripslashes($row['iv']);
}

$site_sql="SELECT * FROM client WHERE client_id ='$client_id' LIMIT 1";
$site_get = mysql_query($site_sql) or die (mysql_error());
while ($row = mysql_fetch_array($site_get))
{
$handle = @mcrypt_module_open ($cipher, '', $mode, '');
if (!$handle)
die ("Couldn't locate open mcrypt module.");
if (@mcrypt_generic_init ($handle, $hash_temp, $iv_temp) == -1)
die ("Error: mcrypt failure.");
$title = $row['title'];
$firstname = trim(stripslashes(@mdecrypt_generic($handle,
$row['firstname'])));
$surname = trim(stripslashes(@mdecrypt_generic($handle,
$row['surname'])));
$address1 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address1'])));
$address2 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address2'])));
$address3 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address3'])));
$address4 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address4'])));
$address5 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address5'])));
$postcode = trim(stripslashes(@mdecrypt_generic($handle,
$row['postcode'])));
$telephone = trim(stripslashes(@mdecrypt_generic($handle,
$row['telephone'])));
$email = trim(stripslashes(@mdecrypt_generic($handle,
$row['email'])));
@mcrypt_generic_deinit($handle);
}

As I said, the data is decrypted fine. But this error keeps popping
up...

Very obscure....

Thanks
SS

Oct 17 '05 #3
As I said, the data is decrypted fine. But this error keeps popping
up...
Suggestions:
$ivector = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$mode) ,$rand_src);


Break this down into two calls, and check that the size returned from
the first call is what you expect.

$ivsize = mcrypt_get_iv_size($cipher,$mode);
// [ check/debug $ivsize before use ]
$ivector = mcrypt_create_iv($ivsize,$rand_src);

Use <http://www.php.net/manual/en/function.mcrypt-enc-get-iv-size.php>
instead to see if it makes a difference.

$handle = mcrypt_module_open($cipher, '', $mode, '');
if(!$handle) die ("Couldn't locate open mcrypt module.");
$ivsize = mcrypt_enc_get_iv_size($handle);
// [ check/debug $ivsize before use ]
$ivector = mcrypt_create_iv($ivsize,$rand_src);

Or suppress the warning as you suggest, as it seems harmless 8-)

---
Steve

Oct 17 '05 #4
I may just try and surpress the error.

I'm probably getting off the point here, but will the following
command:

ini_set('display_errors','0');

surpress ALL errors, or just some errors.

I ask, because on the code I posted above, adding a @ before the mcrypt
functions still caused the error to appear.....

Oct 17 '05 #5
ini_set('display_errors','0');


You could try turning error reporting off just before the rogue
statement and back on again immediately after:
$oldsetting = ini_set( 'error_reporting', E_NONE );
// ...rogue statment(s) here...
ini_set( 'error_reporting', $oldsetting );
---
Steve

Oct 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt McKay | last post by:
I've written a php page which allows users to type in a text string and a key, then choose from a dropdown menu of encryption/decryption cyphers, and a method (encrypt, decrypt). The whole thing...
3
by: Marek Muszak | last post by:
Hello, I try use mcrypt but I want to use key in bytes, not in string. Encrypt text will be decrypt in Delphi with function where key is 16byte not string. How can I do this. Thanks for any...
1
by: BKDotCom | last post by:
I'm writing an app that will use blowfish encryption.. PHP's mcrypt will be used if available. if not, I'll use PHPmyadmin's blowfish.php library. The problem is I can't figure out what...
4
by: believein | last post by:
Hi all, I installed PHP thru the XAMPP package on my windows machine. The problem, I couldn't solve, is that the mcryppt funcs don't work. It return the following message: Call to undefined...
1
by: laredotornado | last post by:
Hello, My hosting company does not support the PHP mcrypt functions. Instead, they recomend using the command line, /usr/local/bin/mcrypt utility via PHP's exec method. Sadly, they do not provide...
0
by: sylvian stone | last post by:
Hi, I'm getting some strange errors that I cannot pin down: Warning: mcrypt_generic_init(): Iv size incorrect; supplied length: 7, needed: 8 in...... This is strange because the data is...
0
by: codearcher | last post by:
I have the latest version of XAMPP installed on Windows XP Pro SP2. I am trying to use mcrypt with rijnndael-128 on ecb: " $cr = mcrypt_module_open('rijndael-128','','ecb','') or...
0
by: E. Recio | last post by:
Long story short. I want to use Mac OS/X and PHP. I have a db with passwords stored under Linux using the crypt("foo", "$1$".$salt."$); scheme. This means that crypt should execute a CRYPT_MD5...
3
by: =?UTF-8?Q?Ahmad_=E3=8B=A1_Baitalmal?= | last post by:
Hi, I'm having a hard time getting python-mcrypt extension to build. I installed libmcrypt with --prefix=/usr and I checked that the library exists -rwxr-xr-x 1 root wheel 352K Sep 19...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.