RSA 2048, Blowfish, Rijndael, Whirlpool PureLib

Developed or developing a new product in PureBasic? Tell the world about it.
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Post by agent »

Hi there.

First, big thanks to JCV for the great libs.

It would be very nice to have a example for the AES. I need to crypt strings. An example is missing ... :roll:

Can someone code one?
Agent_Sasori
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

I would like to see an example of string encryption in memory myself, using AES (dont know if thats possible). I don't understand the AES stuff at all. Anyone got any examples of string encryption in memory with AES, or any examples of string encryption in memory with these libraries (if its even possible)?
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

I don't know if it helps, but I managed to wrap an AES lib in PureBasic. You can find the example inside. The main advantage is that the source is open so it can be tweaked for your needs.

Here's the code
File:1->AES.zip
Image

The thing is that it may contain bugs,etc. but in my test it worked pretty well :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Thanks Inf0Byt3;

I'll give it a try and play around with it some to see what I can come up with.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

And yet, I have used all of those in the military and a couple more...

I knew this was a dicktatorship when the d*c* got re elected!

You watch the Republican Party rig this election as well!

Note to all NIA fugnutz... I didn't download any of the files!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Note to all NIA fugnutz... I didn't download any of the files!
??
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

N @tion al Inte l ligence A gen cy (had to break that up of Cy p h3r would have scanned it)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Post by agent »

Hi Inf0Byt3.

Thanks for you lib.
Works fine for me.

But I have one question left:
In your example, you decrypt a string you crypted before. To decrypt, you need the "neededlength" witch was calculated befor crypting the string.

If you just want (or later want) to decrypt a AES-crypted string, you didnt crypt, you dont know the "neededlength". How can I solve this? Or does calculating-routine work for decrypting too? How can I get this value without knowing it from crypting before?
Agent_Sasori
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Post by agent »

Maybe it is easier to understand if I copy the code:

In your AES.pbi you show an example using

Code: Select all

AESDecrypt(@out,@dec,neededlength,"testpasasdfsdfasfasdfasdfs",#PureAES_CypherMode_256)
My question is:
How can I know the "neededlength" if I did not crypt the text?
Agent_Sasori
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Hi,

I think you'll have to store the length too so you can later decrypt the data. I don't know if there's a way to bypass this.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
agent
New User
New User
Posts: 8
Joined: Fri Dec 03, 2004 1:23 pm
Contact:

Post by agent »

Hm....

But if you have a AES256 crypted file. Generated by anyone. How will you decrypt it without knowing the length?

For my work I can solve this by saving the length for any crypted string or setting the length to a virtual value like 1024 (the max lenght I would crypt ;) ) This works fine too, but it is not very professional.
Agent_Sasori
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

I understand what you're saying, but almost all the programs that crypt files must have a structure inside. If you want to decrypt a file created by another program it's better that you find the way the file was encrypted, it's header. One developer could use for example:

Signature: 4 bytes
Data: n bytes
Data length: 4 bytes (a long)

Then to read it, you go to Lof()-4 , read the data length, go to offset 4 , read n bytes then decrypt. This varies in function to what the developer chose to encrypt and how. I don't know if there's a "magic" method to decrypt files just by opening them. The length must be stored somewhere inside.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

First let me say thank you very much for this. I had to search quite a while to find something wich can encrypt memory of any size while giving the option to set a Key/Password for decryption. I first looked at DES but the input can only be 8 chars long so AES is the way to go for me.

My question is about the memory alignment procedure:

Code: Select all

Procedure Calculate_AES_Padding(*Buffer,Length)

  ;! http://www.purebasic.fr/english/viewtopic.php?p=66818#66818 !
 
  bytes_remaining.l = Length % 16 
  padding.l = 16 - bytes_remaining
  length_required.l = Length + padding
   
  ProcedureReturn length_required
EndProcedure
Why is it 16? I was asuming the input would be quad alinged so it should be 8, shouldn't it?

As a side note, if you change 16 to the size of quad the length will be the same.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Hi,

That's not my procudure there but I think I know why 16 was used:
AES has a fixed block size of 128 bits and a key size of 128, 192, or 256 bits...
Since in computing 1 byte equals 8 bits, the fixed block size of 128 bits is normally 128 / 8 = 16 bytes. AES operates on a 4×4 array of bytes, termed the state (versions of Rijndael with a larger block size have additional columns in the state). Most AES calculations are done in a special finite field.
AES uses blocks of 16 bytes. That function calculates how many bytes are needed to make a full 16 byte block so the data will be encrypted without errors. There are many methods of padding, one of them with zero, one with spaces, etc.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Ah ok, thanks for the info. :)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply