PKSTRAW.H 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/PKSTRAW.H 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : PKSTRAW.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 07/08/96 *
  26. * *
  27. * Last Update : July 8, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef PKSTRAW_H
  33. #define PKSTRAW_H
  34. #include "pk.h"
  35. #include "pkstraw.h"
  36. #include "rndstraw.h"
  37. #include "blwstraw.h"
  38. class PKStraw : public Straw
  39. {
  40. public:
  41. typedef enum CryptControl {
  42. ENCRYPT,
  43. DECRYPT
  44. } CryptControl;
  45. PKStraw(CryptControl control, RandomStraw & rnd);
  46. virtual void Get_From(Straw * straw);
  47. virtual void Get_From(Straw & straw) {Get_From(&straw);}
  48. virtual int Get(void * source, int slen);
  49. // Submit key to be used for encryption/decryption.
  50. void Key(PKey const * key);
  51. private:
  52. enum {
  53. BLOWFISH_KEY_SIZE=BlowfishEngine::MAX_KEY_LENGTH,
  54. MAX_KEY_BLOCK_SIZE=256 // Maximum size of pk encrypted blowfish key.
  55. };
  56. /*
  57. ** This flag indicates whether the PK (fetch blowfish key) phase is
  58. ** in progress or not.
  59. */
  60. bool IsGettingKey;
  61. /*
  62. ** This is the random straw that is needed to generate the
  63. ** blowfish key.
  64. */
  65. RandomStraw & Rand;
  66. /*
  67. ** This is the attached blowfish pipe. After the blowfish key has been
  68. ** decrypted, then the PK processor goes dormant and the blowfish processor
  69. ** takes over the data flow.
  70. */
  71. BlowStraw BF;
  72. /*
  73. ** This control member tells what method (encryption or decryption) that should
  74. ** be performed on the data stream.
  75. */
  76. CryptControl Control;
  77. /*
  78. ** Pointer to the key to use for encryption or decryption. If this pointer is NULL, then
  79. ** the data passing through this segment will not be modified.
  80. */
  81. PKey const * CipherKey;
  82. /*
  83. ** This is the staging buffer for the block of data. This block must be as large as
  84. ** the largest possible key size or the largest blowfish key size (whichever is
  85. ** greater).
  86. */
  87. char Buffer[256];
  88. int Counter;
  89. /*
  90. ** This records the number of bytes remaining in the current block. This
  91. ** will be the number of bytes left to accumulate before the block can be
  92. ** processed either for encryption or decryption.
  93. */
  94. int BytesLeft;
  95. int Encrypted_Key_Length(void) const;
  96. int Plain_Key_Length(void) const;
  97. PKStraw(PKStraw & rvalue);
  98. PKStraw & operator = (PKStraw const & straw);
  99. };
  100. #endif