PKSTRAW.H 4.4 KB

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