CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

PKPIPE.H (5098B)


      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 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: /CounterStrike/PKPIPE.H 1     3/03/97 10:25a Joe_bostic $ */
     17 /***********************************************************************************************
     18  ***              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               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : PKPIPE.H                                                     *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 07/06/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : July 6, 1996 [JLB]                                           *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #ifndef PKPIPE_H
     36 #define PKPIPE_H
     37 
     38 #include	"pipe.h"
     39 #include	"pk.h"
     40 #include "rndstraw.h"
     41 #include	"blowpipe.h"
     42 
     43 
     44 /*
     45 **	This pipe will encrypt/decrypt the data stream. The data is encrypted by generating a
     46 **	symetric key that is then encrypted using the public key system. This symetric key is then
     47 **	used to encrypt the remaining data.
     48 */
     49 class PKPipe : public Pipe
     50 {
     51 	public:
     52 		typedef enum CryptControl {
     53 			ENCRYPT,
     54 			DECRYPT
     55 		} CryptControl;
     56 
     57 		PKPipe(CryptControl control, RandomStraw & rnd);
     58 
     59 		virtual void Put_To(Pipe * pipe);
     60 		virtual void Put_To(Pipe & pipe) {Put_To(&pipe);}
     61 
     62 		// Feed data through for processing.
     63 		virtual int Put(void const * source, int length);
     64 
     65 		// Submit key for encryption/decryption.
     66 		void Key(PKey const * key);
     67 
     68 	private:
     69 		enum {
     70 			BLOWFISH_KEY_SIZE=BlowfishEngine::MAX_KEY_LENGTH,
     71 			MAX_KEY_BLOCK_SIZE=256		// Maximum size of pk encrypted blowfish key.
     72 		};
     73 
     74 		/*
     75 		**	This flag indicates whether the PK (fetch blowfish key) phase is
     76 		**	in progress or not.
     77 		*/
     78 		bool IsGettingKey;
     79 
     80 		/*
     81 		**	This is the random straw that is needed to generate the
     82 		**	blowfish key.
     83 		*/
     84 		RandomStraw & Rand;
     85 
     86 		/*
     87 		**	This is the attached blowfish pipe. After the blowfish key has been
     88 		**	decrypted, then the PK processor goes dormant and the blowfish processor
     89 		**	takes over the data flow.
     90 		*/
     91 		BlowPipe BF;
     92 
     93 		/*
     94 		**	Controls the method of processing the data stream.
     95 		*/
     96 		CryptControl Control;
     97 
     98 		/*
     99 		**	Pointer to the key to use for encryption/decryption. The actual process
    100 		**	performed is controlled by the Control member. A key can be used for
    101 		**	either encryption or decryption -- it makes no difference. However, whichever
    102 		**	process is performed, the opposite process must be performed using the
    103 		**	other key.
    104 		*/
    105 		PKey const * CipherKey;
    106 
    107 		/*
    108 		**	This is the staging buffer for the block of data. This block must be as large as
    109 		**	the largest possible key size or the largest blowfish key (whichever is greater).
    110 		*/
    111 		char Buffer[MAX_KEY_BLOCK_SIZE];
    112 
    113 		/*
    114 		**	The working counter that holds the number of bytes in the staging buffer.
    115 		*/
    116 		int Counter;
    117 
    118 		/*
    119 		**	This records the number of bytes remaining in the current block. This
    120 		**	will be the number of bytes left to accumulate before the block can be
    121 		**	processed either for encryption or decryption.
    122 		*/
    123 		int BytesLeft;
    124 
    125 		int Encrypted_Key_Length(void) const;
    126 		int Plain_Key_Length(void) const;
    127 
    128 		PKPipe(PKPipe & rvalue);
    129 		PKPipe & operator = (PKPipe const & pipe);
    130 };
    131 
    132 
    133 #endif