Rijndael encrypt

Everything else that doesn't fall into one of the other PB categories.
_Slide_
New User
New User
Posts: 2
Joined: Sun Mar 25, 2007 3:40 am

Rijndael encrypt

Post 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);
}
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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?
oh... and have a nice day.
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

FYI - http://www.purebasic.fr/english/viewtop ... t=rijndael
Not sure if that includes the source though.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

that's why I asked for some wiki-link or such. I have no idea what a "rijndeal" is.
oh... and have a nice day.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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) :)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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 :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply