Does PHP mcrypt_get_iv_size really return zero when IV is not required?

The PHP documentation for mcrypt_get_iv_size states that the return value will be zero when the algorithm / block mode combination does not use IV

Returns the size of the initialization vector (IV) in bytes. On error, the function returns FALSE. If IV is ignored in the specified encryption / mode combination, 0 is returned.

When I call this function with MCRYPT_DES as algo and MCRYPT_MODE_ECB as the mode, it returns 8 (eight) instead of the expected 0 (zero).

I understand that the ECB does not and cannot use IV, and therefore I expect a null value. Is this wrong, the documentation is wrong, or am I missing something else?

The following snippet demonstrates the problem:

<?php
// I expect this call to return zero.
$size = mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB);
echo 'IV Size: ' . $size . PHP_EOL;

, ECB , , / IV. ( , mcrypt "mcrypt_enc_mode_has_iv", , , PHP).

PHP v5.3.12 libmcrypt 2.5.8_1.

:

libmcrypt, , mcrypt_enc_get_iv_size() , "" .

int mcrypt_enc_get_iv_size(MCRYPT td)
{
    if (mcrypt_enc_is_block_algorithm_mode(td) == 1) {
        return mcrypt_enc_get_block_size(td);
    } else {
        return mcrypt_get_algo_iv_size(td);
    }
}

mcrypt_get_algo_iv_size() _mcrypt_get_algo_iv_size(). , , , ECB , , IV .

+5
1

, ECB IV, PHP mcrypt_get_iv_size:

MCRYPT_MODE_modename : "ecb", "cbc", "cfb", "ofb", "nofb" "stream". IV ECB, . IV (: ) , , .

mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB) 8 . , .

+1

All Articles