Jacko
Jacko

Reputation: 13195

Mcrypt for rijndael-128 : how do I set the Initialization Vector?

I would like to encrypt a file using AES (rijndael 128) with the mcrypt command line tool. I would like to set the initialization vector to a specific value. How can I do this?

I am pretty new to encryption, btw.

Thanks!

Upvotes: 1

Views: 1311

Answers (1)

Thomas Pornin
Thomas Pornin

Reputation: 74492

Apparently there is no way to specify the IV with the command-line tool, except by using the --noiv flag which sets the IV to a bunch of zeros. From the source code of mcrypt, file src/classic.c, line 142:

IV = _secure_mcrypt_malloc(mcrypt_enc_get_iv_size(td));
if (noiv==FALSE)
        mcrypt_randomize( IV, mcrypt_enc_get_iv_size(td), real_random_flag);
else
        memset( IV, 0, mcrypt_enc_get_iv_size(td));

So the code makes it clear that you either get a random IV or the zeros.

You could patch mcrypt, though. Source code is provided, this is free software. The code snippet I show above is precisely the place where you would like to patch.

Upvotes: 0

Related Questions