Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

  1. //========= Public Domain Code ================================================
  2. //
  3. // Purpose: Header file for the C++ ICE encryption class.
  4. // Taken from public domain code, as written by Matthew Kwan - July 1996
  5. // http://www.darkside.com.au/ice/
  6. //=============================================================================
  7. #ifndef _IceKey_H
  8. #define _IceKey_H
  9. /*
  10. The IceKey class is used for encrypting and decrypting 64-bit blocks of data
  11. with the ICE (Information Concealment Engine) encryption algorithm.
  12. The constructor creates a new IceKey object that can be used to encrypt and decrypt data.
  13. The level of encryption determines the size of the key, and hence its speed.
  14. Level 0 uses the Thin-ICE variant, which is an 8-round cipher taking an 8-byte key.
  15. This is the fastest option, and is generally considered to be at least as secure as DES,
  16. although it is not yet certain whether it is as secure as its key size.
  17. For levels n greater than zero, a 16n-round cipher is used, taking 8n-byte keys.
  18. Although not as fast as level 0, these are very very secure.
  19. Before an IceKey can be used to encrypt data, its key schedule must be set with the set() member function.
  20. The length of the key required is determined by the level, as described above.
  21. The member functions encrypt() and decrypt() encrypt and decrypt respectively data
  22. in blocks of eight chracters, using the specified key.
  23. Two functions keySize() and blockSize() are provided
  24. which return the key and block size respectively, measured in bytes.
  25. The key size is determined by the level, while the block size is always 8.
  26. The destructor zeroes out and frees up all memory associated with the key.
  27. */
  28. class IceSubkey;
  29. class IceKey {
  30. public:
  31. IceKey (int n);
  32. ~IceKey ();
  33. void set (const unsigned char *key);
  34. void encrypt (const unsigned char *plaintext,
  35. unsigned char *ciphertext) const;
  36. void decrypt (const unsigned char *ciphertext,
  37. unsigned char *plaintext) const;
  38. int keySize () const;
  39. int blockSize () const;
  40. private:
  41. void scheduleBuild (unsigned short *k, int n,
  42. const int *keyrot);
  43. int _size;
  44. int _rounds;
  45. IceSubkey *_keysched;
  46. };
  47. #endif