============================== Encryption ==================================

For obvious purpose, we do need sometime to support encryption for files.
We support encryption through access to the file system only.

The encryption scheme must be able to support random access to the data.

We have the following code using encryption :
- Audio Data (porting layer for Win32, Android, IOS)
- File Stream implementation (porting layer for Win32, Android, IOS)
- CKLBDatabase.cpp (wrapper for SQLite)
- CSoundAnalysisMP3.cpp (parser of MP3, used on iOS and Win32)

Everything is based on the CDecryptBaseClass, which could be summarized as :

class CDecryptBaseClass {
	void 		decryptBlck	(void* ptr, u32 length);
	u32			decryptSetup(const u8* ptr, const u8* hdr);
	void		gotoOffset	(u32 offset);
};


The decryption works the following way :

1. Engine call decryptSetup() function with the following arguments:
	Parameter 1 - Name of file without path. Just the file name.
	Parameter 2 - The first 4 byte of the file.
	
	If decryptSetup return 0, the first 4 bytes of the stream are part of the encrypted data.
	If decryptSetup return 1, the first 4 bytes of the stream are not data but header, encrypted info start at +4 bytes.
	
	The reason for such system is that the encryption scheme was changed in between and we wanted to be backward compatible.
	
	0 is the old scheme
	1 is the new scheme with a 4 byte header in front of the encrypted file.
	
2. After that the decryptBlck and gotoOffset can be called anytime, any order.
	If the stream jumps, gotoOffset is ALWAYS called before decryptBlck.
	
As you can notice, the encryption is made in such a way that data is the same length as the original.
Basically for each byte of the stream (except the 4 byte header of the new scheme) you should be able to do :

	[Out] Decrypted Byte = DecryptFunction ( [In] Encrypted Byte )

The concept is to have an encryption algorithm that is efficient enough to support fast and transparent decryption over a file system
with random access.

Which files are subject to encryption (All assets compiled by the tool) :
- Lua files
- SQLite databases (produced by the tool)
- Audio files
- Other assets like textures, forms, etc...

Note that it is IMPOSSIBLE to mix encrypted and unencrypted files within the file system if you support old and new encryption scheme.
Because we have no way to differentiate an encrypted file from a non encrypted file when opening it.
(The 4 byte header allows to select between the old or new encoding scheme)

BUT, if you support only the new format with a 4 byte header, and that the header can NEVER be the first 4 bytes of a non encrypted file.
You could implement the "old scheme" as being a transparent decryption (= does nothing) and the "new scheme" to really perform decryption.

The tool is not supporting partial encryption (ie encrypt this file but not another) but your custom tool chain could do that when publishing.

Android and IOS version only support encrypted.
Win32 version is able to select if encryption is activated or not to allow engine debug.(need to read unencrypted data from the file system)
(-enc true, -enc false option on the command line)

Related files:
	- source/include/encryptFile.h
	- source/core/encryptFile.cpp
