CipherLib for T2D
by Michael Woerister · 03/17/2006 (6:58 pm) · 31 comments
Download Code File
Everything you want to know can be found here on TDN.
Suggestions are welcome! This is fully functional but still work in progress.
EDIT 02/12/06:
- added support for other image file formats.
EDIT 03/09/07:
- fixed a bug in getCipherName() console function
- set default encryption mode from ECB to CBC in console functions
-Michael
Everything you want to know can be found here on TDN.
Suggestions are welcome! This is fully functional but still work in progress.
EDIT 02/12/06:
- added support for other image file formats.
EDIT 03/09/07:
- fixed a bug in getCipherName() console function
- set default encryption mode from ECB to CBC in console functions
-Michael
About the author
#2
Fatal-ISV: (.........\source\dgl\bitmappng.cc @ 85) Error reading PNG file:
IHDR: CRC error
I'm able to run encryptFile on the original file, then run decryptFile on the encrypted file and get a readable PNG. So everything seems to be working fine that way. But when it attempts to read in a .xpng file that is in a datablock, the message above is generated.
I was thinking that the issue is either it is trying to open the .xpng as a .png, or after the file is decrypted it is being send to readPNG in bitmappng.cc and somehow it is getting messed up along the way??
I've registered .xpng in the texture manager and with the resource manager (via script first, then after having this problem adding the code shown on TDN directly in main.cc...both produce this error).
I'm still looking over everything trying to figure out where the issue might actually be occuring, but was hoping someone might know where the issue is and help save me some time ;).
05/25/2006 (9:05 am)
I'm getting the following error after implementing this:Fatal-ISV: (.........\source\dgl\bitmappng.cc @ 85) Error reading PNG file:
IHDR: CRC error
I'm able to run encryptFile on the original file, then run decryptFile on the encrypted file and get a readable PNG. So everything seems to be working fine that way. But when it attempts to read in a .xpng file that is in a datablock, the message above is generated.
I was thinking that the issue is either it is trying to open the .xpng as a .png, or after the file is decrypted it is being send to readPNG in bitmappng.cc and somehow it is getting messed up along the way??
I've registered .xpng in the texture manager and with the resource manager (via script first, then after having this problem adding the code shown on TDN directly in main.cc...both produce this error).
I'm still looking over everything trying to figure out where the issue might actually be occuring, but was hoping someone might know where the issue is and help save me some time ;).
#3
05/25/2006 (9:12 am)
What encryption algorithm do you use? In ECB or CBC mode?
#4
05/25/2006 (9:23 am)
CBC....I still have everything at defaults as I try to get it up and running.
#5
If you encrypt and decrypt the image, can it be opened in some image editing software or is it broken too?
05/25/2006 (9:58 am)
And what is your OS? Because I could only test this on Windows.If you encrypt and decrypt the image, can it be opened in some image editing software or is it broken too?
#6
05/25/2006 (10:00 am)
Using Windows (run into this on both 2000 and XP).
#7
05/25/2006 (10:03 am)
You can send me the png file in question so I can take a look at it when I get time.
#8
01/17/2007 (3:07 pm)
Great resource and tutorial!
#9
Everything is at defaults, *_decrypted.png file is fine (works), but TGB won't recognize the .xpng as an image file. I've tried out multiple .png files with the same problem. Where did I go wrong?
03/05/2007 (4:15 pm)
Did Michael Dolhon's issue get resolved? I'm having *exactly* the same problem. Everything is at defaults, *_decrypted.png file is fine (works), but TGB won't recognize the .xpng as an image file. I've tried out multiple .png files with the same problem. Where did I go wrong?
#10
03/06/2007 (3:28 am)
Yes, the problem was solved. It turned out to be a typo somewhere. I guess I can post his email reply here:Quote:I started fresh and manually entered changes instead of doing any copy/paste stuff. I think the root of my problem was in the main.cc with "ResourceManager->registerExtension(".xpng", constructCipherBitmapPNG);". I double checked it several times...but the manual enter of it seems to have done the trick. I was able to go back to the copy I was working with and re-entered this manually and presto...started working.
#11
03/07/2007 (8:35 pm)
#12
03/07/2007 (8:42 pm)
#13
03/07/2007 (8:55 pm)
#14
I tried to integrate this resource with TGEA, which basically was no problem but only works with gBitmap (ie images).
I've little experience with block ciphers, so if possible, is there something I should know about them or some requirements for them to be applied to a stream?
09/13/2007 (4:44 am)
Is there something special about gBitmap as ResourceInstance compared to TSShape, Interior and Terrain?I tried to integrate this resource with TGEA, which basically was no problem but only works with gBitmap (ie images).
I've little experience with block ciphers, so if possible, is there something I should know about them or some requirements for them to be applied to a stream?
#15
With ECB mode encryption becomes less strong but it also allows random access to the stream. Other than that I can't tell you anything specific without knowing the internals of TSShape, Interior, and Terrain.
09/19/2007 (11:26 pm)
I've never used TGEA so I can just give you some general thoughts here. When using CBC mode encryption of subsequent blocks is interdependent and in this case the CipherLib implementation only allows reading the stream from start to end without re-positioning the stream cursor. This is the case for the loading procedures of PNGs, JPEGs and the image formats.With ECB mode encryption becomes less strong but it also allows random access to the stream. Other than that I can't tell you anything specific without knowing the internals of TSShape, Interior, and Terrain.
#16
They only use read (for loading) and write (for saving) in a subsequent manner as well, no repositioning of the cursor. Was one of the first potential problem ideas I had that their stream handling somehow confuses the cipher.
Is there some kind of offset or blocksize assumed to be present or a different prerequirement?
Because the really strange thing is that a few reads work but after a not really specified point, it will just break and start to spit out really large negative numbers instead of the values they should.
EDIT:
OK now it works.
Don't know what actually made the difference, but I raised the buffer size as this was the only point I haven't considered so far and it now stopped crashing. Beside that I made CBC the default.
Definitely great resource :-)
09/20/2007 (12:48 am)
TGE / TGEA additional resource instances work similar to the gBitmap classes.They only use read (for loading) and write (for saving) in a subsequent manner as well, no repositioning of the cursor. Was one of the first potential problem ideas I had that their stream handling somehow confuses the cipher.
Is there some kind of offset or blocksize assumed to be present or a different prerequirement?
Because the really strange thing is that a few reads work but after a not really specified point, it will just break and start to spit out really large negative numbers instead of the values they should.
EDIT:
OK now it works.
Don't know what actually made the difference, but I raised the buffer size as this was the only point I haven't considered so far and it now stopped crashing. Beside that I made CBC the default.
Definitely great resource :-)
#18
Already realized that while crawling through the sources to find the problem for not working on other resource instances. Luckily its no problem anyway, as I didn't plan to make the editors write out encrypted media but do a post save encryption step to a different folder.
09/23/2007 (2:38 am)
Thank you for pointing that out.Already realized that while crawling through the sources to find the problem for not working on other resource instances. Luckily its no problem anyway, as I didn't plan to make the editors write out encrypted media but do a post save encryption step to a different folder.
#19
Oh, and this still works with TGB 1.6.
12/15/2007 (7:37 pm)
I've added encrypted DTS if anyone is interested :D Oh, and this still works with TGB 1.6.
#20
12/16/2007 (10:43 pm)
Any chance of this working in TGE? 
Torque Owner Tim Doty