pkstraw.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Library/PKSTRAW.H $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 7/22/97 11:37a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef PKSTRAW_H
  36. #define PKSTRAW_H
  37. #include "blwstraw.h"
  38. #include "pk.h"
  39. #include "pkstraw.h"
  40. #include "rndstraw.h"
  41. class PKStraw : public Straw
  42. {
  43. public:
  44. typedef enum CryptControl {
  45. ENCRYPT,
  46. DECRYPT
  47. } CryptControl;
  48. PKStraw(CryptControl control, RandomStraw & rnd);
  49. virtual void Get_From(Straw * straw);
  50. virtual void Get_From(Straw & straw) {Get_From(&straw);}
  51. virtual int Get(void * source, int slen);
  52. // Submit key to be used for encryption/decryption.
  53. void Key(PKey const * key);
  54. private:
  55. enum {
  56. BLOWFISH_KEY_SIZE=BlowfishEngine::MAX_KEY_LENGTH,
  57. MAX_KEY_BLOCK_SIZE=256 // Maximum size of pk encrypted blowfish key.
  58. };
  59. /*
  60. ** This flag indicates whether the PK (fetch blowfish key) phase is
  61. ** in progress or not.
  62. */
  63. bool IsGettingKey;
  64. /*
  65. ** This is the random straw that is needed to generate the
  66. ** blowfish key.
  67. */
  68. RandomStraw & Rand;
  69. /*
  70. ** This is the attached blowfish pipe. After the blowfish key has been
  71. ** decrypted, then the PK processor goes dormant and the blowfish processor
  72. ** takes over the data flow.
  73. */
  74. BlowStraw BF;
  75. /*
  76. ** This control member tells what method (encryption or decryption) that should
  77. ** be performed on the data stream.
  78. */
  79. CryptControl Control;
  80. /*
  81. ** Pointer to the key to use for encryption or decryption. If this pointer is NULL, then
  82. ** the data passing through this segment will not be modified.
  83. */
  84. PKey const * CipherKey;
  85. /*
  86. ** This is the staging buffer for the block of data. This block must be as large as
  87. ** the largest possible key size or the largest blowfish key size (whichever is
  88. ** greater).
  89. */
  90. char Buffer[256];
  91. int Counter;
  92. /*
  93. ** This records the number of bytes remaining in the current block. This
  94. ** will be the number of bytes left to accumulate before the block can be
  95. ** processed either for encryption or decryption.
  96. */
  97. int BytesLeft;
  98. int Encrypted_Key_Length(void) const;
  99. int Plain_Key_Length(void) const;
  100. PKStraw(PKStraw & rvalue);
  101. PKStraw & operator = (PKStraw const & straw);
  102. };
  103. #endif