PKPIPE.H 5.0 KB

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