For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2006 > How does mcrypt encrypt AES/Rijndael?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How does mcrypt encrypt AES/Rijndael?
Jens Müller

2006-09-21, 6:57 pm

Hello,

I try to program a Rijndael encryption in Windows which has to be
compatible with php.

In php I use the code below to encrypt with a 256 Bit Key and a 256 Bit
block cipher.
My windows code has the same specs, but the outcome is different.

So far I use no iv to facilitate.

I want to get more information on mcrypt_generic - how is the data
padded to multiples of 32 - my code adds Ascii 0.
Where is the information about the length of the encoded string stored?
My code uses the first 4 bytes (but even if I so not store the length,
the outcome is different).

If no detailed information about mcrypt is available, I would be helped
if I could find a pute php Rijndael implementation so that I can adjust
it to work with my windows code. Is such an implementation available?

Thanks a lot,
Jens


$key = 'Key';
$string = 'Plain text';

$td = mcrypt_module_open('rijndael-256', '', 'cbc', '');
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = str_repeat(chr(0), $iv_size);
if (mcrypt_generic_init($td, $key, $iv) != -1) {
$c_t = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
}

cwepema

2006-09-22, 3:57 am

In http://www.efgh.com/software/rijndael.htm you can find a c
implementation. Maybe that will help you...
Kees Epema

Jens Müller schreef:
> Hello,
>
> I try to program a Rijndael encryption in Windows which has to be
> compatible with php.
>
> In php I use the code below to encrypt with a 256 Bit Key and a 256 Bit
> block cipher.
> My windows code has the same specs, but the outcome is different.
>
> So far I use no iv to facilitate.
>
> I want to get more information on mcrypt_generic - how is the data
> padded to multiples of 32 - my code adds Ascii 0.
> Where is the information about the length of the encoded string stored?
> My code uses the first 4 bytes (but even if I so not store the length,
> the outcome is different).
>
> If no detailed information about mcrypt is available, I would be helped
> if I could find a pute php Rijndael implementation so that I can adjust
> it to work with my windows code. Is such an implementation available?
>
> Thanks a lot,
> Jens
>
>
> $key = 'Key';
> $string = 'Plain text';
>
> $td = mcrypt_module_open('rijndael-256', '', 'cbc', '');
> $iv_size = mcrypt_enc_get_iv_size($td);
> $iv = str_repeat(chr(0), $iv_size);
> if (mcrypt_generic_init($td, $key, $iv) != -1) {
> $c_t = mcrypt_generic($td, $string);
> mcrypt_generic_deinit($td);
> mcrypt_module_close($td);
> }
>

Jens Müller

2006-09-22, 3:57 am

> In http://www.efgh.com/software/rijndael.htm you can find a c
> implementation. Maybe that will help you...


Thanks for the link.

Unfortunately I have not enought c experiance to convert it to php.
Also, of course I would rather like to use the mcrypt functions, if I
knew how to make compatible encryptions.

Also, the c-code has a weak point:
"They encrypt and decrypt each 128-bit block separately. If the
plaintext contains identical 128-byte blocks, as many text files do,
the blocks will be encrypted identically. This makes some of the
plaintext structure visible in the ciphertext, even to someone who does
not have the key. The usual practice is to combine each block after the
first with the previous blocks (usually by some kind of XOR operation)
before encrypting it."

Colin McKinnon

2006-09-24, 6:57 pm

Jens Müller wrote:

>
> Thanks for the link.
>
> Unfortunately I have not enought c experiance to convert it to php.
> Also, of course I would rather like to use the mcrypt functions, if I
> knew how to make compatible encryptions.
>
> Also, the c-code has a weak point:
> "They encrypt and decrypt each 128-bit block separately. If the


Not a fault of the c-code - it's just that it only supports ECB mode.

I don't know what you're developing in the windows side, but mcrypt was
originally a generic encryption library written in C. There is a Windows
DLL implementation and a command line version.

C.


brianecauchi@hotmail.com

2006-09-24, 6:57 pm

Hi.
You mention AES/Rijndael, but note that all AES variants use
Rijndael-128 (i.e. the block size is fixed at 128, with key sizes
128,192,256). php's Rijndael-192/256, which use correspondingly larger
block sizes, have no AES equivalent.

Regards,
Brian E. Cauchi

P=2ES. You might find my online Crypto-Toolbox useful:
http://www.3amSystems.com/monetics/crypto.php


Jens M=FCller wrote:
> Hello,
>
> I try to program a Rijndael encryption in Windows which has to be
> compatible with php.
>
> In php I use the code below to encrypt with a 256 Bit Key and a 256 Bit
> block cipher.
> My windows code has the same specs, but the outcome is different.
>
> So far I use no iv to facilitate.
>
> I want to get more information on mcrypt_generic - how is the data
> padded to multiples of 32 - my code adds Ascii 0.
> Where is the information about the length of the encoded string stored?
> My code uses the first 4 bytes (but even if I so not store the length,
> the outcome is different).
>
> If no detailed information about mcrypt is available, I would be helped
> if I could find a pute php Rijndael implementation so that I can adjust
> it to work with my windows code. Is such an implementation available?
>
> Thanks a lot,
> Jens
>
>
> $key =3D 'Key';
> $string =3D 'Plain text';
>
> $td =3D mcrypt_module_open('rijndael-256', '', 'cbc', '');
> $iv_size =3D mcrypt_enc_get_iv_size($td);
> $iv =3D str_repeat(chr(0), $iv_size);
> if (mcrypt_generic_init($td, $key, $iv) !=3D -1) {
> $c_t =3D mcrypt_generic($td, $string);
> mcrypt_generic_deinit($td);
> mcrypt_module_close($td);
> }


Jens Müller

2006-09-25, 3:57 am

Colin McKinnon wrote:
> I don't know what you're developing in the windows side, but mcrypt
> was originally a generic encryption library written in C. There is a
> Windows DLL implementation and a command line version.


Ah really, the DLL would probably be useful to me!
I'll see if I can find it on the internet.

Thanks,
Jens


Jens Müller

2006-09-30, 6:57 pm

Jens Müller wrote:[color=darkred]
> Colin McKinnon wrote:

I am trying different declarations of functions in this DLL in VB but
apparently I did not find the right data types or decrlaration.
Is there an example for use of libmcrypt.dll in vb?

Jens

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com