Page 1 of 1

Rijndael encrypt

Posted: Sat Mar 14, 2009 9:23 am
by _Slide_
Hi,

I have search in the forum a free code source of "rijndael encrypt" but all link for download lib or example are down. :(

I search to convert this C++ code to PureBasic.

Can u help me ?
Thx

Code: Select all

m_AES.SessionKey((unsigned char *)REGISTRYKEY);

void CSettings::AESEncrypt(Buffer *in, Buffer *out)
{
	Buffer t;
	char buff[16];

	char *packet = in->Ptr();
	int len = in->Len();

	in->Append("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);

	// let's determine size
	int j = len%16;
	int o = 0;
	While (o<len)
	{
		m_AES.rijndael_encrypt(&m_AES.myaes.enc, (unsigned char *)packet, (unsigned char *)buff);
		packet += 16;
		o += 16;
		t.Append(buff, 16);
	}

	in->ConsumeEnd(16);

	// now convert it To HEX
	ToHex(&t, out);
	out->Append("\0",1);
	out->ConsumeEnd(1);
}

Posted: Sat Mar 14, 2009 12:30 pm
by Kaeru Gaman
would have been nice if you linked some wiki-article or such.
why should a potential helper search on his own before he could start to help you?

Posted: Sat Mar 14, 2009 10:14 pm
by USCode
FYI - http://www.purebasic.fr/english/viewtop ... t=rijndael
Not sure if that includes the source though.

Posted: Wed Mar 18, 2009 3:35 am
by Rook Zimbabwe
OK look... my C is BAD... but as far as I can tell this only converts the input to HEX. What sort of encryption is that?

Or did I miss something?

It is possible that it uses a sort of ENIGMA like twist here... it runs the first value to 16 and then counts on the next value from the first... hmmm...

Posted: Wed Mar 18, 2009 4:53 am
by Kaeru Gaman
that's why I asked for some wiki-link or such. I have no idea what a "rijndeal" is.

Posted: Wed Mar 18, 2009 8:53 am
by gnozal
Rijndael is AES block cypher : http://en.wikipedia.org/wiki/Advanced_E ... n_Standard

There is a lot of public domain code (see links on the same page).

Posted: Thu Mar 19, 2009 9:12 am
by Inf0Byt3
I worked with AES/Rijndael in an open source password manager some time ago. You can find the complete source code here:

http://www.purebasic.fr/english/viewtopic.php?t=35184

I hope it's what you need.

Posted: Mon Apr 06, 2009 5:10 pm
by pdwyer
Note that with the lib in that open source project, there is a note on the web page that says that no block chaining is done and you need to add this little bit of codeyourself. It's not hard but if you don't do it and just throw blocks at the encrypter then you are using "ECB" which for some uses can expose weaknesses if you are encrypting repeating text etc.

http://en.wikipedia.org/wiki/Cipher_blo ... _.28ECB.29

Good example here with a picture to show the weakness caused by not chaining the blocks

(I'm not saying theres a bug in the link or the source, just that there's a bit left over for you to do which is often forgotten) :)

Posted: Mon Apr 06, 2009 7:49 pm
by Inf0Byt3
The code already has an extra encryption round in the loop done with xor-ing (some sort of Integer Counter Mode). Although this is not powerful as CBC (and also not fully implemented in the wrapper).

I did try to implement some better cypher modes but at the time it was too hard for me. Maybe it will be implemented in one of the future versions. Thanks for reminding me this :).