I was testing rc4-40 out with a 200-bit key (25 bytes) and, to my surprise, the results were the same as they were with rc4:

$key_size = 25;
$key = '';
for ($i = 0; $i < $key_size; $i++) {
    $key.= chr(mt_rand(0, 255));

$a = openssl_encrypt(str_repeat('z', 50), 'rc4-40', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
$b = openssl_encrypt(str_repeat('z', 50), 'rc4', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);

echo $a == $b ? 'good' : 'bad';

Source: https://3v4l.org/7n0VC

It was my understanding, based on posts like RC4 doesn't work correctly with openssl command?, that rc4-40 only supported 40-bit keys and rc4 only supported 128-bit keys. But here we have them both seemingly supporting a 200-bit key.

Even https://wiki.openssl.org/index.php/Manual:Enc(1) gives the idea that rc4-40 is fixed at 40-bits and rc4 is fixed at 128-bits (both of which would seem to be disproven by the above code):

 rc4                128 bit RC4
 rc4-64             64 bit RC4
 rc4-40             40 bit RC4

Even if rc4, in this example, simply truncated keys that were to long to 128-bits and rc4-40 truncated longer than supported keys to 40-bits, it still stands to reason that the results would be different, but they're not.

So why does all the literature online imply that they're fixed length when my own tests suggest that they're not?


1 Answer 1


From https://en.wikipedia.org/wiki/Export_of_cryptography_from_the_United_States:

The export of cryptographic technology and devices from the United States was severely restricted by U.S. law until 1992, but was gradually eased until 2000; some restrictions still remain.
In 1992, a deal between NSA and the SPA made 40-bit RC2 and RC4 encryption easily exportable using a Commodity Jurisdiction (which transferred control from the State Department to the Commerce Department).

So this is a remainder (and reminder) of those times when software was only allowed to be exported with very weak ciphers.

  • 1
    I'm aware of the history of cryptography. But even openssl.org implies that rc4-40 is fixed 40-bit and rc4 is 128-bit. See, for example, wiki.openssl.org/index.php/Manual:Enc(1) . And yet my own tests suggest that this is not the case. Maybe rc4-40 was 40-bit twenty years ago but it isn't today. Or has OpenSSL not updated their documentation in twenty years?
    – neubert
    Jan 19, 2017 at 3:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .