Bug #10518: mcrypt_generic is padding input when using cfb and ofb modes
| From: | kettler at gmx dot net | Date: | Thu, 26 Apr 2001 22:28:36 +0000 |
| Subject: | Bug #10518: mcrypt_generic is padding input when using cfb and ofb modes | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-52551@lists.php.net to get a copy of this message | ||
From: kettler@gmx.net
Operating system: Mandrake 7.2, Linux 2.2.19ow1
PHP version: 4.0.4pl1
PHP Bug Type: mcrypt related
Bug description: mcrypt_generic is padding input when using cfb and ofb modes
When encrypting using a block cipher and cfb or ofb mode the mcrypt_generic/mdecrypt_generic
function
still pad the input to a multiple of the underlying algorithm's block size. Input should not be
padded when used with
cfb or ofb mode.
Script showing the bug:
$key = pack("H*",
"0000000000000000000000000000000000000000000000000000000000000000");
$iv = pack("H*", "00000000000000000000000000000000");
$plain = pack("H*", "0000000000000000");
$handle = mcrypt_module_open(MCRYPT_TWOFISH, "", MCRYPT_MODE_CFB, "");
mcrypt_generic_init($handle, $key, $iv);
$crypted = mcrypt_generic($handle, $plain);
mcrypt_generic_end($handle);
print bin2hex($plain)."\n\n";
print bin2hex($crypted)."\n\n";
Proposed patch:
--- mcrypt/mcrypt.c Wed Nov 22 22:40:15 2000
+++ mcrypt-sk/mcrypt.c Fri Apr 27 00:25:16 2001
@@ -498,7 +498,7 @@
convert_to_string_ex (data);
/* Check blocksize */
- if (mcrypt_enc_is_block_algorithm (td) == 1) { /* It's a block algorithm */
+ if (mcrypt_enc_is_block_mode (td) == 1) { /* It's a block algorithm */
block_size = mcrypt_enc_get_block_size (td);
data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size;
data_s = emalloc (data_size);
@@ -539,7 +539,7 @@
convert_to_string_ex (data);
/* Check blocksize */
- if (mcrypt_enc_is_block_algorithm (td) == 1) { /* It's a block algorithm */
+ if (mcrypt_enc_is_block_mode (td) == 1) { /* It's a block algorithm */
block_size = mcrypt_enc_get_block_size (td);
data_size = (((Z_STRLEN_PP(data) - 1) / block_size) + 1) * block_size;
data_s = emalloc (data_size);
--
Edit Bug report at: http://bugs.php.net/?id=10518&edit=1