Page 1 of 1

AES question

Posted: Tue Mar 22, 2011 8:19 pm
by SPP
Hi to all (and sorry for my english),

I've seen some encryption example with AES256 (I really liked NetMaestro code).
My question: it's safe to store the key and initialization vector as a data block?
Is posible to obtain from the compiled exe?

Thanks.

Re: AES question

Posted: Tue Mar 22, 2011 8:34 pm
by idle
yes the key would be visible but not necessarily obvious.

Re: AES question

Posted: Tue Mar 22, 2011 8:48 pm
by SPP
Idle,
Thanks for your reply but... can you explain a little more, please?

Re: AES question

Posted: Tue Mar 22, 2011 10:30 pm
by netmaestro
It's the "not necessarily obvious" part that you would want to focus on. You could, for example, create a datasection with a lot of things in it. Lots of text for messages, all kinds of numbers for various purposes, some needed and some added for ballast. The key here is lots and lots. Then, you would pick a pattern of where various parts of the key and iv are located in the data and your code would build the key/iv combo when it's needed. Nobody perusing your exe in a hex viewer would ever find the key, although someone determined enough and skilled enough could dump the asm instructions and learn how the key is built. An average programmer would probably be beat but a cracker of some skill would get it pretty soon.

Re: AES question

Posted: Wed Mar 23, 2011 12:18 am
by codewalker
Nobody perusing your exe in a hex viewer would ever find the key, although someone determined enough and skilled enough could dump the asm instructions and learn how the key is built. An average programmer would probably be beat but a cracker of some skill would get it pretty soon.
Then this makes me wonder how the guys behind truecrypt are doing it. Truecrypt also uses AES
and in cases where a key of 15 or more random characters was used, even the FBI could not get
into a laptop of a certain suspect. This was not so long ago in the news.
cw

Re: AES question

Posted: Wed Mar 23, 2011 8:45 am
by Shield
netmaestro wrote:[...] although someone determined enough and skilled enough could dump the asm instructions and learn how the key is built. An average programmer would probably be beat but a cracker of some skill would get it pretty soon.
You don't have to evaluate all the ASM stuff and learn how the key is built.
When the application collects all parts of the key, the key has to be loaded into a memory section (string, array, ...) and will be visible.
The only thing a cracker has to do is check where the AES function call is and then grab the key.

(It probably sounds easier then it actually is, but the point is, saving a key in applications is never a good idea).

Re: AES question

Posted: Wed Mar 23, 2011 8:59 am
by SPP
Thanks a lot for your replies,

My conclusion is: Never save the key in the code but for certain applications (i think) is necessary do it.
Then... how?

Best regards.

Re: AES question

Posted: Wed Mar 23, 2011 9:17 am
by Shield
Depends on what you want to do.
Say you want to upload files on a server, it's better to do this via HTTP and user user-logins
instead of giving the user your FTP login, for example.

Re: AES question

Posted: Wed Mar 23, 2011 11:39 am
by SPP
Hi Shield,

Your suggestion is store the key out of the exe?

Re: AES question

Posted: Wed Mar 23, 2011 11:56 am
by Shield
No, I'm asking what you plan to do, maybe there is a safer solution.

Re: AES question

Posted: Wed Mar 23, 2011 12:11 pm
by SPP
Only save partial data of a configuration file in a secure way.

Regards,

Re: AES question

Posted: Wed Mar 23, 2011 1:09 pm
by Inf0Byt3
You don't need to store the key inside, just the IV. Storing the key inside would create a security hole as it could be read with ease by others. What you can do depends on what you are trying to achieve.

For example, if you want to encrypt resources, images, sounds, etc. inside the exe and load them later, you could store the key in such way that it is generated with your own algorithm at program run time. Or store a number inside and derrivate the original key from it.

If you want to encrypt files or data that you want the user to decrypt later (for example a file encryptor or password manger), then you could store the MD5 or CRC32 of the original, unencrypted data inside the file itself. After the user inputs the password, calculate CRC32 again from the decrypted data and compare it with the one in the file. This is pretty secure, as the key is not inside the file, the attacker only knows the CRC32 of the data which is not very concludent.

Re: AES question

Posted: Wed Mar 23, 2011 1:30 pm
by SPP
Inf0Byt3, thanks for your time ,

I take note of your suggestions. These are welcomed; now is all more clear.

Regards