Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
pkpipe.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***********************************************************************************************
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 * $Archive:: /Commando/Library/pkpipe.h $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/22/97 11:37a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#ifndef PKPIPE_H
38#define PKPIPE_H
39
40#include "blowpipe.h"
41#include "pipe.h"
42#include "pk.h"
43#include "rndstraw.h"
44
45
46/*
47** This pipe will encrypt/decrypt the data stream. The data is encrypted by generating a
48** symetric key that is then encrypted using the public key system. This symetric key is then
49** used to encrypt the remaining data.
50*/
51class PKPipe : public Pipe
52{
53 public:
58
59 PKPipe(CryptControl control, RandomStraw & rnd);
60
61 virtual void Put_To(Pipe * pipe);
62 virtual void Put_To(Pipe & pipe) {Put_To(&pipe);}
63
64 // Feed data through for processing.
65 virtual int Put(void const * source, int length);
66
67 // Submit key for encryption/decryption.
68 void Key(PKey const * key);
69
70 private:
71 enum {
72 BLOWFISH_KEY_SIZE=BlowfishEngine::MAX_KEY_LENGTH,
73 MAX_KEY_BLOCK_SIZE=256 // Maximum size of pk encrypted blowfish key.
74 };
75
76 /*
77 ** This flag indicates whether the PK (fetch blowfish key) phase is
78 ** in progress or not.
79 */
80 bool IsGettingKey;
81
82 /*
83 ** This is the random straw that is needed to generate the
84 ** blowfish key.
85 */
86 RandomStraw & Rand;
87
88 /*
89 ** This is the attached blowfish pipe. After the blowfish key has been
90 ** decrypted, then the PK processor goes dormant and the blowfish processor
91 ** takes over the data flow.
92 */
93 BlowPipe BF;
94
95 /*
96 ** Controls the method of processing the data stream.
97 */
98 CryptControl Control;
99
100 /*
101 ** Pointer to the key to use for encryption/decryption. The actual process
102 ** performed is controlled by the Control member. A key can be used for
103 ** either encryption or decryption -- it makes no difference. However, whichever
104 ** process is performed, the opposite process must be performed using the
105 ** other key.
106 */
107 PKey const * CipherKey;
108
109 /*
110 ** This is the staging buffer for the block of data. This block must be as large as
111 ** the largest possible key size or the largest blowfish key (whichever is greater).
112 */
113 char Buffer[MAX_KEY_BLOCK_SIZE];
114
115 /*
116 ** The working counter that holds the number of bytes in the staging buffer.
117 */
118 int Counter;
119
120 /*
121 ** This records the number of bytes remaining in the current block. This
122 ** will be the number of bytes left to accumulate before the block can be
123 ** processed either for encryption or decryption.
124 */
125 int BytesLeft;
126
127 int Encrypted_Key_Length(void) const;
128 int Plain_Key_Length(void) const;
129
130 PKPipe(PKPipe & rvalue);
131 PKPipe & operator = (PKPipe const & pipe);
132};
133
134
135#endif
virtual void Put_To(Pipe *pipe)
Definition pkpipe.cpp:94
PKPipe(CryptControl control, RandomStraw &rnd)
Definition pkpipe.cpp:66
CryptControl
Definition pkpipe.h:54
@ ENCRYPT
Definition pkpipe.h:55
@ DECRYPT
Definition pkpipe.h:56
virtual void Put_To(Pipe &pipe)
Definition pkpipe.h:62
void Key(PKey const *key)
Definition pkpipe.cpp:133
virtual int Put(void const *source, int length)
Definition pkpipe.cpp:168
Definition PK.H:63