Game Development Community

Asset Encryption Resource

by chris · in Torque Game Builder · 04/09/2005 (12:51 pm) · 15 replies

Regarding this resource for encrypting game assets:

I'm just wondering if anyone has been able to use this successfully. It seems to be exactly what I need to at least provide basic protection for game assets, but I'm not having any luck reading the encrypted files into my game.

Any help appreciated :)
Chris

#1
04/09/2005 (1:45 pm)
That resource was used to encrypt the files for Cloudburst
#2
04/09/2005 (1:52 pm)
Thanks Harold - so it works... that's good :)
I wish it would work for me...
#3
05/16/2005 (5:17 pm)
How did you add this to t2d? i keep getting errors

thanks
#4
05/17/2005 (11:50 am)
Hi Chris,

I got this working. Are you still trying to figure it out?
#5
05/18/2005 (5:44 am)
Could you post what you did anyway? Would help out anyone else that has problems.
#6
05/18/2005 (6:41 am)
Sure, you'll have to excuse me if this sounds a little too step-by-step, but the author's explanation was obviously for people with more learnin' than i got, it took me a little while to figure it all out. Actually it was the recompiling of t2d that took the longest.

First I made sure I could recompile T2D, I ( finally) did that with VC7. Once I did that, I checked the files in the zip to see where they went. cryptostream.h, xorstream.h,cryptostream.cpp, xorstream.cpp, go into the "SDK/engine" folder, bitmapPNG.cc replaces the same file in the "SDK/engine/dgl" folder.

I guess this is a good point to say I backed everything up.

In VC7, I added the cryptostream.h, xorstream.h,cryptostream.cpp, xorstream.cpp files to the project (in the same folder as I put them in), then I recompiled T2D. Once I had a working .exe, it was time to make encrypted pngs. I ran the included "xorcrypt.exe" through command-line, encrypting the "playerShip.png". After it was done, i confirmed that i could no longer open it.

Then i made a copy of my spaceshooter game and replaced the playerShip.png with the encrypted version and replaced the T2D.exe with the recompiled one. Then I changed something in the client.cs (i think it was the size of the playership), just to make sure there were no previous builds being run (even though i know that's not the case with datablocks). I ran it. There was the playerShip, unencrypted.

Next I rewrote the "xorcrypt.exe" to handle multiple files, batched all the pngs in the spaceshooter demo and it worked.

I think the next step is to see if i can apply the same code to all bitmaps and sound, maybe use Tiny Encryption Algorithm instead of XOR. I think text files would be good to encrypt as well. I guess if everything is read in as a "stream" it is somehow possible.

Anybody know if any of those things are not possible/desirable?
#7
05/18/2005 (7:24 am)
I'll be the first to admit that I don't really know what I'm doing, but this what I did in TBE.

T2D builds more or less OK if I build the base code.

What I've done to integrate this resource:

Copy cryptostream.h, xorstream.h,cryptostream.cpp, xorstream.cpp into the \engine\dgl directory, as well as replace the bitmapPNG.cc file. I chucked everything in one place to make it easy for me to see what's going on.

Renamed the .cpp files to .cc

Manually edited the engine\targets.torque.mk file to add the new .cc files into the dgl section.

Rebuilt the project.

And I have a new T2D.exe :) Haven't tested it yet, but I'm sure it should work OK.
#8
05/19/2005 (4:20 pm)
@Cal - You know, I had sort of given up on this for a while - but your explanation makes a lot of sense. I'll probably be trying it out tonight. Thanks for the post :)
#9
08/05/2005 (7:17 am)
Has anyone managed to get this working with some sort of block cipher?
I've tried to make an AESStream instead of the XORStream for 2 days now but it won't work. I am pretty sure, it's because of the padding that is necessary for block ciphers.
However I am not familiar with stream encryption. Anyone with more experience here?
#10
08/08/2005 (2:55 am)
It took another 3 days but I could get it to work now.
If anyone is interested the outcome can be found here.

It's a modification of the above mentioned resource:

- aesStream.h & aesStream.cpp contain the new class AESStream
- bitmapPNG.cc is modified to work with AESStream instead of XORStream
- sha2.h & sha2.c contain a SHA256 implementation that is used to generate the 32-bit key from an arbitrary string (the files are taken from www.ouah.org/~ogay/sha2/)
- rindael.h & rijndael.cpp contain the AES implementation used to encrypt the stream. (files created by Szymon Stefanek)
- aescrypt.cpp contains the code to a small commandline tool to encrypt files.

Plus there is an encrypted version of gglogo.png

aesStream.h/.cpp, sha2.h/.c, rindael.h/.cpp go to the "engine/core/" directory. bitmapPNG.cc to "engine/dgl/".
To compile the aescrypt tool, the sha-files and rijndael-files are needed in the same directory as aescrypt.cpp


I didn't have the time to test it very much but it seems to work without errors. However, if you find any (or if you think this is helpful), let me know. I am sure there can be made a lot of optimizations like buffering for the stream or something but I am not very familiar with streams and it works fine for me now.

cheers,
michael
#11
08/10/2005 (9:17 am)
Michael, this is great stuff thanks a lot. I got it working on jpegs as well, and hope to do .dso's eventually.

I did notice one problem however. Not having _write implemented was causing png writes to fail, which seems to include the font cache and PNG screen shots. Have you come across this yet?

EDIT: Since the font files are already non-standard in some way, and I wouldn't want to encrypt screenshots, I've just removed the following from GBitmap_writePNG in bitmapPng.cc:

#ifdef PNGCRYPT
   AESStream xstream( &stream, PNGCRYPT_KEY );
   sg_pStream = &xstream;
#endif

and it appears to be happy.
#12
08/11/2005 (3:24 am)
The part in the write function is still from Pat Wilson's resource. I just replaced XORStream with AESStream via text-editor "search and replace all". You're are right, this must be fixed (as the AESStream doesn't support writing as it is now). I'll update the zip-file as I get home.

Thanks Luke
#13
08/12/2005 (12:18 am)
The file is updated now.
#14
01/03/2006 (12:23 pm)
@Chris && @Michael: thank you thank you very much ^_^ (I have tested with alpha2)
#15
05/22/2006 (8:10 pm)
So... does this work with any resource (like wav and ogg) or PNGs only?