r5sdk/r5dev/mathlib/IceKey.H

63 lines
2.0 KiB
C++
Raw Normal View History

Code base refactor + major performance and readability improvement. Read description for details. * Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable. * Document most functions with valve style 'Purpose' blocks. * Rename variables to match the rest of the codebase and Valve's naming convention. * Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK. * Obtain globals or pointers directly instead of waiting for runtime initialized data. * Dynamically search for all functions and globals (this doesn't count for dedicated yet!). * Initialize most in-SDK variables. * Move certain prints and other utilities under ConVars to reduce verbosity and increase performance. * Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future. * Type global var pointers appropriately if class or type is known and implemented. * Forward declare 'CClient' class to avoid having 2 'g_pClient' copies. * Add IDA's pseudo definitions for easier prototyping with decompiled assembly code. * RPAK decompress Command callback implementation. * Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\'). * VPK decompress Command callback implementation. * Move CRC32 ands Adler32 to implementation files. * Server will print out more details about the connecting client. * Upgrade ImGui lib to v1.86. * Don't compile id3dx.h for dedicated. * Don't compile id3dx.cpp for dedicated * Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console * Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors. * Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up. * Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).
2021-12-25 22:36:38 +01:00
// Purpose: Header file for the C++ ICE encryption class.
// Taken from public domain code, as written by Matthew Kwan - July 1996
// http://www.darkside.com.au/ice/
#ifndef _IceKey_H
#define _IceKey_H
/*
The IceKey class is used for encrypting and decrypting 64-bit blocks of data
with the ICE (Information Concealment Engine) encryption algorithm.
The constructor creates a new IceKey object that can be used to encrypt and decrypt data.
The level of encryption determines the size of the key, and hence its speed.
Level 0 uses the Thin-ICE variant, which is an 8-round cipher taking an 8-byte key.
This is the fastest option, and is generally considered to be at least as secure as DES,
although it is not yet certain whether it is as secure as its key size.
For levels n greater than zero, a 16n-round cipher is used, taking 8n-byte keys.
Although not as fast as level 0, these are very very secure.
Before an IceKey can be used to encrypt data, its key schedule must be set with the set() member function.
The length of the key required is determined by the level, as described above.
The member functions encrypt() and decrypt() encrypt and decrypt respectively data
in blocks of eight characters, using the specified key.
Code base refactor + major performance and readability improvement. Read description for details. * Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable. * Document most functions with valve style 'Purpose' blocks. * Rename variables to match the rest of the codebase and Valve's naming convention. * Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK. * Obtain globals or pointers directly instead of waiting for runtime initialized data. * Dynamically search for all functions and globals (this doesn't count for dedicated yet!). * Initialize most in-SDK variables. * Move certain prints and other utilities under ConVars to reduce verbosity and increase performance. * Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future. * Type global var pointers appropriately if class or type is known and implemented. * Forward declare 'CClient' class to avoid having 2 'g_pClient' copies. * Add IDA's pseudo definitions for easier prototyping with decompiled assembly code. * RPAK decompress Command callback implementation. * Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\'). * VPK decompress Command callback implementation. * Move CRC32 ands Adler32 to implementation files. * Server will print out more details about the connecting client. * Upgrade ImGui lib to v1.86. * Don't compile id3dx.h for dedicated. * Don't compile id3dx.cpp for dedicated * Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console * Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors. * Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up. * Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).
2021-12-25 22:36:38 +01:00
Two functions keySize() and blockSize() are provided
which return the key and block size respectively, measured in bytes.
The key size is determined by the level, while the block size is always 8.
The destructor zeroes out and frees up all memory associated with the key.
*/
class IceSubkey;
class IceKey {
public:
IceKey (int n);
~IceKey ();
void set (const unsigned char *key);
void encrypt (const unsigned char *plaintext,
unsigned char *ciphertext) const;
void decrypt (const unsigned char *ciphertext,
unsigned char *plaintext) const;
int keySize () const;
int blockSize () const;
private:
void scheduleBuild (unsigned short *k, int n,
const int *keyrot);
int _size;
int _rounds;
IceSubkey *_keysched;
};
#endif