CnC_Remastered_Collection

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

PKSTRAW.H (4659B)


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