PKPIPE.H 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/PKPIPE.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 : PKPIPE.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 07/06/96 *
  30. * *
  31. * Last Update : July 6, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef PKPIPE_H
  37. #define PKPIPE_H
  38. #include "pipe.h"
  39. #include "pk.h"
  40. #include "rndstraw.h"
  41. #include "blowpipe.h"
  42. /*
  43. ** This pipe will encrypt/decrypt the data stream. The data is encrypted by generating a
  44. ** symetric key that is then encrypted using the public key system. This symetric key is then
  45. ** used to encrypt the remaining data.
  46. */
  47. class PKPipe : public Pipe
  48. {
  49. public:
  50. typedef enum CryptControl {
  51. ENCRYPT,
  52. DECRYPT
  53. } CryptControl;
  54. PKPipe(CryptControl control, RandomStraw & rnd);
  55. virtual void Put_To(Pipe * pipe);
  56. virtual void Put_To(Pipe & pipe) {Put_To(&pipe);}
  57. // Feed data through for processing.
  58. virtual int Put(void const * source, int length);
  59. // Submit key for encryption/decryption.
  60. void Key(PKey const * key);
  61. private:
  62. enum {
  63. BLOWFISH_KEY_SIZE=BlowfishEngine::MAX_KEY_LENGTH,
  64. MAX_KEY_BLOCK_SIZE=256 // Maximum size of pk encrypted blowfish key.
  65. };
  66. /*
  67. ** This flag indicates whether the PK (fetch blowfish key) phase is
  68. ** in progress or not.
  69. */
  70. bool IsGettingKey;
  71. /*
  72. ** This is the random straw that is needed to generate the
  73. ** blowfish key.
  74. */
  75. RandomStraw & Rand;
  76. /*
  77. ** This is the attached blowfish pipe. After the blowfish key has been
  78. ** decrypted, then the PK processor goes dormant and the blowfish processor
  79. ** takes over the data flow.
  80. */
  81. BlowPipe BF;
  82. /*
  83. ** Controls the method of processing the data stream.
  84. */
  85. CryptControl Control;
  86. /*
  87. ** Pointer to the key to use for encryption/decryption. The actual process
  88. ** performed is controlled by the Control member. A key can be used for
  89. ** either encryption or decryption -- it makes no difference. However, whichever
  90. ** process is performed, the opposite process must be performed using the
  91. ** other key.
  92. */
  93. PKey const * CipherKey;
  94. /*
  95. ** This is the staging buffer for the block of data. This block must be as large as
  96. ** the largest possible key size or the largest blowfish key (whichever is greater).
  97. */
  98. char Buffer[MAX_KEY_BLOCK_SIZE];
  99. /*
  100. ** The working counter that holds the number of bytes in the staging buffer.
  101. */
  102. int Counter;
  103. /*
  104. ** This records the number of bytes remaining in the current block. This
  105. ** will be the number of bytes left to accumulate before the block can be
  106. ** processed either for encryption or decryption.
  107. */
  108. int BytesLeft;
  109. int Encrypted_Key_Length(void) const;
  110. int Plain_Key_Length(void) const;
  111. PKPipe(PKPipe & rvalue);
  112. PKPipe & operator = (PKPipe const & pipe);
  113. };
  114. #endif